Skip to content

Instantly share code, notes, and snippets.

@ZQiang94
Created April 7, 2017 09:48
Show Gist options
  • Save ZQiang94/cec97ced06b3a4a8a2dee6ad0a5b6112 to your computer and use it in GitHub Desktop.
Save ZQiang94/cec97ced06b3a4a8a2dee6ad0a5b6112 to your computer and use it in GitHub Desktop.
检测设备是否有虚拟键
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