Detect accessibility of soft navigation bar in onePlusOne?

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

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

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

returns false, although a soft navigation bar is displayed.

Any idea how I can get the correct result?

I prefer not to calculate the actual width and the available width, this seems like an expensive job.

Thanks.

+5
source share
4 answers

See this answer. However, 100% not sure.

 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 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); } 
+1
source

Yes, you can try the following:

  WindowManager mgr = (WindowManager) getSystemService(WINDOW_SERVICE); boolean hasSoftKey = Utils.hasSoftKeys(mgr, NPTApplication.this); public static boolean hasSoftKeys(WindowManager windowManager, Context c) { boolean hasSoftwareKeys = true; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { Display d = windowManager.getDefaultDisplay(); DisplayMetrics realDisplayMetrics = new DisplayMetrics(); d.getRealMetrics(realDisplayMetrics); int realHeight = realDisplayMetrics.heightPixels; int realWidth = realDisplayMetrics.widthPixels; DisplayMetrics displayMetrics = new DisplayMetrics(); d.getMetrics(displayMetrics); int displayHeight = displayMetrics.heightPixels; int displayWidth = displayMetrics.widthPixels; hasSoftwareKeys = (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0; } else { boolean hasMenuKey = ViewConfiguration.get(c).hasPermanentMenuKey(); boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK); hasSoftwareKeys = !hasMenuKey && !hasBackKey; } return hasSoftwareKeys; } 
+1
source

no will not work the way you need to calculate the size

the method used is described in detail in this SO answer;

How to get the height and width of the navigation bar programmatically

0
source

Well, there is a hasPermanentMenuKey method that checks for MenuKey hardware, usually samsung devices have its size on the left of Home .

So, if it returns true, it means that the phone has hardware keys, and if it is false, then it just means that the phone has a navigation bar.

Method:

 ViewConfiguration.hasPermanentMenuKey() 

I find this very useful for myself. I hope this helps

0
source

All Articles