我将此代码用于 Android <5.0,没有任何问题:
// //////////// save network
WifiConfiguration wc = new WifiConfiguration();
ConfigurationSecuritiesV8 conf = new ConfigurationSecuritiesV8();
conf.setupSecurity(wc, conf.getScanResultSecurity(scanResult), password);
wc.BSSID = scanResult.BSSID;
wc.SSID = "\"" + scanResult.SSID.replace("\"", "") + "\"";
int id = wifiManager.addNetwork(wc);
if (id == -1)
return RESULT_CANT_CREATE_NETWORK;
我刚刚在我的 Nexus 5 上安装了新的 Android 5.0,现在我无法以编程方式添加网络。
最佳答案
我发现了问题,我需要将我的代码更改为
if (Build.VERSION.SDK_INT >= 21)
wc.SSID = "" + scanResult.SSID.replace("\"", "") + "";
else
wc.SSID = "\"" + scanResult.SSID.replace("\"", "") + "\"";
关于android - 无法在 Android 5.0 上添加新的 WiFi 网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26982253/