I would like to detect if the current users phone has a hardware keyboard or only a on-screen keyboard. Is this possible with the SDK?
Asked
Active
Viewed 1,769 times
1 Answers
16
Yes, you can.
Fetch the Configuration object using
Configuration config = getResources().getConfiguration();
...and then look at the keyboard
field.
If they value of keyboard
is not KEYBOARD_NOKEYS, the user has a hardware keyboard.
Note that as @Carl says in his comment below, the user may attach a USB keyboard at any point while your app is running, causing the value of keyboard
to change.
-
1While it is true that the user DOES have a hardware keyboard if config.keyboard is NOT KEYBOARD_NOKEYS, it should be noted that a device may report KEYBOARD_NOKEYS, but then have an external USB keyboard attached to it and report KEYBOARD_QWERTY, all while your app is running. At least, I have a GTablet running CyanogenMod 7.0.3-Harmony / Android 2.3.3 that does exactly that. And also, it is possible that the value of keyboard, when not KEYBOARD_NOKEYS, is KEYBOARD_12KEY, rather than KEYBOARD_QWERTY, so if the type of keyboard is important to you, you may want to test for these specifically. – Carl Aug 20 '12 at 10:31
-
@Carl - updated to include the point re: keyboards being attached mid-execution of the app. Thanks. – razlebe Aug 20 '12 at 10:38