本文主要是介绍Android 12 (InputMethodManagerService) 替换默认输入法为Pinyin输入法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.问题场景
由于系统自带的Latin输入法不支持遥控器操作,需要替换为RK的拼音输入法。
2. 替换步骤
1)将LatinIME从mk中删除,让系统编译的时候不编译该apk
--- a/Android/build/make/target/product/handheld_product.mk
+++ b/Android/build/make/target/product/handheld_product.mk
@@ -23,7 +23,6 @@ $(call inherit-product, $(SRC_TARGET_DIR)/product/media_product.mk)# /product packagesPRODUCT_PACKAGES += \Browser2 \
- LatinIME \preinstalled-packages-platform-handheld-product.xml \SettingsIntelligence \frameworks-base-overlays
2)添加PinyinIME的编译预装
--- a/Android/device/rockchip/common/modules/rockchip_apps.mk
+++ b/Android/device/rockchip/common/modules/rockchip_apps.mk
@@ -20,3 +20,5 @@# RkVideoPlayer \# RkExplorer \# StressTest
+PRODUCT_PACKAGES += \
+ PinyinIME
3)设置PinyinIME为默认输入法。这一步在网上搜了几个方案 ,但是都有些问题,后面自己试验用如下方式可以设置成功,即在InputManagerServices.java的buildInputMethodListLocked函数中添加设置默认输入法值的动作
+++ b/Android/frameworks/base/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
@@ -4560,6 +4560,26 @@ public class InputMethodManagerService extends IInputMethodManager.StubSlog.e(TAG, "buildInputMethodListLocked is not allowed until system is ready");return;}
+ String defaultIme = Settings.Secure.getString(mContext
+ .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
+ if ( defaultIme == null ) {
+ final Resources res = mContext.getResources();
+ try{
+ String myIME = "com.android.inputmethod.pinyin/.PinyinIME";
+ if ( myIME != null && myIME.length() > 0 )
+ {
+ Settings.Secure.putString( mContext.getContentResolver(),
+ Settings.Secure.DEFAULT_INPUT_METHOD,
+ myIME );
+ Settings.Secure.putString( mContext.getContentResolver(),
+ Settings.Secure.ENABLED_INPUT_METHODS,
+ myIME );
+ }
+ } catch( Exception e ) {
+ }
+ }
这篇关于Android 12 (InputMethodManagerService) 替换默认输入法为Pinyin输入法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!