I use wifiManager
in Kotlin to get wifi network list with
wifiManager = applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
wifiManager!!.scanResults
But the list doesn't get updated when I invoke wifiManager!!.scanResults
(I call it every second).
For example let's say I create a new network called net1 but It doesn't see net1 directly
It updates only when I visit WiFi Settings manually net1 shows up there at the settings, and the list updates. Finally wifiManager starts to see net1
How can I invoke what the phone does when I visit WiFi Settings/solve this problem?
So apparently android throttles scanning WiFi for foreground apps.
You can scan only 4 times in 2 minutes, and because I scan every second it just updates for 4 seconds every 2 minutes.
But if I visit WiFi settings device manually scans and the last scan results are displayed in wifiManager!!.scanResults
if scan is failed/not completed.
I solved this disabling Developer options -> Networking -> Wi-Fi scan throttling