Android

关注公众号 jb51net

关闭
首页 > 软件编程 > Android > android wifi 广播地址

android连接wifi时获取广播地址代码

作者:

本文详细介绍android连接wifi时获取广播地址的方法,需要了解的朋友可以参考下,获取对你有所帮助
复制代码 代码如下:

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);
}
您可能感兴趣的文章:
阅读全文