Android6.0设置默认输入法,这里以日文输入法为例,
1.在frameworks/base/packages/SettingsProvider/res/values/defaults.xml 添加:
jp.co.omronsoft.openwnn/.OpenWnnJAJP2.在frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java添加:
loadStringSetting(stmt, Settings.Secure.DEFAULT_INPUT_METHOD,R.string.def_input_method );这个方法加在private void loadSecureSettings(SQLiteDatabase db)这个里面。
3.使能所有输入法,frameworks/base/core/java/com/android/internal/inputmethod/InputMethodUtils.java
--- a/frameworks/base/core/java/com/android/internal/inputmethod/InputMethodUtils.java
+++ b/frameworks/base/core/java/com/android/internal/inputmethod/InputMethodUtils.java
@@ -926,7 +926,7 @@ public class InputMethodUtils {
// At the initial boot, the settings for input methods are not set,
// so we need to enable IME in that case.
public void enableAllIMEsIfThereIsNoEnabledIME() {
- if (TextUtils.isEmpty(getEnabledInputMethodsStr())) {
+ if (!TextUtils.isEmpty(getEnabledInputMethodsStr())) {
StringBuilder sb = new StringBuilder();
final int N = mMethodList.size();
for (int i = 0; i < N; i++) {
这里的jp.co.omronsoft.openwnn/.OpenWnnJAJP是输入法ID,每个输入法都有自己的ID,如果不知道输入法ID,可以通过下面的打印方法获取:
frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
void buildInputMethodListLocked(ArrayList list,
HashMap map, boolean resetDefaultEnabledIme) {
if (DEBUG) {
Slog.d(TAG, "--- re-buildInputMethodList reset = " + resetDefaultEnabledIme
+ " \n ------ \n" + InputMethodUtils.getStackTrace());
}
list.clear();
map.clear();
// Use for queryIntentServicesAsUser
final PackageManager pm = mContext.getPackageManager();
String disabledSysImes = mSettings.getDisabledSystemInputMethods();
if (disabledSysImes == null) disabledSysImes = "";
final List services = pm.queryIntentServicesAsUser(
new Intent(InputMethod.SERVICE_INTERFACE),
PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS,
mSettings.getCurrentUserId());
final HashMap> additionalSubtypes =
mFileManager.getAllAdditionalInputMethodSubtypes();
for (int i = 0; i < services.size(); ++i) {
ResolveInfo ri = services.get(i);
ServiceInfo si = ri.serviceInfo;
ComponentName compName = new ComponentName(si.packageName, si.name);
if (!android.Manifest.permission.BIND_INPUT_METHOD.equals(
si.permission)) {
Slog.w(TAG, "Skipping input method " + compName
+ ": it does not require the permission "
+ android.Manifest.permission.BIND_INPUT_METHOD);
continue;
}
if (DEBUG) Slog.d(TAG, "Checking " + compName);
//打印添加在这里,打印所有输入法的ID
Slog.d(TAG, "Checking packageName:" + si.packageName + " name:" + si.name);
try {
InputMethodInfo p = new InputMethodInfo(mContext, ri, additionalSubtypes);
list.add(p);
final String id = p.getId();
map.put(id, p);
if (DEBUG) {
Slog.d(TAG, "Found an input method " + p);
}
重新编译,烧录测试ok。