Android keyboard input language Settings default to opening myanmar Burmese steps

  • 2020-05-10 18:47:33
  • OfStack

locale is generated by merger through the system Settings locale and latin input language, so you can only set it in "input language Settings" if you support both the system locale and the input language

languageList is read from the latin_preferences.xml file that stores the latin input method Settings. The input language was set last time

If you want to set a language to open by default in the input method, press step 1 to add files, I have verified here when OK, you can try 1.
Provide simple sample code, such as default Burmese, English, French input method tick:

1. Write 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"); // Default will be English, Burmese tick, how to write can refer to inputlanguageselection.java In the WHITELIST_LANGUAGES 
editor.putBoolean("has_set", true); 
Log.d("LatinImeReceiver", "step4"); 
//editor.commit(); 
SharedPreferencesCompat.apply(editor); 
Log.d("LatinImeReceiver", "step5"); 
} 
} 

Place it to the path packages/inputmethods/LatinIME/java/src/com/android inputmethod/latin folder below

2. Registered intent in packages/inputmethods/LatinIME/java/androidManifest xml in the back to join:
And increase < uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" / > permissions
 
<receiver android:name="LatinImeReceiver" android:enabled="true"> 
<intent-filter> 
<action android:name="android.intent.action.BOOT_COMPLETED" /> 
</intent-filter> 
</receiver> 

Related articles: