且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取键盘语言或检测用户输入语言的Andr​​oid

更新时间:2023-01-24 15:33:18

下面是我所做获得可用的输入语言:

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