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

3

11

I am trying to write an app for Android P using the Bluetooth HID device profile service to be used as a Bluetooth keyboard. According to the documentation I am supposed to use the method BluetoothAdapter.getProfileProxy(Context, BluetoothProfile.ServiceListener, int) to get the BluetoothHidDevice proxy object.

During debug on my Android Pie device (Nokia 7 plus) the service listener never get called (onServiceConnected), and i get the following error in Logcat:

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

If I change the last param in the call above from HID_DEVICE to some other bluetooth profile e.g. A2DP, the service listener get the callback onServiceConnected and no error is displayed.

  1. Has anyone created a working HID_DEVICE on Android Pie?
  2. Can BluetoothHidDevice be used to create a hid-device on an Android Pie phone?
  3. Is there any working code that i can look at?
  4. Is there some feature (getPackageManager().hasSystemFeature) missing in my phone?
  5. What could be the reason for the error above?

Any hints would be greatly appreciated :)

This seems to be a third-party issue. Nokia did not enable the hid-profile in Android Pie. I also tried with a Mototorola G7 play, it was also disabled, i guess it's time for a pixel...

Hooves answered 30/11, 2018 at 9:54 Comment(8)
I've tried messing around with this with Xposed on Oreo 8.1 (since it's implemented but disabled and hidden), and I also encountered this issue. For me, it was because the service was disabled in the manifest (android:enabled="@bool/profile_supported_hidd" and the bool set to false). I fixed it with setComponentEnabledSettingDahliadahlstrom
I'd really also like to know if using Android as HID device works in Android Pie.. I'd like to use my Pixel 2XL as a game controller programmaticallySocio
I will also put this here.. maybe someone can reach out to author directly to see if he can help provide an answer xda-developers.com/android-p-bluetooth-keyboard-mouseSocio
@Hooves I am also working on making an app for using android as bluetooth keyboard on android pie. If you'd like we can work on this together.I ll let you know if i get any headway on this issue.Kierkegaardian
I have mentioned this as a bug in google issue tracker. You can star it to get it resolved earlier. issuetracker.google.com/issues/125169815 ....You might need to login firstKierkegaardian
As per the google issue tracker this may be a third party issue. I can confirm that on a OnePlus 6 / OxygenOS 9.0.4 the HID device service is still disabled just like the @ralismark's description for Oreo. :(Rieger
I have successfully make a Bluetooth game controller on Oreo by using Xposed to enable the profile. I've explained the details here in my blog. However, in my experience, the connection has been very unstable.Dahliadahlstrom
Hey @userrk and Kim, did you find anything useful the last 2 years? Or are some devices simply not supported?Despain
K
8

Currently on pixel the HID device Profile is enabled . Nokia, moto(as mentioned above) and One Plus 5T and 6 as far as i know dont support this profile.

We have created an app which lets you use your phone as a bluetooth mouse and keyboard with this HID device profile. https://play.google.com/store/apps/details?id=com.github.roarappstudio.btkontroller

The code is open sourced at https://github.com/raghavk92/Kontroller. If anyone wants to help in making improvements or contribute to the code they are welcome.

You can also check if your phone supports Bluetooth HID device profile with the app - https://play.google.com/store/apps/details?id=com.rkaneapplabs.bluetooth_hid.bluetoothproxy and let your device manufacturer know if they dont support your device because its part of android pie and should be supported.

List of devices that have the Bluetooth HID device profile activated/Not Working(due to manufacturer implementation bugs) is here - https://github.com/raghavk92/Android_Bluetooth_HID_Device_Profile_CompatibilityList

The bugs are due to implementation on the manufacturer's side not google as pixel devices support this Bluetooth HID device profile since android pie

Kierkegaardian answered 6/7, 2019 at 20:24 Comment(0)
E
3

There is a semi-official sample code available here: https://github.com/ginkage/wearmouse — actually by Google itself (see https://opensource.google.com/projects/wearmouse).

It is intended for using on Wear OS watches, but has everything you need to use it on a phone as well: proxy class for the profile, a callback class, HID Descriptor example, QoS, callbacks for cases like battery level inquiry from the host, etc.

The app itself is available at Google Play here: https://play.google.com/store/apps/details?id=com.ginkage.wearmouse (the app supports Android 8 as well, by the way, but that only works on watches, not phones).

Encamp answered 21/7, 2019 at 23:59 Comment(0)
C
2

You can have a look at this https://github.com/kshoji/BLE-HID-Peripheral-for-Android . I was able to build a bluetooth keyboard out of this.

Chambertin answered 19/4, 2019 at 21:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.