欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

程序员文章站 2023-12-14 18:22:46
复制代码 代码如下: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);
}

上一篇:

下一篇: