18446744073709551615 18446744073709551615 - 3 months ago 54x
Android Question

Android: switch to a different IME programmatically


Because multiple IMEs may be installed on the device, provide a way for the user to switch to a different IME directly from the input method UI.

Let's assume I have the source of two input methods and can modify it.
I want to let the user switch between them quickly and am ready to reserve a button for that.
How do I "switch to a different IME directly from the input method UI"?


Switching to the previous input method from the current input method is:

//final String LATIN = "com.android.inputmethod.latin/.LatinIME";
// 'this' is an InputMethodService
try {
    InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
    final IBinder token = this.getWindow().getAttributes().token;
    //imm.setInputMethod(token, LATIN);
} catch (Throwable t) { // java.lang.NoSuchMethodError if API_level<11
    Log.e(TAG,"cannot set the previous input method:");

If you want to switch to a particular input method whose ID you know, you may do as the commented-out lines suggest.