Background: I have an Android app which configures an IoT device's Wi-Fi connection:
- The IoT device exposes an Access Point with a specific name
- The app connects to the AP
- The app sends the SSID & passphrase of the user's Wi-Fi network to the device
- Both the device and the smartphone connect to the home Wi-Fi network.
I've had a working solution based on WifiManager.addNetwork & WiFiManager.enableNetwork, but these APIs are unavailable with targetSdkLevel set to 29 or above (which is a hard requirement now on Google Play).
The new API offered by Android is ConnectivityManager.requestNetwork. This works quite well during steps 1-3, but after disconnecting from the temporary network (by removing the network request with ConnectivityManager.unregisterNetworkCallback), the smartphone does not reconnect to the original Wi-Fi network - it stays disconnected from Wi-Fi until the user manually selects a Wi-Fi network in Settings. Even if there is no other data connection available.
Is there a way to force the phone to connect to its preferred Wi-Fi network after using requestNetwork?
question from:
https://stackoverflow.com/questions/65938574/how-to-restore-wi-fi-connection-after-using-requestnetwork-on-android 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…