Skip to content

Instantly share code, notes, and snippets.

@mpuz
Created March 29, 2017 17:26
Show Gist options
  • Save mpuz/81ff82e858776ec47b4255817f5f0a87 to your computer and use it in GitHub Desktop.
Save mpuz/81ff82e858776ec47b4255817f5f0a87 to your computer and use it in GitHub Desktop.
Android, Java: Get Your OWN IP ADDRESS
WifiManager wifiMan = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInf = wifiMan.getConnectionInfo();
int ipAddress = wifiInf.getIpAddress();
String ip = String.format("%d.%d.%d.%d", (ipAddress & 0xff),(ipAddress >> 8 & 0xff),(ipAddress >> 16 & 0xff),(ipAddress >> 24 & 0xff));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment