1

我必须在 android 中获取当前选择的键盘语言。到目前为止,我正在使用这个:

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

但三星键盘和 Swiftkey 键盘总是返回设备的语言,而不是选择的键盘语言。在 Swiftkey 上,当设备的语言与英语不同时,它会为所有语言返回类似的内容:

“it_it”、“ru_ru”、“bg_bg”

如何正确获取当前的键盘语言?

4

1 回答 1

0

现在 getEnabledInputMethodSubtypeList 的最低 API 必须为 11 以下是我为获取可用输入语言所做的工作:

 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);
          }
       }
    }
 }
于 2016-04-28T11:28:40.613 回答