了解 Android 上的默认键盘

2024-05-02

我想知道 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){
        ...
    }

然而班级InputMethodInfo不包含该方法是否为默认输入法的信息。

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

我知道这个问题可能是重复的,因为它与this https://stackoverflow.com/questions/13678258/how-programmatically-switch-to-default-softkeyboard一。然而这个问题没有得到答案,所以我真的希望有人现在可以帮助我。

谢谢。


使用它来获取默认键盘。

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))) {
    ...
  }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

了解 Android 上的默认键盘 的相关文章

随机推荐