android连接wifi时获取广播地址代码_安卓软件开发教程-查字典教程网
android连接wifi时获取广播地址代码
android连接wifi时获取广播地址代码
发布时间:2016-12-28 来源:查字典编辑
摘要:复制代码代码如下:privateInetAddressgetBroadcastAddress()throwsIOException{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);

}

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新安卓软件开发学习
    热门安卓软件开发学习
    编程开发子分类