Search code examples
androidkeyboard

How to disable softKeyboard if there is a hardware Keyboard


Actually i'm checking by this method if there is a hardware keyboard on my device

 private boolean isHardwareKeyboardAvailable() { return getResources().getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS; }

But now i would be able to disable the softKeyboard for that activity if the result of that boolean is true. How can i do?

Actually for a target of devices i set in my manifest

 android:windowSoftInputMode="stateVisible"

But i have to disable even it.

Any suggestion?


Solution

  • The easiest way to do it is by preventing the keyboard from popping up automatically:

    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    Put this code when you realized that the phone has physical keyboard.