知道Android上的默认键盘 [英] Know default keyboard on android

查看:59
本文介绍了知道Android上的默认键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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){
        ...
    }

但是,类 InputMethodInfo 不包含有关此方法是否为默认输入法的信息.

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

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

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.

谢谢.

推荐答案

使用它来获取默认键盘.

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))) {
    ...
  }
}

这篇关于知道Android上的默认键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆