首页 > 解决方案 > Android - 靠近 BLE 设备时收到通知

问题描述

我需要我的应用程序在特定 BLE 设备范围内时收到通知。一旦进入范围,我想连接到设备并向其发送数据。

方法 1:
以某个时间间隔(即每 30 秒)定期进行 BLE 扫描。但是,这对电池不利。我可以通过仅在设备位置靠近 BLE 设备位置时(通过 Android Geofence API)进行扫描来改进这一点。但是,对于电池来说仍然不是很好。

方法 2:
使用 Android Awareness API。这似乎是一个很好的候选人。但是,您似乎被迫向 Google 注册您的 BLE 设备作为 BLE 信标。有谁知道这是否是绝对要求?我不想在 Google 上注册它。

标签: androidbluetooth-lowenergybeacongoogle-awareness

解决方案


你为什么不直接使用https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#connectGatt(android.content.Context,%20boolean,%20android.bluetooth.BluetoothGattCallback,%20int,%20int )与 autoConnect=true?收音机的占空比约为 4%,因此几乎不会消耗任何电池。


推荐阅读