Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 384
kate bruce Avatar asked Jul 31 '10 23:07

kate bruce


1 Answers

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;
        }
    }
like image 106
user701595 Avatar answered Nov 17 '22 15:11

user701595