Android10 内置第三方输入法

1. 本文使用的是展锐平台安卓10,自行酌情参考。

2. 本文内置的是百度输入法

一、 准备百度APK以及package包

  • 下载最新的输入法apk(手动安装确认系统是否支持该输入法)

  • 提取apk中的lib文件

    将APK改成.zip后缀的文件,然后通过unzip来解压,获取apk中的lib目录

  • 写Android.mk文件

Android10 内置第三方输入法_第1张图片

# ///ADD START
# ///ADD END
# 设置当前工作路径
LOCAL_PATH:= $(call my-dir)
# 清除变量值
include $(CLEAR_VARS)
# 生成的模块名称
LOCAL_MODULE := baiduinput
# 生成的模块类型
LOCAL_MODULE_CLASS := APPS
# 生成的模块后缀名,此处为apk
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
# 设置模块tag,tags取值可以为:user debug eng tests optional
# optional表示全平台编译
LOCAL_MODULE_TAGS := optional
# LOCAL_PRIVILEGED_MODULE := true
#LOCAL_BUILT_MODULE_STEM := package.apk
LOCAL_PACKAGE_NAME := baiduinput
# 设置源文件
LOCAL_SRC_FILES := baiduinput_AndroidPhone_1000e.apk
# LOCAL_CERTIFICATE := platform
# 设置签名,此处表示保持apk原有签名
LOCAL_CERTIFICATE := PRESIGNED

JNI_LIBS := $(foreach FILE,$(shell find $(LOCAL_PATH)/lib/armeabi-v7a/ -name *.so), $(eval JNI_LIBS += $(FILE)))
LOCAL_PREBUILT_JNI_LIBS := $(subst $(LOCAL_PATH),,$(JNI_LIBS))

LOCAL_MULTILIB := 32

# 此处表示预编译方式
include $(BUILD_PREBUILT)
  • 制作package包目录

    目录:packages/apps/baiduinput

Android10 内置第三方输入法_第2张图片

  • 加入编译系统(DeviceCommon.mk 文件)
diff --git a/device/sprd/sharkl3/common/DeviceCommon.mk b/device/sprd/sharkl3/common/DeviceCommon.mk
index 1b51f03..526eef5 100755
--- a/device/sprd/sharkl3/common/DeviceCommon.mk
+++ b/device/sprd/sharkl3/common/DeviceCommon.mk
@@ -227,6 +227,8 @@ PRODUCT_PACKAGES += \
 PRODUCT_PACKAGES += \
     gwe_tty_loop_test
 
+PRODUCT_PACKAGES += \
+       baiduinput
 # sensor
 PRODUCT_PACKAGES += \
     [email protected] \ 

二、设置为系统默认输入法

diff --git a/frameworks/base/packages/SettingsProvider/res/values/defaults.xml b/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
index fb804c1..ffb4ce9 100644
--- a/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
+++ b/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
@@ -26,6 +26,8 @@
     cell,bluetooth,wifi,nfc,wimax
     bluetooth,wifi,nfc
     0
+    com.baidu.input/.ImeService
+    com.baidu.input/.ImeService
     true
     true
     false
diff --git a/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java b/frameworks/base/packages/SettingsProvider/src/com/android/providers/s
index 8d3c472..f443964 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
@@ -2434,6 +2434,12 @@ class DatabaseHelper extends SQLiteOpenHelper {
             loadIntegerSetting(stmt, Settings.Secure.SLEEP_TIMEOUT,
                     R.integer.def_sleep_timeout);
 
+            loadStringSetting(stmt, Settings.Secure.DEFAULT_INPUT_METHOD,
+                    R.string.default_input_method);
+
+            loadStringSetting(stmt, Settings.Secure.ENABLED_INPUT_METHODS,
+                    R.string.enabled_input_method);
+
             /*
              * IMPORTANT: Do not add any more upgrade steps here as the global,
              * secure, and system settings are no longer stored in a database

三、 解决切换系统语言导致输入被切换成安卓默认的输入法

diff --git a/frameworks/base/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/frameworks/base/services/core/java/com/android/server/inputmethod/Inp
index 50c7666..8e58616 100644
--- a/frameworks/base/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
+++ b/frameworks/base/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
@@ -1525,7 +1525,7 @@ public class InputMethodManagerService extends AbsInputMethodManager
         if (DEBUG) {
             Slog.i(TAG, "Default found, using " + defIm.getId());
         }
-        setSelectedInputMethodAndSubtypeLocked(defIm, NOT_A_SUBTYPE_ID, false);
+        //setSelectedInputMethodAndSubtypeLocked(defIm, NOT_A_SUBTYPE_ID, false);
     }
 
     @GuardedBy("mMethodMap")

你可能感兴趣的:(安卓开发,第三方输入法,Android10)