1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | public boolean hasSoftwareKeys() { boolean hasSoftwareKeys = true; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){ Display display = getWindowManager().getDefaultDisplay(); DisplayMetrics realMetrics = new DisplayMetrics(); display.getRealMetrics(realMetrics); DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics); hasSoftwareKeys = (realMetrics.widthPixels - metrics.widthPixels) > 0 || (realMetrics.heightPixels - metrics.heightPixels) > 0; } else { boolean hasMenuKey = ViewConfiguration.get(this).hasPermanentMenuKey(); boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK); hasSoftwareKeys = !hasMenuKey && !hasBackKey; } return hasSoftwareKeys; } |