-1

I would like to check menu key presence in the device in android application. To achieve that i used following code to detect weather device is having hardware menu or not and it is working fine

!ViewConfiguration.get(ScsCommander.getInstance().getApplicationContext()).hasPermanentMenuKey()

But i did not find a logic to find weather the device is having soft menu present or not.

Please suggest me is there any way to detect soft menu is available or not in the device.

Raghu Mudem
  • 6,793
  • 13
  • 48
  • 69
  • What makes you think it will not be available? A hardware key requires a hardware part, but a soft key has no requirements whatsoever, it should be there. A function to check for its availability will be useless. – dtech Jul 14 '15 at 11:51
  • @ddriver thanks for your response. Can we have a way to find the soft navigation bar is presented on device? or menu button with 3 dots is available for the application? – Raghu Mudem Jul 14 '15 at 11:55

1 Answers1

1

There is no reliable/clean way to check if soft menu (aka Navigation bar) is present or not!

You may try using below code (not tested on all devices and not a reliable solution anyways):

boolean hasNavBar(Context context) {
    Resources resources = context.getResources();
    int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
    if (id > 0) {
        return resources.getBoolean(id);
    } else {    // Check for keys
        boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
        boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
        return !hasMenuKey && !hasBackKey;
    }
}

Here, we are fetching the resource identifier using Resources class. We are looking for a resource "navigation bar" which is passed as the 1st parameter.

The getIdentifier returns the associated resource identifier. Returns 0 if no such resource was found. (0 is not a valid resource ID.)

In case if this approach fails, in else we are trying to see check if certain physical keys are present on the device like back or Home which usually constitute Navigation bar.

AADProgramming
  • 6,077
  • 11
  • 38
  • 58
  • thanks for your replay. If case is working fine in so many devices. But else case is not giving the reliable result. We can not use the else case. And any idea from which api level onwards "config_showNavigationBar" is available? – Raghu Mudem Jul 17 '15 at 10:08