我有一个问题。我以这种方式在我的应用程序中显示网络信息:
// Some wifi info
d=wifiManager.getDhcpInfo();
s_dns1="DNS 1: "+intToIp(d.dns1);
s_dns2="DNS 2: "+intToIp(d.dns2);
s_gateway="Default Gateway: "+intToIp(d.gateway);
s_ipAddress="IP Address: "+intToIp(d.ipAddress);
s_leaseDuration="Lease Time: "+String.valueOf(d.leaseDuration);
s_netmask="Subnet Mask: "+intToIp(d.netmask);
s_serverAddress="Server IP: "+intToIp(d.serverAddress);
所有当然都使用
wifiManager
。现在我有一种方法来转换值public String intToIp(int i) {
return ((i >> 24 ) & 0xFF ) + "." +
((i >> 16 ) & 0xFF) + "." +
((i >> 8 ) & 0xFF) + "." +
( i & 0xFF) ;
}
它有效。但是改为显示:
192.168.0.0
它显示0.0.168.192
..我该如何解决? 最佳答案
只需反转您的intToIp方法:
public String intToIp(int i) {
return (i & 0xFF) + "." +
((i >> 8 ) & 0xFF) + "." +
((i >> 16) & 0xFF) + "." +
((i >> 24) & 0xFF);
}