Android saves WIFI details into WifiConfiguration class. When WIFI is ON and SSID, Pass-key details matches with WIFI network then Android auto connect with the particular WIFI Network. How to disable that auto-connect feature ? purpose behind asking this question is, I have two configured networks (already saved) and i want to connect WIFI on the button click event, but auto connect feature of android connects with the WIFI itself.
8 Answers
No. You cannot do this. The OS keeps track of the networks which are configured in the device. It tries to find those networks and based on the priority driven method, chooses an appropriate network and connects to it as soon as WiFi is turned on. As Arpit suggested, you can forget those networks and OS will remove it's configuration from memory.
1) Get an instance of class WifiManager by calling Context.getSystemService(Context.WIFI_SERVICE).
2) Enable or disable Wifi using wifimanager.setWifiEnabled(true); and wifimanager.setWifiEnabled(false); respectively.
public void DisableWiFi(){
wifimanager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifimanager.setWifiEnabled(false);
}
required permissions
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
or
To stop your Android device from auto-connecting to open networks, open the settings and go to Network & Internet > Wi-Fi > Wi-Fi preferences. Tap the button next to Connect to open networks to disable it.
Note :This is confirmed to work in Android 10 Q for Pixel, but might work in older versions of Android, too. If you don't see these specific screens, look through Settings for something like Mobile Networks or Connections.
There's a way for your android to not auto-connect. The trick is to press & hold the connected network to modify it, then enter a hexa password. I.e. a password that is hexa or either characters or 8 numbers long or a combination then save the password.
When you try to re-connect the next time it will say "authentication problem"