Know default keyboard on android

给你一囗甜甜゛ 提交于 2021-02-10 15:16:22

问题


I want to know the default keyboard chosen by the user in Android. I know I can access the list of enabled input methods using the InputMethodManager, but I want to know which one is the user currently using.

So far, I've tried to get the current input method subtype:

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

But this object only seems to give me the Locale the user has picked and the input type (voice, keyboard,..).

I've also tried through the list of enabled input methods:

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

However the class InputMethodInfo does not contain information of whether this method is the default input method or not.

I know there must be a way, because everytime I open SwiftKey Keyboard and is not set as the default keyboard a input method picker appears. So, how do they know their keyboard is not currently set as default?

I'm aware this question might be a duplicate, since it's the same as this one. However that question didn't get an answer, so I'm really hoping someone can help me now.

Thank you.


回答1:


Use this to get default keyboard.

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

To get more information about current keyboard:

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


来源:https://stackoverflow.com/questions/28803878/know-default-keyboard-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!