我正在开发一个 android 应用程序,其中一项活动显示了一个 IPconfig 列表。我正在使用以下代码获取信息:
public String s_dns1 ;
public String s_dns2;
public String s_gateway;
public String s_ipAddress;
public String s_leaseDuration;
public String s_netmask;
public String s_serverAddress;
DhcpInfo d;
WifiManager wifii;
wifii= (WifiManager) getSystemService(Context.WIFI_SERVICE);
d=wifii.getDhcpInfo();
s_dns1="DNS 1: "+String.valueOf(d.dns1);
s_dns2="DNS 2: "+String.valueOf(d.dns2);
s_gateway="Default Gateway: "+String.valueOf(d.gateway);
s_ipAddress="IP Address: "+String.valueOf(d.ipAddress);
s_leaseDuration="Lease Time: "+String.valueOf(d.leaseDuration);
s_netmask="Subnet Mask: "+String.valueOf(d.netmask);
s_serverAddress="Server IP: "+String.valueOf(d.serverAddress);
info= (TextView) findViewById(R.id.info1);
info.setText("\n"+s_dns1+"\n"+s_dns2+"\n"+s_gateway+"\n"+s_ipAddress+"\n"+s_leaseDuration+"\n"+s_netmask+"\n"+s_serverAddress);
在模拟器中,我得到以下信息:
DNS1:0
DNS2:0
Default gateway:0
IP address:0
Lease time:0
Subnet mask:-1
Server IP:0
但是,当我在 Galaxy 标签 GT-P1000 上测试 APK 时,我得到以下信息:
DNS1:16820416
DNS2:0
Default gateway:16820416
IP address:33597632
Lease time:86400
Subnet mask:16777215
Server IP:16820416
我究竟做错了什么?
谢谢。