需求
安卓8.1 SDK原生的输入法只能打英文, 需要替换成中文输入法.
以高通平台为例, 其它平台也适用.
查看设备当前默认输入法
adb shell
settings list secure | grep input
可以看到当前默认是LatinIME这个安卓原生输入法.
default_input_method=com.android.inputmethod.latin/.LatinIME
enabled_input_methods=com.android.inputmethod.latin/.LatinIME
input_methods_subtype_history=com.android.inputmethod.latin/.LatinIME;-921088104
selected_input_method_subtype=-921088104
selected_spell_checker=com.android.inputmethod.latin/.spellcheck.AndroidSpellCheckerService
修改SDK替换输入法
这里以百度输入法为例
需要修改settings secure中的default_input_method与enabled_input_methods
在frameworks/base/packages/SettingsProvider/res/values/defaults.xml中添加string
然后在frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java的private void loadSecureSettings(SQLiteDatabase db)函数后面调用loadStringSetting
diff --git a/frameworks/base/packages/SettingsProvider/res/values/defaults.xml b/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
index e6a14ec..2bdad47 100644
--- a/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
+++ b/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
@@ -193,4 +193,7 @@<!-- Default for Settings.Global.CAPTIVE_PORTAL_DETECTION_ENABLED --><integer name="def_captive_portal_detection_enabled" translatable="false">1</integer>
+
+ <string name="config_default_input_method" translatable="false">com.baidu.input/.ImeService</string>
+ <string name="config_enabled_input_method" translatable="false">com.baidu.input/.ImeService</string></resources>
diff --git a/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java b/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/
index 9274f39..5202d1a 100644
--- a/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
+++ b/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
@@ -2464,6 +2464,11 @@ class DatabaseHelper extends SQLiteOpenHelper {loadIntegerSetting(stmt, Settings.Secure.SLEEP_TIMEOUT,R.integer.def_sleep_timeout);+ loadStringSetting(stmt, Settings.Secure.DEFAULT_INPUT_METHOD,
+ R.string.config_default_input_method);
+ loadStringSetting(stmt, Settings.Secure.ENABLED_INPUT_METHODS,
+ R.string.config_enabled_input_method);
+
不同输入法,要替换不同的包与类名
常见输入法
百度:com.baidu.input/.ImeService
讯飞:com.iflytek.inputmethod/.FlyIME
腾讯:com.tencent.qqpinyin/.QQPYInputMethodService
谷歌:com.google.android.inputmethod.pinyin/.PinyinIME
搜狗:com.sohu.inputmethod.sogou/.SogouIME
触宝:com.cootek.smartinput5/.TouchPalIME
Settings Provider值保存在data分区中的数据库(旧版本)或xml(新版本)中,所以编译出固件后,要烧录userdata.img.
安装输入法
上面已经修改了新的默认输入法配置, 然后再安装新输入法进去就可以了.
或者在SDK中内置.
内置输入法步骤
- mk中添加编译
build/make/target/product/core.mk
PRODUCT_PACKAGES += BaiduIME - 网上下载百度输入法apk重命名为BaiduIME.apk放入packages/apps/BaiduIME/下
- 新增Android.mk
LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE := BaiduIME
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_MODULE_CLASS := APPS
LOCAL_CERTIFICATE := platform
LOCAL_DEX_PREOPT := false
LOCAL_PROPRIETARY_MODULE :=true
include $(BUILD_PREBUILT)
编译后烧录system.img就完成内置输入法为系统应用了,如果要内置成非系统应用则Android.mk写法是不一样的,SDK中也要做修改,这些就不表述了.
作者:帅得不敢出门 csdn原创谢绝收录及转换