我在一个活动中实际连接了一些WiFi,我在另一个活动中需要相同的连接。我不想在从活动切换到另一个活动时断开wifi连接。
以下是连接到wifi的代码,
WifiInfo connInfo = wifiManager.getConnectionInfo();
if (null != connInfo) {
//connect to previous network
WifiConfiguration wifiConfig = new WifiConfiguration();
wifiConfig.SSID = "\"" + prefSSID + "\"";
wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
otvNetworkID = wifiManager.addNetwork(wifiConfig);
wifiManager.enableNetwork(otvNetworkID, true);
wifiManager.saveConfiguration();