通过网络搜索查到一种做法:
在应用中增加广播:
<receiver android:name="com.tcl.inputmethod.LatinImeReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
并需要增加3个权限
<uses-permission android:name="android.permission.WRITE_SETTINGS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
public class LatinImeReceiver extends BroadcastReceiver {
private static final String TAG = LatinImeReceiver.class.getSimpleName();
private static final String[] DEFAULT_LATIN_IME_LANGUAGES = {"en_US","th"};//默认开启输入法的语言
@Override
public void onReceive(Context context, Intent intent) {
final String intentAction = intent.getAction();
// Set the default input language at the system boot completed.
Logger.d(TAG, "LatinImeReceiver onReceive getAction:" + intentAction);
final LanguageSelectManager richImm = LanguageSelectManager.getInstance();
if (Intent.ACTION_BOOT_COMPLETED.equals(intentAction)) {
Logger.i(TAG,"onReceive:ACTION_BOOT_COMPLETED");
SharedPreferences sp = context.getSharedPreferences("default_input_language_config", Context.MODE_PRIVATE);
boolean hasSet = sp.getBoolean("has_set", false);
if (!hasSet) {
setDefaultSubtypes(context);
sp.edit().putBoolean("has_set", true).commit();
}
}
}
private void setDefaultSubtypes(Context context) {
Logger.i(TAG, "setDefaultSubtypes");
final String serviceName = "com.tcl.inputmethod.international/.T_IME";
final String currentPackageName = "com.tcl.inputmethod.international";
final String enable = Settings.Secure.getString(context.getContentResolver(),
Settings.Secure.ENABLED_INPUT_METHODS);
Logger.i(TAG, "setDefaultSubtypes enable :" + enable);//com.tcl.inputmethod.international/.T_IME
final InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
final StringBuilder builder = new StringBuilder();
// Get sub type hash code
for (InputMethodInfo info : imm.getInputMethodList()) {
if (currentPackageName.equals(info.getPackageName())) {
Logger.i(TAG, "info.getSubtypeCount()=" + info.getSubtypeCount());//42
for (int i = 0; i < info.getSubtypeCount(); i++) {
final InputMethodSubtype subtype = info.getSubtypeAt(i);
final String locale = subtype.getLocale().toString();
Logger.i(TAG, "locale = " + locale);
if (isDefaultLocale(locale)) {
Logger.i(TAG, "default enabled subtype locale = " + locale);
builder.append(';');
builder.append(subtype.hashCode());
}
}
break;
}
}
// Insert the sub type
if (builder.length() > 0 && !TextUtils.isEmpty(enable)) {
final String subtype = builder.toString();
builder.setLength(0);
final int index = enable.indexOf(serviceName) + serviceName.length();
if (enable.length() > index) {
builder.append(enable.substring(0, index));
builder.append(subtype);
builder.append(enable.substring(index));
} else if (enable.length() == index) {
builder.append(enable);
builder.append(subtype);
} else {
return;
}
} else {
Logger.w(TAG, "Build Latin IME subtype failed: " + " builder length = " + builder.length() +
"; enable isEmpty :" + TextUtils.isEmpty(enable));
return;
}
/*android/packages/inputmethods/LatinIME/java/res/xml/method.xml
-921088104;529847764分别代表en_US和th
*/
Logger.i(TAG, "commoit:" + builder.toString());//com.android.inputmethod.latin/.LatinIME;-921088104;529847764
// Commit the result
android.provider.Settings.Secure.putString(context.getContentResolver(),
android.provider.Settings.Secure.ENABLED_INPUT_METHODS, builder.toString());
String lastInputMethodId = Settings.Secure.getString(context.getContentResolver(),
Settings.Secure.DEFAULT_INPUT_METHOD);
Logger.w(TAG, "DEFAULT_INPUT_METHOD = " + lastInputMethodId); //com.android.inputmethod.latin/.LatinIME
if (lastInputMethodId.equals(serviceName)) {
Logger.w(TAG, "DEFAULT_INPUT_METHOD = com.android.inputmethod.latin/.LatinIME");
for (InputMethodInfo info : imm.getInputMethodList()) {
if (currentPackageName.equals(info.getPackageName())) {
for (int i = 0; i < info.getSubtypeCount(); i++) {
final InputMethodSubtype subtype = info.getSubtypeAt(i);
final String[] locales = DEFAULT_LATIN_IME_LANGUAGES;
Logger.w(TAG, "i = " + i + ", locales[0] = " + locales[0]);
if ((subtype.getLocale()).equals(locales[0])) {
Logger.w(TAG, "putString " + subtype.hashCode());
Settings.Secure.putInt(context.getContentResolver(),
Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, subtype.hashCode());
}
}
}
}
}
}
/**
* M: Check if the current locale is default or not.
*/
private boolean isDefaultLocale(String locale) {
final String[] locales = DEFAULT_LATIN_IME_LANGUAGES;
for (String s : locales) {
if (s.equals(locale)) {
return true;
}
}
return false;
}
这种方法试了一下可行,但是需要把应用放在/system/app/ 路径下才能获取到权限,否则一直会报错
AndroidRuntime: java.lang.RuntimeException: Unable to create service com.tcl.inputmethod.international.T_IME: java.lang.SecurityException: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS
另外还有一个弊端就是这种方法在开机向导起来的时候应用获取的开机广播才能生效
针对以上问题我调研了google 的Gboard 和Latin输入法,都能在某些系统语言下,使用系统语言开关开的时候,同时使得系统语言和英语键盘都打开,通过查看和分析google的源码,SettingsLib 最终是做设置输入法的 Subtype 的,但是这个对系统对Gboard 和Latin输入法并没有做特殊处理,那么它是怎么做到系统语言开关开的时候,同时使得系统语言和英语键盘都打开呢?
此时我认为只能通过 Gboard 和Latin输入法 的源码找端倪。
对于输入法来说最重要的就是,method.xml 方法,我发现即便输入法没有启动,系统的设置菜单里面输入法设置中系统语言开关的功能也是生效的,那么对于输入法端肯定是设置某些属性或者配置文件配置内容就能生效的。先看一下Latin输入法的method.xml
<?xml version="1.0" encoding="utf-8"?>
<!--
/**
* Copyright (c) 2008, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<!-- The attributes in this XML file provide configuration information -->
<!-- for the Input Method Manager. -->
<!-- Supported subtypes
keyboard_locale: script_name/keyboard_layout_set
af: Afrikaans/qwerty
ar: Arabic/arabic
az_AZ: Azerbaijani (Azerbaijan)/qwerty
be_BY: Belarusian (Belarus)/east_slavic
bg: Bulgarian/bulgarian
bg: Bulgarian/bulgarian_bds
bn_BD: Bengali (Bangladesh)/bengali_akkhor
bn_IN: Bengali (India)/bengali
ca: Catalan/spanish
cs: Czech/qwertz
da: Danish/nordic
de: German/qwertz
de_CH: German (Switzerland)/swiss
el: Greek/greek
en_IN: English (India)/qwerty
en_US: English (United States)/qwerty
en_GB: English (Great Britain)/qwerty
eo: Esperanto/spanish
es: Spanish/spanish
es_US: Spanish (United States)/spanish
es_419: Spanish (Latin America)/spanish
et_EE: Estonian (Estonia)/nordic
eu_ES: Basque (Spain)/spanish
fa: Persian/farsi
fi: Finnish/nordic
fr: French/azerty
fr_CA: French (Canada)/qwerty
fr_CH: French (Switzerland)/swiss
gl_ES: Galician (Spain)/spanish
hi: Hindi/hindi
hi: Hindi/hindi_compact
hi_ZZ: Hinglish/qwerty # This is a preliminary keyboard layout.
hr: Croatian/qwertz
hu: Hungarian/qwertz
hy_AM: Armenian (Armenia) Phonetic/armenian_phonetic
in: Indonesian/qwerty # "id" is the official language code of Indonesian.
is: Icelandic/qwerty
it: Italian/qwerty
it_CH: Italian (Switzerland)/swiss
iw: Hebrew/hebrew # "he" is the official language code of Hebrew.
ka_GE: Georgian (Georgia)/georgian
kk: Kazakh/east_slavic
km_KH: Khmer (Cambodia)/khmer
kn_IN: Kannada (India)/kannada
ky: Kyrgyz/east_slavic
lo_LA: Lao (Laos)/lao
lt: Lithuanian/qwerty
lv: Latvian/qwerty
mk: Macedonian/south_slavic
ml_IN: Malayalam (India)/malayalam
mn_MN: Mongolian (Mongolia)/mongolian
mr_IN: Marathi (India)/marathi
ms_MY: Malay (Malaysia)/qwerty
nb: Norwegian Bokmål/nordic
ne_NP: Nepali (Nepal) Romanized/nepali_romanized
ne_NP: Nepali (Nepal) Traditional/nepali_traditional
nl: Dutch/qwerty
nl_BE: Dutch (Belgium)/azerty
pl: Polish/qwerty
pt_BR: Portuguese (Brazil)/qwerty
pt_PT: Portuguese (Portugal)/qwerty
ro: Romanian/qwerty
ru: Russian/east_slavic
si_LK: Sinhala (Sri Lanka)/sinhala # This is a preliminary keyboard layout.
sk: Slovak/qwerty
sl: Slovenian/qwerty
sr: Serbian/south_slavic
sr_ZZ: Serbian (Latin)/serbian_qwertz # This is a preliminary keyboard layout.
sv: Swedish/nordic
sw: Swahili/qwerty
ta_IN: Tamil (India)/tamil
ta_LK: Tamil (Sri Lanka)/tamil # Disabled in conjunction with si_LK.
ta_SG: Tamil (Singapore)/tamil
te_IN: Telugu (India)/telugu
th: Thai/thai
tl: Tagalog/spanish
tr: Turkish/qwerty
uk: Ukrainian/east_slavic
uz_UZ: Uzbek (Uzbekistan)/uzbek # This is a preliminary keyboard layout.
vi: Vietnamese/qwerty
zu: Zulu/qwerty
zz: QWERTY/qwerty
(zz: Emoji/emoji)
-->
<!-- TODO: use <lang>_keyboard icon instead of a common keyboard icon. -->
<!-- TODO: Remove "AsciiCapable" from the extra values when we can stop supporting JB-MR1 -->
<!-- Note: SupportTouchPositionCorrection extra value is obsolete and maintained for backward
compatibility. -->
<!-- If IME doesn't have an applicable subtype, the first subtype will be used as a default
subtype.-->
<input-method xmlns:android="http://schemas.android.com/apk/res/android"
android:settingsActivity="com.android.inputmethod.latin.settings.SettingsActivity"
android:isDefault="@bool/im_is_default"
android:supportsSwitchingToNextInputMethod="true">
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_en_US"
android:subtypeId="0xc9194f98"
android:imeSubtypeLocale="en_US"
android:languageTag="en-US"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="TrySuppressingImeSwitcher,AsciiCapable,SupportTouchPositionCorrection,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_en_GB"
android:subtypeId="0xb045e755"
android:imeSubtypeLocale="en_GB"
android:languageTag="en-GB"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="TrySuppressingImeSwitcher,AsciiCapable,SupportTouchPositionCorrection,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x6f972360"
android:imeSubtypeLocale="af"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x590dde40"
android:imeSubtypeLocale="ar"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="SupportTouchPositionCorrection,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x70b0f974"
android:imeSubtypeLocale="az_AZ"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x1dc3a859"
android:imeSubtypeLocale="be_BY"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=east_slavic,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x0ba9c0e8"
android:imeSubtypeLocale="bg"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=bulgarian,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_bulgarian_bds"
android:subtypeId="0x5f51ba9a"
android:imeSubtypeLocale="bg"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=bulgarian_bds,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0xa2144b0c"
android:imeSubtypeLocale="bn_BD"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=bengali_akkhor,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0xbff5986c"
android:imeSubtypeLocale="bn_IN"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=bengali,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0xd2e520d5"
android:imeSubtypeLocale="ca"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=spanish,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x2d3d2ed0"
android:imeSubtypeLocale="cs"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x2df4605d"
android:imeSubtypeLocale="da"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x2e2cbe61"
android:imeSubtypeLocale="de"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x7acfd0aa"
android:imeSubtypeLocale="de_CH"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=swiss,AsciiCapable,SupportTouchPositionCorrection,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x0e7802d3"
android:imeSubtypeLocale="el"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=greek,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x8d58fc2d"
android:imeSubtypeLocale="en_IN"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x4090554a"
android:imeSubtypeLocale="eo"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=spanish,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x30a6e00e"
android:imeSubtypeLocale="es"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_es_US"
android:subtypeId="0x84d2efc6"
android:imeSubtypeLocale="es_US"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=spanish,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0xa23e5d19"
android:imeSubtypeLocale="es_419"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=spanish,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0xec2d3955"
android:imeSubtypeLocale="et_EE"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=nordic,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x070e5c07"
android:imeSubtypeLocale="eu_ES"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=spanish,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0xbe66c254"
android:imeSubtypeLocale="fa"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=farsi,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x31cecda3"
android:imeSubtypeLocale="fi"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x324da12c"
android:imeSubtypeLocale="fr"
android:languageTag="fr"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0xeadbb691"
android:imeSubtypeLocale="fr_CA"
android:languageTag="fr-CA"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0xeadc55f5"
android:imeSubtypeLocale="fr_CH"
android:languageTag="fr-CH"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=swiss,AsciiCapable,SupportTouchPositionCorrection,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0xb939573c"
android:imeSubtypeLocale="gl_ES"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=spanish,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x39753b7f"
android:imeSubtypeLocale="hi"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=hindi,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic_compact"
android:subtypeId="0xe49c89a1"
android:imeSubtypeLocale="hi"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=hindi_compact,EmojiCapable"
android:isAsciiCapable="false"
/>
<!-- TODO: This Hinglish keyboard is a preliminary layout.
This isn't based on the final specification. -->
<!-- Disabled because there is no LM yet, and this layout does not offer anything different.
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_hi_ZZ"
android:subtypeId="0x352eb37c"
android:imeSubtypeLocale="hi_ZZ"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="AsciiCapable,KeyboardLayoutSet=qwerty,EmojiCapable"
android:isAsciiCapable="true"
/>
-->
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x35b7526a"
android:imeSubtypeLocale="hr"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x35e198ed"
android:imeSubtypeLocale="hu"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0xe39ac3ca"
android:imeSubtypeLocale="hy_AM"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=armenian_phonetic,EmojiCapable"
android:isAsciiCapable="false"
/>
<!-- Java uses the deprecated "in" code instead of the standard "id" code for Indonesian. -->
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x7daea460"
android:imeSubtypeLocale="in"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x7df519e5"
android:imeSubtypeLocale="is"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x37885a0b"
android:imeSubtypeLocale="it"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0xd914fe1a"
android:imeSubtypeLocale="it_CH"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=swiss,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<!-- Java uses the deprecated "iw" code instead of the standard "he" code for Hebrew. -->
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x66fb18bd"
android:imeSubtypeLocale="iw"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="SupportTouchPositionCorrection,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x6e119e6a"
android:imeSubtypeLocale="ka_GE"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=georgian,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x2d73d2f6"
android:imeSubtypeLocale="kk"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=east_slavic,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x1365683a"
android:imeSubtypeLocale="km_KH"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=khmer,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x8c78064f"
android:imeSubtypeLocale="kn_IN"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=kannada,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x2e391c04"
android:imeSubtypeLocale="ky"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=east_slavic,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x8315772c"
android:imeSubtypeLocale="lo_LA"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=lao,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x8321bb43"
android:imeSubtypeLocale="lt"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x833dea45"
android:imeSubtypeLocale="lv"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0xaf50ab7c"
android:imeSubtypeLocale="mk"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=south_slavic,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0xc182ebd4"
android:imeSubtypeLocale="ml_IN"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=malayalam,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0xcdcfc3ab"
android:imeSubtypeLocale="mn_MN"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=mongolian,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x747b9f03"
android:imeSubtypeLocale="mr_IN"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=marathi,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x84c87c61"
android:imeSubtypeLocale="ms_MY"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x3f12ee14"
android:imeSubtypeLocale="nb"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0xd80a4cee"
android:imeSubtypeLocale="ne_NP"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=nepali_romanized,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic_traditional"
android:subtypeId="0x5fafea88"
android:imeSubtypeLocale="ne_NP"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=nepali_traditional,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x3f9fd91e"
android:imeSubtypeLocale="nl"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x500ca92c"
android:imeSubtypeLocale="nl_BE"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=azerty,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x43098a5c"
android:imeSubtypeLocale="pl"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0xcafff4a6"
android:imeSubtypeLocale="pt_BR"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0xe2fffc5a"
android:imeSubtypeLocale="pt_PT"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x8d185978"
android:imeSubtypeLocale="ro"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x763a8752"
android:imeSubtypeLocale="ru"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="SupportTouchPositionCorrection,EmojiCapable"
android:isAsciiCapable="false"
/>
<!-- TODO: This Sinhala keyboard is a preliminary layout.
This isn't based on the final specification. -->
<!-- si_LK is currently disabled due to lack of combination rules.
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x5c6b3bde"
android:imeSubtypeLocale="si_LK"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=sinhala,EmojiCapable"
android:isAsciiCapable="false"
/>
-->
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x8e94d413"
android:imeSubtypeLocale="sk"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x8ea2eb94"
android:imeSubtypeLocale="sl"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x77c5196e"
android:imeSubtypeLocale="sr"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="SupportTouchPositionCorrection,EmojiCapable"
android:isAsciiCapable="false"
/>
<!-- TODO: This Serbian Latin keyboard is a preliminary layout.
This isn't based on the final specification. -->
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_sr_ZZ"
android:subtypeId="0xf4a5569c"
android:imeSubtypeLocale="sr_ZZ"
android:languageTag="sr-Latn"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=serbian_qwertz,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x48b4ff43"
android:imeSubtypeLocale="sv"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x8f3dee1f"
android:imeSubtypeLocale="sw"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x67acea2a"
android:imeSubtypeLocale="ta_IN"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=tamil,EmojiCapable"
android:isAsciiCapable="false"
/>
<!-- TODO: Enabling/Disabling ta_LK subtype must be aligned with si_LK subtype. -->
<!-- ta_LK disabled alongside si_LK subtype due to lack of combination rules.
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x6ca12d84"
android:imeSubtypeLocale="ta_LK"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=tamil,EmojiCapable"
android:isAsciiCapable="false"
/>
!-->
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x785abbd9"
android:imeSubtypeLocale="ta_SG"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=tamil,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x1e177389"
android:imeSubtypeLocale="te_IN"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=telugu,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x1f94d5d4"
android:imeSubtypeLocale="th"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=thai,EmojiCapable"
android:isAsciiCapable="false"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0xf08285ef"
android:imeSubtypeLocale="tl"
android:languageTag="fil"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=spanish,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x4a3179de"
android:imeSubtypeLocale="tr"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x3e84492c"
android:imeSubtypeLocale="uk"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=east_slavic,EmojiCapable"
android:isAsciiCapable="false"
/>
<!-- TODO: This Uzbek keyboard is a preliminary layout.
This isn't based on the final specification. -->
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0xad5cf7f6"
android:imeSubtypeLocale="uz_UZ"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=uzbek,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x93972eee"
android:imeSubtypeLocale="vi"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
android:subtypeId="0x9b13ab76"
android:imeSubtypeLocale="zu"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_no_language_qwerty"
android:subtypeId="0xa239ebad"
android:imeSubtypeLocale="zz"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable,EnabledWhenDefaultIsNotAsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<!-- Emoji subtype has to be an addtional subtype added at boot time because ICS doesn't
support Emoji. -->
<!--<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_emoji"
android:subtypeId="0xc14d88b2"
android:imeSubtypeLocale="zz"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=emoji,EmojiCapable"
android:isAsciiCapable="false"
/>-->
</input-method>
subtype_emoji是额外增加的,会在代码里面动态添加,这个看起来不特别

这样看的更清晰,我测试并发现,只有设置了 android:isAsciiCapable="false" 的语言,设置菜单会显示多一种语言打开中文翻译 字母(qwerty)
对应的字段是 subtype_no_language_qwerty ,此时我发现 在method.xml 中刚好有个语言用到了这个字段
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_no_language_qwerty"
android:subtypeId="0xa239ebad"
android:imeSubtypeLocale="zz"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable,EnabledWhenDefaultIsNotAsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
此时我发现这个应该就是多显示出来的那种语言
结合以上分析,我在我自己的输入法中增加了这个zz语言的配置,并且其他语言按照类似的方式加了android:isAsciiCapable="false"或者android:isAsciiCapable="true"的配置,最终惊喜的发现,做到了无论什么语言下,使用系统语言开的情况下,默认都能英语键盘可切换,可打开。
这种总结一下输入法常用的命令:
查看系统权限:
系统android SettingsProvider 配置属性存储位置:https://blog.csdn.net/hnlgzb/article/details/117029126
输入法命令
获取当前设备有效的输入法列表
adb shell ime list -s
注意:-s并不是已安装的所有输入法,而是安装并已勾选的输入法。
启用方式:
系统设置>>通用>>语言和输入法>>勾选输入法
使用命令的方式
adb shell ime enable jp.jun_nama.test.utf7ime/.Utf7ImeService
若需要全部的输入法,需要使用-a命令
adb shell ime list -a
获取当前设备有效输入法的详细信息
adb shell ime list
当前正在使用的输入法
settings get secure enabled_input_methods
adb shell settings get secure default_input_method
settings get secure enabled_input_methods
切换输入法(设置默认输入法)
adb shell settings put secure default_input_method com.sohu.inputmethod.sogou/.SogouIME
注意:系统设置中未开启状态的输入法,只要你知道了它的名字,也可以使用这个命令切换使用。
zekylldeMacBook-Pro:~ zekyll$ adb shell ime -h
ime <command>:
list [-a] [-s]
prints all enabled input methods.
-a: see all input methods
-s: only a single summary line of each
enable [--user <USER_ID>] <ID>
allows the given input method ID to be used.
--user <USER_ID>: Specify which user to enable. Assumes the current user if not specified.
disable [--user <USER_ID>] <ID>
disallows the given input method ID to be used.
--user <USER_ID>: Specify which user to disable. Assumes the current user if not specified.
set [--user <USER_ID>] <ID>
switches to the given input method ID.
--user <USER_ID>: Specify which user to enable. Assumes the current user if not specified.
reset [--user <USER_ID>]
reset currently selected/enabled IMEs to the default ones as if the device is initially booted w
ith the current locale.
--user <USER_ID>: Specify which user to reset. Assumes the current user if not specified.