android连接wifi时获取广播地址代码
时间:2021-07-10 09:34:08|栏目:Android代码|点击: 次
复制代码 代码如下:
private InetAddress getBroadcastAddress() throws IOException {
WifiManager myWifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
DhcpInfo myDhcpInfo = myWifiManager.getDhcpInfo();
if (myDhcpInfo == null) {
System.out.println("Could not get broadcast address");
return null;
}
int broadcast = (myDhcpInfo.ipAddress & myDhcpInfo.netmask)
| ~myDhcpInfo.netmask;
byte[] quads = new byte[4];
for (int k = 0; k < 4; k++)
quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);
return InetAddress.getByAddress(quads);
}
上一篇:Android截屏SurfaceView黑屏问题的解决办法
栏 目:Android代码
下一篇:android之HttpPost&HttpGet使用方法介绍
本文地址:http://www.codeinn.net/misctech/155496.html