on Android M: I am using below code to remove current connected AP.
void RemoveConnectedNetwork(){
int ID=_wifiManager.getConnectionInfo().getNetworkId();
Log.d("test", "network id = ["+ID+"]");
boolen ret =_wifiManager.removeNetwork(ID);
Log.d("test", "removeNetwork return ="+ret);
_wifiManager.saveConfiguration();
}
but removeNetwork always return false. although this API was working well in previous releases. any idea, same can be achieved using any other API?
As of Android M apps are not allowed to modify networks that they did not create. Any network can be removed from an app if it is configured by that app itself. Check the log from "WifiConfigManager" after calling removeNetwork(int), you will get an error like this UID (app UID) does not have permission to delete configuration ("wifi SSID"capabilities)
There are so many reasons for this, refer to the following code and link for further details. https://android.googlesource.com/platform/frameworks/opt/net/wifi/+/master/service/java/com/android/server/wifi/WifiConfigManager.java
There are some changes in the Wifi Manager in Android 6.0 Any Wi-Fi configuration created by an active Device Owner can no longer be modified or deleted by the user if WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN is non-zero. The user can still create and modify their own Wi-Fi configurations. Active Device Owners have the privilege of editing or removing any Wi-Fi configurations, including those not created by them.
Please refer to this link for further details https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html