Search code examples
androidbluetoothandroid-bluetoothhidinput-devices

connect to HID keyboard device as input device in android pragmatically




I have HID BLE keyboard which normally when I want to connect to it in android os environment, I go to Bluetooth page, search for it then tap on keyboard name and connect to it.
now I want to know that can I write an app that automatically finds the device and then connect to it as an input device or not?

I'm already read the documents about BLE communication in Android, but none of them does not explain how to connect HID keyboard as an input device looks like android itself connect to it.


Solution

  • No the public API does not allow you to activate the "use as only device" switch shown in the Android Bluetooth Settings UI.

    However up to Nougat you can do it with Reflection. Just read the source code of the Settings app and do the same thing.