Discussion:
Detect connected Bluetooth keyboard under Android
(too old to reply)
Roman Wüger
2018-10-29 22:37:32 UTC
Permalink
Hi @all,

i played with the QBluetoothLocalDevice and QBluetoothDiscoveryAgent to detected if a Bluetooth keyboard is connected to an android tablet.

However, I can’t find out the correct way. I tried to read the majordeviceclass and minordeviceclass but it doesn‘t work, I only get 31,0 but the documentation says that 5 should be the major device class. The keyboard works in any input fields, but I can‘t find it.

I only need a signal if a keyboard connects/disconnects like hardwareKeyboardConnected(bool)

What do I need for that?

Thanks in advance
Alex Blasche
2018-10-30 07:24:12 UTC
Permalink
As a disclaimer I have not really done any HID work on Android, but based on the Android docs you need to use the BluetoothHidDevice class to interact with such keyboards. BluetoothHidDevice.Callback.onConnectionStateChanged is probably what you need.

This Android API is not available via Qt APIs. QBluetoothLocalDevice is for the local Bluetooth device which is not the remote Bluetooth keyboard and HID connects/disconnects cannot be done programmatically by design. The user has to make the connection manually. Therefore I am assuming the platform does not expose such devices via the usual discovery mechanisms either. You have to write your own Java/JNI code to interact with the class.

--
Alex

________________________________________
From: Interest <interest-bounces+alexander.blasche=***@qt-project.org> on behalf of Roman Wüger <***@gmx.at>
Sent: Monday, 29 October 2018 11:37:32 PM
To: Qt Project MailingList
Subject: [Interest] Detect connected Bluetooth keyboard under Android

Hi @all,

i played with the QBluetoothLocalDevice and QBluetoothDiscoveryAgent to detected if a Bluetooth keyboard is connected to an android tablet.

However, I can’t find out the correct way. I tried to read the majordeviceclass and minordeviceclass but it doesn‘t work, I only get 31,0 but the documentation says that 5 should be the major device class. The keyboard works in any input fields, but I can‘t find it.

I only need a signal if a keyboard connects/disconnects like hardwareKeyboardConnected(bool)

What do I need for that?

Thanks in advance
Roman Wüger
2018-11-01 09:58:21 UTC
Permalink
Hi Alex,
thanks for the hint. My plan was that the user should pair and connect the keyboard manually in the settings dialog. In the application i only want to know if a keyboard is connected, otherwise I will show an onscreen keyboard.

Thanks

Regards
Roman


> Am 30.10.2018 um 08:24 schrieb Alex Blasche <***@qt.io>:
>
> As a disclaimer I have not really done any HID work on Android, but based on the Android docs you need to use the BluetoothHidDevice class to interact with such keyboards. BluetoothHidDevice.Callback.onConnectionStateChanged is probably what you need.
>
> This Android API is not available via Qt APIs. QBluetoothLocalDevice is for the local Bluetooth device which is not the remote Bluetooth keyboard and HID connects/disconnects cannot be done programmatically by design. The user has to make the connection manually. Therefore I am assuming the platform does not expose such devices via the usual discovery mechanisms either. You have to write your own Java/JNI code to interact with the class.
>
> --
> Alex
>
> ________________________________________
> From: Interest <interest-bounces+alexander.blasche=***@qt-project.org> on behalf of Roman Wüger <***@gmx.at>
> Sent: Monday, 29 October 2018 11:37:32 PM
> To: Qt Project MailingList
> Subject: [Interest] Detect connected Bluetooth keyboard under Android
>
> Hi @all,
>
> i played with the QBluetoothLocalDevice and QBluetoothDiscoveryAgent to detected if a Bluetooth keyboard is connected to an android tablet.
>
> However, I can’t find out the correct way. I tried to read the majordeviceclass and minordeviceclass but it doesn‘t work, I only get 31,0 but the documentation says that 5 should be the major device class. The keyboard works in any input fields, but I can‘t find it.
>
> I only need a signal if a keyboard connects/disconnects like hardwareKeyboardConnected(bool)
>
> What do I need for that?
>
> Thanks in advance
> _______________________________________________
> Interest mailing list
> ***@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
> _______________________________________________
> Interest mailing list
> ***@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
Jérôme Godbout
2018-11-01 18:07:22 UTC
Permalink
There is no way yet to achieve that, at least that I know of, the only thing you can do is monitor the space and dimension to see if the virtual keyboard is displayed. The Android OS will display the soft keyboard or not on his own. You can only try to monitor to see if any changes on size have occurred and you can assume it's for a keyboard. More info can be found over here:
https://stackoverflow.com/questions/2150078/how-to-check-visibility-of-software-keyboard-in-android
https://groups.google.com/forum/#!topic/android-platform/FyjybyM0wGA

It's really sad this cannot be easily monitored.

-----Original Message-----
From: Interest <interest-bounces+godboutj=***@qt-project.org> On Behalf Of Roman Wüger
Sent: November 1, 2018 5:58 AM
To: Alex Blasche <***@qt.io>
Cc: Qt Project MailingList <***@qt-project.org>
Subject: Re: [Interest] Detect connected Bluetooth keyboard under Android

Hi Alex,
thanks for the hint. My plan was that the user should pair and connect the keyboard manually in the settings dialog. In the application i only want to know if a keyboard is connected, otherwise I will show an onscreen keyboard.

Thanks

Regards
Roman


> Am 30.10.2018 um 08:24 schrieb Alex Blasche <***@qt.io>:
>
> As a disclaimer I have not really done any HID work on Android, but based on the Android docs you need to use the BluetoothHidDevice class to interact with such keyboards. BluetoothHidDevice.Callback.onConnectionStateChanged is probably what you need.
>
> This Android API is not available via Qt APIs. QBluetoothLocalDevice is for the local Bluetooth device which is not the remote Bluetooth keyboard and HID connects/disconnects cannot be done programmatically by design. The user has to make the connection manually. Therefore I am assuming the platform does not expose such devices via the usual discovery mechanisms either. You have to write your own Java/JNI code to interact with the class.
>
> --
> Alex
>
> ________________________________________
> From: Interest <interest-bounces+alexander.blasche=***@qt-project.org> on behalf of Roman Wüger <***@gmx.at>
> Sent: Monday, 29 October 2018 11:37:32 PM
> To: Qt Project MailingList
> Subject: [Interest] Detect connected Bluetooth keyboard under Android
>
> Hi @all,
>
> i played with the QBluetoothLocalDevice and QBluetoothDiscoveryAgent to detected if a Bluetooth keyboard is connected to an android tablet.
>
> However, I can’t find out the correct way. I tried to read the majordeviceclass and minordeviceclass but it doesn‘t work, I only get 31,0 but the documentation says that 5 should be the major device class. The keyboard works in any input fields, but I can‘t find it.
>
> I only need a signal if a keyboard connects/disconnects like hardwareKeyboardConnected(bool)
>
> What do I need for that?
>
> Thanks in advance
> _______________________________________________
> Interest mailing list
> ***@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
> _______________________________________________
> Interest mailing list
> ***@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

_______________________________________________
Interest mailing list
***@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
Roman Wüger
2018-11-03 07:45:23 UTC
Permalink
@Alex: i tried your suggestion but the problem is that the BluetoothHIDDevice class was introduced in API level 28, but I need Level 24.

Maybe this can be done differently with Java?

Regards
Roman

> Am 01.11.2018 um 19:07 schrieb Jérôme Godbout <***@amotus.ca>:
>
> There is no way yet to achieve that, at least that I know of, the only thing you can do is monitor the space and dimension to see if the virtual keyboard is displayed. The Android OS will display the soft keyboard or not on his own. You can only try to monitor to see if any changes on size have occurred and you can assume it's for a keyboard. More info can be found over here:
> https://stackoverflow.com/questions/2150078/how-to-check-visibility-of-software-keyboard-in-android
> https://groups.google.com/forum/#!topic/android-platform/FyjybyM0wGA
>
> It's really sad this cannot be easily monitored.
>
> -----Original Message-----
> From: Interest <interest-bounces+godboutj=***@qt-project.org> On Behalf Of Roman Wüger
> Sent: November 1, 2018 5:58 AM
> To: Alex Blasche <***@qt.io>
> Cc: Qt Project MailingList <***@qt-project.org>
> Subject: Re: [Interest] Detect connected Bluetooth keyboard under Android
>
> Hi Alex,
> thanks for the hint. My plan was that the user should pair and connect the keyboard manually in the settings dialog. In the application i only want to know if a keyboard is connected, otherwise I will show an onscreen keyboard.
>
> Thanks
>
> Regards
> Roman
>
>
>> Am 30.10.2018 um 08:24 schrieb Alex Blasche <***@qt.io>:
>>
>> As a disclaimer I have not really done any HID work on Android, but based on the Android docs you need to use the BluetoothHidDevice class to interact with such keyboards. BluetoothHidDevice.Callback.onConnectionStateChanged is probably what you need.
>>
>> This Android API is not available via Qt APIs. QBluetoothLocalDevice is for the local Bluetooth device which is not the remote Bluetooth keyboard and HID connects/disconnects cannot be done programmatically by design. The user has to make the connection manually. Therefore I am assuming the platform does not expose such devices via the usual discovery mechanisms either. You have to write your own Java/JNI code to interact with the class.
>>
>> --
>> Alex
>>
>> ________________________________________
>> From: Interest <interest-bounces+alexander.blasche=***@qt-project.org> on behalf of Roman Wüger <***@gmx.at>
>> Sent: Monday, 29 October 2018 11:37:32 PM
>> To: Qt Project MailingList
>> Subject: [Interest] Detect connected Bluetooth keyboard under Android
>>
>> Hi @all,
>>
>> i played with the QBluetoothLocalDevice and QBluetoothDiscoveryAgent to detected if a Bluetooth keyboard is connected to an android tablet.
>>
>> However, I can’t find out the correct way. I tried to read the majordeviceclass and minordeviceclass but it doesn‘t work, I only get 31,0 but the documentation says that 5 should be the major device class. The keyboard works in any input fields, but I can‘t find it.
>>
>> I only need a signal if a keyboard connects/disconnects like hardwareKeyboardConnected(bool)
>>
>> What do I need for that?
>>
>> Thanks in advance
>> _______________________________________________
>> Interest mailing list
>> ***@qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>> _______________________________________________
>> Interest mailing list
>> ***@qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>
> _______________________________________________
> Interest mailing list
> ***@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
Alex Blasche
2018-11-05 08:57:44 UTC
Permalink
Hi Roman,

I am not aware of any other API. The only reference I can find is pointing the BluetoothHIDDevice. I'd say this feature is simply not available for any earlier devices. Of course you can always use reflection via e.g. QtAndroidExtras to add conditional support for this feature to your application. You would guard it behind a runtime version check similar to

http://code.qt.io/cgit/qt/qtconnectivity.git/tree/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp#n216

--
Alex

________________________________________
From: Roman Wüger <***@gmx.at>
Sent: Saturday, 3 November 2018 8:45:23 AM
To: Jérôme Godbout
Cc: Alex Blasche; Qt Project MailingList
Subject: Re: [Interest] Detect connected Bluetooth keyboard under Android

@Alex: i tried your suggestion but the problem is that the BluetoothHIDDevice class was introduced in API level 28, but I need Level 24.

Maybe this can be done differently with Java?

Regards
Roman

> Am 01.11.2018 um 19:07 schrieb Jérôme Godbout <***@amotus.ca>:
>
> There is no way yet to achieve that, at least that I know of, the only thing you can do is monitor the space and dimension to see if the virtual keyboard is displayed. The Android OS will display the soft keyboard or not on his own. You can only try to monitor to see if any changes on size have occurred and you can assume it's for a keyboard. More info can be found over here:
> https://stackoverflow.com/questions/2150078/how-to-check-visibility-of-software-keyboard-in-android
> https://groups.google.com/forum/#!topic/android-platform/FyjybyM0wGA
>
> It's really sad this cannot be easily monitored.
>
> -----Original Message-----
> From: Interest <interest-bounces+godboutj=***@qt-project.org> On Behalf Of Roman Wüger
> Sent: November 1, 2018 5:58 AM
> To: Alex Blasche <***@qt.io>
> Cc: Qt Project MailingList <***@qt-project.org>
> Subject: Re: [Interest] Detect connected Bluetooth keyboard under Android
>
> Hi Alex,
> thanks for the hint. My plan was that the user should pair and connect the keyboard manually in the settings dialog. In the application i only want to know if a keyboard is connected, otherwise I will show an onscreen keyboard.
>
> Thanks
>
> Regards
> Roman
>
>
>> Am 30.10.2018 um 08:24 schrieb Alex Blasche <***@qt.io>:
>>
>> As a disclaimer I have not really done any HID work on Android, but based on the Android docs you need to use the BluetoothHidDevice class to interact with such keyboards. BluetoothHidDevice.Callback.onConnectionStateChanged is probably what you need.
>>
>> This Android API is not available via Qt APIs. QBluetoothLocalDevice is for the local Bluetooth device which is not the remote Bluetooth keyboard and HID connects/disconnects cannot be done programmatically by design. The user has to make the connection manually. Therefore I am assuming the platform does not expose such devices via the usual discovery mechanisms either. You have to write your own Java/JNI code to interact with the class.
>>
>> --
>> Alex
>>
>> ________________________________________
>> From: Interest <interest-bounces+alexander.blasche=***@qt-project.org> on behalf of Roman Wüger <***@gmx.at>
>> Sent: Monday, 29 October 2018 11:37:32 PM
>> To: Qt Project MailingList
>> Subject: [Interest] Detect connected Bluetooth keyboard under Android
>>
>> Hi @all,
>>
>> i played with the QBluetoothLocalDevice and QBluetoothDiscoveryAgent to detected if a Bluetooth keyboard is connected to an android tablet.
>>
>> However, I can’t find out the correct way. I tried to read the majordeviceclass and minordeviceclass but it doesn‘t work, I only get 31,0 but the documentation says that 5 should be the major device class. The keyboard works in any input fields, but I can‘t find it.
>>
>> I only need a signal if a keyboard connects/disconnects like hardwareKeyboardConnected(bool)
>>
>> What do I need for that?
>>
>> Thanks in advance
>> _______________________________________________
>> Interest mailing list
>> ***@qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>> _______________________________________________
>> Interest mailing list
>> ***@qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>
> _______________________________________________
> Interest mailing list
> ***@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
Roman Wüger
2018-11-26 12:19:07 UTC
Permalink
Thanks for the hints.

I found the solution in https://stackoverflow.com/questions/2415558/how-to-detect-hardware-keyboard-presence

in combination with QJNI

Regards
RomN

> Am 01.11.2018 um 19:07 schrieb JérÎme Godbout <***@amotus.ca>:
>
> There is no way yet to achieve that, at least that I know of, the only thing you can do is monitor the space and dimension to see if the virtual keyboard is displayed. The Android OS will display the soft keyboard or not on his own. You can only try to monitor to see if any changes on size have occurred and you can assume it's for a keyboard. More info can be found over here:
> https://stackoverflow.com/questions/2150078/how-to-check-visibility-of-software-keyboard-in-android
> https://groups.google.com/forum/#!topic/android-platform/FyjybyM0wGA
>
> It's really sad this cannot be easily monitored.
>
> -----Original Message-----
> From: Interest <interest-bounces+godboutj=***@qt-project.org> On Behalf Of Roman WÃŒger
> Sent: November 1, 2018 5:58 AM
> To: Alex Blasche <***@qt.io>
> Cc: Qt Project MailingList <***@qt-project.org>
> Subject: Re: [Interest] Detect connected Bluetooth keyboard under Android
>
> Hi Alex,
> thanks for the hint. My plan was that the user should pair and connect the keyboard manually in the settings dialog. In the application i only want to know if a keyboard is connected, otherwise I will show an onscreen keyboard.
>
> Thanks
>
> Regards
> Roman
>
>
>> Am 30.10.2018 um 08:24 schrieb Alex Blasche <***@qt.io>:
>>
>> As a disclaimer I have not really done any HID work on Android, but based on the Android docs you need to use the BluetoothHidDevice class to interact with such keyboards. BluetoothHidDevice.Callback.onConnectionStateChanged is probably what you need.
>>
>> This Android API is not available via Qt APIs. QBluetoothLocalDevice is for the local Bluetooth device which is not the remote Bluetooth keyboard and HID connects/disconnects cannot be done programmatically by design. The user has to make the connection manually. Therefore I am assuming the platform does not expose such devices via the usual discovery mechanisms either. You have to write your own Java/JNI code to interact with the class.
>>
>> --
>> Alex
>>
>> ________________________________________
>> From: Interest <interest-bounces+alexander.blasche=***@qt-project.org> on behalf of Roman WÃŒger <***@gmx.at>
>> Sent: Monday, 29 October 2018 11:37:32 PM
>> To: Qt Project MailingList
>> Subject: [Interest] Detect connected Bluetooth keyboard under Android
>>
>> Hi @all,
>>
>> i played with the QBluetoothLocalDevice and QBluetoothDiscoveryAgent to detected if a Bluetooth keyboard is connected to an android tablet.
>>
>> However, I can’t find out the correct way. I tried to read the majordeviceclass and minordeviceclass but it doesn‘t work, I only get 31,0 but the documentation says that 5 should be the major device class. The keyboard works in any input fields, but I can‘t find it.
>>
>> I only need a signal if a keyboard connects/disconnects like hardwareKeyboardConnected(bool)
>>
>> What do I need for that?
>>
>> Thanks in advance
>> _______________________________________________
>> Interest mailing list
>> ***@qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>> _______________________________________________
>> Interest mailing list
>> ***@qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>
> _______________________________________________
> Interest mailing list
> ***@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
Continue reading on narkive:
Loading...