WifiUtils
WifiUtils copied to clipboard
Android 9 throttling
In Android 9, when I execute the code below 5 times , in the 5th attempt, I won't be able to connect. That's because every time I make a connection, a scan is triggered. Why's that? Is it really necessary?
WifiUtils.withContext(requireContext())
.connectWith("ssid", "pass")
.setTimeout(5000)
.onConnectionResult(object : ConnectionSuccessListener {
override fun success() {
isConnected = true
Toast.makeText(activity, "Connect success!", Toast.LENGTH_SHORT)
.show()
}
override fun failed(errorCode: ConnectionErrorCode) {
Toast.makeText(
activity,
"Failed to connect: $errorCode",
Toast.LENGTH_SHORT
).show()
}
})
.start()
Hello,
At the moment WiFIUtils indeed performs a scan before connecting to a wifi and there is currently no way to override this behavior.
This was a design choice back in the day when android wouldn't impose throttling on wifi scanning.
It is a good idea to deprecate that behavior now. Hopefully I will get around to it as soon as I find some time. Pull requests are also welcome.
Got it! I'll see if I can work on that and make a PR
Is it not possible to use the old scan results instead of scanning all the time? I mean if the scan fails then provide the old scan results. This is what the official document says, how to perform a network scan.
Got it! I'll see if I can work on that and make a PR
any progress yet?
@vanenshi I ended up not being to take a look at it, and I think I won't be to do it in the next 1 or 2 months