Peter
Peter

Reputation: 393

Android Oreo, wifiManager.getScanResults() returns empty list in Doze

I'm having issues with wifiManager.getScanResults() returning empty list on Oreo (API26), when device enters Doze mode. Before it enters Doze, and also on earlier API versions everything works fine (I get a list of ScanResults).

I call this method very often, once per minute, in foreground service.

How can I deal with this new Android's behavior?

Any tips or even code examples are welcome.

Upvotes: 0

Views: 401

Answers (1)

Flowwlol
Flowwlol

Reputation: 21

First of all, there is two kind of doze : Let's call them the Light Doze and the Deep sleep doze.

The light doze starts few minutes after you leave your phone without charging it on your table, this doze will limit the access of a number of service.

The Deep sleep doze starts after 20 to 30 minutes without moving (and still not charging) and will reduce the usage of your phone to the minimum, it'll wake up for some notifications and calls.

The doze mode only appears when the phone is not moving, so when the phones move, it's not considered as a doze mode.

For your issue, it's related to Android 8 that kills background services when the app is not in foreground.

For your issue, your background services will be killed after few minutes. The location service will be unaccessible, so you wont be able to have wifi updates. (The answer here would be : Don't fight the doze mode, you will loose).

So if you want to get updates of wifi scans while your app is killed and or the screen is off :

  • Using JobDispatcher to create a job that will be executed every x seconds and get your scan. The jobDispatcher still works during the light doze mode
  • if the phone enters in deep doze, the phone is not moving and therefore you can conclude that the scan will be the same and don't have to update it, your job will resume once the phone exit the doze.

Upvotes: 1

Related Questions