1
A
回答
1
2
0
刪除/忘記WIFI網絡請嘗試以下兩個鏈接,Android - Cant Remove Wifi Network Programatically- The method removeNetwork(int) in the type WifiManager is not applicable for the arguments (String)和How to forget a wireless network in android programmatically?。而對於修改特定的網絡,我認爲你應該先先刪除它,然後要求新密碼,並設置它是這樣的:
if(scanResultSecurity.equals(Constants.WEP)){
wifiConfiguration.SSID = "\"" + networkSSID + "\"";
wifiConfiguration.wepKeys[0] = "\"" + password + "\"";
wifiConfiguration.wepTxKeyIndex = 0;
wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
wifiConfiguration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
//Adds to the list of network and returns the network id which can be used to enable it later.
networkId = wifiManager.addNetwork(wifiConfiguration);
if(networkId != -1){
connectToWifi(wifiConfiguration);
}
}
else if(scanResultSecurity.equals(Constants.PSK)){
wifiConfiguration.SSID = "\"" + networkSSID + "\"";
wifiConfiguration.preSharedKey = "\"" + password + "\"";
wifiConfiguration.hiddenSSID = true;
wifiConfiguration.status = WifiConfiguration.Status.ENABLED;
wifiConfiguration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wifiConfiguration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
wifiConfiguration.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wifiConfiguration.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wifiConfiguration.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
wifiConfiguration.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
//Adds to the list of network and returns the network id which can be used to enable it later.
networkId = wifiManager.addNetwork(wifiConfiguration);
if(networkId != -1){
connectToWifi(wifiConfiguration);
}
}
private void connectToWifi(WifiConfiguration wifiConfiguration){
wifiManager.disconnect();
wifiManager.setWifiEnabled(true);
boolean enableNetworkBoolean = wifiManager.enableNetwork(wifiConfiguration.networkId, true);
Log.i(Constants.LOG_TAG, "networkId "+wifiConfiguration.networkId);
Log.i(Constants.LOG_TAG, "SSID "+wifiConfiguration.SSID);
Log.i(Constants.LOG_TAG, enableNetworkBoolean+" enableNetworkBoolean");
boolean reconnectBoolean = wifiManager.reconnect();
Log.i(Constants.LOG_TAG, reconnectBoolean+" reconnectBoolean");
boolean changeHappen = wifiManager.saveConfiguration();
Log.i(Constants.LOG_TAG, changeHappen+" changeHappen");
if(enableNetworkBoolean && reconnectBoolean && changeHappen){
Log.i(Constants.LOG_TAG, "Change Happen");
// Utility.showToast(MainActivity.this, Constants.CONNECTED);
wifiListViewAdapter.notifyDataSetChanged();
}
else{
Log.i(Constants.LOG_TAG, "Change not Happen");
Utility.showToast(MainActivity.this, Constants.CONNECTING_ERROR);
}
}
相關問題
- 1. 以編程方式修改ServiceInstall配置
- 2. 以編程方式修改Django設置
- 3. 以編程方式刪除Web.config設置
- 4. iOS以編程方式設置wifi配置
- 5. 以編程方式修改Azure Cloud Service配置?
- 6. Android - 仍然無法以編程方式刪除Wifi網絡
- 7. 以編程方式修改樣式
- 8. 無法以編程方式配置WiFi開放網絡android?
- 9. Android:如何以編程方式創建EAP wifi配置?
- 10. 從命令行或以編程方式更改配置參數
- 11. 是否有可能以編程方式修改ATS設置
- 12. 以編程方式在Windows中添加帶有密碼的wifi配置文件
- 13. 刪除或刪除現有的Websphere Application Server的配置文件
- 14. 以編程方式修改csproj文件
- 15. 以編程方式修改Spring bean
- 16. 以編程方式修改UIToolBar項目
- 17. 以編程方式修改SipAddress
- 18. 以編程方式修改FieldDefinitions
- 19. 以編程方式修改端點ReaderQuotas
- 20. 如何以編程方式修改DataTemplate?
- 21. 以編程方式修改EditForm.aspx
- 22. 修改NSLocationWhenInUseUsageDescription以編程方式
- 23. 以編程方式配置IPhone設置
- 24. 以編程方式刪除控件
- 25. Angular2以編程方式刪除組件。
- 26. data.table - 以編程方式刪除列
- 27. 如何以編程方式刪除AlertDialog
- 28. HTML5 appcache以編程方式刪除
- 29. 如何以編程方式刪除plist?
- 30. NSArrayController - 添加:&刪除:以編程方式
你是不是想以編程方式做到這一點或這是一般的使用問題? – 2011-05-04 18:08:02