Is there any way that we can switch installed keyboards programmatically (without going to the settings section manually)?
My requirement is that the user is presented with all the keyboards which are installed on the phone and gets a chooser dialog to switch to the one wishes?
(basically we want to cut down the step to transfer him to the settings page)
If your app has system privileges, and has the permission
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
you can programatically enable the keyboard and set it as the current keyboard by making it the default keyboard WITHOUT USER KNOWLEDGE OR INTERVENTION!
//get the old default keyboard in case you want to use it later, or keep it enabled
String oldDefaultKeyboard = Settings.Secure.getString(resolver, Setting.Secure.DEFAULT_INPUT_METHOD);
//enable your keyboard
Settings.Secure.putString(resolver, Settings.Secure.ENABLED_INPUT_METHODS, "com.my.keyboard/.full.path");
//set your keyboard as the new default keyboard
Settings.Secure.putString(resolver, Settings.Secure.DEFAULT_INPUT_METHOD, "com.my.keyboard/.full.path");
You can enable multiple keyboards (such as the default keyboard and your own) by providing a list of keyboards to the ENABLED_INPUT_METHODS
, separated by ':'. See docs
You can verify your keyboard's full package and path ID by invoking ime list -a
through adb shell
This piece of code will fulfill your requirements:
InputMethodManager imeManager = (InputMethodManager) getApplicationContext().getSystemService(INPUT_METHOD_SERVICE);
imeManager.showInputMethodPicker();
As Commonsware points out in his answer, there is no way to do this behind the user's back.
If you have rooted device, you can use /system/bin/ime
utility.
List all installed input methods: # ime list -a
Set google's keyboard as default:# ime set com.google.android.inputmethod.latin/com.android.inputmethod.latin.LatinIME
On Java side use Runtime.getRuntime().exec(...).
Is there any way that we can switch installed keyboards programmatically (without going to the settings section)?
Fortunately, no, for security reasons. If an app could dictate what input method editor is used, malware would change the input method editor to their keylogger.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With