This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

【求助】怎样取得GATT_Notification发出来的message内的数据



如题,GATT_Notification的parameter2(attHandleValueNoti_t),设定的值(attHandleValueNoti_t.value),在android蓝牙中怎么接收呢?

我用BluetoothGatt的setCharacteristicNotification设定该character的notification为enable后,
在onCharacteristicChanged时用BluetoothGattCharacteristic.getValue取似乎不对,是不是有另外的方式取得这个数据

望不吝赐教!!!

  • 爱德华,

    类似如下

  • thx yan

    您这程序是不是【ti-sensortag-android-master】,我看了一下代码。

    源头还是在

    public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    broadcastUpdate(ACTION_DATA_NOTIFY,characteristic,BluetoothGatt.GATT_SUCCESS);
    }

      -》

    private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic, final int status) {
    final Intent intent = new Intent(action);
    intent.putExtra(EXTRA_UUID, characteristic.getUuid().toString());
    intent.putExtra(EXTRA_DATA, characteristic.getValue());
    intent.putExtra(EXTRA_STATUS, status);
    sendBroadcast(intent);
    mBusy = false;
    }

    所以,还是从 characteristic.getValue()得到的,我现在的蓝牙芯片内的值大概是

     0xf0 0xff 00x2 xx
    四个字节,但是这个characteristic的value的属性是float型的,这个属性是芯片内设定的,还是android下能指定?
    不管怎样,这个value现在取上来永远是芯片初始化时的0x03,但是在usb dongle时,能够正常取到那4个字节。不知哪里有问题,望赐教。