'Disconnect Wifi programmatically on Android 10

I use WifiNetworkSuggestion to connect programmatically my app to my hotspot, but when I tried to disconnect from this connection programmatically I used removeNetworkSuggestions like the doc mention

Remove some or all of the network suggestions that were previously provided by the app. If one of the suggestions being removed was used to establish connection to the current network, then the device will immediately disconnect from that network.

I found that it's a bug https://issuetracker.google.com/issues/140398818, so my question is : there's no way right now to disconnect from a wifi programmatically on Android 10 ??

Thank's



Solution 1:[1]

You can't do that, But you can open WIFI Settings from your app.

Solution 2:[2]

There is Settings.Panel in Android 10+, where you can show popup intents to prompt user to change settings like Wifi, NFC etc. quickly without opening up the settings menu.

You can simply show the WiFi popup as follows.

startActivityForResult(Intent(Settings.Panel.ACTION_WIFI), ENABLE_WIFI_REQUEST)

From here, user can toggle WiFi as well as connect to a different network without having to leave the app.

Solution 3:[3]

It's a little bit late, but I am also searching for a solution to disconnect correctly.
My workaround is very dirty, because to cancel my connection I am using System.exit(0) when I stop my application for Android Q devices.

Maybe that helps until you find a better solution.

Solution 4:[4]

This is working:

_connectivityManager.UnregisterNetworkCallback(_callback);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Syed Irfan Hussaini
Solution 2 Siddharth Kamaria
Solution 3 סטנלי גרונן
Solution 4