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

爱⌒轻易说出口 提交于 2019-12-24 01:54:11

问题


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:


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.



来源:https://stackoverflow.com/questions/44079858/dealing-with-android-doze-mode-on-my-ble-monitoring-app-while-users-sleeping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!