'Store WiFi network credentials after calling requestNetwork in Android
I'm connecting to a WiFi hotspot using:
val wifiNetworkSpecifier: WifiNetworkSpecifier = WifiNetworkSpecifier.Builder()
.setSsid(ssid)
.setWpa2Passphrase(passphrase)
.build()
val networkRequest: NetworkRequest = NetworkRequest.Builder()
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
.removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.setNetworkSpecifier(wifiNetworkSpecifier)
.build()
connectivityManager.requestNetwork(networkRequest, networkCallback)
I'd like to store the credentials, so the user would be able to connect to it also by selecting the hotspot from the list of SSIDs (from the system's WiFi menu).
I've searched alot, looked into the developer docs, but found nothing helpful.
Thank you for any advice!
UPDATE:
I've found out that using WiFiSuggestions, the credentials are stored and I can connect to the hotspot from the phone settings -> WiFi list.
Drawbacks:
- it seems that in only works from Android R (SDK 30+)
- slow
- less intuitive UI
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
