I'm currently struggling with this issue. I need to check if the device, where the app is installed, has a hardware menu key. Because it is not existing on some devices like Galaxy Nexus, I'm showing it directly in the UI in this case.
I have already looked at PackageManager.hasSystemFeature(), but didn't find anything useful there.
Has anyone already done this?
ViewConfiguration.get(context).hasPermanentMenuKey()
See ViewConfiguration#hasPermanentMenuKey()
for more information. Note that this is only available for API level 14+ (Android 4.0 Ice Cream Sandwich or newer).
if(Build.VERSION.SDK_INT <= 10 || (Build.VERSION.SDK_INT >= 14 &&
ViewConfiguration.get(this).hasPermanentMenuKey()))
{
// menu key is present
}
else
{
//No menu key
}
Even on devices running Honeycomb and later, the system will supply a “Menu button” for apps written for 2.x versions of Android. Only it’s called the “overflow menu”. So there’s no point checking whether there will be such a button or not—it will be there if it’s needed.
As a general guideline, you should check for specific functionality, not look at system/API version numbers. Use the ActionBar class if it’s available, otherwise fallback to the 2.x options menu.
Have you looked at Google’s action-bar tutorial? That makes it clearer what you should be doing.
I think a possible and better solution is to add a own actionbar. So every device can see it and you don't have to check hardware configuration or Api version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With