【发布时间】:2014-05-19 13:47:15
【问题描述】:
我是 android 新手,我正在创建一个应用程序,其中显示 LAN IP 地址、子网掩码、默认网关和其他信息我使用以下代码获得 IP 地址
try{
WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wi = wm.getConnectionInfo();
String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
TextView ipAddressText = (TextView)findViewById(R.id.productInfo_lanIpAddress);
ipAddressText.setText(ip);
DhcpInfo dInfo = wm.getDhcpInfo();
ip = String.valueOf(dInfo.gateway);
TextView defaultGateway = (TextView)findViewById(R.id.productInfo_defaultGateway);
defaultGateway.setText(ip);
}//*/
catch (Exception ex) {
TextView ipAddressText = (TextView)findViewById(R.id.productInfo_lanIpAddress);
ipAddressText.setText(ex.toString());
}
/*
现在我相信我得到了默认网关,但它是数字格式的,所以它不能正确显示(我得到 16885352)有没有像我们用来格式化 IP 地址的 Formatter 一样的方法? 我还想获得有关如何在其他 Internet 信息上实现相同效果的链接或指南。 谢谢!
【问题讨论】:
标签: android android-wifi android-internet android-wireless