xxxxxxxxxx
If you would like to get the private IP address of your device when connected to Wi-Fi, you can try this.
WifiManager wifiMgr = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
int ip = wifiInfo.getIpAddress();
String ipAddress = Formatter.formatIpAddress(ip);
Be sure to add the permission to your manifest.
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
xxxxxxxxxx
WifiManager wifiMgr = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
int ip = wifiInfo.getIpAddress();
String ipAddress = Formatter.formatIpAddress(ip);
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
xxxxxxxxxx
If you would like to get the private IP address of your device when connected to Wi-Fi, you can try this.
WifiManager wifiMgr = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
int ip = wifiInfo.getIpAddress();
String ipAddress = Integer.toString(ip);
Be sure to add the permission to your manifest.
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />