问题
After reading several other questions/answers, I'm still having an issue using wifiManager.removeNetwork to work.
According to:
Android - Cant Remove Wifi Network Programatically- The method removeNetwork(int) in the type WifiManager is not applicable for the arguments (String)
and
How to forget a wireless network in android programmatically?
...my code should work:
WifiManager wifiMAN = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
for (WifiConfiguration wifiCon : wifiMAN.getConfiguredNetworks()) {
if (wifiCon.SSID.equals( "\""+ targetNetworkName +"\"")) {
wifiMAN.removeNetwork(wifiCon.networkId)) {
wifiMAN.saveConfiguration();
break;
}
}
However, when I test on API 23 it doesn't work. Looking through the code nothing appears depreciated and the code works on API 21. Anyone have any ideas?
回答1:
This is intended behavior. As of Android M apps are not allowed to modify networks that they did not create.
See: https://code.google.com/p/android/issues/detail?id=187347 and https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-network
来源:https://stackoverflow.com/questions/42466602/android-still-cant-remove-wifi-network-programatically