Android WifiManager.startScan() returning false when screen is off

228 Views Asked by At

I have a ForgeroundService triggering a wifi scan every 30 seconds. Everything is working fine until I press the power button (eg turn off the screen). My service keeps running, but WifiManager.startScan() returns false until I turn the screen back on.

What I have tried:

  • Adding the app to the Doze-Mode-Whitelist via the Android setting to keep my app from being effected by doze mode (since the official Android Dev site claims that network scans wont be possible while in Doze mode)
  • Createing and holding a WakeLock while my ForegroundService is running
  • Creating and holding a WifiLock (wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "package:wifiLock"))

Does someone has any idea how I can get the wifi scan to continue working?

I can't even find any source that tells that WifiManager won't scan when the screen is turned off...

0

There are 0 best solutions below