Programatically establish serverless bluetooth connection with computer

I made an app to turn my phone (LGV20) into a PC keyboard using Android Bluetooth. I'm trying to remove the PC server code by getting my app to pair my phone as a keyboard instead of a phone.

The only app I found that doesn't require a PC setup or rooting is Blek. It seems that when you turn the app on it tries to pair your phone as a keyboard like I want. However, I can't figure out how they did it. I imagine they did something like this:

public class MyBluetoothAdapter extends BluetoothAdapter {
    private static final String DEVICE_PAIR_TYPE = "Keyboard"

That's not a real variable in BluetoothAdapter but I imagine something like this was used.

1 answer

  • answered 2018-02-13 01:24 Morrison Chang

    The hint should be when you looked at the app's description:

    The receiver device must have Bluetooth 4.0 ....

    So a search shows that among the many GATT specifications:

    There is a HID over GATT profile

    And it appears that each Bluetooth LE chip manufacturer has a keyboard HID over GATT example.

    I suspect that each Bluetooth LE chip SDK has some JNI/C level type stuff to enable keyboard HID over GATT.

    From this SO post: is there any ble api in Ndk

    It looks like lower level Bluetooth access is available but invocation may vary on a chip to chip basis.

    Given that Android allows for a number of different chip vendors, the author of the app you cite may have some of such SDK based code installed but may not work on all devices.

    One open source(ish) implementation that I've found but not tested is:

    which appears to have a min SDK of 21. However the 'secret sauce' is still 'hidden' in an AAR in the author's lib directory.

    So what else can be done?

    1. Find out what Bluetooth Low Energy chipset your device uses. I don't have access to a LGV20 but perhaps something in the logcat will point to a manufacturer.
    2. Once you know the manufacturer and chipset series, see if you can get access to that chipset makers particular Bluetooth Low Energy SDK for any sample code/modules which can enable HID over GATT.
    3. Write app with such code/module with the understanding that you may need to deal with JNI/C.