BLE 4.0 getting the broadcast data from device to phone

后端 未结 2 1897
Happy的楠姐
Happy的楠姐 2020-12-11 08:55

\"enter

I have two devices. one Android phone with API level more than 18 and other is

2条回答
  •  心在旅途
    2020-12-11 09:23

    Two things I see that you should be doing.

    1. BluetoothGatt has its own setCharacteristicNotification method. In addition to writing the characteristic descriptor to enable notifications, you need to call that method to enable notifications. Think of it as writing the descriptor enables notifications on the BLE device and setCharacteristicNotification enables it on the Android device.

    So in your setCharacteristicNotification method above I would add the following:

    // I'm assuming you have access to the BluetoothGatt object in your BluetoothGattService object
    gatt.setCharacteristicNotification(characteristic, true);
    
    1. You shouldn't be trying to write any data to the characteristic until you have received confirmation that the descriptor was written. That means you need to wait until you get the callback to onDescriptorWrite in your implementation of BluetoothGattCallback.

提交回复
热议问题