当我连接WiFi时,我可以获取到Android手机的IP地址。
但是在3G等移动网络上,是否还能获取到安卓手机的IP地址呢?
如果是,请发布相同的代码。
最佳答案
尝试这样的事情
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) {}
关于java - 连接到3G移动网络时获取android设备的IP地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5818725/