Skip to content Skip to sidebar Skip to footer

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?

Solution 1:

"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

Solution 2:

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

publicstaticbooleanisHardKB(Context ctx) {
    Configurationcf= 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()

@OverridepublicvoidonConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    // Optionally employ 'isHardKB()'   
}

Solution 3:

To detect common qwerty keyboard connected use this:

privatebooleanisKeyboardConnected() {
    returngetResources().getConfiguration().keyboard == KEYBOARD_QWERTY;
}

Post a Comment for "How To Detect Hardware Keyboard Presence?"