我已成功在我的应用程序中以编程方式添加并连接到open和PSK网络(在运行5.1和6.0的设备上尝试过)。但是当我为企业网络尝试这个时,它不起作用。我看到addNetwork()成功(返回正网络ID),但当我查看设置 - > Wi-Fi时,我没有像我为其他添加的SSID那样看到SSID。谁知道为什么会这样?如果我以编程方式搜索WiFiConfiguration列表,它确实找到了SSID。这是我使用的代码:
wifiConf = new WifiConfiguration();
wifiConf.SSID = "\"dot1x-test\"";
wifiConf.BSSID = "c4:e9:84:43:48:e8";
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
wifiConf.enterpriseConfig.setIdentity("name");
wifiConf.enterpriseConfig.setPassword("testpassword");
wifiConf.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.PEAP);
wifiConf.enterpriseConfig.setPhase2Method(WifiEnterpriseConfig.Phase2.MSCHAPV2);
}
netId = wifiMgr.addNetwork(wifiConf);
wifiMgr.disconnect();
wifiMgr.enableNetwork(netId, true);
wifiMgr.saveConfiguration();
wifiMgr.reconnect();