Get keyboard language or detect user input language in Android
android, android-softkeyboard, java
Solution
Here's what I did to get the available input languages:
private void printInputLanguages() {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
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();
Log.i(TAG, "Available input method locale: " + currentLocale);
}
}
}
}
Problem
Problem Description I'm trying to detect current selected language of the keyboard. For that purpose I use following code: Code ``` /* Return the handle to a system-level service by name. The class of the returned * object varies by the requested name. */ InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); /* Returns the current input method subtype. This subtype is one of the subtypes in the * current input method. This method returns null when the current input method doesn't * have any input method subtype. */ InputMethodSubtype ims = imm.getCurrentInputMethodSubtype(); /* The locale of the subtype. This method returns the "locale" string parameter passed * to the constructor. */ String locale = ims.getLocale(); ``` but application throes `NoSuchMethodError` exception on `getCurrentInputMethodSubtype` function. Question Is there any way to get Keyboard selected language? If no how I can detect the language in which user typing in the application?