how to get user keyboard language

旧时模样 提交于 2019-12-25 06:44:34

问题


I am writing an application which is using a edit text .i want to know whats users input language in oncreate method or when keyboard input type changes. Is there any way to set a listener to get that change? All the answer i found were about locale and not about input language. I don't want to handle locale, locale has no effect in application, the input language does. i used this codes.

private void printInputLanguages() {

    List<InputMethodInfo> ims = imm.getEnabledInputMethodList();
    for (InputMethodInfo method : ims) {
        List<InputMethodSubtype> submethods = imm
                .getEnabledInputMethodSubtypeList(method, true);
        for (InputMethodSubtype submethod : submethods) {
            if (submethod.getMode().equals("keyboard")) {
                String currentLocale =

                submethod.getLocale();
                tv.setText(currentLocale);
                Log.i("sara", "Available input method locale: "
                        + currentLocale);
            }
        }
    }

}

and this codes but none of them wasnt help full.

    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    InputMethodSubtype ims = imm.getCurrentInputMethodSubtype();
    String localeString = ims.getLocale();
    Locale locale = new Locale(localeString);
    String currentLanguage = locale.getDisplayLanguage();

thanks for ur helps.


回答1:


There is no way to do this. The input language of a keyboard is not reported to the OS- in fact Android doesn't have the concept of an input language. It was an idea created by 3rd party keyboard manufacturers. So really a keyboard can be typing in any language and the OS would have no idea.



来源:https://stackoverflow.com/questions/33383972/how-to-get-user-keyboard-language

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