val ssid = "Your WiFi SSID"
val password = "Your WiFi password"
val networkSSID = "\"$ssid\""
val networkPassword = "\"$password\""
val wifiConfiguration = WifiConfiguration()
wifiConfiguration.SSID = networkSSID
wifiConfiguration.preSharedKey = networkPassword
val networkId = wifiManager.addNetwork(wifiConfiguration)
wifiManager.disconnect()
wifiManager.enableNetwork(networkId, true)
wifiManager.reconnect()
Used this code but it is not working on Android 10 and above.Also followed https://github.com/ThanosFisherman/WifiUtils but which also not working on Android 10 and above. Can some one suggest how to connect to wifi network.
You should try ConnectivityManager and NetworkCallbacks to do this task like this way: