Dealing with Android-Doze mode on my BLE monitoring app while user's sleeping

2.5k views Asked by At

I made the device which monitors person's health in sleep time and it connects to a smartphone via BLE.

It's working great with the iOS app. But since Doze mode came on Android world. It's really hard to deal with it because my device is working in his sleep time.

The main feature is that it detects particular danger and notify to the user while he is sleeping with the device. I need a network connection when it occurs.

Many articles tell me that I can use a network even in the doze mode if my app is in the whitelist. But it does not seem true after I tested Doze mode. Am I right?

I can ensure that I can find my app in the lists, when I fire

adb shell dumpsys deviceidle

What is the best approach that I can take to make my app working correctly?

  • foreground services
  • alarm manager with SetExactAndAllowWhileIdle.
  • GCM (it means push, right?)
  • anything else

Any tips will help me. Thanks.

Edit

Unfortunately, I tested with using GCM but it only wakes my app in short time. It means I have to send GCM as many as I want to keep it awake. I don't think I can use it.

1

There are 1 answers

11
Tim On BEST ANSWER

Many articles tell me that I can use a network even in the doze mode if my app is in the whitelist. But it does not seem true after I tested Doze mode. Am I right?

You are not right. One of the restrictions of doze that are lifted when your app is on the whitelist, is the ability to use the network when doze is active.

An app that is whitelisted can use the network and hold partial wake locks during Doze and App Standby. However, other restrictions still apply to the whitelisted app, just as they do to other apps. For example, the whitelisted app’s jobs and syncs are deferred (on API level 23 and below), and its regular AlarmManager alarms do not fire.

From here.

In other words: you should be able to use the network in doze if you are on the whitelist.

What is the best approach that I can take to make my app working correctly?

Considering your app is a health monitor and thus should be able to do its work constantly or at least very regularly, you could put the functionality in a foreground service. Foreground services are not effected by doze.

You should be aware that you should have a good reason to use a foreground service since the user is aware of them, but I think you have one with the health monitoring etc.

Note: You should only use a foreground service for tasks the user expects the system to execute immediately or without interruption. Such cases include uploading a photo to social media, or playing music even while the music-player app is not in the foreground. You should not start a foreground service simply to prevent the system from determining that your app is idle.

From here.