private String getLocalIPAddress() {

try {

for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterface(); en.hasMoreElements(); ) {

NetworkInterface intf = en.nextElement();

for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {

InetAddress inetAddress = enumIpAddr.nextElements();

if ( !inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {

// 这里增加限定条件inetAddress instanceof Inet4Address主要是在Android4.0高版本中可能优先得到的是IPV6地址

return inetAddress.getHostAddress().toString();

}

}

}

} catch (SocketException ex) {

Log.e("getIP", ex.toString());

ex.printStackTrace();

}

return null;

}



更多相关文章

  1. ionic 自动编译android的release版本
  2. Android版本28使用http请求报错not permitted by network securi
  3. Android android 6.0权限校验及版本兼容问题
  4. Android App 版本更新
  5. android 对比版本号
  6. android官方下载链接最新版 (Windows版本)
  7. android 版本更新和下载安装 适配android 7.0
  8. Android获取已安装应用信息(图标,名称,版本号,包)
  9. Android的版本的介绍

随机推荐

  1. Android(安卓)Glide v4使用(基础篇)
  2. Android(安卓)Jetpack - 使用 Navigation
  3. Caused by: com.android.builder.dexing.
  4. Android通过点击按钮改变Activity的背景
  5. android PathData生成问题
  6. Android Studio报错:Could not GET 'https
  7. Android Studio(十):添加assets目录
  8. Android 复习资料
  9. Android(安卓)GPS 定位的实现
  10. Android界面编程之实现改变图片透明度并