在用户睡觉时处理我的 BLE 监控应用程序上的 Android-打瞌睡模式

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

我制作了在睡眠时间监测人的健康状况的设备,它通过 BLE 连接到智能手机。

它与 iOS 应用程序配合得很好。 但是自从打瞌睡模式出现在 Android 世界。 真的很难处理,因为我的设备在他的睡眠时间工作。

主要特点是它会检测到特定的危险并在用户睡觉时通知该设备。发生时我需要网络连接。

很多文章告诉我,如果我的应用程序在白名单中,即使在打瞌睡模式下也可以使用网络。但在我测试了 Doze 模式后,情况似乎并非如此。 我说的对吗?

我可以确保在我启动时可以在列表中找到我的应用

adb shell dumpsys deviceidle

让我的应用正常运行的最佳方法是什么?

任何提示都会对我有所帮助。 谢谢

编辑

不幸的是,我使用 GCM 进行了测试,但它只能在短时间内唤醒我的应用程序。这意味着我必须尽可能多地发送 GCM 以使其保持清醒。我觉得我用不了。

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?

你说的不对。当您的应用程序在白名单上时,打瞌睡的限制之一是解除打瞌睡时使用网络的能力。

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.

来自 here.

换句话说:如果你在白名单上,你应该可以在打瞌睡的情况下使用网络。

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

考虑到您的应用程序是一个运行状况监视器,因此应该能够持续或至少非常定期地执行其工作,您可以将该功能放在前台服务中。前台服务不受打瞌睡影响。

你应该知道你应该有充分的理由使用前台服务,因为用户知道它们,但我认为你有健康监控等。

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.

来自 here.