1

I am trying to solve the same thing as the following post posts:

How to toggle "Use Physical Keyboard". and Switch from physical to software keyboard

Basicaly I want to toggle the native option from android to turn the physical keyboard on or off. However, I want to create this button through code.

None of those links have one good answer. Can anyone help me?

Community
  • 1
  • 1
  • I will be rather surprised if this is possible. – CommonsWare Nov 05 '12 at 12:24
  • The thing is, they already have an option to do that in the system, why not letting that option to be made by the users? :S... I realy hope you are wrong :P – hsr-eufinity Nov 05 '12 at 12:33
  • The reason that I will be surprised if this is possible is that changing input methods (e.g., from soft keyboard A to soft keyboard B) is not possible (for privacy and security reasons), and my guess is that a hardware keyboard will just be considered another input method. – CommonsWare Nov 05 '12 at 12:47
  • I understand what you are saying, but I don't see any problem with this since this toggle button only controlls the use or not of the soft-keyboard. If i toggle off the physical keyboard, but I still have it connected, I can still use it to type, the only thing that happens is that the OS will display the soft-keyboard also. – hsr-eufinity Nov 05 '12 at 12:57

1 Answers1

0

NO, there is currently no way to programmatically accomplish this. The most we can do is detect when a keyboard/scanner is connected and redirect the user to the Input Method selection window, by overriding the onConfigurationChanged method in your Application class:

@Override
public void onConfigurationChanged(Configuration newConfig) {
  super.onConfigurationChanged(newConfig);
  if(newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {

    ((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE))
                                  .showInputMethodPicker();
    Toast.makeText(this, "Barcode Scanner detected. Please turn OFF Hardware/Physical keyboard to enable softkeyboard to function.", Toast.LENGTH_LONG).show();
  }
}
desidigitalnomad
  • 1,443
  • 21
  • 33