How to check if a phone has hardware menu button in Android 2.1?

4.2k Views Asked by At

I'm trying to figure out if an Android phone has hardware menu button, I've searched and found this method:

ViewConfiguration.get(getApplicationContext()).hasPermanentMenuKey();

But this doesn't seem to work in Android 2.1, and I'm trying to create an app that works on Android 2.1 and higher. Is it possible to detect if there is an hardware button on a phone with Android version less than 3.0?

3

There are 3 best solutions below

3
On BEST ANSWER

Every compatible 2.1 android device had a menu key as it was part of the CDD:

http://source.android.com/compatibility/2.1/android-2.1-cdd.pdf

See section 8.7:

"The Home, Menu and Back functions are essential to the Android navigation paradigm. Device implementations MUST make these functions available to the user at all times, regardless of application state."

Therefore, if the device is running android 2.1 it's safe to assume it has a menu key. If it's running a later version you can use the API you found.

4
On

hasPermanentMenuKey() was introduced since API Level 14 because from Android 3.0 the devices were allowed not to have a menu key. so I assume that you can safely assume that a 2.1 device will have a menu key. Check the android documentatin on this for more. Android view Configuration hasPermanantMenuKey

1
On

hasPermanentMenuKey() became available at API level 14 (3.0). I would believe it is safe to assume there is a key on devices running below 3.0. Above 3.0 you can call this method to determine if you need to provide an alternative method.