try
{
//Get list of input methods
List InputMethods=((InputMethodManager)myActivity.getSystemService(Context.INPUT_METHOD_SERVICE)).getEnabledInputMethodLis t();
String nameIME = InputMethods.get(0).getServiceName();
Log.i("Demo Error", "SWITCHING TO: "+nameIME);
String NewInputMethodName=InputMethods.get(0).getId(); //Pick the first input method to switch to
Log.i("Demo Error", "SWITCHING TO: "+NewInputMethodName);
String curInputMethodId = Settings.Secure.getString(myActivity
.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
Log.i("Demo Error", "CURRENT IME: "+curInputMethodId);
// Solution 1 (X)
// switchInputMethod is a method of android.inputmethodservice.InputMethodService
// switchInputMethod(NewInputMethodName); //This throws an error
// Solution 2 (OK)
Settings.Secure.putString(myActivity.getContentResolver(),
Settings.Secure.DEFAULT_INPUT_METHOD, NewInputMethodName);
// Solution 3 (OK)
if (myActivity.checkCallingOrSelfPermis sion(
android.Manifest.permission.WRITE_SECURE_SETTINGS)
!= 0) {
// PERMISSION_GRANTED == 0
Log.i("Demo Error", "myActivity requires permission "
+ android.Manifest.permission.WRITE_SECURE_SETTINGS);
}
((InputMethodManager)myActivity.getSystemService(Context.INPUT_METHOD_SERVICE))
.setInputMethod(null, NewInputMethodName);
// Show SoftInput Keyboard
EditText inputText = (EditText)myActivity.findViewById(R.id.inputText);
((InputMethodManager)myActivity.getSystemService(Context.INPUT_METHOD_SERVICE))
.showSoftInput(inputText, 0);
} catch(Exception e) {
Log.i("Demo Error", e.getMessage());
Android 切换输入法
原创
©著作权归作者所有:来自51CTO博客作者Bensantan的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
adb 切换输入法
adb 切换输入法
adb android 输入法 ico