Created
November 5, 2016 09:48
-
-
Save ueno-yuhei/2d26f608edb6f59a86e8a89365568824 to your computer and use it in GitHub Desktop.
Android端末でソフトウェアキーのナビゲーションバーの有無を判定 ref: http://qiita.com/ueno-yuhei/items/4bd7c46bf3665bee0cad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ViewConfiguration.get(context).hasPermanentMenuKey() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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