Arav K.
Arav K.

Reputation: 110

Android - change keyboard programmatically

On Android, can we change the keyboard input language (English(US), Hindi, French, etc.) from Java/C++ or the terminal(like the imein /system/bin?

Upvotes: 0

Views: 4884

Answers (1)

tanmeet
tanmeet

Reputation: 220

For those who said not possible here it is, it's very much possible but device needs to be rooted or your app needs to be system signed.

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

in keyboardID you need to pass the keyboardID of the keyboard you want to set.

or you may get the list of all keyboards and get the ID from there and pass it

Like this:

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

Upvotes: 4

Related Questions