Android: Determine active input method from code

kate bruce picture kate bruce · Aug 1, 2010 · Viewed 9.8k times · Source

How do you determine which input method is currently active - A user can change the input method (soft keyboard) by long pressing on a text edit field - From code, how does one determine which input method the user has chosen

Answer

user701595 picture user701595 · Apr 20, 2011

I realise you probably don't need this anymore, but someone might want the answer to this. You can use this line to get the String ID of the Input Method in use:

String id = Settings.Secure.getString(
   getContentResolver(), 
   Settings.Secure.DEFAULT_INPUT_METHOD
);

If you want to get more information about the current keyboard, you can use:

    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    List<InputMethodInfo> mInputMethodProperties = imm.getEnabledInputMethodList();

    final int N = mInputMethodProperties.size();

    for (int i = 0; i < N; i++) {

        InputMethodInfo imi = mInputMethodProperties.get(i);

        if (imi.getId().equals(Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD))) {

            //imi contains the information about the keyboard you are using
            break;
        }
    }