android - Android - 靠近 BLE 设备时收到通知
问题描述
我需要我的应用程序在特定 BLE 设备范围内时收到通知。一旦进入范围,我想连接到设备并向其发送数据。
方法 1:
以某个时间间隔(即每 30 秒)定期进行 BLE 扫描。但是,这对电池不利。我可以通过仅在设备位置靠近 BLE 设备位置时(通过 Android Geofence API)进行扫描来改进这一点。但是,对于电池来说仍然不是很好。
方法 2:
使用 Android Awareness API。这似乎是一个很好的候选人。但是,您似乎被迫向 Google 注册您的 BLE 设备作为 BLE 信标。有谁知道这是否是绝对要求?我不想在 Google 上注册它。
解决方案
你为什么不直接使用https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#connectGatt(android.content.Context,%20boolean,%20android.bluetooth.BluetoothGattCallback,%20int,%20int )与 autoConnect=true?收音机的占空比约为 4%,因此几乎不会消耗任何电池。
推荐阅读
- java - 当应用程序关闭或移动到其他应用程序时重新发送代码停止
- java - 如何在“onException”中设置标题以使其在骆驼路线结束之前可见?
- ios - 未调用 iOS 后台提取
- azure - 配置 Azure DevOps 电子邮件模板
- reactjs - 在 React 中拆分字符串
- spring - Spring Security:不同路径的多个 OpenID Connect 客户端?
- sql - ALTER SESSION over Ms Access Passtrough for Oracle
- angular - 如何在 IONIC 3 的 ion-list 中验证动态离子输入
- android-studio - 如何解决android studio运行时错误?
- python - 尝试在 Django 中提供媒体文件时找不到页面 404 错误