Skip to content

Instantly share code, notes, and snippets.

@wutianlong
Created April 28, 2017 03:24
Show Gist options
  • Save wutianlong/f103f20d73b881081ab9da628e8597d8 to your computer and use it in GitHub Desktop.
Save wutianlong/f103f20d73b881081ab9da628e8597d8 to your computer and use it in GitHub Desktop.
judge weather have navigation bar, if want to know navigation bar at left or bottom , can through judge screen-size
//获取是否存在NavigationBar
public static boolean checkDeviceHasNavigationBar(Context context) {
boolean hasNavigationBar = false;
Resources rs = context.getResources();
int id = rs.getIdentifier("config_showNavigationBar", "bool", "android");
if (id > 0) {
hasNavigationBar = rs.getBoolean(id);
}
try {
Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
Method m = systemPropertiesClass.getMethod("get", String.class);
String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys");
if ("1".equals(navBarOverride)) {
hasNavigationBar = false;
} else if ("0".equals(navBarOverride)) {
hasNavigationBar = true;
}
} catch (Exception e) {
}
return hasNavigationBar;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment