Search code examples
androidkeyboardandroid-input-methodandroid-inputtype

how to get user keyboard language


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.


Solution

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