| Name | Date | Size | #Lines | LOC | ||
|---|---|---|---|---|---|---|
| .. | - | - | ||||
| AppScope/ | 06-May-2025 | - | 36 | 33 | ||
| entry/ | 06-May-2025 | - | 1,998 | 1,875 | ||
| hvigor/ | 06-May-2025 | - | 23 | 22 | ||
| libraryOverlay/ | 06-May-2025 | - | 190 | 166 | ||
| libraryRuntimeOverlay/ | 06-May-2025 | - | 189 | 165 | ||
| sceenshots/device/ | 06-May-2025 | - | ||||
| .gitignore | D | 06-May-2025 | 143 | 12 | 11 | |
| README.md | D | 06-May-2025 | 735 | 18 | 7 | |
| README_zh.md | D | 06-May-2025 | 5.4 KiB | 158 | 93 | |
| build-profile.json5 | D | 06-May-2025 | 1.5 KiB | 67 | 66 | |
| hvigorfile.ts | D | 06-May-2025 | 158 | 2 | 1 | |
| hvigorw | D | 06-May-2025 | 2.1 KiB | 62 | 28 | |
| hvigorw.bat | D | 06-May-2025 | 2 KiB | 72 | 56 | |
| oh-package.json5 | D | 06-May-2025 | 212 | 12 | 11 | |
| ohosTest.md | D | 06-May-2025 | 2.3 KiB | 19 | 19 |
README.md
1# eTS Resource Management 2 3 4 5### Introduction 6 7This sample shows how to call resource management APIs in eTS to obtain strings and images. 8 9### Usage 10 11The application page displays the calling of resource management APIs, such as obtaining a string or string array, obtaining a string in singular or plural form represented by the specified ID based on the quantity specified, setting the number of bytes of the media file content corresponding to the specified resource ID, and setting the length of the Base64 string of the image resource corresponding to the specified resource ID, and obtaining the device status and capabilities supported by the device. 12 13 14 15### Constraints 16 17This sample can only be run on standard-system devices. 18
README_zh.md
1# 资源管理器 2 3### 介绍 4 5本工程使用[@ohos.app.ability.common](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-common.md) 6接口中的AbilityContext类,获取资源管理器resourceManager,使用[@ohos.resourceManager.d.ts](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-localization-kit/js-apis-resource-manager.md) 7中的接口,展示了格式化字符串查询、基于指定屏幕分辨率查询媒体资源、获取系统资源管理对象等基础功能,以及展示了资源静态overlay以及运行时overlay的特性功能。 8 9### 效果预览 10 11|主页| 12|---| 13|| 14 15#### 使用说明 16 17此界面为主页面,其中展示了资源管理API各类接口的调用以及特性Overlay场景功能。其作用有: 18 191、点击资源API调用示例按钮,可跳转到资源API示例页面 20 212、点击Overlay使用示例,可以跳转到Overlay的使用示例界面。 22 23#### 资源API调用示例 24 25|资源API测试| 26|---| 27|| 28 29#### 使用说明 30 31此页面展示了当前资源管理接口的调用以及接口对应的返回结果。 32 33#### 静态overlay场景 34 35|overlay场景| 36|---| 37|| 38 39#### 使用说明 40 41此页面展示静态overlay功能,功能使用如下: 42 431、静态overlay是默认使能的,当前显示的是静态overlay中的字符串和图标。 44 452、点击Disable可以触发去使能,重启应用可以恢复显示应用的字符串和图标。 46 473、点击enable可以触发使能,重启应用可以再次显示overlay中的字符串和图标。 48 49源码参考:[Overlay示例](entry/src/main/ets/pages/Overlay.ets) 50 51#### 运行时overlay场景 52 53|运行时overlay场景| 54|---| 55|| 56 57#### 使用说明 58 59此页面展示运行时overlay功能,功能使用如下: 60 611、点击addResource可以触发运行时overlay,此时会使用运行时overlay中的资源覆盖之前的字符串和图标。 62 632、点击removeResource可以触发移除运行时overlay,此时会移除运行时overlay,恢复到覆盖前的字符串和图标。 64 65### 工程目录 66 67``` 68entry/src/main/ets/ 69|---entryability 70|---pages 71| |---Index.ets // 场景首页 72| |---BasicResources.ets // 基础资源场景 73| |---Overlay.ets // overlay场景 74|---libraryOverlay // 静态overlay 75|---libraryRuntimeOverlay // 运行时overlay 76``` 77 78### 具体实现 79 80#### 资源API调用示例具体实现: 81 821、使用getContext()接口获取context对象,使用context.resourceManager获取资源管理对象,然后调用resourceManager内部的相关接口获取对应资源,例如: 83* 获取字符串资源:resourceManager.getStringValue() 84* 获取字符串数组资源:resourceManager.getStringArrayValue() 85* 获取图片资源:resourceManager.getMediaContent() 86* 获取格式化字符串资源:resourceManager.getStringSync() 87* 获取指定屏幕分辨率媒体资源:resourceManager.getMediaContentBase64() 88 892、导包resourceManager,使用resourceManager.getSystemResourceManager()获取系统资源管理对象,然后获取系统资源。 90 91源码参考:[资源API调用示例](entry/src/main/ets/pages/BasicResources.ets) 92 93#### overlay场景的具体实现: 94 951、静态overlay主要是通过加载overly中的资源实现资源覆盖,需要在对应的module.json中添加"targetModuleName":"entry", 表示覆盖entry中的资源,默认使能,也可调用包管理接口进行使能和去使能。 96 97使用步骤为:在安装完entry的hap后,需要把library模块生成的library-default-signed.hsp推送到/data/test下,使用bm install命令进行安装。 98 99脚本语言如下: 100 101hdc_std shell mount -o remount,rw / 102 103hdc_std install ./entry-default-signed.hap 104 105hdc_std shell mkdir /data/test 106 107hdc_std file send ./libraryOverlay-default-signed.hsp /data/test 108 109hdc_std shell bm install -p "/data/test/libraryOverlay-default-signed.hsp" 110 111pause 112 1132、运行时overlay资源加载,主要是在应用运行过程中实现资源的覆盖,需要应用主动调用资源的addResource接口实现资源的覆盖以及资源的移除,此功能不持久化。 114 115使用步骤为: 在安装完entry的hap后,需要把libraryRuntimeOverlay模块生成的libraryRuntimeOverlay-default-signed.hsp推送到应用对应的安装目录下。 116 117脚本语言如下: 118 119hdc_std shell mount -o remount,rw / 120 121hdc_std install ./entry-default-signed.hap 122 123hdc_std file send ./libraryRuntimeOverlay-default-signed.hsp /data/app/el1/bundle/public/ohos.samples.resourcemanager 124 125pause 126 127源码参考:[Overlay示例](entry/src/main/ets/pages/Overlay.ets) 128 129 130### 相关权限 131 132不涉及。 133 134### 依赖 135 136不涉及。 137 138### 约束与限制 139 1401. 本工程示例仅支持标准系统上运行。 141 1422. 本工程仅支持API10版本SDK,SDK版本号(API Version 10 Release),镜像版本号(4.0Release)。 143 1443. 本工程示例需要使用DevEco Studio 版本号(4.0Release)及以上版本才可编译运行。 145 146### 下载 147 148如需单独下载本工程,执行如下命令: 149 150``` 151git init 152git config core.sparsecheckout true 153echo code/BasicFeature/Resource/ResourceManager/ > .git/info/sparse-checkout 154git remote add origin https://gitee.com/openharmony/applications_app_samples.git 155git pull origin master 156``` 157 158