The mobile IP address returned from the Android app is different from that shown in the settings of the phone.
I tried to use the following sample code to read the IP assigned from the mobile network to an Android phone (running Android 7) connected to mobile network only. The Android app returns 10.130.151.51 but the IP address found from the phone menu is 49.130.28.201.
Anybody knows why and how can I get the correct one ?
public String Get_Mobile_IP(){
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkinterfaces();
en.hasMoreElements();) {
NetworkInterface networkinterface = en.nextElement();
for (Enumeration<InetAddress> en_IP = networkinterface.getInetAddresses(); en__IP.hasMoreElements();) {
InetAddress mobile_IPaddr = en_IP.nextElement();
if (!mobile_IPaddr.isLoopbackAddress() && mobile_IPaddr instanceof Inet4Address) {
return mobileIPAddr.getHostAddress();
}
}
}
} catch (Exception ex) {
}
return null;
}