简体   繁体   English

配对/绑定的蓝牙设备能否唤醒 Oreo 或更高版本的 Android 设备

[英]Can a paired/bonded bluetooth device wake an Oreo or higher Android device

I have a security system where moving a Bluetooth LE device causes my android application to do some work.我有一个安全系统,移动蓝牙 LE 设备会导致我的 android 应用程序执行一些工作。 After some of the newer Android updates, I believe API 26, I could no longer get these updates if the Android device's screen was off.在一些较新的 Android 更新后,我相信 API 26,如果 Android 设备的屏幕关闭,我将无法再获得这些更新。 I was trying to think of a way around this and came up with an idea:我试图想办法解决这个问题并想出了一个主意:

What if I paired the Android device and the Bluetooth device - would this allow for the message to be received when the Android screen is off?如果我将 Android 设备与蓝牙设备配对会怎么样 - 这是否允许在 Android 屏幕关闭时接收消息?

Previously, all my BLE devices were part of a mesh, so I would regularly have the Android app check for changes in the mesh and turn the screen on to notify the user if needed.以前,我所有的 BLE 设备都是网格的一部分,所以我会定期让 Android 应用程序检查网格中的变化,并在需要时打开屏幕通知用户。 Now, because of the background execution limits introduced, I must require the Android device to have the screen on at all times, which leads to the death of display over time.现在由于引入了后台执行限制,我必须要求Android设备一直亮着屏幕,这导致显示时间一长就死了。

I'm not that great at programming in C, which is the language the BLE chips are programmed in, so I wanted to ask this first before spending hours just to see this NOT work.我不太擅长 C 的编程,这是 BLE 芯片的编程语言,所以我想先问这个,然后再花几个小时才发现这不起作用。 So, just to repeat the question: Will having a BLE device paired with the Android device allow a message through these restrictions when the Android screen is off?那么,重复一下这个问题:当 Android 屏幕关闭时,将 BLE 设备与 Android 设备配对是否允许通过这些限制发送消息?

If not - is there a way I can make this work?如果没有 - 有什么办法可以让这项工作成功吗?

Thank you for any info!感谢您提供任何信息!

  1. Use notifications instead of advertisements.使用通知而不是广告。 This will deliver data instantly and works even if the screen is off.这将立即传送数据,即使屏幕关闭也能正常工作。 Newer versions of Android have introduced more restrictions for BLE scanning when the screen is off. Android 的较新版本在屏幕关闭时对 BLE 扫描引入了更多限制。

  2. Use connectGatt with autoConnect set to true to automatically connect and reconnect in case the connection drops.使用connectGatt并将autoConnect设置为 true 以自动连接并在连接断开时重新连接。

  3. Use a Foreground Service in your app process to prevent the app process from being killed.在您的应用程序进程中使用前台服务以防止应用程序进程被终止。 If your app process exits, all Bluetooth connections are dropped as well.如果您的应用程序进程退出,所有蓝牙连接也会断开。

  4. You could use CompanionDeviceManager to gain some extra permissions.您可以使用 CompanionDeviceManager 获得一些额外的权限。

You don't really need to be paired but it has some benefits such as faster connection setup and correctly remembering the address type (flaw in the API that this is missing).您实际上并不需要配对,但它有一些好处,例如更快的连接设置和正确记住地址类型(API 中缺少的缺陷)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM