Obtain IP address of current device

1 vote · 0 comments

I'm adding this here on behalf of Damian as I think it's quite useful. The author's post is here: http://damianflannery.wordpress.com/2010/03/28/obtaining-your-ip-address-on-android/

raw ·
copy
· download
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) ; }

Be the first to comment

Sign in with OpenID