Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 357
Bryan Avatar asked Jul 11 '11 17:07

Bryan


People also ask

How do you detect a keyboard?

getConfiguration(). keyboard are a good way of checking which keyboard (if any) is available. Yes, if for your purposes you are counting a "12-key keyboard" as a "hardware keyboard".

How do I know if my keyboard is visible on Android?

Android provides no direct way to determine if the keyboard is open, so we have to get a little creative. The View class has a handy method called getWindowVisibleDisplayFrame from which we can retrieve a rectangle which contains the portion of the view visible to the user.

How do I keep my Android keyboard open?

To be able to open it anywhere, you go into the settings for the keyboard and check the box for 'permanent notification'. It will then keep an entry in the notifications which you can tap to bring up the keyboard at any point.


1 Answers

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.

like image 90
razlebe Avatar answered Nov 15 '22 08:11

razlebe