Android获取可用的输入语言 [英] Android get available input languages

查看:105
本文介绍了Android获取可用的输入语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取Android上可用的输入设备,为此,我使用InputMethodManager并使用getEnabledInputMethodList()的API,如下所示:

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

但是,尽管我在LG G3和MEIZU M2上有更多输入语言可用,但是此API仅返回一种输入语言-英语. 看来该API仅能在Google Nexus手机上正常工作.

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 我已经阅读了该线程上的解决方案,但并没有太大帮助: 如何获取用户键盘语言

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

推荐答案

无法执行此操作.键盘不会向Android报告其支持的语言列表.

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

实际上,大多数键盘将输入语言与手机的语言环境区分开来,以便在不重置整个手机UI的情况下进行切换.因此,操作系统不知道键盘可以输入或当前正在使用哪种语言.

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.

这篇关于Android获取可用的输入语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆