Anybody help me to get IP Address whenever I use mobile data. When I am using wifi then I am getting IP Address, but while using mobile data its not working.
Thanks in advance..
Anybody help me to get IP Address whenever I use mobile data. When I am using wifi then I am getting IP Address, but while using mobile data its not working.
Thanks in advance..
From here: https://groups.google.com/forum/#!topic/android-developers/a5loFkRuV3w
public String getLocalIpAddress() {
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()) {
return inetAddress.getHostAddress().toString
();
}
}
}
} catch (SocketException ex) {
Log.e(S.TAG, ex.toString());
}
return null;
}
Although I havent tried it myself