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?
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.
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.
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.
Android. Open 'Settings', then select 'Wi-Fi'. Tap and hold the network you want to remove, then select 'Forget network'.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With