Android 5.1获取IP
来源:互联网 发布:淘宝30天最低价 编辑:程序博客网 时间:2024/05/16 12:20
在Android 5.1的系统,获取IP地址,试了好几个方法都无法得到正确的和系统设置中一致的IP,最后发现下面这个是唯一可以使用的,其他有几个要么是乱码要么和系统设置里的不一致。
public static String getLocalIpAddress() {String ip="";try {for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {NetworkInterface intf = en.nextElement();if (intf.getName().equals("usbnet0")) {continue;}for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {InetAddress inetAddress = enumIpAddr.nextElement();if (!inetAddress.isLoopbackAddress()&& (inetAddress instanceof Inet4Address)) {ip=inetAddress.getHostAddress();}}}} catch (SocketException ex) {Log.e(TAG, ex.toString());}return ip;}
阅读全文
0 0
- Android 5.1获取IP
- android 获取IP地址
- android获取网关ip
- ANDROID 获取IP地址
- 获取android手机ip
- android 获取ip地址
- android获取IP地址
- android 获取IP地址
- android获取手机ip
- android 获取IP
- Android之获取IP
- android获取当前ip
- android 获取IP
- android获取手机ip
- android 获取正确IP
- 获取Android IP信息
- android获取手机ip
- android 获取IP地址
- 全面了解Android热修复技术
- Android 自定义空数据提示界面 EmptyView
- 关于tomcat文件传输大小
- 将Linux文件清空的几种方法
- UART串口通信浅谈之(二)--寄存器设置
- Android 5.1获取IP
- URL与资源
- SSH框架的基本整合
- Java设计模式——代理模式(Proxy Pattern)
- mybatis学习之路----打印sql语句
- C#中的 具名参数 和 可选参数
- ORA-00911: invalid character
- 获取war包中配置文件路径API
- TypeError: super(type, obj): obj must be an instance or subtype of type