Android 获取当前设备的IP地址

Android 获取当前设备的IP地址
文章分类:移动开发
获取当前设备的IP地址
 
Java代码 
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);    
WifiInfo wifiInfo = wifiManager.getConnectionInfo();    
int ipAddress = wifiInfo.getIpAddress();    
String ip = intToIp(ipAddress);    
   
public String intToIp(int i) {    
   
   return ((i >> 24 ) & 0xFF ) + "." +    
               ((i >> 16 ) & 0xFF) + "." +    
               ((i >> 8 ) & 0xFF) + "." +    
               ( i & 0xFF) ;    
}   
 

你可能感兴趣的:(android,移动开发,职场,休闲)