kate bruce
kate bruce

Reputation: 141

Android: Determine active input method from code

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

Upvotes: 14

Views: 11500

Answers (1)

user701595
user701595

Reputation: 473

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;
        }
    }

Upvotes: 31

Related Questions