Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to forget a wireless network in android programmatically?

I am working on an app which wifi , where user will be asked to enter password for the scanned network he selects, if user enters a correct password, it connects and works well. But when user enters wrong password, a new network is added with that name, and will be failing to authenticate cos of wrong password, and it will be having authentication problem status.

Now if user tries to again scan and select the same network, and enters correct password, it fails to connect even though password now is correct and will have disabled status, since the previous connection is still showing that authentication problem status.

How to solve this problem? Is there any way to forget all networks using ConnectivityManager or wifimanager? Or any other solution?

like image 974
Adarsh H S Avatar asked Jun 21 '12 08:06

Adarsh H S


People also ask

How do I completely forget a WiFi network on Android?

For Android (general instruction using Google Marshmallow): Open Settings on your device, and tap on the WiFI icon to access WiFi network options. Tap and hold the WiFi network you want to delete, then select Forget Network from the menu that appears.

How do I forget a specific WiFi network?

Go to Settings > Wi-Fi. Tap next to the Wi-Fi network that you want your device to forget. Tap Forget This Network, then tap Forget to confirm.

How do I forget a WiFi network using CMD?

Open Start. Search for Command Prompt, right-click the top result, and select the Run as administrator option. Type the following command to delete a network profile and press Enter: netsh wlan delete profile name="WLAN-PROFILE-NAME" In the command, replace WLAN-PROFILE-NAME with the name of the wireless profile.

How do I make a network forget a device?

Android. Open 'Settings', then select 'Wi-Fi'. Tap and hold the network you want to remove, then select 'Forget network'.


1 Answers

Yes, removeNetwork() works. I used this to remove all networks.

List<WifiConfiguration> list = wifiManager.getConfiguredNetworks(); for( WifiConfiguration i : list ) {     wifiManager.removeNetwork(i.networkId);     //wifiManager.saveConfiguration();   } 

wifiManager.saveConfiguration()

This method was deprecated in API level 26. There is no need to call this method - addNetwork(WifiConfiguration), updateNetwork(WifiConfiguration) and removeNetwork(int) already persist the configurations automatically.

https://developer.android.com/reference/android/net/wifi/WifiManager.html#saveConfiguration()

like image 200
krishnan Avatar answered Oct 01 '22 08:10

krishnan