首页 > 系统 > Android > 正文

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

2019-10-24 21:09:21
字体:
来源:转载
供稿:网友
本文详细介绍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); 
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表