Android: programmatically determine if a device has a hardware menu

I am currently struggling with this issue. I need to check if there is a hardware menu key on the device where the application is installed. Since it does not exist on some devices, such as the Galaxy Nexus, I display it directly in the user interface in this case.

I already looked at PackageManager.hasSystemFeature (), but did not find anything useful there.

Has anyone already done this?

+42
android key hardware menu
Jan 28 '12 at 11:28
source share
6 answers
ViewConfiguration.get(context).hasPermanentMenuKey() 

See ViewConfiguration#hasPermanentMenuKey() more details. Please note that this is only available for API level 14+ (Android 4.0 Ice Cream Sandwich or later).

+90
Feb 28 '12 at 12:33
source share
β€” -
 if(Build.VERSION.SDK_INT <= 10 || (Build.VERSION.SDK_INT >= 14 && ViewConfiguration.get(this).hasPermanentMenuKey())) { // menu key is present } else { //No menu key } 
+23
Jun 13 '13 at 8:56
source share

Even on devices running Honeycomb, then the system will supply a β€œmenu button” for applications written for Android 2.x versions. Only it is called the "overflow menu". So it’s not worth checking if such a button will be there or not - it will be there if necessary.

As a general guide, you should check certain functionality, and not look at the system / API version numbers. Use the ActionBar class if available, otherwise in the 2.x options menu.

Have you looked at the Googles training tutorial ? This makes it clearer what you should do.

+3
Jan 29 2018-12-12T00:
source share

I think the possible and best solution is to add your own action bar. Therefore, each device can see it, and you do not need to check the hardware configuration or version of Api.

+1
Nov 17 '12 at 11:00
source share

keysoft qualifier is used to detect a hardware keyboard, not a navigation bar.

This article resolves:

Check navigation bar

+1
Sep 05 '14 at 22:06
source share

If you need a resource qualifier, which may be the case since you want to distinguish between user interfaces, use the keyssoft resource classifier.

0
Nov 12 '13 at
source share



All Articles