HasPermanentMenuKey () alternative for Android 2.3.3

I am building my application with a level 10 API. But it can be installed and used in later versions. I need to show the action bar only if the device does not have a menu button. For example, tablets, Google Galaxy Nexus Phone, etc. People suggest using the hasPermanentMenuKey () function. But it is only available after API level 14, I think. Can someone suggest me how to get around this problem?

Thank you Kartik

+1
source share
3 answers

Use the following code:

ViewConfiguration.get(context).hasPermanentMenuKey();

First set the build target to API level 14 or UP , which will stop Eclipse from getting any error when using the above code.

API

1., API: 10

.

2., API: 11 13 (HoneyComb)

HW MENU, .

3., API: 14

API 14 , hasPermanentMenuKey().

, .

+12

:

public static boolean hasPermanentKeys(Activity activity) {
        //
        int height=0;
        int realHeight=0;

        WindowManager w = activity.getWindowManager();
        Display d = w.getDefaultDisplay();
        DisplayMetrics metrics = new DisplayMetrics();
        d.getMetrics(metrics);
        // since SDK_INT = 1;
         height = metrics.heightPixels;

    // includes window decorations (statusbar bar/menu bar)
        if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT < 17)
            try {
                realHeight = (Integer) Display.class.getMethod("getRawHeight").invoke(d);
            } catch (Exception ignored) {
            }
    // includes window decorations (statusbar bar/menu bar)
        if (Build.VERSION.SDK_INT >= 17)
            try {
                Point realSize = new Point();
                Display.class.getMethod("getRealSize", Point.class).invoke(d, realSize);
                realHeight = realSize.y;
            } catch (Exception ignored) {
            }
        if(height == realHeight){
            return true;
        }
        else{
            return false;
        }
    }
0

, - , , -v4 ( 24.2.0 API-9):

ViewConfigurationCompat.hasPermanentMenuKey(ViewConfiguration.get(context))

https://developer.android.com/topic/libraries/support-library/index.html

0
source

All Articles