AndroidBLE:onDescriptorWrite,onCharacteristicWrite,onCharacteristicReadnonearebeingcalled,butothercallbackswork
创始人
2024-10-06 12:03:50
0

可能是由于GattCallback注册了不同的UUID导致,建议检查Descriptor UUID、Characteristic UUID和Service UUID是否与设备的UUID匹配。此外,也可以尝试使用BluetoothGatt#readCharacteristic(BluetoothGattCharacteristic)和BluetoothGatt#writeCharacteristic(BluetoothGattCharacteristic)直接读写特征值并检查是否会触发相应的回调。以下是一个示例代码:

private BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
    @Override
    public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
        // ...
    }

    @Override
    public void onServicesDiscovered(BluetoothGatt gatt, int status) {
        if (status == BluetoothGatt.GATT_SUCCESS) {
            List services = gatt.getServices();
            for (BluetoothGattService service : services) {
                Log.d(TAG, "getService(): " + service.getUuid());
                List characteristics = service.getCharacteristics();
                for (BluetoothGattCharacteristic characteristic : characteristics) {
                    Log.d(TAG, "getCharcteristic(): " + characteristic.getUuid());
                    List descriptors = characteristic.getDescriptors();
                    for (BluetoothGattDescriptor descriptor : descriptors) {
                        Log.d(TAG, "getDescriptor(): " + descriptor.getUuid());
                    }
                }
            }
        }
    }

    @Override
    public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
        // ...
    }

    @Override
    public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
        // ...
    }

    @Override
    public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
        // ...
    }

    @Override
    public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
        // ...
    }
};

// 读取特征值
BluetoothGattCharacteristic characteristic = gatt.getService(serviceUuid)
    .getCharacteristic(characteristicUuid);
gatt.readCharacteristic(characteristic);

// 写入特征值
BluetoothGattCharacteristic characteristic = gatt.getService(serviceUuid)
    .getCharacteristic(characteristicUuid);
characteristic.setValue(value);
gatt.writeCharacteristic(characteristic);

相关内容

热门资讯

第6分钟开挂!葫芦娃七子连心攻... 第6分钟开挂!葫芦娃七子连心攻略,飞驰娱乐科技软件,曝光教程-2026最新版本葫芦娃七子连心攻略辅助...
此事引发网友热议!关春天辅助凑... 关春天辅助凑一桌 无需打开直接搜索微信:136704302本司针对手游进行,选择我们的四大理由: 1...
七分钟开挂!蜀山手游全自动辅助... 七分钟开挂!蜀山手游全自动辅助,边锋老友内蒙古辅助,2025新版-2026最新版本一、边锋老友内蒙古...
有了最新消息!亲友圈辅助吧(辅... 有了最新消息!亲友圈辅助吧(辅助挂)一直是有挂的(有挂学习)-哔哩哔哩您好:亲友圈辅助吧这款游戏可以...
9分钟开挂!哥哥打大a辅助工具... 9分钟开挂!哥哥打大a辅助工具,榕城510k有没有挂,微扑克教程-2026最新版本1、哥哥打大a辅助...
在玩家背景下!乐易四川麻将辅助... 您好:这款乐易四川麻将辅助游戏是可以开挂的,确实是有挂的,很多玩家在这款乐易四川麻将辅助游戏中打牌都...
第九分钟开挂!传送屋辅助脚本,... 第九分钟开挂!传送屋辅助脚本,广西友乐软件辅助,扑克教程-2026最新版本1)广西友乐软件辅助辅助挂...
现有关情况通报如下!九酷众娱辅... 【亲,九酷众娱辅助 这款游戏可以开挂的,确实是有挂的,很多玩家在这款九酷众娱辅助中打牌都会发现很多用...
第3分钟开挂!顺欣茶楼辅助视频... 第3分钟开挂!顺欣茶楼辅助视频,天天飞小鸡辅助,辅助教程-2026最新版本;顺欣茶楼辅助视频是一种具...
据目击者称!微信小程序辅助器脚... 大家好,今天小编来为大家解答微信小程序辅助器脚本这个问题咨询软件客服可以免费测试直接加微信(1367...