我如何在 Android Pie 中使用蓝牙 HID 设备配置文件?

How can i use the Bluetooth HID Device profile in Android Pie?

我正在尝试使用蓝牙 HID 设备配置文件服务为 Android P 编写应用程序以用作蓝牙键盘。根据 documentation 我应该使用方法 BluetoothAdapter.getProfileProxy(Context, BluetoothProfile.ServiceListener, int) 来获取 BluetoothHidDevice 代理对象。

在我的 Android Pie 设备(Nokia 7 plus)上调试期间,服务侦听器从未被调用(onServiceConnected),我在 Logcat 中收到以下错误:

Could not bind to Bluetooth HID Device Service with Intent { act=android.bluetooth.IBluetoothHidDevice }

如果我将上面调用中的最后一个参数从 HID_DEVICE 更改为其他蓝牙配置文件,例如A2DP,服务监听得到回调onServiceConnected,没有报错

  1. 有人在 Android Pie 上创建了有效的 HID_DEVICE 吗?
  2. 能否BluetoothHidDevice用于在Android上创建隐藏设备 馅饼 phone?
  3. 有没有我可以查看的工作代码?
  4. 有什么特点吗(getPackageManager().hasSystemFeature) 在我的 phone?
  5. 中丢失
  6. 出现上述错误的原因可能是什么?

任何提示将不胜感激:)

这似乎是第三方问题。诺基亚未在 Android Pie 中启用隐藏配置文件。我也试过用摩托罗拉G7玩,它也被禁用了,我想是时候像素了...

你可以看看这个 https://github.com/kshoji/BLE-HID-Peripheral-for-Android。 我能够用它构建蓝牙键盘。

目前在 Pixel 上启用了 HID 设备配置文件。据我所知,诺基亚、moto(如上所述)和 One Plus 5T 和 6 不支持此配置文件。

我们创建了一个应用程序,可让您将 phone 用作具有此 HID 设备配置文件的蓝牙鼠标和键盘。 https://play.google.com/store/apps/details?id=com.github.roarappstudio.btkontroller

代码在 https://github.com/raghavk92/Kontroller 开源。如果有人想帮助改进或贡献代码,欢迎他们。

您还可以检查您的 phone 是否支持应用程序的蓝牙 HID 设备配置文件 - https://play.google.com/store/apps/details?id=com.rkaneapplabs.bluetooth_hid.bluetoothproxy 如果他们不支持您的设备,请告知您的设备制造商,因为它是 android 馅饼,应该支持。

具有蓝牙 HID 设备配置文件的设备列表 activated/Not 工作(由于制造商实施错误)在这里 - https://github.com/raghavk92/Android_Bluetooth_HID_Device_Profile_CompatibilityList

错误是由于制造商方面的实施而不是 google 因为像素设备支持此蓝牙 HID 设备配置文件,因为 android pie

此处提供了 semi-official 示例代码:https://github.com/ginkage/wearmouse — actually by Google itself (see https://opensource.google.com/projects/wearmouse)。

它旨在用于 Wear OS 手表,但也具有在 phone 上使用它所需的一切:配置文件的代理 class,回调 class、HID 描述符示例、QoS、主机电池电量查询等情况的回调

该应用程序本身可在 Google 此处播放:https://play.google.com/store/apps/details?id=com.ginkage.wearmouse(顺便说一下,该应用程序也支持 Android 8,但这仅适用于手表,不适用于 phones).