欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

為Android系統(tǒng)添加config.xml 新配置的設置

 更新時間:2020年03月23日 10:43:52   作者:xcy2011sky  
這篇文章主要介紹了為Android系統(tǒng)添加config.xml 新配置的設置,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

在日常系統(tǒng)開發(fā)中,經(jīng)常需要在adroid的framework修改或添加自己的配置。例如在config.xml 添加一個新的變量。我這邊測試發(fā)現(xiàn)如果只是簡單的添加配置項,在代碼里面怎么也訪問不到。為了解決這個問題仔細看了一下代碼,最終發(fā)現(xiàn)需要在public.xml 定義才可以。

下面用一個例子來說明一下。

1.在framework/base/core/res/res/valus/config.xml 添加默認輸入配置:

<!--
set default inputmethod.
-->
<string translatable="false" name="config_def_input_method">com.taypo.android.trskb/.TRSoftKeyboard</string>

這是默認輸入法為土耳其語。

修改后,需要在framework/base/core/res/res z執(zhí)行mm 編譯一下修改。

完成后,croot到根目錄,執(zhí)行make update-api 更新一下api。

2.如果使用這個配置項

我這邊在framework/base/service/java/com/android/interanl/InputMethodManangerService.java 中的resetDefaultIMeLocked函數(shù)使用這個變量

 private void resetDefaultImeLocked(Context context) {
    // Do not reset the default (current) IME when it is a 3rd-party IME
    if (mCurMethodId != null
        && !InputMethodUtils.isSystemIme(mMethodMap.get(mCurMethodId))) {
      return;
    }
 
 
    InputMethodInfo defIm = null;
 String id=context.getResources().getString(com.android.internal.R.string.config_def_input_method);
 Slog.i(TAG, "internal.id: " + id);
    for (InputMethodInfo imi : mMethodList) {
 
  if(imi.getId().equals(id)) defIm=imi;
  
   
     }
  
     /* if (defIm == null) {
        if (InputMethodUtils.isValidSystemDefaultIme(
            mSystemReady, imi, context)) {
          defIm = imi;
          Slog.i(TAG, "Selected default: " + imi.getId());
        }
      }
    }
    if (defIm == null && mMethodList.size() > 0) {
      defIm = InputMethodUtils.getMostApplicableDefaultIME(
          mSettings.getEnabledInputMethodListLocked());
      Slog.i(TAG, "No default found, using " + defIm.getId());
    }
    */
    if (defIm != null) {
      setSelectedInputMethodAndSubtypeLocked(defIm, NOT_A_SUBTYPE_ID, false);
    }
  }

這樣使用很簡單吧,一開始我以為就是這樣,查了很多資料大家都是這樣使用的。最后編譯吧報了如下錯誤

frameworks/base/services/java/com/android/server/InputMethodManagerService.java:726: 找不到符號

符號: 變量

config_def_input_method

位置: 類

com.android.internal.R.string
String id=context.getResources().getString(com.android.internal.R.string.config_def_input_method);

但是我明明定義了,為什么還是找不到呢。

解決方案:

1.在framework/base/core/res/res/values/public.xml文件里增加對這些string的聲明。

2.framework/base/core/res/res/ 下mm編譯

3.到根目錄下執(zhí)行make update-api 更新api。

<public type="string" name="config_def_input_method" id="0x01040018" />

注意在 里面的id時一個遞增的值,在系統(tǒng)中是唯一的,千萬不要重復。

到此,在變異inputmethodmanagerService.java 就可以pass啦。

補充知識:向config.xml中添加一個配置項

1. 在config.xml中添加一項(路徑:frameworks/base/core/res/res/values/)

如:

<bool name="config_myValue">true</bool>

2. 在 frameworks/base/core/res/res/values/symbols.xml中,添加:

<java-symbol type="bool" name="config_myValue"/>

3. 在frameworks/base/core/res/res/values/android.xml中,添加

一帶有id的項,但此id怎么生成呢?如下步驟:

首先:在frameowrks/base/tools/aapt/ResourceTable.cpp中

在addSymbols()函數(shù)中,把如下的注釋去掉:

//printf("<android type=\"%\" name=\"%\" id=...>,

然后,在代碼根目錄下,執(zhí)行:

make framework-res > res.txt

就可以把android原始資源輸出到res.txt文件中。

然后,把其中的

<android type="bool" name="config_myValue" id="0x0111005b"/>

的代碼拷貝出來放到android.xml文件中即可。

以上這篇為Android系統(tǒng)添加config.xml 新配置的設置就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

最新評論