3

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();

and i used this link but again i couldn't solve my problem

Get keyboard language or detect user input language in Android

pls someone help me to know to get user input method when activity create. thanks.

Community
  • 1
  • 1

1 Answers1

0

Please check this: I think all you need is inside, note it's fully working code.

Android: Detect softkeyboard RTL Vs LTR (language direction)

Here a short code to detect current language of the softkeyboard (on screen keyboard - Input method language): localeDisplayName is the language of the keyboard...

InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
InputMethodSubtype inputMethodSubtype = inputMethodManager.getCurrentInputMethodSubtype();
Locale mLocale = new Locale(inputMethodSubtype.getLocale());
String localeDisplayName = mLocale.getDisplayName();  //e.g. "English"
Community
  • 1
  • 1
michael
  • 3,835
  • 14
  • 53
  • 90