Hello I am using the code below to get IP address of android device,
private String returnIPAdrress()
{
String IPAddress = null;
try
{
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();)
{
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();)
{
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress())
{
IPAddress = inetAddress.getHostAddress().toString();
}
}
}
}
catch (SocketException ex)
{
Log.e("ServerActivity", ex.toString());
return null;
}
return IPAddress;
}
When i test it on Galaxy tablet(os=2.3) it works fine and gives me valid IP address.
I have test it on emulator(os=2.2) and it gives me IP address as 10.0.2.15 which is also valid i guess.
But when run it on Micromax canvas(os=4.1) it gives me IP address as fe80::d0b3:3fff:fe9d:f68c%p2p0 which is wrong.
is it because of different OS version?
How can i solve this?