如何检查我的自定义键盘是否已在设置中启用

时间:2016-04-24 20:26:00

标签: android android-softkeyboard

我正在制作自定义软键盘。无论如何都要检查它是否已在设置中启用?

3 个答案:

答案 0 :(得分:8)

检查以下代码: -

    String packageLocal = getPackageName();
    boolean isInputDeviceEnabled = false;
    InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    List<InputMethodInfo> list = inputMethodManager.getEnabledInputMethodList();

    // check if our keyboard is enabled as input method
    for (InputMethodInfo inputMethod : list) {
        String packageName = inputMethod.getPackageName();
        if (packageName.equals(packageLocal)) {
            Toast.makeText(getApplicationContext(),"Your Keyboard Enable",Toast.LENGTH_SHORT).show();
        }
    }

答案 1 :(得分:4)

原来我必须这样做:

 InputMethodManager im = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
   String list = im.getEnabledInputMethodList().toString();
   if(list.contains(<MY KEYBOARD ID>)){
   //Do something
   }

答案 2 :(得分:0)

科特琳风格:

    fun isCodeBoardEnabled(): Boolean {
        val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
        return imm.enabledInputMethodList.any { it.packageName == packageName }
    }