Android获取本机IP地址
private String getIp(){WifiManager wm=(WifiManager)getSystemService(Context.WIFI_SERVICE);//检查Wifi状态if(!wm.isWifiEnabled())wm.setWifiEnabled(true);WifiInfo wi=wm.ge
·
private String getIp(){
WifiManager wm=(WifiManager)getSystemService(Context.WIFI_SERVICE);
//检查Wifi状态
if(!wm.isWifiEnabled())
wm.setWifiEnabled(true);
WifiInfo wi=wm.getConnectionInfo();
//获取32位整型IP地址
int ipAdd=wi.getIpAddress();
//把整型地址转换成“*.*.*.*”地址
String ip=intToIp(ipAdd);
return ip;
}
private String intToIp(int i) {
return (i & 0xFF ) + "." +
((i >> 8 ) & 0xFF) + "." +
((i >> 16 ) & 0xFF) + "." +
( i >> 24 & 0xFF) ;
}
更多推荐



所有评论(0)