【问题标题】:Minimal Bluetooth Keyboard on AndroidAndroid 上的最小蓝牙键盘
【发布时间】:2023-02-13 17:19:41
【问题描述】:

我正在尝试使用 GATT 为 Android 编写蓝牙键盘的最小实现。那里有很多例子,但仍然缺少一些东西。该设备连接到我的 Windows 机器。然后读取 GATT 数据库:

onCharacteristicReadRequest: 00002a50-0000-1000-8000-00805f9b34fb, id: 7, offset: 0, data: 02 00 00 00 00 00 00 
onCharacteristicReadRequest: 00002a4a-0000-1000-8000-00805f9b34fb, id: 8, offset: 0, data: 01 11 00 02 
onCharacteristicReadRequest: 00002a4d-0000-1000-8000-00805f9b34fb, id: 9, offset: 0, data: 00 00
onDescriptorReadRequest: 00002908-0000-1000-8000-00805f9b34fb, id: 10, offset: 0, data: 00 01 
onDescriptorReadRequest: 00002902-0000-1000-8000-00805f9b34fb, id: 11, offset: 0, data: 00 00
onCharacteristicReadRequest: 00002a4b-0000-1000-8000-00805f9b34fb, id: 12, offset: 0, data: 05 0c 09 01 a1 01 05 07 15 00 25 01 75 01 95 08 09 e0 09 e1 09 e2 09 e3 09 e4 09 e5 09 e6 09 e7 81 02 05 07 95 01 75 08 15 04 25 df 19 04 29 df 81 00 c0 
onDescriptorReadRequest: 00002907-0000-1000-8000-00805f9b34fb, id: 13, offset: 0, data: 2a 4d
onDescriptorWriteRequest: 00002902-0000-1000-8000-00805f9b34fb, id: 18, offset: 0, data: 01 00

之后,我尝试按如下方式发送键 H 的击键:

public void sendTestNotification(BluetoothDevice device) {
        BluetoothGattCharacteristic report = gattServer.getService(UUID.fromString(HID_SERVICE)).getCharacteristic(
                UUID.fromString(BtConstants.REPORT_CHARACTERISTIC));
        byte[] data = {0x0, 0xB};
        report.setValue(data);
        // (permission check - omitted)
        gattServer.notifyCharacteristicChanged(device, report, true);
    }

但是没有任何反应。

GATT 配置明显有问题吗?

【问题讨论】:

    标签: android bluetooth-gatt


    【解决方案1】:

    我在这里使用的方法是从头开始构建 GATT 数据库并手动添加不同的特征。我仍然不能说这里出了什么问题,但是更好的方法是使用 HID 配置文件。您仍然需要处理 Report Map Characteristic,但这是本例中唯一的障碍。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-08
      • 1970-01-01
      • 1970-01-01
      • 2018-09-15
      • 1970-01-01
      • 1970-01-01
      • 2015-11-23
      • 2011-12-17
      相关资源
      最近更新 更多