Android之获取移动网络ip
16lz
2022-07-26
1、获取移动网络ip
2、代码
public String getLocalIpAddress() { try { for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration 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 ""; }
加上权限
&l
更多相关文章
- 【阿里云镜像】切换阿里巴巴开源镜像站镜像——Debian镜像
- Android屏幕分辨率正确获取及PX,DPI,DP,SP等的对应关系
- android 获取唯一标识
- android拍照与读取相册
- Android(安卓)给 app默认权限(不弹窗申请权限)
- Android(安卓)热点开关状态的判断和获取热点ssid
- Android软键盘适配问题
- AIR Native Extension的使用(Android)一 : 打包ane
- android之BitMap