Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell whether an android device has hard keys

Tags:

android

How can I tell whether an android device has physical keys or the software navigation bar? I need to change the layout dependant on whether the software navigation is drawn.

For example the HTC Desire C has hardware keys: enter image description here

I should clarify - Im looking at the navigation bar, not the keyboard. Home, back etc. I've tried:

        getResources().getConfiguration().keyboard);
        getResources().getConfiguration().navigation);
        getResources().getConfiguration().navigationHidden);

return the same values on both devices.

like image 793
serenskye Avatar asked Feb 13 '13 11:02

serenskye


People also ask

How to detect keylogger on Android phone?

How To Detect Keylogger On Android Phone. An Android keylogger will need to be download to your device in order to work. So, you’ll be able to see the file in your phone’s Downloads folder. Usually, you can find this by searching Downloads on your phone, going to your My Files app, or checking your settings.

What is Android keystore security features?

Security features Android Keystore system protects key material from unauthorized use. Firstly, Android Keystore mitigates unauthorized use of key material outside of the Android device by preventing extraction of the key material from application processes and from the Android device as a whole.

How to tell if your Android phone is spying on You?

When an Android phone battery drains quickly, it’s usually because an app or software is running in the background. In the case of Android keyloggers, they are designed to be undetectable and don’t appear as a typical phone app/software would. So at first, you may not realize a keylogger is spying on you. 2. Your Phone Is HOT

How does Android keystore prevent key material from being stolen?

Secondly, Android KeyStore mitigates unauthorized use of key material on the Android device by making apps specify authorized uses of their keys and then enforcing these restrictions outside of the apps' processes. Key material of Android Keystore keys is protected from extraction using two security measures:


2 Answers

Solved by doing this the first time the app is launched and saving to preferences:

public static boolean hasSoftKeys(WindowManager windowManager){
    boolean hasSoftwareKeys = true;
    //c = context; use getContext(); in fragments, and in activities you can 
    //directly access the windowManager();

    if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN_MR1){
        Display d = c.getWindowManager().getDefaultDisplay();

        DisplayMetrics realDisplayMetrics = new DisplayMetrics();
        d.getRealMetrics(realDisplayMetrics);

        int realHeight = realDisplayMetrics.heightPixels;
        int realWidth = realDisplayMetrics.widthPixels;

        DisplayMetrics displayMetrics = new DisplayMetrics();
        d.getMetrics(displayMetrics);

        int displayHeight = displayMetrics.heightPixels;
        int displayWidth = displayMetrics.widthPixels;

        hasSoftwareKeys =  (realWidth - displayWidth) > 0 ||
                           (realHeight - displayHeight) > 0;
    } else {
        boolean hasMenuKey = ViewConfiguration.get(c).hasPermanentMenuKey();
        boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
        hasSoftwareKeys = !hasMenuKey && !hasBackKey;
    }
    return hasSoftwareKeys;
}
like image 67
serenskye Avatar answered Jan 17 '23 17:01

serenskye


Here you go.. this should do what you want.

@SuppressLint("NewApi")
private static boolean hasSoftNavigation(Context context)
{
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH){
        return !ViewConfiguration.get(context).hasPermanentMenuKey();
    }
    return false;
}
like image 32
Simon Avatar answered Jan 17 '23 18:01

Simon