locale是通過系統設定的地區和latinIME語言通過merger出來的,所以在系統地區設定和IME語言中同時支援才可以在“輸入語言設定“裡設定
languageList是從儲存latinIME設定的latin_preferences.xml檔案裡讀取出來的,上一次設定的輸入語言
如果要設定某種語言在IME預設開啟可按一下步驟添加檔案,我這裡已經驗證時OK的,你可以試一下。
提供簡單的sample code,如預設將緬甸語、英文、法語IME勾選:
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>