amlogic平台,给LatinIME输入法添加语言

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);

重新编译烧录就可以了

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值