Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect soft navigation bar availability in onePlusOne device progmatically?

Tags:

android

I need to check if a device has the soft navigation bar, and I followed the suggestions here.

It works great, except on onePlus devices, for some reason, this code:

int id = resources.getIdentifier("config_showNavigationBar", "bool", android");
    return id > 0 && resources.getBoolean(id);

returns false, although the soft navigation bar is displayed.

Any idea how can I get the correct result?

I prefer not to calculate the real width and available width, it seems like expensive operation.

Thanks.

like image 362
Sharas Avatar asked Oct 19 '22 07:10

Sharas


1 Answers

See this answer. There is no way be 100% sure, though.

boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
boolean hasHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);

if (hasBackKey && hasHomeKey) {
    // no navigation bar, unless it is enabled in the settings
} else {
    // 99% sure there's a navigation bar
}

Edit

Another approach

public boolean hasNavBar (Resources resources) {
    int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
    return id > 0 && resources.getBoolean(id);
}
like image 143
Amit Tiwari Avatar answered Nov 16 '22 09:11

Amit Tiwari