手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >android连接wifi时获取广播地址代码
android连接wifi时获取广播地址代码
摘要:复制代码代码如下: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);

}

【android连接wifi时获取广播地址代码】相关文章:

android panellistview 圆角实现代码

Android实现屏幕旋转方法总结

Android中获得手机屏幕大小实现代码

Android打开GPS导航并获取位置信息返回null解决方案

android如何设置小区广播默认信道(50与60并支持双卡)

Android在OnCreate中获取控件的宽度和高度的实现代码

Android通过手势实现的缩放处理实例代码

Android获取版本号等信息

Android重启运用程序的代码

android4.0 获取手机IP地址的问题

精品推荐
分类导航