Scripts 学盟
标题:
Android 获取IP地址
[打印本页]
作者:
那个谁
时间:
2011-9-23 13:19:05
标题:
Android 获取IP地址
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(LOG_TAG, ex.toString());
}
return null;
}
复制代码
欢迎光临 Scripts 学盟 (http://www.iscripts.org/)
Powered by Discuz! X2