I am using the following function to get the local IP address of the Android device:
/**
* Loops through all network interfaces to find one with a connection
* @return the IP of the connected network device, on error returns null
*/
public String getIPAddress()
{
String strIPaddress = null;
try
{
Enumeration<NetworkInterface> enumNetIF = NetworkInterface.getNetworkInterfaces();
NetworkInterface netIF = null;
//loop whilst there are more interfaces
while(enumNetIF.hasMoreElements())
{
netIF = enumNetIF.nextElement();
for (Enumeration<InetAddress> enumIP = netIF.getInetAddresses(); enumIP.hasMoreElements();)
{
InetAddress inetAddress = enumIP.nextElement();
//check for valid IP, but exclude the loopback address
if(inetAddress.isLoopbackAddress() != true)
{
strIPaddress = inetAddress.getHostAddress();
break;
}
}
}
}
catch (SocketException e)
{
Log.e(TAG, e.getMessage());
}
return strIPaddress;
}
However, I also need to know for how long this IP address has been connected for. I've searched through the InetAddress structure and couldn't find it: http://developer.android.com/reference/java/net/InetAddress.html
is there another way to find out for how long the local IP address has existed / connected ?