Android get available input languages

时光毁灭记忆、已成空白 提交于 2020-01-07 03:04:05

问题


I'm trying to get the available input devices on Android, in order to do that I'm using the InputMethodManager and using the API of getEnabledInputMethodList() as follows:

InputMethodManager inputMgr = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
    List<InputMethodInfo> inputMethodList = inputMgr.getEnabledInputMethodList();

    for (InputMethodInfo method : inputMethodList) {
        List<InputMethodSubtype> subMethods = inputMgr.getEnabledInputMethodSubtypeList(method, true);
        for (InputMethodSubtype submethod : subMethods) {
            if (submethod.getMode().equals("keyboard")) {    //Ignore voice input method
                String localeString = submethod.getLocale();
                                Locale locale = new Locale(localeString);
                                String currentLanguage = locale.getLanguage();
                                //do something...
            }
        }
    }

However, although I've got many more input languages available on my LG G3 and MEIZU M2, this API returns only 1 input language - English. It seems that this API works as expected only on Google Nexus phones.

Has anyone tried to do the same and succeeded?

P.S I've already read the solution on this thread but it doesn't help much: how to get user keyboard language


回答1:


There is no way to do this. A keyboard doesn't report to Android the list of languages it supports.

In fact, most keyboards keep the input language separate from the phone's locale, in order to switch without resetting the UI of the entire phone. So the OS has no idea what languages a keyboard can write in or is currently writing in.



来源:https://stackoverflow.com/questions/35534958/android-get-available-input-languages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!