Android设置系统首次开机的默认输入法
16 Jan 2015Android OS: 4.4.4 需求:Android系统首次开机(恢复出厂状态),读取build.prop中的属性来设置默认的输入法。
增加系统属性
ro.product.IME.default
修改InputMethodService
打开文件 frameworks/base/services/java/com/android/server/InputMethodManagerService.java
增加如下方法:
/**
* 0: not first boot
* 1: first boot
*/
static final String FIRST_BOOT_FLAG = "first_boot_flag";
private void setCustomDefaultIME() {
int firstBootFlag = Settings.System.getInt(
mContext.getContentResolver(), FIRST_BOOT_FLAG, 1);
if(DEBUG)
Slog.d(TAG, "First Boot Flag: " + firstBootFlag);
if (1 == firstBootFlag) {// first boot
String defaultIme = SystemProperties.get("ro.product.IME.default", "");
if(DEBUG)
Slog.d(TAG, "Customer Default IME: " + defaultIme);
if (defaultIme != null && defaultIme.length() > 0)
mSettings.putSelectedInputMethod(defaultIme);
// set first boot flag to 0
Settings.System.putInt(mContext.getContentResolver(),
FIRST_BOOT_FLAG, 0);
}
}
在InputMethodManagerService()的构造方法中调用它:
// mSettings should be created before buildInputMethodListLocked
mSettings = new InputMethodSettings(
mRes, context.getContentResolver(), mMethodMap, mMethodList, userId);
mFileManager = new InputMethodFileManager(mMethodMap, userId);
mImListManager = new InputMethodAndSubtypeListManager(context, this);
setCustomDefaultIME();
// Just checking if defaultImiId is empty or not
final String defaultImiId = mSettings.getSelectedInputMethod();
if (DEBUG) {
Slog.d(TAG, "Initial default ime = " + defaultImiId);
}
mImeSelectedOnBoot = !TextUtils.isEmpty(defaultImiId);
点击 这里 查看如何在Android源码中增加自定义属性