手机号码

Android获取本机信息(随时更新)

自闭症网瘾萝莉.ら 提交于 2019-12-10 01:25:53
1、获取IP(ipv4)地址 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.isLinkLocalAddress()) { //!inetAddress.isLinkLocalAddress() Android4.0以上排除IPv6地址 return inetAddress.getHostAddress().toString(); } } } } catch (SocketException ex) { Log.e("WifiPreference