首页 > 解决方案 > 当 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()}")}

标签: javaandroidandroid-studiokotlin

解决方案


推荐阅读