amlogic平台,给LatinIME输入法添加语言
1、frameworks\base\packages\SettingsProvider\res\values\defaults.xml
添加
<string name="def_input_methods">com.android.inputmethod.latin/.LatinIME;-921088104;1983547218</string>
这里的数字串:-921088104 :英语;1983547218 :俄语
源码中packages\inputmethods\LatinIME\java\res\xml\method.xml可以看到对应的值
也可以写调试代码:
private static final String[] DEFAULT_LANGUAGES = {"en_US","ru"};//英语,俄语
private void getCommoit(Context context) {
final String serviceName = "com.android.inputmethod.latin/.LatinIME";
final String currentPackageName = "com.android.inputmethod.latin";
final String enable = Settings.Secure.getString(context.getContentResolver(),
Settings.Secure.ENABLED_INPUT_METHODS);
final InputMethodManager imm = (InputMethodManager) context.getSystemService( Context.INPUT_METHOD_SERVICE);
final StringBuilder builder = new StringBuilder();
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 locale = subtype.getLocale().toString();
if (isDefaultLocale(locale)) {
builder.append(';');
builder.append(subtype.hashCode());
}
}
break;
}
}
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 {
return;
}
//这里是我想要的信息了
Log.i(TAG,"debug by 123 commoit:"+builder.toString());//com.android.inputmethod.latin/.LatinIME;-921088104;1983547218
}
private boolean isDefaultLocale (String locale) {
final String[] locales = DEFAULT_LANGUAGES;
for (String str : locales) {
if (str.equals(locale)) {
return true;
}
}
return false;
}
2、在frameworks\base\packages\SettingsProvider\src\com\android\providers\settings\DatabaseHelper.java中 loadSecureSettings 函数新增:
loadStringSetting(stmt, Settings.Secure.ENABLED_INPUT_METHODS, R.string.def_input_methods);
重新编译烧录就可以了