Android:从未收到BLE Gatt通知

时间:2018-10-29 09:24:56

标签: javascript android bluetooth-lowenergy android-notifications gatt

使用的设备:Galaxy S9,Android 8.0。

连接工作正常,但从未调用我的回调onCharacteristicChangedMethod。但是,我已经使用setCharacteristicNotification(char, true)注册了通知。特征通知代码:

mBluetoothGatt.setCharacteristicNotification(characteristic, true);
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor);

特性配置。 UUID是00002902-0000-1000-8000-00805f9b34fb

权限已添加到Android清单:

<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

我已阅读到我需要显式声明broadcastReceiver,并在日志中观察以下消息:

W/BroadcastQueue: Background execution not allowed: receiving Intent

这是问题吗?如果是的话,我将如何明确声明此接收者?

1 个答案:

答案 0 :(得分:0)

由于在动态声明broadcastReceiver时没有关闭该问题,因此已解决了有关后台执行(原始查询)的问题。