android 5.0以前的方法:
1. frameworks\base\packages\SettingsProvider\res\values\defaults.xml 文件中修改默认输入法为搜狗输入法
2. frameworks\base\packages\SettingsProvider\src\com\Android\providers\settings\DatabaseHelper.Java
在loadSecureSettings()中增加一条语句,制定默认使能的输入法
loadStringSetting(stmt, Settings.Secure.DEFAULT_INPUT_METHOD,R.string.config_default_input_method);
loadStringSetting(stmt, Settings.Secure.DEFAULT_INPUT_METHOD,R.string.def_enabled_input_methods);
3. 将搜狗输入法放到system/app中
android 6.0与7.1的方法
1、android\frameworks\base\packages\SettingsProvider\res\values\defaults.xml
此文件里面增加配置:
2、android\frameworks\base\packages\SettingsProvider\src\com\android\providers\settings\DatabaseHelper.java
此文件里面loadSecureSettings方法里面增加此设置:
loadStringSetting(stmt, Settings.Secure.DEFAULT_INPUT_METHOD,
R.string.config_default_input_method);
loadStringSetting(stmt, Settings.Secure.ENABLED_INPUT_METHODS,
R.string.def_enabled_input_methods);
3、android\frameworks\base\core\java\com\android\internal\inputmethod\InputMethodUtils.java
此文件里面enableAllIMEsIfThereIsNoEnabledIME 方法里面这样修改加了 ! 号
//if (TextUtils.isEmpty(getEnabledInputMethodsStr())) {
if (!TextUtils.isEmpty(getEnabledInputMethodsStr())) {
4、android\frameworks\base\services\core\java\com\android\server\InputMethodManagerService.java
此文件里面此buildInputMethodListLocked 方法里面注释掉这些内容
// TODO: The following code should find better place to live.
/* if (!resetDefaultEnabledIme) {
boolean enabledImeFound = false;
final List
final int N = enabledImes.size();
for (int i = 0; i < N; ++i) {
final InputMethodInfo imi = enabledImes.get(i);
if (mMethodList.contains(imi)) {
enabledImeFound = true;
break;
}
}
if (!enabledImeFound) {
Slog.i(TAG, "All the enabled IMEs are gone. Reset default enabled IMEs.");
resetDefaultEnabledIme = true;
resetSelectedInputMethodAndSubtypeLocked("");
}
}
*/
mContext.registerReceiver(
new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
synchronized(mMethodMap) {
//resetStateIfCurrentLocaleChangedLocked();//注释此函数
}
}
}, filter);
调试:
//adb修改默认输入法
adb shell settings put secure default_input_method com.sohu.inputmethod.sogou/.SogouIME
//adb获取默认输入法
adb shell settings get secure def_enable_input_methods
推荐最简单粗暴的方法在主Launcher onCreate方法里面增加代码
//设置默认输入法
Settings.Secure.putString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD,
"com.sohu.inputmethod.sogou/.SogouIME");
注解:前提是搜狗输入法已经安装