java - 当 BLE 设备特性的某个值在 Android 上发生变化时如何通知用户?
问题描述
想问一下BLE设备在改变特定的特征值时如何得到通知?例如,当电池电量达到 50% 时,我想收到通知,它达到了具体的 50%,而不是每一个百分比移动。
我希望这显然发生在背景上。
非常感谢。
更新。这是我读取特征的代码
override fun onCharacteristicRead(gatt: BluetoothGatt?, characteristic: BluetoothGattCharacteristic?, status: Int) {
super.onCharacteristicRead(gatt, characteristic, status)
bluetoothGatt = gatt
var charValue = characteristic?.value
var decode = charValue?.toString(Charset.defaultCharset())
Log.d("onCharacteristicRead", "Hits here: ${bluetoothGatt?.device} $decode ${charValue?.first()?.toInt()}")}
解决方案
推荐阅读
- python - 如何处理 Selenium 中的侧窗格
- react-native - 请求失败,状态码为 429 - react-native,redux-saga,axios
- delphi - Delphi 中是否有排序集合,例如 C++ 的 std::set?
- css - NativeScript 8 未将 SCSS 编译为 CSS
- ios - 在 Swift 中以编程方式同时在同一个 SVG 上应用 2 种不同的颜色
- perl - 如何在 perl 的相同列上重写文本文件?
- ios - Extern ARSCNView 反应原生
- reactjs - 无法对未安装的组件执行 React 状态更新 2021
- c# - 如何测试 PayBySquare 标准二维码
- three.js - 三个 js XRMediaBinding ( webXR ) - 如何在 equirectLayer 上添加自定义片段着色器?