我有以下功能:
public void Connect(String ssid, String bssid) throws Exception {
try {
wm.disconnect();
// A:here i want to make the network i disconenct from has info
// saved
List<WifiConfiguration> configlist = wm.getConfiguredNetworks();
for (WifiConfiguration i : configlist) {
if (i.SSID != null && i.SSID.equals("\"" + ssid + "\"")) {
wm.disconnect();
wm.enableNetwork(i.networkId, true);
wm.reconnect();
break;
}
}
/*
* B: adding a new network that is not saved WifiConfiguration
* config = new WifiConfiguration(); config.SSID = "\"" + ssid +
* "\""; config.wepKeys[0] = "\"" + "hajabihajabi" + "\"";
* config.wepTxKeyIndex = 0;
* config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
* config
* .allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
* config.preSharedKey = "\"" + "hajabihajabi" + "\"";
* wm.addNetwork(config); wm.disconnect(); for (WifiConfiguration i
* : configlist) { if (i.SSID != null && i.SSID.equals("\"" + ssid +
* "\"")) { wm.disconnect(); wm.enableNetwork(i.networkId, true);
* wm.reconnect();
*
* break; } }
*/
} catch (Exception ex) {
throw ex;
}
}// ends ConnectWiFi
当传递的ssid已经保存在手机上时,它运行正常问题出现在新的WifiConfig代码中,该代码应根据传递的信息添加新的wifi配置然后连接到它。
同时评论A:当一个wifinetwork断开连接时,其状态显示在wifi设置已断开连接,而如果它与正常的手机设置断开连接,其状态将被保存,如何在我断开连接后保存状态,如正常设置
和评论B:我需要传递给函数的额外参数才能创建新的WifiConfiguration。
提前感谢。