2

In recent versions of Android it's possible for devices to either have software or hardware buttons. I'd like to find out which is the case for the device my app is running on.

Some background information: It is possible to hide the softkeys as they are displayed on the screen but if you do this they automatically get shown if the user touches the display which is perfectly fine. Now if you do the same on a device with hardware keys the first touch still gets caught by the system like as if it would show the softkeys again but as there are none, nothing happens and the touch event does not get passed to the app.

OldPeculier
  • 11,049
  • 13
  • 50
  • 76
Julian
  • 2,051
  • 2
  • 22
  • 30

2 Answers2

3

You could use ViewConfiguration.hasPermanentMenuKey(), to check for a menu key.

Gubbel
  • 2,327
  • 1
  • 24
  • 35
  • Thank you, this works great. (Just keep in mind that this only works for SDK >= 14) – Julian Jun 03 '12 at 18:59
  • You're right, but I think for lower API levels you can assume the answer. <= 10 should always have hardware buttons and the honeycomb tablets have no physical buttons. – Gubbel Jun 04 '12 at 07:00
  • 1
    this is answer is wrong. documentation says `Report if the device has a permanent menu key available to the user` not that the soft keys are present or not – xedo Jan 29 '15 at 09:52
  • 4
    This does not work on all devices. The galaxy s5 has hardware buttons but no menu key – Darussian Feb 24 '15 at 15:05
  • DON'T use this, rather http://stackoverflow.com/a/16608481/900608 It doesn't work on all the devices out there.. – Damian Walczak Apr 15 '15 at 14:53
0

For the Keyboard-question try

getResources().getConfiguration().keyboard

that gives you one of the following:

  • KEYBOARD_NOKEYS
  • KEYBOARD_QWERTY
  • KEYBOARD_12KEY

check for KEYBOARD_NOKEYS.

libjup
  • 4,019
  • 2
  • 18
  • 23
  • * source: http://developer.android.com/reference/android/content/res/Configuration.html#keyboard – libjup Jun 03 '12 at 16:25
  • Well that's for the keyboard but I need this for the system buttons like back and home which you can see in the red box on this screenshot: http://i.imgur.com/7QiKu.png – Julian Jun 03 '12 at 16:45
  • I'm sorry... Must have misunderstood your question. I just checked the docu but I'm not sure if the Android API provides such a functionality at all. – libjup Jun 03 '12 at 18:02