Skip to content

Instantly share code, notes, and snippets.

@ueno-yuhei
Created November 5, 2016 09:48
Show Gist options
  • Save ueno-yuhei/2d26f608edb6f59a86e8a89365568824 to your computer and use it in GitHub Desktop.
Save ueno-yuhei/2d26f608edb6f59a86e8a89365568824 to your computer and use it in GitHub Desktop.
Android端末でソフトウェアキーのナビゲーションバーの有無を判定 ref: http://qiita.com/ueno-yuhei/items/4bd7c46bf3665bee0cad
ViewConfiguration.get(context).hasPermanentMenuKey()
public static boolean hasNavigationBar(Context context) {
Resources res = context.getResources();
int resourceId = res.getIdentifier("config_showNavigationBar", "bool", "android");
if (resourceId != 0) {
String sNavBarOverride = "";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
try {
Class c = Class.forName("android.os.SystemProperties");
Method m = c.getDeclaredMethod("get", String.class);
m.setAccessible(true);
vsNavBarOverride = (String) m.invoke(null, "qemu.hw.mainkeys");
} catch (Throwable e) {
e.printStackTrace();
sNavBarOverride = "";
}
}
boolean hasNav = res.getBoolean(resourceId);
// check override flag (see static block)
if ("1".equals(sNavBarOverride))
hasNav = false;
else if ("0".equals(sNavBarOverride))
hasNav = true;
return hasNav;
} else { // fallback
return !ViewConfiguration.get(context).hasPermanentMenuKey();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment