首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

失去设备的ip

2012-09-09 
得到设备的ip1.4.WifiManager wifiManager (WifiManager) getSystemService(WIFI_SERVICE)??? ??? Wifi

得到设备的ip

1.

4.

WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);???
??? WifiInfo wifiInfo = wifiManager.getConnectionInfo();
??? DhcpInfo dhcpInfo = wifiManager.getDhcpInfo();
?
// [...]
?
tv = (TextView) findViewById(R.id.id_wlan_ip_address);
tv.setText(intToIp(dhcpInfo.ipAddress));
?
// [...]
?
??? /**
???? * http://teneo.wordpress.com/2008/12/23/java-ip-address-to-integer-and-back/
???? */
??? private String intToIp(int i) {
??? return ( i??????? & 0xFF) + "." +
??? ((i >>? 8 ) & 0xFF) + "." +
??? ((i >> 16 ) & 0xFF) + "." +
??????? ((i >> 24 ) & 0xFF)
??????? ;
??? }

热点排行