Android - 以编程方式更改键盘

时间:2016-06-30 12:09:38

标签: android

在Android上,我们可以从Java / C ++或终端更改键盘输入语言(英语(美国),印地语,法语等)(如ime中的/system/bin吗?

1 个答案:

答案 0 :(得分:2)

对于那些在这里说不可能的人来说,它非常可能,但设备需要植根,或者你的应用需要系统签名。

protected static void changekeyboard(String keyboardID, ContentResolver contentResolver)
    {
        String oldDefaultKeyboard = Secure.getString(contentResolver, "default_input_method");
        Secure.putString(contentResolver, "enabled_input_methods", keyboardID);
        Secure.putString(contentResolver, "default_input_method", keyboardID);
    }

在keyboardID中,您需要传递要设置的键盘的keyboardID。

或者您可以获取所有键盘的列表并从那里获取ID并将其传递

像这样:

 List<InputMethodInfo> InputMethods = ((InputMethodManager) getApplicationContext().getSystemService("input_method")).getInputMethodList();
            this.keyboard_name = new ArrayList();
            int numOfKeEyboards = InputMethods.size();
            for (int i = 0; i < numOfKeEyboards; i++)
            {
                fullKeyboardName = ((InputMethodInfo) InputMethods.get(i)).toString();
                keyboard_package = fullKeyboardName.substring(fullKeyboardName.indexOf("{") + 1, fullKeyboardName.indexOf("/"));
                try
                {
                    // by package name getting app name
                    inputKeyboardName = getPackageManager().getApplicationInfo(keyboard_package, 0).loadLabel(getPackageManager()).toString();
                }
                catch (NameNotFoundException e)
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                this.keyboard_name.add(inputKeyboardName);
            }