发布于 2016-03-06 05:08:35 | 250 次阅读 | 评论: 0 | 来源: 网友投递
Android移动端操作系统
Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。
本文实例讲述了android实现获取有线和无线Ip地址的方法。分享给大家供大家参考。具体如下:
做android的开发时,遇到了获取有线ip地址的问题.不多说 上代码!
for (Enumeration<NetworkInterface> en = NetworkInterface
.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
if (intf.getName().toLowerCase().equals("eth0") || intf.getName().toLowerCase().equals("wlan0")) {
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
ipaddress = inetAddress.getHostAddress().toString();
if(!ipaddress.contains("::")){//ipV6的地址
return ipaddress;
}
}
}
} else {
continue;
}
}
分析:
先看这段代码:
intf.getName().toLowerCase().equals("eth0") || intf.getName().toLowerCase().equals("wlan0")
再看这段:
if(!ipaddress.contains("::")){//ipV6的地址
希望本文所述对大家的Android程序设计有所帮助。