Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
1
Help us understand the problem. What is going on with this article?
@ueno-yuhei

Android端末でソフトウェアキーのナビゲーションバーの有無を判定

More than 3 years have passed since last update.
ViewConfiguration.get(context).hasPermanentMenuKey()

Galaxy端末で、上手くいかないことがあった。
以下でうまくいった!
調べていくとconfig_showNavigationBarという値のナビゲーションバーの指定されているとか
どこかのライブラリの中で見たソースを参考にして書いたコード
何のライブラリかは忘れてしまった・・・

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();
        }
    }
1
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ueno-yuhei
水樹奈々が好き!

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
1
Help us understand the problem. What is going on with this article?