Android BLE特性getValue没有任何反应?
Android BLE characteristics getValue is no any response?
我正在尝试使用通知属性配置 READ 特征。目前,我可以在 android 具有 READ 和 NOTIFY 属性的应用程序上看到此特征。
这是我设备的 uuid 信息:
UUID info
是的,我需要先通知属性,然后再发送命令,这将是接收值,但是,
事实上,我没有收到任何价值,我什至不知道出了什么问题,这是我的代码:
public void onServicesDiscovered(BluetoothGatt gatt, int status){
if (status == gatt.GATT_SUCCESS){
runOnUiThread(new Runnable(){
public void run() {
BluetoothGattService gattService = gatt.getService(SERVICE_UUID);
if(gattService != null){
BluetoothGattCharacteristic gattCharacteristic = gattService.getCharacteristic(NOTIF_UUID);
if (gattCharacteristic != null ){
for (BluetoothGattDescriptor descriptor : gattCharacteristic.getDescriptors()){
descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
boolean sucess = gatt.writeDescriptor(descriptor);
}
gatt.setCharacteristicNotification(gattCharacteristic, true);
}
characteristic = gattService.getCharacteristic(WRITE_DATA);
if (characteristic != null){
sendCommand(characteristic, gatt); //send command
}
now , I have already send command , and it's return success , because onCharacteristicWrite() has response,
but onCharacteristicRead() and onCharacteristicChanged() is not any response? Why ?
which part I missing?
descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
而不是
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
我正在尝试使用通知属性配置 READ 特征。目前,我可以在 android 具有 READ 和 NOTIFY 属性的应用程序上看到此特征。
这是我设备的 uuid 信息:
UUID info
是的,我需要先通知属性,然后再发送命令,这将是接收值,但是, 事实上,我没有收到任何价值,我什至不知道出了什么问题,这是我的代码:
public void onServicesDiscovered(BluetoothGatt gatt, int status){
if (status == gatt.GATT_SUCCESS){
runOnUiThread(new Runnable(){
public void run() {
BluetoothGattService gattService = gatt.getService(SERVICE_UUID);
if(gattService != null){
BluetoothGattCharacteristic gattCharacteristic = gattService.getCharacteristic(NOTIF_UUID);
if (gattCharacteristic != null ){
for (BluetoothGattDescriptor descriptor : gattCharacteristic.getDescriptors()){
descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
boolean sucess = gatt.writeDescriptor(descriptor);
}
gatt.setCharacteristicNotification(gattCharacteristic, true);
}
characteristic = gattService.getCharacteristic(WRITE_DATA);
if (characteristic != null){
sendCommand(characteristic, gatt); //send command
}
now , I have already send command , and it's return success , because onCharacteristicWrite() has response,
but onCharacteristicRead() and onCharacteristicChanged() is not any response? Why ?
which part I missing?
descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
而不是
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);