Search code examples
androidandroid-keypad

Is there a way in Android to tell if a users device has an actual keyboard or not?


I would like to detect if the current users phone has a hardware keyboard or only a on-screen keyboard. Is this possible with the SDK?


Solution

  • Yes, you can.

    Fetch the Configuration object using

    Configuration config = getResources().getConfiguration();
    

    ...and then look at the keyboard field.

    If they value of keyboard is not KEYBOARD_NOKEYS, the user has a hardware keyboard.

    Note that as @Carl says in his comment below, the user may attach a USB keyboard at any point while your app is running, causing the value of keyboard to change.