Reputation: 59
I have to get currently selected keyboard language in android. So far I am using this:
InputMethodManager imm = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
InputMethodSubtype ims = imm.getCurrentInputMethodSubtype();
if(ims != null)
{
String lName = ims.getLocale();
Locale locale = new Locale(lName);
String lang = locale.getLanguage();
}
but Samsung keyboard and Swiftkey keyboard always return device's language, not the selected keyboard language. And on Swiftkey when the device's language is different from English it returns something like that for all languages:
"it_it", "ru_ru", "bg_bg"
How to get the current keyboard language properly?
Upvotes: 1
Views: 862
Reputation: 294
Minimum API must be 11 for getEnabledInputMethodSubtypeList now 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);
}
}
}
}
Upvotes: 0