Android 如何检测用户';s的键盘是Swype吗?

Android 如何检测用户';s的键盘是Swype吗?,android,keyboard,ime,Android,Keyboard,Ime,有可能知道用户正在使用的键盘吗?如何检查用户是否使用Swype键盘?您的答案如下: 有时,这只是了解正确的搜索词。您可以使用以下方法检索当前默认键盘: String currentKeyboard = Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); 对于各种键盘,您将得到类似于com.touchtype.swiftkey/com.touchtype.Keyboard

有可能知道用户正在使用的键盘吗?如何检查用户是否使用Swype键盘?

您的答案如下:


有时,这只是了解正确的搜索词。

您可以使用以下方法检索当前默认键盘:

String currentKeyboard =  Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);

对于各种键盘,您将得到类似于
com.touchtype.swiftkey/com.touchtype.KeyboardService
的结果。第一部分是键盘的主包名,第二部分是它使用的键盘服务的名称。只需解析此字符串,看看它是否与Swype的信息匹配(我现在只能提供SwiftKey的详细信息,因为我没有安装Swype)。

下面让您确定是否使用三星、谷歌或Swype键盘

public boolean usingSamsungKeyboard(Context context){
    return usingKeyboard(context, "com.sec.android.inputmethod/.SamsungKeypad");
}

public boolean usingSwypeKeyboard(Context context){
    return usingKeyboard(context, "com.nuance.swype.input/.IME");
}

public boolean usingGoogleKeyboard(Context context){
    return usingKeyboard(context, "com.google.android.inputmethod.latin/com.android.inputmethod.latin.LatinIME");
}   

public boolean usingKeyboard(Context context, String keyboardId)
    {
        final InputMethodManager richImm =
          (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);

        boolean isKeyboard = false;

        final Field field;
        try
        {
            field = richImm.getClass().getDeclaredField("mCurId");
            field.setAccessible(true);
            Object value = field.get(richImm);
            isKeyboard = value.equals(keyboardId);

        }
        catch (IllegalAccessException e)
        {

        }
        catch (NoSuchFieldException e)
        {

        }
        return  isKeyboard;
    }

这是其他的一切:谢谢!是的,我试图搜索它,但似乎我没有使用正确的关键字。我想把你的答案设置为正确答案,但拉格哈夫也在这里发布了答案,并解释了答案。完整性赢得了胜利。这很公平。无论如何,谢谢你的支持(我想这是你给我的)。谢谢!:)我现在明白了!在没有解释和赋值变量的情况下,我认为代码是用于选择要使用的键盘。请检查以下答案: