亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

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

下面用一個(gè)例子來說明一下。

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

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

這是默認(rèn)輸入法為土耳其語。

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

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

2.如果使用這個(gè)配置項(xiàng)

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

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

這樣使用很簡(jiǎn)單吧,一開始我以為就是這樣,查了很多資料大家都是這樣使用的。最后編譯吧報(bào)了如下錯(cuò)誤

frameworks/base/services/java/com/android/server/InputMethodManagerService.java:726: 找不到符號(hào)

符號(hào): 變量

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文件里增加對(duì)這些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時(shí)一個(gè)遞增的值,在系統(tǒng)中是唯一的,千萬不要重復(fù)。

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

補(bǔ)充知識(shí):向config.xml中添加一個(gè)配置項(xiàng)

1. 在config.xml中添加一項(xiàng)(路徑: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的項(xiàng),但此id怎么生成呢?如下步驟:

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

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

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

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

make framework-res > res.txt

就可以把a(bǔ)ndroid原始資源輸出到res.txt文件中。

然后,把其中的

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

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

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

相關(guān)文章

最新評(píng)論