Skip to content

Instantly share code, notes, and snippets.

@dingbuoyi
Created December 1, 2016 02:36
Show Gist options
  • Save dingbuoyi/e993259153ea0dc3dc1eca2170b724d8 to your computer and use it in GitHub Desktop.
Save dingbuoyi/e993259153ea0dc3dc1eca2170b724d8 to your computer and use it in GitHub Desktop.
private static boolean hasNavBar(Context context) {
Resources res = context.getResources();
int resourceId = res.getIdentifier("config_showNavigationBar", "bool", "android");
if (resourceId != 0) {
boolean hasNav = res.getBoolean(resourceId);
// check override flag
String sNavBarOverride = getNavBarOverride();
if ("1".equals(sNavBarOverride)) {
hasNav = false;
} else if ("0".equals(sNavBarOverride)) {
hasNav = true;
}
return hasNav;
} else { // fallback
return !ViewConfiguration.get(context).hasPermanentMenuKey();
}
}
private static String getNavBarOverride() {
String sNavBarOverride = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
try {
Class c = Class.forName("android.os.SystemProperties");
Method m = c.getDeclaredMethod("get", String.class);
m.setAccessible(true);
sNavBarOverride = (String) m.invoke(null, "qemu.hw.mainkeys");
} catch (Throwable e) {
}
}
return sNavBarOverride;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment