Android之获取移动网络ip
来源:互联网 发布:砍柴网源码 编辑:程序博客网 时间:2024/06/05 16:50
1、获取移动网络ip
2、代码
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() && inetAddress instanceof Inet4Address) { return inetAddress.getHostAddress().toString(); } } } } catch (SocketException ex) { Log.e("get IpAddress fail", ex.toString()); return ""; } return ""; }
加上权限
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
3、总结
记得
inetAddress instanceof Inet4Address
不要忘记,不然在Android6.0以上系统获取不到ip
阅读全文
0 0
- Android之获取移动网络ip
- android 获取网络IP地址
- Android之获取IP
- Android获取移动设备的IP地址
- Android获取移动设备IP地址
- Android系统信息获取 之十:移动网络相关信息获取
- Android系统信息获取 之十:移动网络相关信息获取
- 移动网络IP化
- android之获取网络图片
- android网络通信之获取网络图片
- android网络通信之获取网络图片
- Android-->分享工具类:判断网络状态,网络类型,获取网络IP(包括GSM IP)
- android开发之网络学习-TCP/IP
- 【Android基础】Android网络类型判断及IP地址获取
- 获取网络IP信息
- 获取当前网络ip
- iOS 获取网络ip
- android开发获取网络图片并可拖拽移动
- [ElasticStack系列]docker部署logstash
- OJ 2552: 好好学习天天向上
- hdu 1024 最大上升子序列
- java的properties文件-jdbc优化编程(五)
- IO流
- Android之获取移动网络ip
- Functors, Applicatives, And Monads 图解
- 0906 JSP标准标签库JSTL
- myeclipse 10卡死强退后再打开就卡在 loading workbench解决方法
- Path of Equal Weight
- eplise 连接谷歌服务器
- Dynamic Shadow Projector
- HDU5402 Travelling Salesman Problem 【模拟】
- 自我介绍以及对于软件工程的看法