我遇到了问题。我以这种方式在我的应用程序中显示网络信息:网络信息android ip倒置问题
// 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
..我该如何解决?
除了将订单更改为i,i >> 8等? – user3125280
另请参阅http://developer.android.com/reference/android/text/format/Formatter.html#formatIpAddress(int) – laalto