With the verbosity (I mean that in a good way) of the Android APIs, you’d think that it would be extremely straightforward to get a handle on the ip address for your android device.  It’s not – but with the code below you can obtain this information in the most efficient possible way using some math to translate the returned integer from WifiInfo into it’s component string ip address.

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) ;

Debugging in Eclipse

March 25, 2010

This morning I discovered an excellent step by step (excuse the pun) series of video tutorials on how to use the debugger in Eclipse. I was looking for a good learning resource to help teach programming to a colleague but actually I learned a few things myself while watching the tutorial set :p.

This is an excellent series for those who are new to debugging or those that are new to using Eclipse.