If you are playing around WiFi on the android and checking WiFiManager documentation, you will notice for most of the methods 👇
So, Android is deprecating most of the functionality which allows us to scan, connect, enable WiFi 🤷 which is a kind of smart decision from their side.
If you search in the Google “How do I connect to the specific WiFi”, you will find something like this 👇
How do I connect to a specific Wi-Fi network in Android programmatically?
Before connecting WIFI network you need to check security type of the WIFI network ScanResult class has a capabilities…
First, you need to create a WiFiConfiguration [deprecated]
Second, if you are configuring WEP, you need to set [deprecated]
Third, you need to add configured WiFi to the WiFiManager [deprecated]
And finally, you need to connect to the WiFi [deprecated]
but the problem is that 99% of the methods are currently deprecated, and if you try to run the application with the code above on the Android device running API level 29 and more, your application will not do what it supposed to do. 🤦♂️
But come on, it’s can’t be so bad, there should be something, right 🧑🎓
Suggest a WiFi
Instead of connecting to a WiFi without asking the user, now you can suggest WiFi(s) to which the user can connect, and if the user accepts your suggestion, then you can connect to a WiFi. So basically from now on now more hidden connections.
So how to suggest a WiFi
Wi-Fi suggestion API for internet connectivity | Android Developers
Devices running Android 10 (API level 29) and higher allow your app to add network credentials for a device to…
First, you need to create a WiFi suggestion
Second, you need to add the suggestion or list of suggestions to the WiFiManager
Finally, if you run your application, you will see
Interestingly, if you run the application on android Q, then a notification will be shown, and if you run the same application on the Android R, then a Dialog will be shown to the user, which is, in my opinion, better, as I notification is popping up silently and the user can easily miss it.
If at this point your are lucky and user press “Allow”, your device will connect to the specified WiFi.
In the WiFi settings of the device, it will be mentioned that you are connected to a WiFi via your “application name”.
Also what is important to mention here is
If the user uses the Wi-Fi picker to explicitly disconnect from one of the network suggestions when connected to it, then that network is ignored for 24 hours. During this period, that network will not be considered for auto-connection, even if the app removes and re-adds the network suggestion corresponding to the network.
Of course, this can be fixed by changing the time on the phone.