我正在调用函数WifiManager.addNetwork(WifiConfiguration)尝试将adhoc wifi网络添加到设备的wifi配置中。但是在Android M上这个函数返回-1,我假设因为它没有互联网访问权限。它在大多数其他设备上运行良好。下面是我正在使用的代码段。
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.SSID = '\"' + ssid + '\"';
wifiConfiguration.hiddenSSID = false;
wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
wifiManager.addNetwork(wifiConfiguration);
如何绕过互联网连接检查并强制添加网络?
答案 0 :(得分:0)
之后您需要启用网络:
List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
for( WifiConfiguration i : list ) {
if(i.SSID != null && i.SSID.equals("\"" + ssid + "\"")) {
wifiManager.disconnect();
wifiManager.enableNetwork(i.networkId, true);
wifiManager.reconnect();
enter code here
break;
}
}