我遇到了問題。我以這種方式在我的應用程序中顯示網絡信息:網絡信息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