且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

安卓:确定从code动态输入法

更新时间:2023-02-26 21:48:11

我知道你可能不需要这个了,但有人可能会想这个问题的答案。您可以使用此行来获得输入法的使用串ID:

I realise you probably don't need this anymore, but someone might want the answer to this. You can use this line to get the String ID of the Input Method in use:

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

如果你想获得关于当前键盘的更多信息,你可以使用:

If you want to get more information about the current keyboard, you can use:

    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    List<InputMethodInfo> mInputMethodProperties = imm.getEnabledInputMethodList();

    final int N = mInputMethodProperties.size();

    for (int i = 0; i < N; i++) {

        InputMethodInfo imi = mInputMethodProperties.get(i);

        if (imi.getId().equals(Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD))) {

            //imi contains the information about the keyboard you are using
            break;
        }
    }