如何确定Android中的当前IME?

时间:2010-04-30 13:17:45

标签: android keyboard ime android-input-method

我有一个应用程序,我想警告用户他们是否使用默认的Android软键盘。 (即他们正在使用Swype或其他东西)。

如何查看当前选择的输入法?

3 个答案:

答案 0 :(得分:25)

您可以使用默认的IME:

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

答案 1 :(得分:5)

InputMethodManagergetEnabledInputMethodList()。您的InputMethodManager中的getSystemService()会收到Activity

答案 2 :(得分:1)

以下是我用来确定是否使用GoogleKeyboard,Samsung Keyboard键盘或Swype Keyboard的一些代码。通过反射返回的mCurId的值表示IME ID。

使用您要寻找的不同键盘/输入法进行测试以找到相关的键盘

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;
    }