android - 在用户 sleep 时处理我的 BLE 监控应用程序上的 Android-Doze 模式

标签 android bluetooth background bluetooth-lowenergy doze

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

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

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

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

我可以确保在我开火时可以在列表中找到我的应用

adb shell dumpsys deviceidle

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

  • 前台服务
  • 带有 SetExactAndAllowWhileIdle 的警报管理器。
  • GCM(意思是推送,对吗?)
  • 还有什么

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

编辑

不幸的是,我使用 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?

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

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

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 .

关于android - 在用户 sleep 时处理我的 BLE 监控应用程序上的 Android-Doze 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44079858/

相关文章:

java - Android WebView 加载速度太慢

安卓: Canvas 不缩放

iOS 13 - 未实例化 CBCentralManager 的蓝牙 radio 状态

android - 如何更改选项卡布局中所选选项卡的形状?

javascript - Canvas .toDataURL() 返回部分损坏的图像

python - Mac OS 上的 pybluez 安装错误

ios - CoreBluetooth 广告未启动

html - 如何在 div "container"(950px) 上填充 div 的背景色

python - 检查窗口是否在后台 Tkinter

android - 更改 Actionbar 溢出的样式