简体   繁体   English

Android 上的最小蓝牙键盘

[英]Minimal Bluetooth Keyboard on Android

I am trying to write a minimal implementation of a Bluetooth Keyboard for Android using GATT.我正在尝试使用 GATT 为 Android 编写蓝牙键盘的最小实现。 They are plenty of examples out there, but something is still missing.那里有很多例子,但仍然缺少一些东西。 The device connects to my Windows Machine.该设备连接到我的 Windows 机器。 Then the GATT database is read:然后读取 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

After that I try to send a key stroke of key H as follows:之后,我尝试按如下方式发送键 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);
    }

But nothing happens.但是没有任何反应。

Is something apparently wrong with the GATT configuration? GATT 配置明显有问题吗?

The approach I used here was contstructing a GATT database from scratch and adding different characteristics manually.我在这里使用的方法是从头开始构建 GATT 数据库并手动添加不同的特征。 I still cannot say, that is wrong here, however the better approach is to use HID profile.我仍然不能说,这里是错误的,但是更好的方法是使用 HID 配置文件。 You will still have to deal with the Report Map Characteristic, but it's the only hurdle in this case.您仍然需要处理 Report Map Characteristic,但这是本例中唯一的障碍。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM