- <span style="font-size:16px;">JAVA代码:
- 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) ;
- }
- </span>
- //该片段来自于http://www.codesnippet.cn/detail/290720134851.html
来源: http://www.codesnippet.cn/detail/290720134851.html