Android 13 内置可卸载的搜狗输入法

2023-12-22 20:38:32

环境

系统:Android 13
芯片厂商:展锐

需求

默认只有英文输入法,没有中文,需要中文输入法,且可以卸载的。
实测为搜狗输入法,百度等其它输入法也同样适用。

实现

在SDK目录中创建packages/apps/SogouIME
从网上下载搜狗的apk重命名为SogouIME.apk放到SogouIME文件夹中。

  1. 创建Android.mk
    注意有2个关键行
    LOCAL_ENFORCE_USES_LIBRARIES := false 不加这个在安卓13中会编译不过
    LOCAL_MODULE_PATH := $(TARGET_OUT)/vital-app 这行代码安装到/system/vital-app中,实现展锐的内置APP可卸载(恢复出厂可恢复)
    整个mk内容如下
###############################################################################
# SogouIME
LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := SogouIME
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_TAGS := optional
LOCAL_BUILT_MODULE_STEM := package.apk
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_ENFORCE_USES_LIBRARIES := false
LOCAL_MODULE_PATH := $(TARGET_OUT)/vital-app

LOCAL_PREBUILT_JNI_LIBS := \
    @lib/armeabi/libac_checker.so \
    @lib/armeabi/libaffinity.so \
    @lib/armeabi/libawp.so \
    @lib/armeabi/libcrash_collect.so \
    @lib/armeabi/libc++_shared.so \
    @lib/armeabi/libCtaApiLib.so \
    @lib/armeabi/libframesequence_doutu.so \
    @lib/armeabi/libframesequence.so \
    @lib/armeabi/libkoom-java.so \
    @lib/armeabi/libkwai-linker.so \
    @lib/armeabi/liblogan.so \
    @lib/armeabi/libluajava.so \
    @lib/armeabi/libmarsxlog.so \
    @lib/armeabi/libmmkv.so \
    @lib/armeabi/libnative-sec.so \
    @lib/armeabi/libopus_v1.so \
    @lib/armeabi/libostar.so \
    @lib/armeabi/libqmp.so \
    @lib/armeabi/libSGMtlgShell.so \
    @lib/armeabi/libsimple_vad.so \
    @lib/armeabi/libsimplevadwrapper.so \
    @lib/armeabi/libSogouAgc_v1.so \
    @lib/armeabi/libsogou_speex_nt_v01.so \
    @lib/armeabi/libsogouupdcore.so \
    @lib/armeabi/libtgpalite.so \
    @lib/armeabi/libtrace-canary.so \
    @lib/armeabi/libvivo_account_wave.so \
    @lib/armeabi/libweibosdkcore.so \
    @lib/armeabi/libwind.so \
    @lib/armeabi/libxgVipSecurity.so \
    @lib/armeabi/libxhook_lib.so

include $(BUILD_PREBUILT)
  1. 去掉LatinIME英文输入法,加上SogouIME
diff --git a/build/make/target/product/handheld_product.mk b/build/make/target/product/handheld_product.mk
index 2199c570a01..ae70564f858 100644
--- a/build/make/target/product/handheld_product.mk
+++ b/build/make/target/product/handheld_product.mk
@@ -28,13 +28,14 @@ PRODUCT_PACKAGES += \
     Contacts \
     DeskClock \
     Gallery2 \
-    LatinIME \
     Music \
     OneTimeInitializer \
     preinstalled-packages-platform-handheld-product.xml \
     QuickSearchBox \
     SettingsIntelligence \
-    frameworks-base-overlays
+    frameworks-base-overlays \
+    SogouIME
+
 
 PRODUCT_PACKAGES_DEBUG += \
     frameworks-base-overlays-debug
  1. 设置默认输入法
    如果要改成百度输入法,可以把里面的默认百度输入法的2行配置注释去掉,把搜狗的删除就行.
diff --git a/frameworks/base/packages/SettingsProvider/res/values/defaults.xml b/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
index 9b688fe1c66..96c047b5577 100755
--- a/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
+++ b/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
@@ -346,4 +346,10 @@
     <integer name="def_vibrate_settings">0</integer>
     <!--Hxy:add by yangsong fot set defaultvalues  of three pointer screenshot :0默认打开,1默认关闭 at 20230225-->
     <integer name="def_three_pointer_screenshot">1</integer>	 
+    <!-- 默认百度输入法 -->
+    <!-- <string name="config_default_input_method" translatable="false">com.baidu.input_benewtech/com.baidu.input.ImeService</string>
+    <string name="def_enabled_input_methods" translatable="false">com.baidu.input_benewtech/com.baidu.input.ImeService</string> -->
+    <!-- 默认搜狗输入法 -->
+    <string name="config_default_input_method" translatable="false">com.sohu.inputmethod.sogou/.SogouIME</string>
+    <string name="def_enabled_input_methods" translatable="false">com.sohu.inputmethod.sogou/.SogouIME</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/DatabaseHelper.java
index 7eab15f4bd1..7e5989ba259 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
@@ -2479,7 +2479,9 @@ class DatabaseHelper extends SQLiteOpenHelper {
             loadIntegerSetting(stmt, UnisocSettings.Secure.THREE_POINTER_SCREENSHOT,
                     R.integer.def_three_pointer_screenshot);                    
              ///&&}}                     
-                       
+
+            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);
 
             /*
              * IMPORTANT: Do not add any more upgrade steps here as the global,

这样编译后烧录,设备中就有中文输入法了.
作者:帅得不敢出门 csdn原创谢绝任何形式的转载及收录

文章来源:https://blog.csdn.net/zmlovelx/article/details/135159790
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。