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.
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);
}
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