Search code examples
androidandroid-wifiwifimanager

Android M: Unable to remove WIFI AP programmatically


In Android M: I am using below code to remove current connected WIFI 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 RemoveConnectedNetwork() always returns false.

Although this API was working well in previous releases.

Any solution that can be achieved on this using any other API in Android M?

Thanks.


Solution

  • 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