系统自带的输入法源码在packages\inputmethods\目录,像谷歌输入法和谷歌拼音输入法的源码都是在这里!
系统的默认输入法,修改掉其系统的语言,输入法键盘布局也会改变!
因为系统中的Android键盘(AOSP)有个语言设置选项,里面默认的是“使用系统语言”,
现在客户要求关闭默认“使用系统语言”,默认语言是英语,但是键盘要其它语言的
默认输入键盘布局由Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE属性报错,保存的值是一个哈希码-921088104,对应其默认输入语言 。
在设置输入法的时候,传入输入法默认输入语言的哈希值,达到修改输入键盘布局的目的!
即在设置Settings.Secure.ENABLED_INPUT_METHODS属性值的时候,后面添加默认语言。
1.先添加输入法包名和服务名后面加输入语言的哈希值
public static final String ENABLED_INPUT_METHODS = "enabled_input_methods";
adb shell settings get secure enabled_input_methods
com.android.inputmethod.latin/.LatinIME;843948332
adb pull data/data/com.android.providers.settings/databases/settings.db
打开Secure表,查看default_input_method,enabled_input_methods和selected_input_method_subtype三个字段内容,:
default_input_method com.android.inputmethod.latin/.LatinIME
enabled_input_methods com.android.inputmethod.latin/.LatinIME;816242702;-921088104
selected_input_method_subtype 816242702
frameworks\base\packages\SettingsProvider\res\values\defaults.xml
<string name="config_enable_input_method" translatable="false">com.android.inputmethod.latin/.LatinIME;-921088104</string>
<string name="def_input_method_franch_keyboard" translatable="false">com.android.inputmethod.latin/.LatinIME;843948332</string> 法语
<string name="config_default_input_method" translatable="false">com.android.inputmethod.latin/.LatinIME</string>
// -921088104对应的是en_US,即美式英语。 获取哈希码的函数
private void getSubtypeHashCode(Context context) {
//String[] LOCAL_LANGUAGES = {"en_US","en_GB"};
final String inputmethodPackageName = "com.android.inputmethod.latin";
final InputMethodManager imm = (InputMethodManager) context.getSystemService( Context.INPUT_METHOD_SERVICE);
final StringBuilder builder = new StringBuilder();
for (InputMethodInfo info : imm.getInputMethodList()) {
if (inputmethodPackageName.equals(info.getPackageName())) {
for (int i = 0; i < info.getSubtypeCount(); i++) {
final InputMethodSubtype subtype = info.getSubtypeAt(i);
final String locale = subtype.getLocale().toString();
//for (String str : LOCAL_LANGUAGES) {
// if (str.equals(locale)) {
builder.append(locale);
builder.append(" hashcode:");
builder.append(subtype.hashCode());
builder.append("\n");
Log.i(TAG,"get local:"+ locale + "hashcode:" + subtype.hashCode());
// }
//}
}
break;
}
}
//frhashcode:843948332 法语
Log.i(TAG,"get hascode end--->"+builder.toString());
}
2.frameworks\base\packages\SettingsProvider\src\com\android\providers\settings\DatabaseHelper.java
private void loadSecureSettings(SQLiteDatabase db) {
SQLiteStatement stmt = null;
try {
stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
+ " VALUES(?,?);");
// Don't do this. The SystemServer will initialize ADB_ENABLED from a
// persistent system property instead.
//loadSetting(stmt, Settings.Secure.ADB_ENABLED, 0);
//loadSetting(stmt, Settings.Secure.ENABLED_INPUT_METHODS, defaultIme);
//loadSetting(stmt, Settings.Secure.DEFAULT_INPUT_METHOD, defaultIme);
//demo
//loadSetting(stmt, Settings.Secure.ENABLED_INPUT_METHODS,"com.android.inputmethod.latin/.LatinIME;816242702;-921088104");//选中的输入法
//loadSetting(stmt, Settings.Secure.DEFAULT_INPUT_METHOD, "com.android.inputmethod.latin/.LatinIME");// 默认输入法为系统输入法
//loadSetting(stmt, Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, "816242702"); // 默认输入法的默认语言
//success
+loadStringSetting(stmt, Settings.Secure.ENABLED_INPUT_METHODS,R.string.config_enable_input_method );
+loadStringSetting(stmt, Settings.Secure.DEFAULT_INPUT_METHOD,R.string.config_default_input_method );
https://blog.csdn.net/qq503393230/article/details/133762312
安卓系统修改默认输入键盘_mf34键盘在线修改-CSDN博客
Android 9.0 默认输入法的设置流程分析 - 二的次方 - 博客园 (cnblogs.com)
标签:输入法,Secure,Android11,默认,AOSP,INPUT,android,com From: https://www.cnblogs.com/kato-T/p/18212449