How to get user input language
I am writing an application that uses text editing. i want to know what the user is entering language in oncreate method or when input type changes. Is there a way to set a listener to receive this change? All the answer I found was about locale, not input language. I don't want to handle locale, language doesn't affect the application, input language does. I have used these 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 these codes, but none of them were complete.
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 was unable to solve my problem.
Get keyboard language or detect user input language in Android
Pls someone help me know to get the user input method when creating an activity. thank.
Please check it out: I think everything you need is inside, please note the fully working code.
Android: RTL Vs LTR softkey detection (language direction)
Here's a shortcode to detect the current language of the on-screen keyboard (on-screen keyboard is the input method language): localeDisplayName
is the keyboard language ...
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"