The obvious way to get the IP-Address of your device simply doesn’t work on Android.
The first thing I tried was using the WifiInfo.
1 2 3 | WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); int ipAddress = wifiInfo.getIpAddress(); |
But wait: ipAddress is an integer? Of course not. I also did the math but couldn’t find a way to get the IP out of this integer. So thats not the right way.
continue reading…