Android: Determine active input method from code
Asked Answered
M

1

14

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

Marlinmarline answered 31/7, 2010 at 23:59 Comment(4)
it's difficult to tell what you're asking here. Can you provide more context, and some code to highlight the problem?Guidebook
Sorry - I added the tag for Android - In Android, the user can change input methods by a long press on an edit field and what I want to know is how does one query the Android system to determine which of the many possible input methods the user has selected.Marlinmarline
Why does your app want to know this?Obsequent
I am writing software that evaluates the relative effectiveness of various input methods (in this case soft keyboards) in terms of how long it takes to type a given input string. Rather than having to ask the user which keyboard he is currently using, it would be easier to be able to just query the system to ask which soft keyboard he is usingMarlinmarline
M
30

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;
        }
    }
Mummify answered 19/4, 2011 at 22:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.