Android之获取移动网络ip

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

你可能感兴趣的:(Andriod,积累,Android,移动网络ip)