Skip to content

Instantly share code, notes, and snippets.

@thanhit93
Created July 12, 2018 14:37
Show Gist options
  • Save thanhit93/d4721d99d3ced12d37af03a999f2fc29 to your computer and use it in GitHub Desktop.
Save thanhit93/d4721d99d3ced12d37af03a999f2fc29 to your computer and use it in GitHub Desktop.
Check nav bar
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment