【问题标题】:How to detect if user's keyboard is Swype?如何检测用户的键盘是否为 Swype?
【发布时间】:2012-12-31 12:11:46
【问题描述】:

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

【问题讨论】:

    标签: android keyboard ime


    【解决方案1】:

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

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

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

    【讨论】:

    【解决方案2】:

    看起来你的答案在这里:

    How to determine the current IME in Android?

    有时只是要知道正确的搜索词。

    【讨论】:

    • 谢谢!是的,我试图搜索它,但似乎我没有使用正确的关键字。我想将您的答案设置为正确答案,但 Raghav 也在此处发布了答案并附有解释。
    • 完整性赢得了胜利。这还算公平。无论如何,感谢您的支持(我假设 ti 来自您)。
    【解决方案3】:

    以下内容可让您确定是否使用三星、Google 或 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;
        }
    

    【讨论】:

      猜你喜欢
      • 2022-12-05
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-20
      • 2012-04-04
      相关资源
      最近更新 更多