門戶網(wǎng)站做壓力測試搜索引擎的工作原理是什么?
【HarmonyOS】鴻蒙應(yīng)用子模塊module資源如何獲取
一、問題背景:
在多模塊項目工程中,單個模塊的資源不會放在主模塊中,所以我們需要在子模塊中訪問自己的資源。如果使用默認的資源獲取api,會提示找不到資源。
那如何獲取子模塊下的資源呢?
二、API說明:
DEMO講解通過注釋的方式表明。若有不清楚的點,可關(guān)注私信我溝通。
以獲取音效文件舉例:
// 主模塊中的resource-rawfile中let fileDescriptor = await getContext(this).resourceManager.getRawFd("test.mp3");// 子模塊中的resource-rawfile中let fileDescriptor = await getContext(this).createModuleContext("模塊名").resourceManager.getRawFd("test.mp3");// 主模塊中的resource-element-字符串資源getContext(this).resourceManager.getStringByNameSync('app.string.EntryAbility_label');// 子模塊中的resource-element-字符串資源getContext(this).createModuleContext("模塊名").resourceManager.getStringByNameSync('app.string.EntryAbility_label');// 同理顏色,字體大小等配置資源的獲取都是如此。需要在上下文后面,在指定創(chuàng)建子模塊的上下文。再通過resourceManager操作獲取資源。