2

I am using below code to remove or forgot configure Wi-Fi network:

WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifiManager.removeNetwork(networkID);

but its not working in os 6.0, please suggest?

aman arora
  • 263
  • 5
  • 16

1 Answers1

1

You should use like this:

WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
       int networkId = wifiManager.getConnectionInfo().getNetworkId();
       wifiManager.removeNetwork(networkId);
       wifiManager.saveConfiguration();      

Hope it will helps you !!

Jhaman Das
  • 1,094
  • 13
  • 28
  • Any exception or something else ? – Jhaman Das Apr 12 '16 at 07:42
  • Nothing no exception, disableNetwork function is working fine but removeNetwork doesn't remove the configure network – aman arora Apr 12 '16 at 07:47
  • 1
    Please have a look : http://stackoverflow.com/questions/32756690/android-m-unable-to-remove-wi-fi-ap-programmatically – Jhaman Das Apr 12 '16 at 07:50
  • 1
    Thanks for help, this is the exact problem wifi was created by me in wifi settings, when I tried to remove the wifi through my app its not working because of WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN, but wifi created by me in my app I am able to remove that network – aman arora Apr 12 '16 at 08:18
  • Great !! Happy Coding – Jhaman Das Apr 12 '16 at 08:20