Android - Still can't remove Wifi Network Programatically

偶尔善良 提交于 2020-02-05 05:27:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!