android连接wifi时获取广播地址代码
程序员文章站
2023-12-04 11:24:58
复制代码 代码如下:private inetaddress getbroadcastaddress() throws ioexception { wifimanager m...
复制代码 代码如下:
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);
}
上一篇: Html5 语法与规则简要概述