Android 获取当前设备的IP地址

获取当前设备的IP地址

 

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)