6

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?

razlebe
  • 7,134
  • 6
  • 42
  • 57
Bryan
  • 115
  • 1
  • 4

1 Answers1

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.

Community
  • 1
  • 1
razlebe
  • 7,134
  • 6
  • 42
  • 57
  • 1
    While 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