如何在移植Android时设置默认输入法?

4
  • 我在 build/target/product/generic.xml 中添加了 PinyinIME 来将其加入我的构建。
  • 我在 makefile 中设置了 CUSTOM_LOCALES:= zh_CN en_USADDITIONAL_BUILD_PROPERTIES := persist.sys.timezone=Asia/Shanghai persist.sys.language=zh persist.sys.country=CN 以仅使 US 和 CN 可用,并将 CN 设置为默认值。

但是,尽管我的默认语言设置为 CN,手机的默认输入法仍然是 LatinIME。在 PinyinIME 中,values-zh/bools.xml 包含 <bool name="im_is_default">true</bool>

请问如何实现我的目标?

1个回答

4

根据http://hi.baidu.com/wishwingliao/blog/item/65a2d03f7dde8dd17d1e71ec.html提供的方法进行解决。 在frameworks\base\core\res\res\values\config.xml中添加以下内容:

<string name="config_default_input_method">com.android.inputmethod.pinyin/.PinyinIME</string>

在frameworks\base\services\java\com\android\server\InputMethodManagerService.java中,在buildInputMethodListLocked()函数中添加以下内容。
String defaultIme = Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
    //leo

    if ( defaultIme == null )
    {
        final Resources res = mContext.getResources();
        try
        {
            //frameworks\base\core\res\res\values\config.xml
            String myIME = res.getString( com.android.internal.R.string.config_default_input_method );
            if ( myIME != null && myIME.length() > 0 )
            {
               Settings.Secure.putString( mContext.getContentResolver(),
                        Settings.Secure.DEFAULT_INPUT_METHOD,
                        myIME );
            }
        }

        catch ( Exception e )
        {
        }
    }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接