在kitkat和以下它正在成功工作,但在Lollipop它不工作.
这是代码:
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);WifiConfiguration wifiConfiguration = new WifiConfiguration();wifiConfiguration.SSID = "\"testSSID\"";wifiConfiguration.hIDdenSSID = true;wifiConfiguration.status = WifiConfiguration.Status.ENABLED;wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);netID = wifiManager.addNetwork(wifiConfiguration);Log.d("WifiPreference","add Network returned " + netID);boolean checkEnableWifi = wifiManager.enableNetwork(netID,true);Log.d("WifiPreference","enableNetwork returned " + checkEnableWifi);
我的测试设备是nexus 5 build number LRX21O,在我的代码或Lollipop上的错误中有什么问题吗?
解决方法 面对类似的棒棒糖问题.手动禁用其他网络,然后重新连接的WiFi管理器解决了这个问题.
boolean enableNework(String ssID,Context cxt) { boolean state = false; WifiManager wm = (WifiManager) cxt.getSystemService(Context.WIFI_SERVICE); if (wm.setWifIEnabled(true)) { List<WifiConfiguration> networks = wm.getConfigurednetworks(); Iterator<WifiConfiguration> iterator = networks.iterator(); while (iterator.hasNext()) { WifiConfiguration wifiConfig = iterator.next(); if (wifiConfig.SSID.equals(ssID)) state = wm.enableNetwork(wifiConfig.networkID,true); else wm.disableNetwork(wifiConfig.networkID); } wm.reconnect(); } return state;}总结
以上是内存溢出为你收集整理的android – WifiConfiguration在Lollipop中启用网络全部内容,希望文章能够帮你解决android – WifiConfiguration在Lollipop中启用网络所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)