1

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

1 Answer 1

8

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! This is helpful!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.