Android SensorTag: writeDescriptor failed

你。 提交于 2019-12-11 02:18:17

问题


Device for testing:android 4.4

Connection is working fine but the onDescriptorWrite Method of my callback is never called. And the bluetoothGatt and characteristics are got. But when I want to setCharacteristicNotification and writeDescriptor, no callback is recieved, including onDescriptorWrite and onCharacteristicChanged. The notification code is showed as following:

    private static void enableMagnetometerNotifications(BluetoothGatt     bluetoothGatt) {
    UUID magnetServiceUuid = UUID.fromString("f000aa30-0451-4000-b000-000000000000");
    UUID magnetDataUuid = UUID.fromString("f000aa31-0451-4000-b000-000000000000");
    UUID CCC = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
    boolean ok = false;
    boolean notify = false;

    BluetoothGattService magnetService = bluetoothGatt.getService(magnetServiceUuid);
    BluetoothGattCharacteristic magnetDataCharacteristic = magnetService.getCharacteristic(
            magnetDataUuid);
    notify = bluetoothGatt.setCharacteristicNotification(
            magnetDataCharacteristic, true); //Enabled locally

    if (notify){
        BluetoothGattDescriptor config = magnetDataCharacteristic.getDescriptor(CCC);
        List<BluetoothGattDescriptor> cof = magnetDataCharacteristic.getDescriptors();
        for(BluetoothGattDescriptor a: cof  ){
            Log.i("GattDescriptor ",a.getUuid().toString());
        }
        ok = config.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        if(ok){
            mBusy = true;
            bluetoothGatt.writeDescriptor(config); //Enabled remotely
            //delay 300 seconds
            waitIdle(300);
        }
    }

来源:https://stackoverflow.com/questions/31400114/android-sensortag-writedescriptor-failed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!