為Android系統(tǒng)添加config.xml 新配置的設(shè)置
在日常系統(tǒng)開(kāi)發(fā)中,經(jīng)常需要在adroid的framework修改或添加自己的配置。例如在config.xml 添加一個(gè)新的變量。我這邊測(cè)試發(fā)現(xiàn)如果只是簡(jiǎn)單的添加配置項(xiàng),在代碼里面怎么也訪問(wèn)不到。為了解決這個(gè)問(wèn)題仔細(xì)看了一下代碼,最終發(fā)現(xiàn)需要在public.xml 定義才可以。
下面用一個(gè)例子來(lái)說(shuō)明一下。
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)輸入法為土耳其語(yǔ)。
修改后,需要在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)單吧,一開(kāi)始我以為就是這樣,查了很多資料大家都是這樣使用的。最后編譯吧報(bào)了如下錯(cuò)誤
frameworks/base/services/java/com/android/server/InputMethodManagerService.java:726: 找不到符號(hào)
符號(hào): 變量
config_def_input_method
位置: 類(lèi)
com.android.internal.R.stringString 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時(shí)一個(gè)遞增的值,在系統(tǒng)中是唯一的,千萬(wàn)不要重復(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' />
的代碼拷貝出來(lái)放到android.xml文件中即可。
以上這篇為Android系統(tǒng)添加config.xml 新配置的設(shè)置就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. React+umi+typeScript創(chuàng)建項(xiàng)目的過(guò)程2. ASP中常用的22個(gè)FSO文件操作函數(shù)整理3. ASP.NET Core 5.0中的Host.CreateDefaultBuilder執(zhí)行過(guò)程解析4. SharePoint Server 2019新特性介紹5. .Net core 的熱插拔機(jī)制的深入探索及卸載問(wèn)題求救指南6. 解決ASP中http狀態(tài)跳轉(zhuǎn)返回錯(cuò)誤頁(yè)的問(wèn)題7. 讀大數(shù)據(jù)量的XML文件的讀取問(wèn)題8. ASP編碼必備的8條原則9. 無(wú)線標(biāo)記語(yǔ)言(WML)基礎(chǔ)之WMLScript 基礎(chǔ)第1/2頁(yè)10. ASP調(diào)用WebService轉(zhuǎn)化成JSON數(shù)據(jù),附j(luò)son.min.asp
