了解 android 上的默认键盘

Know default keyboard on android

我想知道 Android 中用户选择的默认键盘。我知道我可以使用 InputMethodManager 访问已启用的输入法列表,但我想知道用户当前使用的是哪一个。

到目前为止,我已经尝试获取当前的输入法子类型:

InputMethodManager imeManager = (InputMethodManager) getApplicationContext().getSystemService(INPUT_METHOD_SERVICE);
InputMethodSubtype subtype =imeManager.getCurrentInputMethodSubtype();

但是这个对象似乎只提供了用户选择的语言环境和输入类型(语音、键盘等)。

我也试过已启用的输入法列表:

InputMethodManager imeManager = (InputMethodManager) getApplicationContext().getSystemService(INPUT_METHOD_SERVICE);
List<InputMethodInfo> list =imeManager.getEnabledInputMethodList();
    for(InputMethodInfo i: list){
        ...
    }

但是classInputMethodInfo不包含此方法是否为默认输入法的信息。

我知道一定有办法,因为每次我打开 SwiftKey 键盘但未设置为默认键盘时,都会出现输入法选择器。那么,他们怎么知道他们的键盘当前未设置为默认键盘?

我知道这个问题可能是重复的,因为它与 this 相同。但是这个问题没有得到答案,所以我真的希望现在有人能帮助我。

谢谢。

使用它来获取默认键盘。

Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);

要获取有关当前键盘的更多信息:

for(InputMethodInfo i: list){
  if (i.getId().equals(Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD))) {
    ...
  }
}