Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect hardware keyboard presence?

Is there a way to detect if the device I'm currently running on has a hardware keyboard installed?

How do I query device capabilities anyway?

like image 997
Marcus Avatar asked Mar 10 '10 08:03

Marcus


People also ask

How do I check hardware on keyboard?

Right-click on the listing for your computer's keyboard. Select the "Scan for Hardware Changes" option from the menu. The Device Manager will now test your computer's keyboard. If an "error" icon appears next to the listing, there is a problem with your computer's keyboard.

How do I know if my keyboard is visible?

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.

Why does it say physical keyboard not connected?

i would go to settings>language & keyboard... and check you keyboard settings... see if "shortcuts" is ON... Also, try clearing out "Learned Words"... that usually helps with any OS keyboard issue... :-) if not, then get 1-click Cleaner from Market... its free... download... install.. run it...


2 Answers

"The flags provided by getResources().getConfiguration().keyboard are a good way of checking which keyboard (if any) is available." [1]

http://d.android.com/reference/android/content/res/Configuration.html#keyboard

like image 195
HostileFork says dont trust SE Avatar answered Sep 27 '22 21:09

HostileFork says dont trust SE


Use the following method to ascertain presence of hard keyboard at any time:
(To my knowledge, soft keyboards all lack the features tested below )

public static boolean isHardKB(Context ctx) {     Configuration cf = ctx.getResources().getConfiguration();     return cf.navigation==Configuration.NAVIGATION_DPAD         || cf.navigation==Configuration.NAVIGATION_TRACKBALL         || cf.navigation==Configuration.NAVIGATION_WHEEL; } 

Optionally trap all run-time keyboard changes for each affected Activity via AndroidManifest:

android:configChanges="keyboard|keyboardHidden|navigation" 

But be sure to support the above manifest change with (at least) a dummy onConfigurationChanged()

@Override public void onConfigurationChanged(Configuration newConfig) {     super.onConfigurationChanged(newConfig);     // Optionally employ 'isHardKB()'    } 
like image 32
Bad Loser Avatar answered Sep 27 '22 23:09

Bad Loser