Skip to content

Instantly share code, notes, and snippets.

@ahmadrosid
Last active October 17, 2019 17:51
Show Gist options
  • Save ahmadrosid/24c26ed51d59456a2c858a39aa3ad09c to your computer and use it in GitHub Desktop.
Save ahmadrosid/24c26ed51d59456a2c858a39aa3ad09c to your computer and use it in GitHub Desktop.
Get Android WIFI ip address v4

On your manifest

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

Get android wifi ip address v4.

WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
int ip = wm.getConnectionInfo().getIpAddress();
String ipv4 = String.format("%d.%d.%d.%d", (ip & 0xff), (ip >> 8 & 0xff), (ip >> 16 & 0xff), (ip >> 24 & 0xff));
Log.d("MAIN", "onCreate: " + ipv4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment