Skip to content

Instantly share code, notes, and snippets.

@novoda
Created April 21, 2010 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save novoda/374530 to your computer and use it in GitHub Desktop.
Save novoda/374530 to your computer and use it in GitHub Desktop.
Android: Get the IP Address of the current device. In the latest versions of Android on the trunk this built into the platform so you will probably be able to just call an intent.
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ipAddress = wifiInfo.getIpAddress();
String ip = intToIp(ipAddress);
public String intToIp(int i) {
return ((i >> 24 ) & 0xFF ) + "." +
((i >> 16 ) & 0xFF) + "." +
((i >> 8 ) & 0xFF) + "." +
( i & 0xFF) ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment