1# Resourcemanager 2 3 4## 概述 5 6提供c相关获取资源的接口。 7 8**起始版本:** 12 9 10 11## 汇总 12 13 14### 文件 15 16| 名称 | 描述 | 17| -------- | -------- | 18| [ohresmgr.h](ohresmgr_8h.md) | 提供资源管理native侧获取资源的能力。 | 19| [resmgr_common.h](resmgr__common_8h.md) | 提供接口所需要的枚举类型和结构体。 | 20 21 22### 枚举 23 24| 名称 | 描述 | 25| -------- | -------- | 26| [ResourceManager_ErrorCode](#resourcemanager_errorcode) {<br/>SUCCESS = 0, ERROR_CODE_INVALID_INPUT_PARAMETER = 401, ERROR_CODE_RES_ID_NOT_FOUND = 9001001, ERROR_CODE_RES_NOT_FOUND_BY_ID = 9001002,<br/>ERROR_CODE_RES_NAME_NOT_FOUND = 9001003, ERROR_CODE_RES_NOT_FOUND_BY_NAME = 9001004, ERROR_CODE_RES_PATH_INVALID = 9001005, ERROR_CODE_RES_REF_TOO_MUCH = 9001006,<br/>ERROR_CODE_RES_ID_FORMAT_ERROR = 9001007, ERROR_CODE_RES_NAME_FORMAT_ERROR = 9001008, ERROR_CODE_SYSTEM_RES_MANAGER_GET_FAILED = 9001009, ERROR_CODE_OVERLAY_RES_PATH_INVALID = 9001010,<br/>ERROR_CODE_OUT_OF_MEMORY = 9001100<br/>} | 资源管理错误码。 | 27| [ScreenDensity](#screendensity) {<br/>SCREEN_SDPI = 120, SCREEN_MDPI = 160, SCREEN_LDPI = 240, SCREEN_XLDPI = 320,<br/>SCREEN_XXLDPI = 480, SCREEN_XXXLDPI = 640<br/>} | 屏幕密度类型的枚举。 | 28 29 30### 函数 31 32| 名称 | 描述 | 33| -------- | -------- | 34| [ResourceManager_ErrorCode](#resourcemanager_errorcode)[OH_ResourceManager_GetMediaBase64](#oh_resourcemanager_getmediabase64) (const NativeResourceManager \*mgr, uint32_t resId, char \*\*resultValue, uint64_t \*resultLen, uint32_t density=0) | 获取指定资源ID,指定屏幕密度对应的media资源的Base64码。 | 35| [ResourceManager_ErrorCode](#resourcemanager_errorcode)[OH_ResourceManager_GetMediaBase64ByName](#oh_resourcemanager_getmediabase64byname) (const NativeResourceManager \*mgr, const char \*resName, char \*\*resultValue, uint64_t \*resultLen, uint32_t density=0) | 获取指定资源名称,指定屏幕密度对应的media资源的Base64码。 | 36| [ResourceManager_ErrorCode](#resourcemanager_errorcode)[OH_ResourceManager_GetMedia](#oh_resourcemanager_getmedia) (const NativeResourceManager \*mgr, uint32_t resId, uint8_t \*\*resultValue, uint64_t \*resultLen, uint32_t density=0) | 获取指定资源ID,指定屏幕密度对应的media资源的内容。 | 37| [ResourceManager_ErrorCode](#resourcemanager_errorcode)[OH_ResourceManager_GetMediaByName](#oh_resourcemanager_getmediabyname) (const NativeResourceManager \*mgr, const char \*resName, uint8_t \*\*resultValue, uint64_t \*resultLen, uint32_t density=0) | 获取指定资源名称,指定屏幕密度对应的media资源的内容。 | 38| [ResourceManager_ErrorCode](#resourcemanager_errorcode)[OH_ResourceManager_GetDrawableDescriptor](#oh_resourcemanager_getdrawabledescriptor) (const NativeResourceManager \*mgr, uint32_t resId, ArkUI_DrawableDescriptor \*\*drawableDescriptor, uint32_t density=0, uint32_t type=0) | 获取指定资源Id,指定屏幕密度对应的图标资源的DrawableDescriptor。 | 39| [ResourceManager_ErrorCode](#resourcemanager_errorcode)[OH_ResourceManager_GetDrawableDescriptorByName](#oh_resourcemanager_getdrawabledescriptorbyname) (const NativeResourceManager \*mgr, const char \*resName, ArkUI_DrawableDescriptor \*\*drawableDescriptor, uint32_t density=0, uint32_t type=0) | 获取指定资源名称,指定屏幕密度对应的图标资源的DrawableDescriptor。 | 40 41 42## 枚举类型说明 43 44 45### ResourceManager_ErrorCode 46 47``` 48enum ResourceManager_ErrorCode 49``` 50 51**描述** 52 53资源管理错误码。 54 55**起始版本:** 12 56 57| 枚举值 | 描述 | 58| -------- | -------- | 59| SUCCESS | 成功。 | 60| ERROR_CODE_INVALID_INPUT_PARAMETER | 输入参数无效。 | 61| ERROR_CODE_RES_ID_NOT_FOUND | 无效的资源ID。 | 62| ERROR_CODE_RES_NOT_FOUND_BY_ID | 无效的资源名称。 | 63| ERROR_CODE_RES_NAME_NOT_FOUND | 没有根据资源ID找到匹配的资源。 | 64| ERROR_CODE_RES_NOT_FOUND_BY_NAME | 没有根据资源名称找到匹配的资源。 | 65| ERROR_CODE_RES_PATH_INVALID | 无效的相对路径。 | 66| ERROR_CODE_RES_REF_TOO_MUCH | 资源被循环引用。 | 67| ERROR_CODE_RES_ID_FORMAT_ERROR | 无法格式化基于资源ID获得的资源。 | 68| ERROR_CODE_RES_NAME_FORMAT_ERROR | 无法格式化基于资源名称获得的资源。 | 69| ERROR_CODE_SYSTEM_RES_MANAGER_GET_FAILED | 访问系统资源失败。 | 70| ERROR_CODE_OVERLAY_RES_PATH_INVALID | 无效的overlay路径。 | 71| ERROR_CODE_OUT_OF_MEMORY | 内存溢出。 | 72 73 74### ScreenDensity 75 76``` 77enum ScreenDensity 78``` 79 80**描述** 81 82屏幕密度类型的枚举。 83 84**起始版本:** 12 85 86| 枚举值 | 描述 | 87| -------- | -------- | 88| SCREEN_SDPI | 表示小屏幕密度。 | 89| SCREEN_MDPI | 表示中屏幕密度。 | 90| SCREEN_LDPI | 表示大屏幕密度。 | 91| SCREEN_XLDPI | 表示特大屏幕密度。 | 92| SCREEN_XXLDPI | 表示超大屏幕密度。 | 93| SCREEN_XXXLDPI | 表示超特大屏幕密度。 | 94 95 96## 函数说明 97 98 99### OH_ResourceManager_GetDrawableDescriptor() 100 101``` 102ResourceManager_ErrorCode OH_ResourceManager_GetDrawableDescriptor (const NativeResourceManager * mgr, uint32_t resId, ArkUI_DrawableDescriptor ** drawableDescriptor, uint32_t density = 0, uint32_t type = 0 ) 103``` 104 105**描述** 106 107获取指定资源Id,指定屏幕密度对应的图标资源的DrawableDescriptor。 108 109**起始版本:** 12 110 111**参数:** 112 113| 名称 | 描述 | 114| -------- | -------- | 115| mgr | 指向**NativeResourceManager**的指针,此指针通过**OH_ResourceManager_InitNativeResourceManager**方法获取。 | 116| resId | 资源ID。 | 117| density | 可选参数screen、enddensity、enddensity,值为0表示使用当前系统dpi的密度。 | 118| type | 选参数表示图标类型,0表示自身图标,1表示主题图标。 | 119| drawableDescriptor | 写入drawableDescriptor的结果。 | 120 121**返回:** 122 123SUCCESS 0:成功。 124 125ERROR_CODE_INVALID_INPUT_PARAMETER 401 :输入参数无效。可能的原因:1。参数类型不正确;2.参数验证失败。 126 127ERROR_CODE_RES_ID_NOT_FOUND 9001001:无效的资源ID。 128 129ERROR_CODE_RES_NOT_FOUND_BY_ID 9001002:没有根据资源ID找到匹配的资源。 130 131 132### OH_ResourceManager_GetDrawableDescriptorByName() 133 134``` 135ResourceManager_ErrorCode OH_ResourceManager_GetDrawableDescriptorByName (const NativeResourceManager * mgr, const char * resName, ArkUI_DrawableDescriptor ** drawableDescriptor, uint32_t density = 0, uint32_t type = 0 ) 136``` 137 138**描述** 139 140获取指定资源名称,指定屏幕密度对应的图标资源的DrawableDescriptor。 141 142**起始版本:** 12 143 144**参数:** 145 146| 名称 | 描述 | 147| -------- | -------- | 148| mgr | 指向**NativeResourceManager**的指针,此指针通过**OH_ResourceManager_InitNativeResourceManager**方法获取。 | 149| resName | 资源名称。 | 150| density | 可选参数screen enddensity **enddensity**,值为0表示使用当前系统dpi的密度。 | 151| type | 可选参数表示图标类型,0表示自身图标,1表示主题图标,2表示动态图标。 | 152| drawableDescriptor | 写入drawableDescriptor的结果。 | 153 154**返回:** 155 156SUCCESS 0 :成功。 157 158ERROR_CODE_INVALID_INPUT_PARAMETER 401:输入参数无效。可能的原因:1。参数类型不正确;2.参数验证失败。 159 160ERROR_CODE_RES_NAME_NOT_FOUND 9001003:无效的资源名称。 161 162ERROR_CODE_RES_NOT_FOUND_BY_NAME 9001004:没有根据资源名称找到匹配的资源。 163 164 165### OH_ResourceManager_GetMedia() 166 167``` 168ResourceManager_ErrorCode OH_ResourceManager_GetMedia (const NativeResourceManager * mgr, uint32_t resId, uint8_t ** resultValue, uint64_t * resultLen, uint32_t density = 0 ) 169``` 170 171**描述** 172 173获取指定资源ID,指定屏幕密度对应的media资源的内容。 174 175**起始版本:** 12 176 177**参数:** 178 179| 名称 | 描述 | 180| -------- | -------- | 181| mgr | 指向**NativeResourceManager**的指针,此指针通过**OH_ResourceManager_InitNativeResourceManager**方法获取。 | 182| resId | 资源ID。 | 183| density | 可选参数screen enddensity **enddensity**,值为0表示使用当前系统dpi的密度。 | 184| resultValue | 写入resultValue的结果。 | 185| resultLen | 写入resultLen的media长度。 | 186 187**返回:** 188 189SUCCESS 0:成功。 190 191ERROR_CODE_INVALID_INPUT_PARAMETER 401:输入参数无效。可能的原因:1。参数类型不正确;2.参数验证失败。 192 193ERROR_CODE_RES_ID_NOT_FOUND 9001001:无效的资源ID。 194 195ERROR_CODE_RES_NOT_FOUND_BY_ID 9001002:没有根据资源ID找到匹配的资源。 196 197ERROR_CODE_OUT_OF_MEMORY 9001100:内存溢出。 198 199 200### OH_ResourceManager_GetMediaBase64() 201 202``` 203ResourceManager_ErrorCode OH_ResourceManager_GetMediaBase64 (const NativeResourceManager * mgr, uint32_t resId, char ** resultValue, uint64_t * resultLen, uint32_t density = 0 ) 204``` 205 206**描述** 207 208获取指定资源ID,指定屏幕密度对应的media资源的Base64码。 209 210**起始版本:** 12 211 212**参数:** 213 214| 名称 | 描述 | 215| -------- | -------- | 216| mgr | 指向**NativeResourceManager**的指针,此指针通过**OH_ResourceManager_InitNativeResourceManager**方法获取。 | 217| resId | 资源ID。 | 218| density | 可选参数screen enddensity **enddensity**,值为0表示使用当前系统dpi的密度。 | 219| resultValue | 写入resultValue的结果。 | 220| resultLen | 写入resultLen的media长度。 | 221 222**返回:** 223 224SUCCESS 0:成功。 225 226ERROR_CODE_INVALID_INPUT_PARAMETER 401:输入参数无效。可能的原因:1。参数类型不正确;2.参数验证失败。 227 228ERROR_CODE_RES_ID_NOT_FOUND 9001001:无效的资源ID。 229 230ERROR_CODE_RES_NOT_FOUND_BY_ID 9001002:没有根据资源ID找到匹配的资源。 231 232ERROR_CODE_OUT_OF_MEMORY 9001100:内存溢出。 233 234 235### OH_ResourceManager_GetMediaBase64ByName() 236 237``` 238ResourceManager_ErrorCode OH_ResourceManager_GetMediaBase64ByName (const NativeResourceManager * mgr, const char * resName, char ** resultValue, uint64_t * resultLen, uint32_t density = 0 ) 239``` 240 241**描述** 242 243获取指定资源名称,指定屏幕密度对应的media资源的Base64码。 244 245**起始版本:** 12 246 247**参数:** 248 249| 名称 | 描述 | 250| -------- | -------- | 251| mgr | 指向**NativeResourceManager**的指针,此指针通过**OH_ResourceManager_InitNativeResourceManager**方法获取。 | 252| resName | 资源名称。 | 253| density | 可选参数screen enddensity **enddensity**,值为0表示使用当前系统dpi的密度。 | 254| resultValue | 写入resultValue的结果。 | 255| resultLen | 写入resultLen的media长度。 | 256 257**返回:** 258 259SUCCESS 0 - 成功。 ERROR_CODE_INVALID_INPUT_PARAMETER 401 - 输入参数无效。可能的原因:1。参数类型不正确;2.参数验证失败。 ERROR_CODE_RES_NAME_NOT_FOUND 9001003 - 无效的资源名称。 ERROR_CODE_RES_NOT_FOUND_BY_NAME 9001004 - 没有根据资源名称找到匹配的资源。 ERROR_CODE_OUT_OF_MEMORY 9001100 - 内存溢出。 260 261 262### OH_ResourceManager_GetMediaByName() 263 264``` 265ResourceManager_ErrorCode OH_ResourceManager_GetMediaByName (const NativeResourceManager * mgr, const char * resName, uint8_t ** resultValue, uint64_t * resultLen, uint32_t density = 0 ) 266``` 267 268**描述** 269 270获取指定资源名称,指定屏幕密度对应的media资源的内容。 271 272**起始版本:** 12 273 274**参数:** 275 276| 名称 | 描述 | 277| -------- | -------- | 278| mgr | 指向**NativeResourceManager**的指针,此指针通过**OH_ResourceManager_InitNativeResourceManager**方法获取。 | 279| resName | 资源名称。 | 280| density | 可选参数screen enddensity **enddensity**,值为0表示使用当前系统dpi的密度。 | 281| resultValue | 写入resultValue的结果。 | 282| resultLen | 写入resultLen的media长度。 | 283 284**返回:** 285 286SUCCESS 0 :成功。 287 288ERROR_CODE_INVALID_INPUT_PARAMETER 401:输入参数无效。可能的原因:1。参数类型不正确;2.参数验证失败。 289 290ERROR_CODE_RES_NAME_NOT_FOUND 9001003:无效的资源名称。 291 292ERROR_CODE_RES_NOT_FOUND_BY_NAME 9001004:没有根据资源名称找到匹配的资源。 293 294ERROR_CODE_OUT_OF_MEMORY 9001100:内存溢出。 295