获取键盘语言或检测用户输入语言的Android [英] Get keyboard language or detect user input language in Android
本文介绍了获取键盘语言或检测用户输入语言的Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检测键盘的当前选择的语言。为了这个目的我用下面的code:
I'm trying to detect current selected language of the keyboard. For that purpose I use following 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();
但应用阵痛的NoSuchMethodError
的异常 getCurrentInputMethodSubtype
功能。
有没有什么办法让键盘选择的语言?如果没有我怎么可以检测所用的语言输入用户在应用程序?
Is there any way to get Keyboard selected language? If no how I can detect the language in which user typing in the application?
推荐答案
下面是我所做获得可用的输入语言:
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);
}
}
}
}
这篇关于获取键盘语言或检测用户输入语言的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文