Change Keyboard Input Language Programmatically
Solution 1:
You can change keyboard without user notification only and only if your app is running as a System app for security reasons.
You need to give Android permission first in your app's AndroidManifest.xml
"android.permission.WRITE_SECURE_SETTINGS"
Then you need to determine id of your keyboard.
-> To know id, you need to keep your keyboard default from setting menu manually then put this print somewhere,
System.out.println(Settings.Secure.getString(getContentResolver(),Settings.Secure.DEFAULT_INPUT_METHOD));
Once you print id and you know your keyboard id you can do as per below ( I have changed my default keyboard to Japanese )
InputMethodManagerimeManager= (InputMethodManager) getApplicationContext().getSystemService(INPUT_METHOD_SERVICE);
//imeManager.showInputMethodPicker(); //This is to see available keyboards.
imeManager.setInputMethod(null,"jp.co.omronsoft.openwnn/.OpenWnnJAJP");
Enjoy !!
Solution 2:
After doing some research here and there found the answer, first of all you have to create a custom keyboard View which extends keyboardView and in it create static key value variable like
staticfinalint KEYCODE_LANGUAGE_SWITCH_ENG = -102;
staticfinalint KEYCODE_LANGUAGE_SWITCH_URDU = -103;
after that in your IME class where you have implemented the inputMethodService, create the keyboards inside the onInitializeInterface override function. like
mSymbolsKeyboard = new Keyboard(this, R.xml.qwerty2);mEngQwertyKeyboard = new Keyboard(this, R.xml.eng_qwerty);
after this add these final static keys in the onKey override function as switch cases, and in the cases set the keyboards accordingly:
setKeyboard(mEngQwertyKeyboard);
Post a Comment for "Change Keyboard Input Language Programmatically"