Android获取本机信息(随时更新)
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