Android键盘输入语言设置默认打开myanmar缅甸语的步骤
locale是通过系统设置的地区和latin输入法语言通过merger出来的,所以在系统地区设置和输入法语言中同时支持才可以在“输入语言设置“里设置
languageList是从存储latin输入法设置的latin_preferences.xml文件里读取出来的,上一次设置的输入语言
如果要设置某种语言在输入法默认打开可按一下步骤添加文件,我这里已经验证时OK的,你可以试一下。
提供简单的sample code,如默认将缅甸语、英文、法语输入法勾选:
1.书写文件LatinImeReceiver.java
代码如下:
package com.android.inputmethod.latin;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.util.Log;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
//import android.view.inputmethod.InputMethodSubtype;
import android.text.TextUtils;
public class LatinImeReceiver extends BroadcastReceiver {
private static final String TAG = LatinImeReceiver.class.getSimpleName();
@Override
public void onReceive(Context context, Intent intent) {
Log.d("LatinImeReceiver", "step1");
SharedPreferences sp = context.getSharedPreferences("com.android.inputmethod.latin_preferences",
Context.MODE_PRIVATE);
boolean hasSet = sp.getBoolean("has_set", false);
if (!hasSet) {
Log.d("LatinImeReceiver", "step2");
Editor editor = sp.edit();
Log.d("LatinImeReceiver", "step3");
editor.putString(LatinIME.PREF_SELECTED_LANGUAGES, "en_US,my,fr"); //默认将英语、缅甸语勾选,具体该怎么写可以参考inputlanguageselection.java中的WHITELIST_LANGUAGES
editor.putBoolean("has_set", true);
Log.d("LatinImeReceiver", "step4");
//editor.commit();
SharedPreferencesCompat.apply(editor);
Log.d("LatinImeReceiver", "step5");
}
}
将其放置到路径packages/inputmethods/LatinIME/java/src/com/android/inputmethod/latin文件夹下面
2.注册intent,在packages/inputmethods/LatinIME/java/androidManifest.xml中的最后面加入:
并增加 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />权限
代码如下:
<receiver android:name="LatinImeReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>