0

I am writing a custom InputMethod from scratch and would like to show the user a button in my Activity to enable my InputMethod in case it is disabled...

I would need to find out programmatically if my InputMethod is enabled in the device or not.

How can I do that?

Kamran Ahmed
  • 7,661
  • 4
  • 30
  • 55

1 Answers1

1

You can use InputMethodManager to get the list of enabled InputMethodInfo and iterate over it to find out if your InputMethod is enabled or not.

public boolean isMyInputMethodEnabled() {
    boolean isEnabled = false;

    InputMethodManager inputMethodManager
            = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    List<InputMethodInfo> inputMethodList = inputMethodManager
            .getEnabledInputMethodList();

    for (InputMethodInfo inputMethodInfo : inputMethodList) {
        if (inputMethodInfo.getPackageName().equals(getPackageName())) {
            isEnabled = true;
            break;
        }
    }

    return isEnabled;
}
Kamran Ahmed
  • 7,661
  • 4
  • 30
  • 55