js-apis-resource-manager.md 166.7 KB
Newer Older
Z
zengyawen 已提交
1
# @ohos.resourceManager (资源管理)
Z
zengyawen 已提交
2

F
fangyunzhong 已提交
3
资源管理模块,根据当前configuration:语言、区域、横竖屏、Mcc(移动国家码)和Mnc(移动网络码)、Device capability(设备类型)、Density(分辨率)提供获取应用资源信息读取接口。
4

5 6
> **说明:**
>
W
wplan1 已提交
7
> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
Z
zengyawen 已提交
8

Z
zengyawen 已提交
9 10

## 导入模块
Z
zengyawen 已提交
11

H
HelloCrease 已提交
12
```js
Z
zengyawen 已提交
13 14 15
import resourceManager from '@ohos.resourceManager';
```

H
huangjie 已提交
16 17
## 使用说明

H
huangjie 已提交
18
从API Version9开始,Stage模型通过context获取resourceManager对象的方式后,可直接调用其内部获取资源的接口,无需再导入包。此方式FA模型不适用,FA模型还需要先导入包,再调用[getResourceManager](#resourcemanagergetresourcemanager)接口获取资源对象。
Z
zengyawen 已提交
19
Stage模型下Context的引用方法请参考[Stage模型的Context详细介绍](../../application-models/application-context-stage.md)
H
huangjie 已提交
20

H
HelloCrease 已提交
21
```ts
22 23 24
import UIAbility from '@ohos.app.ability.UIAbility';

export default class EntryAbility extends UIAbility {
25 26 27 28
  onWindowStageCreate(windowStage) {
    let context = this.context;
    let resourceManager = context.resourceManager;
  }
F
fangyunzhong 已提交
29
}
H
huangjie 已提交
30 31
```

Z
zengyawen 已提交
32 33 34
## resourceManager.getResourceManager

getResourceManager(callback: AsyncCallback<ResourceManager>): void
Z
zengyawen 已提交
35 36 37

获取当前应用的资源管理对象,使用callback形式返回ResourceManager对象。

V
VictoriaGuo 已提交
38 39
**系统能力**:SystemCapability.Global.ResourceManager

Z
zt147369 已提交
40 41
**模型约束**:此接口仅可在FA模型下使用。

H
HelloCrease 已提交
42
**参数:** 
H
huangjie 已提交
43

H
HelloCrease 已提交
44 45 46
| 参数名      | 类型                                       | 必填   | 说明                            |
| -------- | ---------------------------------------- | ---- | ----------------------------- |
| callback | AsyncCallback<[ResourceManager](#resourcemanager)> | 是    | callback方式返回ResourceManager对象 |
Z
zengyawen 已提交
47

H
HelloCrease 已提交
48
**示例:** 
H
HelloCrease 已提交
49
  ```js
Z
zengyawen 已提交
50
  resourceManager.getResourceManager((error, mgr) => {
51 52 53 54 55
    if (error != null) {
      console.log("error is " + error);
      return;
    }
    mgr.getStringValue(0x1000000, (error, value) => {
Z
zengyawen 已提交
56
      if (error != null) {
57 58 59
        console.log("error is " + error);
      } else {
        let str = value;
Z
zengyawen 已提交
60
      }
61
    });
Z
zengyawen 已提交
62 63
  });
  ```
H
huangjie 已提交
64
注:示例代码中的0x1000000表示资源对应的id, 其可在编译后的文件ResourceTable.txt中找到。
Z
zengyawen 已提交
65 66 67 68 69


## resourceManager.getResourceManager

getResourceManager(bundleName: string, callback: AsyncCallback<ResourceManager>): void
Z
zengyawen 已提交
70 71 72

获取指定应用的资源管理对象,使用callback形式返回ResourceManager对象。

V
VictoriaGuo 已提交
73 74
**系统能力**:SystemCapability.Global.ResourceManager

Z
zt147369 已提交
75 76
**模型约束**:此接口仅可在FA模型下使用。

H
HelloCrease 已提交
77
**参数:** 
H
huangjie 已提交
78

H
HelloCrease 已提交
79 80 81 82
| 参数名        | 类型                                       | 必填   | 说明                            |
| ---------- | ---------------------------------------- | ---- | ----------------------------- |
| bundleName | string                                   | 是    | 指定应用的Bundle名称                 |
| callback   | AsyncCallback<[ResourceManager](#resourcemanager)> | 是    | callback方式返回ResourceManager对象 |
Z
zengyawen 已提交
83

H
HelloCrease 已提交
84
**示例:** 
H
HelloCrease 已提交
85
  ```js
Z
zengyawen 已提交
86 87 88 89 90 91 92 93
  resourceManager.getResourceManager("com.example.myapplication", (error, mgr) => {
  });
  ```


## resourceManager.getResourceManager

getResourceManager(): Promise<ResourceManager>
Z
zengyawen 已提交
94 95 96

获取当前应用的资源管理对象,使用Promise形式返回ResourceManager对象。

V
VictoriaGuo 已提交
97 98
**系统能力**:SystemCapability.Global.ResourceManager

Z
zt147369 已提交
99 100
**模型约束**:此接口仅可在FA模型下使用。

H
huangjie 已提交
101 102
**返回值:**

H
HelloCrease 已提交
103 104 105
| 类型                                       | 说明                |
| ---------------------------------------- | ----------------- |
| Promise<[ResourceManager](#resourcemanager)> | Promise方式返回资源管理对象 |
Z
zengyawen 已提交
106

H
HelloCrease 已提交
107
**示例:** 
H
HelloCrease 已提交
108
  ```js
F
fangyunzhong 已提交
109 110 111 112
  import resourceManager from '@ohos.resourceManager';
  import { BusinessError } from '@ohos.base';

  resourceManager.getResourceManager().then((mgr: resourceManager.ResourceManager) => {
113 114 115 116 117 118 119
    mgr.getStringValue(0x1000000, (error, value) => {
      if (error != null) {
        console.log("error is " + error);
      } else {
        let str = value;
      }
    });
F
fangyunzhong 已提交
120
  }).catch((error: BusinessError) => {
121
    console.log("error is " + error);
Z
zengyawen 已提交
122 123
  });
  ```
H
huangjie 已提交
124
注:示例代码中的0x1000000表示资源对应的id, 其可在编译后的文件ResourceTable.txt中找到。
Z
zengyawen 已提交
125 126 127 128 129


## resourceManager.getResourceManager

getResourceManager(bundleName: string): Promise<ResourceManager>
Z
zengyawen 已提交
130 131 132

获取指定应用的资源管理对象,使用Promise形式返回ResourceManager对象。

V
VictoriaGuo 已提交
133 134
**系统能力**:SystemCapability.Global.ResourceManager

Z
zt147369 已提交
135 136
**模型约束**:此接口仅可在FA模型下使用。

H
HelloCrease 已提交
137
**参数:** 
H
huangjie 已提交
138

H
HelloCrease 已提交
139 140 141
| 参数名        | 类型     | 必填   | 说明            |
| ---------- | ------ | ---- | ------------- |
| bundleName | string | 是    | 指定应用的Bundle名称 |
Z
zengyawen 已提交
142

H
huangjie 已提交
143 144
**返回值:**

H
HelloCrease 已提交
145 146 147
| 类型                                       | 说明                 |
| ---------------------------------------- | ------------------ |
| Promise<[ResourceManager](#resourcemanager)> | Promise方式返回的资源管理对象 |
Z
zengyawen 已提交
148

H
HelloCrease 已提交
149
**示例:** 
H
HelloCrease 已提交
150
  ```js
F
fangyunzhong 已提交
151 152 153 154 155
  import resourceManager from '@ohos.resourceManager';
  import { BusinessError } from '@ohos.base';

  resourceManager.getResourceManager("com.example.myapplication").then((mgr: resourceManager.ResourceManager) => {
  }).catch((error: BusinessError) => {
Z
zengyawen 已提交
156 157 158
  });
  ```

159
## resourceManager.getSystemResourceManager<sup>10+</sup>
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183

getSystemResourceManager(): ResourceManager

获取系统资源管理对象,返回系统资源的ResourceManager对象。

**系统能力**:SystemCapability.Global.ResourceManager

**返回值:**

| 类型                                       | 说明                 |
| ---------------------------------------- | ------------------ |
| Resourcemanager | 返回系统资源的管理对象 |

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001009  | If application can't access system resource.                       |

**示例:**
  ```js
import resourceManager from '@ohos.resourceManager';
F
fangyunzhong 已提交
184
import { BusinessError } from '@ohos.base';
185

186
  try {
187
    let systemResourceManager = resourceManager.getSystemResourceManager();
F
fangyunzhong 已提交
188
    systemResourceManager.getStringValue($r('sys.string.ohos_lab_vibrate').id).then((value: string) => {
189
      let str = value;
F
fangyunzhong 已提交
190
    }).catch((error: BusinessError) => {
191
      console.log("systemResourceManager getStringValue promise error is " + error);
192
    });
193
  } catch (error) {
Z
zt147369 已提交
194
    console.error(`systemResourceManager getStringValue failed, error code: ${error.code}, message: ${error.message}.`);
195
  }
196 197 198
  ```


Z
zengyawen 已提交
199
## Direction
Z
zengyawen 已提交
200 201 202

用于表示设备屏幕方向。

H
HelloCrease 已提交
203
**系统能力**:SystemCapability.Global.ResourceManager
H
HelloCrease 已提交
204

H
huangjie 已提交
205
| 名称                   | 值  | 说明   |
H
HelloCrease 已提交
206 207 208
| -------------------- | ---- | ---- |
| DIRECTION_VERTICAL   | 0    | 竖屏   |
| DIRECTION_HORIZONTAL | 1    | 横屏   |
Z
zengyawen 已提交
209 210 211


## DeviceType
Z
zengyawen 已提交
212 213 214

用于表示当前设备类型。

H
HelloCrease 已提交
215
**系统能力**:SystemCapability.Global.ResourceManager
H
HelloCrease 已提交
216

H
huangjie 已提交
217
| 名称                   | 值  | 说明   |
H
HelloCrease 已提交
218 219 220 221 222 223 224
| -------------------- | ---- | ---- |
| DEVICE_TYPE_PHONE    | 0x00 | 手机   |
| DEVICE_TYPE_TABLET   | 0x01 | 平板   |
| DEVICE_TYPE_CAR      | 0x02 | 汽车   |
| DEVICE_TYPE_PC       | 0x03 | 电脑   |
| DEVICE_TYPE_TV       | 0x04 | 电视   |
| DEVICE_TYPE_WEARABLE | 0x06 | 穿戴   |
Z
zengyawen 已提交
225 226 227


## ScreenDensity
Z
zengyawen 已提交
228 229 230

用于表示当前设备屏幕密度。

H
HelloCrease 已提交
231
**系统能力**:SystemCapability.Global.ResourceManager
H
HelloCrease 已提交
232

H
huangjie 已提交
233
| 名称             | 值  | 说明         |
H
HelloCrease 已提交
234 235 236 237 238 239 240
| -------------- | ---- | ---------- |
| SCREEN_SDPI    | 120  | 小规模的屏幕密度   |
| SCREEN_MDPI    | 160  | 中规模的屏幕密度   |
| SCREEN_LDPI    | 240  | 大规模的屏幕密度   |
| SCREEN_XLDPI   | 320  | 特大规模的屏幕密度  |
| SCREEN_XXLDPI  | 480  | 超大规模的屏幕密度  |
| SCREEN_XXXLDPI | 640  | 超特大规模的屏幕密度 |
Z
zengyawen 已提交
241 242 243


## Configuration
Z
zengyawen 已提交
244 245 246

表示当前设备的状态。

H
HelloCrease 已提交
247
**系统能力**:SystemCapability.Global.ResourceManager
H
HelloCrease 已提交
248

H
huangjie 已提交
249
**参数:** 
Z
zengyawen 已提交
250

H
huangjie 已提交
251
| 名称        | 类型                    | 可读   | 可写   | 说明       |
H
HelloCrease 已提交
252 253 254
| --------- | ----------------------- | ---- | ---- | -------- |
| direction | [Direction](#direction) | 是    | 否    | 当前设备屏幕方向 |
| locale    | string                  | 是    | 否    | 当前系统语言   |
Z
zengyawen 已提交
255 256 257


## DeviceCapability
Z
zengyawen 已提交
258 259 260

表示设备支持的能力。

H
HelloCrease 已提交
261
**系统能力**:SystemCapability.Global.ResourceManager
H
HelloCrease 已提交
262

H
huangjie 已提交
263
**参数:**
Z
zengyawen 已提交
264

H
huangjie 已提交
265
| 名称            | 类型                            | 可读   | 可写   | 说明       |
H
HelloCrease 已提交
266 267 268
| ------------- | ------------------------------- | ---- | ---- | -------- |
| screenDensity | [ScreenDensity](#screendensity) | 是    | 否    | 当前设备屏幕密度 |
| deviceType    | [DeviceType](#devicetype)       | 是    | 否    | 当前设备类型   |
Z
zengyawen 已提交
269 270


W
wplan1 已提交
271 272
## RawFileDescriptor<sup>8+</sup>

H
HelloCrease 已提交
273 274 275
表示rawfile的descriptor信息。

**系统能力:** SystemCapability.Global.ResourceManager
W
wplan1 已提交
276

H
huangjie 已提交
277 278 279 280
**参数:**

| 名称     | 类型    | 可读   | 可写  | 说明           |
| ------ | ------  | ---- | ---- | ------------------ |
H
huangjie 已提交
281
| fd     | number  | 是    | 否 | rawfile所在hap的文件描述符 |
H
huangjie 已提交
282 283
| offset | number  | 是    | 否 | rawfile的起始偏移量      |
| length | number  | 是    | 否 | rawfile的文件长度       |
W
wplan1 已提交
284

285
## Resource<sup>9+</sup>
286 287 288 289 290

表示的资源信息。

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Global.ResourceManager

H
huangjie 已提交
291 292 293 294 295 296 297
**参数:**

| 名称         | 类型     | 可读   | 可写  |说明          |
| ---------- | ------ | ----- | ----  | ---------------|
| bundleName | string | 是    | 否 | 应用的bundle名称 |
| moduleName | string | 是    | 否 | 应用的module名称 |
| id         | number | 是    | 否 | 资源的id值      |
298

W
wplan1 已提交
299

Z
zengyawen 已提交
300
## ResourceManager
Z
zengyawen 已提交
301 302 303

提供访问应用资源的能力。

304 305
> **说明:**
>
Z
zengyawen 已提交
306
> - ResourceManager涉及到的方法,仅限基于TS扩展的声明式开发范式使用。
H
HelloCrease 已提交
307
>
Z
zengyawen 已提交
308 309
> - 资源文件在工程的resources目录中定义,id可通过$r(资源地址).id的方式获取,例如$r('app.string.test').id。

310
### getStringSync<sup>9+</sup>
Z
zengyawen 已提交
311

312
getStringSync(resId: number): string
Z
zengyawen 已提交
313

314
用户获取指定资源ID对应的字符串,使用同步方式返回字符串。
Z
zengyawen 已提交
315

V
VictoriaGuo 已提交
316 317
**系统能力**:SystemCapability.Global.ResourceManager

H
HelloCrease 已提交
318
**参数:** 
H
huangjie 已提交
319

320 321 322 323 324 325 326 327 328
| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resId | number | 是    | 资源ID值 |

**返回值:**

| 类型     | 说明          |
| ------ | ----------- |
| string | 资源ID值对应的字符串 |
Z
zengyawen 已提交
329

H
huangjie 已提交
330 331 332 333 334 335
**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
336 337 338
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |
H
huangjie 已提交
339

340
**示例:** 
H
HelloCrease 已提交
341
  ```ts
342 343 344 345 346
  try {
    this.context.resourceManager.getStringSync($r('app.string.test').id);
  } catch (error) {
    console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`);
  }
Z
zengyawen 已提交
347 348
  ```

349
### getStringSync<sup>10+</sup>
Z
zengyawen 已提交
350

351
getStringSync(resId: number, ...args: Array<string | number>): string
Z
zengyawen 已提交
352

353
用户获取指定资源ID对应的字符串,根据args参数进行格式化,使用同步方式返回相应字符串。
Z
zengyawen 已提交
354

V
VictoriaGuo 已提交
355 356
**系统能力**:SystemCapability.Global.ResourceManager

H
HelloCrease 已提交
357
**参数:** 
H
huangjie 已提交
358

H
HelloCrease 已提交
359 360 361
| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resId | number | 是    | 资源ID值 |
362
| args | Array<string \| number> | 否    | 格式化字符串资源参数 <br> 支持参数类型:<br /> %d、%f、%s、%% <br> 说明:%%转译符,转译%<br>举例:%%d格式化后为%d字符串|
Z
zengyawen 已提交
363

H
huangjie 已提交
364 365
**返回值:**

366 367 368
| 类型     | 说明          |
| ------ | ---------------------------- |
| string | 资源ID值对应的格式化字符串|
Z
zengyawen 已提交
369

H
huangjie 已提交
370 371
**错误码:**

372 373
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)

H
huangjie 已提交
374
| 错误码ID | 错误信息 |
375 376 377 378 379
| -------- | ----------------------------------------------- |
| 9001001  | If the resId invalid.                               |
| 9001002  | If the resource not found by resId.                 |
| 9001006  | If the resource re-ref too much.                    |
| 9001007  | If the resource obtained by resId formatting error. |
H
huangjie 已提交
380

H
HelloCrease 已提交
381
**示例:** 
H
HelloCrease 已提交
382
  ```ts
H
huangjie 已提交
383
  try {
384
    this.context.resourceManager.getStringSync($r('app.string.test').id, "format string", 10, 98.78);
H
huangjie 已提交
385
  } catch (error) {
386
    console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
387
  }
Z
zengyawen 已提交
388 389
  ```

390
### getStringSync<sup>9+</sup>
Z
zengyawen 已提交
391

392
getStringSync(resource: Resource): string
393

394
用户获取指定resource对象对应的字符串,使用同步方式返回字符串。
395 396 397

**系统能力**:SystemCapability.Global.ResourceManager

Z
zt147369 已提交
398 399
**模型约束**:此接口仅可在Stage模型下使用。

400
**参数:** 
H
huangjie 已提交
401

402 403 404 405 406 407 408 409 410
| 参数名      | 类型                     | 必填   | 说明   |
| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | 是    | 资源信息 |

**返回值:**

| 类型     | 说明               |
| ------ | ---------------- |
| string | resource对象对应的字符串 |
411

H
huangjie 已提交
412 413
**错误码:**

414 415
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)

H
huangjie 已提交
416 417
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
H
huangjie 已提交
418 419 420
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |
H
huangjie 已提交
421

422
**示例:** 
H
HelloCrease 已提交
423
  ```ts
F
fangyunzhong 已提交
424 425 426
  import resourceManager from '@ohos.resourceManager';

  let resource: resourceManager.Resource = {
427 428 429
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.string.test').id
430
  };
H
huangjie 已提交
431
  try {
432
    this.context.resourceManager.getStringSync(resource);
H
huangjie 已提交
433
  } catch (error) {
434
    console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
435
  }
436 437
  ```

438
### getStringSync<sup>10+</sup>
439

440
getStringSync(resource: Resource, ...args: Array<string | number>): string
441

442
用户获取指定resource对象对应的字符串,根据args参数进行格式化,使用同步方式返回相应字符串。
443 444 445

**系统能力**:SystemCapability.Global.ResourceManager

Z
zt147369 已提交
446 447
**模型约束**:此接口仅可在Stage模型下使用。

448
**参数:** 
H
huangjie 已提交
449

H
HelloCrease 已提交
450 451
| 参数名      | 类型                     | 必填   | 说明   |
| -------- | ---------------------- | ---- | ---- |
452
| resource | [Resource](#resource9) | 是    | 资源信息 |
453
| args | Array<string \| number> | 否    | 格式化字符串资源参数 <br> 支持参数类型:<br /> %d、%f、%s、%% <br> 说明:%%转译符,转译%<br>举例:%%d格式化后为%d字符串|
454

H
huangjie 已提交
455
**返回值:**
H
huangjie 已提交
456

457 458 459
| 类型     | 说明          |
| ------ | ---------------------------- |
| string | resource对象对应的格式化字符串|
460

H
huangjie 已提交
461 462
**错误码:**

463 464
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)

H
huangjie 已提交
465 466
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
H
huangjie 已提交
467 468 469
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |
470
| 9001007  | If the resource obtained by resId formatting error. |
H
huangjie 已提交
471

472
**示例:** 
H
HelloCrease 已提交
473
  ```ts
F
fangyunzhong 已提交
474 475 476
  import resourceManager from '@ohos.resourceManager';

  let resource: resourceManager.Resource = {
477 478 479
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.string.test').id
480
  };
H
huangjie 已提交
481
  try {
482
    this.context.resourceManager.getStringSync(resource, "format string", 10, 98.78);
H
huangjie 已提交
483
  } catch (error) {
484
    console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
485
  }
486
 ```
Z
zengyawen 已提交
487

488
### getStringByNameSync<sup>9+</sup>
H
huangjie 已提交
489

490
getStringByNameSync(resName: string): string
Z
zengyawen 已提交
491

492
用户获取指定资源名称对应的字符串,使用同步方式返回字符串。
Z
zengyawen 已提交
493

V
VictoriaGuo 已提交
494 495
**系统能力**:SystemCapability.Global.ResourceManager

H
HelloCrease 已提交
496
**参数:** 
H
huangjie 已提交
497

498 499 500 501 502 503 504 505 506
| 参数名     | 类型     | 必填   | 说明   |
| ------- | ------ | ---- | ---- |
| resName | string | 是    | 资源名称 |

**返回值:**

| 类型     | 说明         |
| ------ | ---------- |
| string | 资源名称对应的字符串 |
Z
zengyawen 已提交
507

H
huangjie 已提交
508 509
**错误码:**

510 511
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
512 513
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
514 515
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
H
huangjie 已提交
516
| 9001006  | If the resource re-ref too much.            |
H
huangjie 已提交
517

H
HelloCrease 已提交
518
**示例:** 
H
HelloCrease 已提交
519
  ```ts
H
huangjie 已提交
520
  try {
521
    this.context.resourceManager.getStringByNameSync("test");
H
huangjie 已提交
522
  } catch (error) {
523
    console.error(`getStringByNameSync failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
524
  }
Z
zengyawen 已提交
525 526
  ```

527
### getStringByNameSync<sup>10+</sup>
Z
zengyawen 已提交
528

529
getStringByNameSync(resName: string, ...args: Array<string | number>): string
Z
zengyawen 已提交
530

531
用户获取指定资源名称对应的字符串,根据args参数进行格式化,使用同步方式返回相应字符串。
Z
zengyawen 已提交
532

V
VictoriaGuo 已提交
533 534
**系统能力**:SystemCapability.Global.ResourceManager

H
HelloCrease 已提交
535
**参数:** 
H
huangjie 已提交
536

537 538 539 540
| 参数名     | 类型     | 必填   | 说明   |
| ------- | ------ | ---- | ---- |
| resName | string | 是    | 资源名称 |
| args | Array<string \| number> | 否    | 格式化字符串资源参数 <br> 支持参数类型:<br /> %d、%f、%s、%% <br> 说明:%%转译符,转译%<br>举例:%%d格式化后为%d字符串|
Z
zengyawen 已提交
541

H
huangjie 已提交
542 543
**返回值:**

544 545 546
| 类型     | 说明          |
| ------ | ---------------------------- |
| string | 资源名称对应的格式化字符串|
Z
zengyawen 已提交
547

H
huangjie 已提交
548 549
**错误码:**

550 551
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
552 553
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
554 555
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
H
huangjie 已提交
556
| 9001006  | If the resource re-ref too much.            |
557
| 9001008  | If the resource obtained by resName formatting error. |
H
huangjie 已提交
558

H
HelloCrease 已提交
559
**示例:** 
H
HelloCrease 已提交
560
  ```ts
H
huangjie 已提交
561
  try {
562
    this.context.resourceManager.getStringByNameSync("test", "format string", 10, 98.78);
H
huangjie 已提交
563
  } catch (error) {
564
    console.error(`getStringByNameSync failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
565
  }
566
 ```
Z
zengyawen 已提交
567

568
### getStringValue<sup>9+</sup>
569

570
getStringValue(resId: number, callback: AsyncCallback&lt;string&gt;): void
571

572
用户获取指定资源ID对应的字符串,使用callback形式返回字符串。
573 574 575 576

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
577

578 579 580 581
| 参数名      | 类型                          | 必填   | 说明              |
| -------- | --------------------------- | ---- | --------------- |
| resId    | number                      | 是    | 资源ID值           |
| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,用于返回获取的字符串 |
582

H
huangjie 已提交
583 584
**错误码:**

585 586
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
587 588
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
589 590 591
| 9001001  | If the module resId invalid.             |
| 9001002  | If the resource not found by resId.      |
| 9001006  | If the resource re-ref too much.         |
H
huangjie 已提交
592

593
**示例Stage:** 
H
HelloCrease 已提交
594
  ```ts
H
huangjie 已提交
595
  try {
596
    this.context.resourceManager.getStringValue($r('app.string.test').id, (error, value) => {
597
      if (error != null) {
598
        console.log("error is " + error);
599
      } else {
600
        let str = value;
601
      }
H
huangjie 已提交
602 603
    });
  } catch (error) {
604
    console.error(`callback getStringValue failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
605
  }
606 607
  ```

608
### getStringValue<sup>9+</sup>
609

610
getStringValue(resId: number): Promise&lt;string&gt;
611

612
用户获取指定资源ID对应的字符串,使用Promise形式返回字符串。
613 614 615 616

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
617

618 619 620
| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resId | number | 是    | 资源ID值 |
H
huangjie 已提交
621

622 623 624 625 626
**返回值:**

| 类型                    | 说明          |
| --------------------- | ----------- |
| Promise&lt;string&gt; | 资源ID值对应的字符串 |
627

H
huangjie 已提交
628 629
**错误码:**

630 631
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
632 633
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
H
huangjie 已提交
634 635 636
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |
H
huangjie 已提交
637

638
**示例:** 
H
HelloCrease 已提交
639
  ```ts
F
fangyunzhong 已提交
640 641
  import { BusinessError } from '@ohos.base';

H
huangjie 已提交
642
  try {
F
fangyunzhong 已提交
643
    this.context.resourceManager.getStringValue($r('app.string.test').id).then((value: string) => {
644
      let str = value;
F
fangyunzhong 已提交
645
    }).catch((error: BusinessError) => {
646
      console.log("getStringValue promise error is " + error);
H
huangjie 已提交
647 648
    });
  } catch (error) {
649
    console.error(`promise getStringValue failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
650
  }
651
  ```
Z
zengyawen 已提交
652

653
### getStringValue<sup>9+</sup>
H
huangjie 已提交
654

655
getStringValue(resource: Resource, callback: AsyncCallback&lt;string&gt;): void
Z
zengyawen 已提交
656

657
用户获取指定resource对象对应的字符串,使用callback形式返回字符串。
Z
zengyawen 已提交
658

V
VictoriaGuo 已提交
659 660
**系统能力**:SystemCapability.Global.ResourceManager

661 662
**模型约束**:此接口仅可在Stage模型下使用。

H
HelloCrease 已提交
663
**参数:** 
H
huangjie 已提交
664

665 666 667 668
| 参数名      | 类型                          | 必填   | 说明              |
| -------- | --------------------------- | ---- | --------------- |
| resource | [Resource](#resource9)      | 是    | 资源信息            |
| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,用于返回获取的字符串 |
Z
zengyawen 已提交
669

H
huangjie 已提交
670 671
**错误码:**

672 673
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
674 675
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
H
huangjie 已提交
676 677
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
678
| 9001006  | If the resource re-ref too much.            |
H
huangjie 已提交
679

H
HelloCrease 已提交
680
**示例:** 
H
HelloCrease 已提交
681
  ```ts
F
fangyunzhong 已提交
682 683 684
  import resourceManager from '@ohos.resourceManager';

  let resource: resourceManager.Resource = {
685 686 687 688
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.string.test').id
  };
H
huangjie 已提交
689
  try {
690 691 692 693 694 695
    this.context.resourceManager.getStringValue(resource, (error, value) => {
      if (error != null) {
        console.log("error is " + error);
      } else {
        let str = value;
      }
H
huangjie 已提交
696 697
    });
  } catch (error) {
698
    console.error(`callback getStringValue failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
699
  }
Z
zengyawen 已提交
700 701
  ```

702
### getStringValue<sup>9+</sup>
Z
zt147369 已提交
703

704
getStringValue(resource: Resource): Promise&lt;string&gt;
Z
zt147369 已提交
705

706
用户获取指定resource对象对应的字符串,使用Promise形式返回字符串。
Z
zt147369 已提交
707 708 709

**系统能力**:SystemCapability.Global.ResourceManager

710
**模型约束**:此接口仅可在Stage模型下使用。
Z
zt147369 已提交
711

712 713 714 715 716 717 718 719 720 721 722
**参数:**

| 参数名      | 类型                     | 必填   | 说明   |
| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | 是    | 资源信息 |

**返回值:**

| 类型                    | 说明               |
| --------------------- | ---------------- |
| Promise&lt;string&gt; | resource对象对应的字符串 |
Z
zt147369 已提交
723 724 725

**错误码:**

726 727
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

Z
zt147369 已提交
728 729 730 731
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
732
| 9001006  | If the resource re-ref too much.            |
Z
zt147369 已提交
733 734 735

**示例:** 
  ```ts
F
fangyunzhong 已提交
736 737 738 739
  import resourceManager from '@ohos.resourceManager';
  import { BusinessError } from '@ohos.base';

  let resource: resourceManager.Resource = {
740 741 742 743
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.string.test').id
  };
Z
zt147369 已提交
744
  try {
F
fangyunzhong 已提交
745
    this.context.resourceManager.getStringValue(resource).then((value: string) => {
746
      let str = value;
F
fangyunzhong 已提交
747
    }).catch((error: BusinessError) => {
748
      console.log("getStringValue promise error is " + error);
Z
zt147369 已提交
749 750
    });
  } catch (error) {
751
    console.error(`promise getStringValue failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
752 753
  }
  ```
Z
zengyawen 已提交
754

755
### getStringByName<sup>9+</sup>
Z
zengyawen 已提交
756

757
getStringByName(resName: string, callback: AsyncCallback&lt;string&gt;): void
Z
zengyawen 已提交
758

759
用户获取指定资源名称对应的字符串,使用callback形式返回字符串。
Z
zengyawen 已提交
760

V
VictoriaGuo 已提交
761 762
**系统能力**:SystemCapability.Global.ResourceManager

763
**参数:**
H
huangjie 已提交
764

765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807
| 参数名      | 类型                          | 必填   | 说明              |
| -------- | --------------------------- | ---- | --------------- |
| resName  | string                      | 是    | 资源名称            |
| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,用于返回获取的字符串 |

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
| 9001006  | If the resource re-ref too much.            |

**示例:**
  ```ts
  try {
    this.context.resourceManager.getStringByName("test", (error, value) => {
      if (error != null) {
        console.log("error is " + error);
      } else {
        let str = value;
      }
    });
  } catch (error) {
    console.error(`callback getStringByName failed, error code: ${error.code}, message: ${error.message}.`);
  }
  ```

### getStringByName<sup>9+</sup>

getStringByName(resName: string): Promise&lt;string&gt;

用户获取指定资源名称对应的字符串,使用Promise形式返回字符串。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:**

| 参数名     | 类型     | 必填   | 说明   |
| ------- | ------ | ---- | ---- |
| resName | string | 是    | 资源名称 |
Z
zengyawen 已提交
808

H
huangjie 已提交
809 810
**返回值:**

811 812 813
| 类型                    | 说明         |
| --------------------- | ---------- |
| Promise&lt;string&gt; | 资源名称对应的字符串 |
Z
zengyawen 已提交
814

H
huangjie 已提交
815 816
**错误码:**

817 818
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
819 820
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
821 822 823
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
| 9001006  | If the resource re-ref too much.            |
H
huangjie 已提交
824

825
**示例:**
H
HelloCrease 已提交
826
  ```ts
F
fangyunzhong 已提交
827 828
  import { BusinessError } from '@ohos.base';

H
huangjie 已提交
829
  try {
F
fangyunzhong 已提交
830
    this.context.resourceManager.getStringByName("test").then((value: string) => {
831
      let str = value;
F
fangyunzhong 已提交
832
    }).catch((error: BusinessError) => {
833 834
      console.log("getStringByName promise error is " + error);
    });
H
huangjie 已提交
835
  } catch (error) {
836
    console.error(`promise getStringByName failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
837
  }
Z
zengyawen 已提交
838 839
  ```

840
### getStringArrayValueSync<sup>10+</sup>
Z
zt147369 已提交
841

842
getStringArrayValueSync(resId: number): Array&lt;string&gt;
Z
zt147369 已提交
843

844
用户获取指定资源ID对应的字符串数组,使用同步方式返回字符串数组。
Z
zt147369 已提交
845 846 847 848 849 850 851 852 853 854 855

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 

| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resId | number | 是    | 资源ID值 |

**返回值:**

856 857 858
| 类型                    | 说明          |
| --------------------- | ----------- |
| Array&lt;string&gt; | 资源ID值对应的字符串数组 |
Z
zt147369 已提交
859 860 861

**错误码:**

862 863
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

Z
zt147369 已提交
864 865 866 867
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
868
| 9001006  | If the resource re-ref too much.            |
Z
zt147369 已提交
869 870 871 872

**示例:** 
  ```ts
  try {
873
    this.context.resourceManager.getStringArrayValueSync($r('app.strarray.test').id);
Z
zt147369 已提交
874
  } catch (error) {
875
    console.error(`getStringArrayValueSync failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
876 877 878
  }
  ```

879
### getStringArrayValueSync<sup>10+</sup>
880

881
getStringArrayValueSync(resource: Resource): Array&lt;string&gt;
882

883
用户获取指定resource对象对应的字符串数组,使用同步方式返回字符串数组。
884 885 886

**系统能力**:SystemCapability.Global.ResourceManager

Z
zt147369 已提交
887 888
**模型约束**:此接口仅可在Stage模型下使用。

889
**参数:** 
H
huangjie 已提交
890

891 892 893 894 895 896 897 898 899
| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resource | [Resource](#resource9) | 是    | 资源信息 |

**返回值:**

| 类型                    | 说明          |
| --------------------- | ----------- |
| Array&lt;string&gt; | resource对象对应的字符串数组 |
900

H
huangjie 已提交
901 902
**错误码:**

903 904
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
905 906
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
H
huangjie 已提交
907 908
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
909
| 9001006  | If the resource re-ref too much.            |
H
huangjie 已提交
910

911
**示例:** 
H
HelloCrease 已提交
912
  ```ts
F
fangyunzhong 已提交
913 914 915
  import resourceManager from '@ohos.resourceManager';

  let resource: resourceManager.Resource = {
916 917 918
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.strarray.test').id
919
  };
H
huangjie 已提交
920
  try {
921
    this.context.resourceManager.getStringArrayValueSync(resource);
H
huangjie 已提交
922
  } catch (error) {
923
    console.error(`getStringArrayValueSync failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
924
  }
925 926
  ```

F
fangyunzhong 已提交
927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965
### getStringArrayByNameSync<sup>10+</sup>

getStringArrayByNameSync(resName: string): Array&lt;string&gt;

用户获取指定资源名称对应的字符串数组,使用同步方式返回字符串数组。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 

| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resName | string | 是    | 资源名称 |

**返回值:**

| 类型                    | 说明          |
| --------------------- | ----------- |
| Array&lt;string&gt; | 对应资源名称的字符串数组 |

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                       |
| 9001004  | If the resource not found by resName.         |
| 9001006  | If the resource re-ref too much.            |

**示例:** 
  ```ts
  try {
    this.context.resourceManager.getStringArrayByNameSync("test");
  } catch (error) {
    console.error(`getStringArrayByNameSync failed, error code: ${error.code}, message: ${error.message}.`);
  }
  ```

966
### getStringArrayValue<sup>9+</sup>
Z
zt147369 已提交
967

968
getStringArrayValue(resId: number, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
Z
zt147369 已提交
969

970
用户获取指定资源ID对应的字符串数组,使用callback形式返回字符串数组。
Z
zt147369 已提交
971 972 973 974 975

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 

976 977 978 979
| 参数名      | 类型                                       | 必填   | 说明                |
| -------- | ---------------------------------------- | ---- | ----------------- |
| resId    | number                                   | 是    | 资源ID值             |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | 是    | 异步回调,用于返回获取的字符串数组 |
Z
zt147369 已提交
980 981 982

**错误码:**

983 984
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

Z
zt147369 已提交
985 986 987 988
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
989
| 9001006  | If the resource re-ref too much.            |
Z
zt147369 已提交
990 991 992 993

**示例:** 
  ```ts
  try {
994 995 996 997 998 999
    this.context.resourceManager.getStringArrayValue($r('app.strarray.test').id, (error, value) => {
      if (error != null) {
        console.log("error is " + error);
      } else {
        let strArray = value;
      }
Z
zt147369 已提交
1000 1001
    });
  } catch (error) {
1002
    console.error(`callback getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
1003 1004 1005
  }
  ```

1006
### getStringArrayValue<sup>9+</sup>
1007

1008
getStringArrayValue(resId: number): Promise&lt;Array&lt;string&gt;&gt;
1009

1010
用户获取指定资源ID对应的字符串数组,使用Promise形式返回字符串数组。
1011 1012 1013 1014

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
1015

1016 1017 1018
| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resId | number | 是    | 资源ID值 |
1019

H
huangjie 已提交
1020 1021
**返回值:**

1022 1023 1024
| 类型                                 | 说明            |
| ---------------------------------- | ------------- |
| Promise&lt;Array&lt;string&gt;&gt; | 资源ID值对应的字符串数组 |
1025

H
huangjie 已提交
1026 1027
**错误码:**

1028 1029
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
1030 1031
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
H
huangjie 已提交
1032 1033
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
1034
| 9001006  | If the resource re-ref too much.            |
H
huangjie 已提交
1035

1036
**示例:** 
H
HelloCrease 已提交
1037
  ```ts
F
fangyunzhong 已提交
1038 1039
  import { BusinessError } from '@ohos.base';

H
huangjie 已提交
1040
  try {
F
fangyunzhong 已提交
1041
    this.context.resourceManager.getStringArrayValue($r('app.strarray.test').id).then((value: Array<string>) => {
1042
      let strArray = value;
F
fangyunzhong 已提交
1043
    }).catch((error: BusinessError) => {
1044
      console.log("getStringArrayValue promise error is " + error);
H
huangjie 已提交
1045 1046
    });
  } catch (error) {
1047
    console.error(`promise getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
1048
  }
1049
  ```
Z
zengyawen 已提交
1050

1051
### getStringArrayValue<sup>9+</sup>
Z
zt147369 已提交
1052

1053
getStringArrayValue(resource: Resource, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
Z
zt147369 已提交
1054

1055
用户获取指定resource对象对应的字符串数组,使用callback形式返回回字符串数组。
Z
zt147369 已提交
1056 1057 1058

**系统能力**:SystemCapability.Global.ResourceManager

Z
zt147369 已提交
1059 1060
**模型约束**:此接口仅可在Stage模型下使用。

Z
zt147369 已提交
1061 1062
**参数:** 

1063 1064 1065 1066
| 参数名      | 类型                                       | 必填   | 说明                |
| -------- | ---------------------------------------- | ---- | ----------------- |
| resource | [Resource](#resource9)                   | 是    | 资源信息              |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | 是    | 异步回调,用于返回获取的字符串数组 |
Z
zt147369 已提交
1067 1068 1069

**错误码:**

1070 1071
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

Z
zt147369 已提交
1072 1073 1074 1075
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
1076
| 9001006  | If the resource re-ref too much.            |
Z
zt147369 已提交
1077 1078 1079

**示例:** 
  ```ts
F
fangyunzhong 已提交
1080 1081 1082
  import resourceManager from '@ohos.resourceManager';

  let resource: resourceManager.Resource = {
1083 1084 1085
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.strarray.test').id
Z
zt147369 已提交
1086 1087
  };
  try {
1088 1089 1090 1091 1092 1093
    this.context.resourceManager.getStringArrayValue(resource, (error, value) => {
      if (error != null) {
        console.log("error is " + error);
      } else {
        let strArray = value;
      }
Z
zt147369 已提交
1094 1095
    });
  } catch (error) {
1096
    console.error(`callback getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
1097 1098
  }
  ```
Z
zengyawen 已提交
1099

1100
### getStringArrayValue<sup>9+</sup>
H
huangjie 已提交
1101

1102
getStringArrayValue(resource: Resource): Promise&lt;Array&lt;string&gt;&gt;
Z
zengyawen 已提交
1103

1104
用户获取指定resource对象对应的字符串数组,使用Promise形式返回字符串数组。
Z
zengyawen 已提交
1105

V
VictoriaGuo 已提交
1106 1107
**系统能力**:SystemCapability.Global.ResourceManager

1108 1109
**模型约束**:此接口仅可在Stage模型下使用。

H
HelloCrease 已提交
1110
**参数:** 
H
huangjie 已提交
1111

1112 1113 1114 1115 1116 1117 1118 1119 1120
| 参数名      | 类型                     | 必填   | 说明   |
| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | 是    | 资源信息 |

**返回值:**

| 类型                                 | 说明                 |
| ---------------------------------- | ------------------ |
| Promise&lt;Array&lt;string&gt;&gt; | resource对象对应的字符串数组 |
Z
zengyawen 已提交
1121

H
huangjie 已提交
1122 1123
**错误码:**

1124 1125
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
1126 1127
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
H
huangjie 已提交
1128 1129
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
1130
| 9001006  | If the resource re-ref too much.            |
H
huangjie 已提交
1131

H
HelloCrease 已提交
1132
**示例:** 
H
HelloCrease 已提交
1133
  ```ts
F
fangyunzhong 已提交
1134 1135 1136 1137
  import resourceManager from '@ohos.resourceManager';
  import { BusinessError } from '@ohos.base';

  let resource: resourceManager.Resource = {
1138 1139 1140 1141
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.strarray.test').id
  };
H
huangjie 已提交
1142
  try {
F
fangyunzhong 已提交
1143
    this.context.resourceManager.getStringArrayValue(resource).then((value: Array<string>) => {
1144
      let strArray = value;
F
fangyunzhong 已提交
1145
    }).catch((error: BusinessError) => {
1146 1147
      console.log("getStringArray promise error is " + error);
    });
H
huangjie 已提交
1148
  } catch (error) {
1149
    console.error(`promise getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
1150
  }
Z
zengyawen 已提交
1151 1152
  ```

1153
### getStringArrayByName<sup>9+</sup>
Z
zt147369 已提交
1154

1155
getStringArrayByName(resName: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
Z
zt147369 已提交
1156

1157
用户获取指定资源名称对应的字符串数组,使用callback形式返回字符串数组。
Z
zt147369 已提交
1158 1159 1160

**系统能力**:SystemCapability.Global.ResourceManager

1161
**参数:**
Z
zt147369 已提交
1162

1163 1164 1165 1166
| 参数名      | 类型                                       | 必填   | 说明                |
| -------- | ---------------------------------------- | ---- | ----------------- |
| resName  | string                                   | 是    | 资源名称              |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | 是    | 异步回调,用于返回获取的字符串数组 |
Z
zt147369 已提交
1167 1168 1169

**错误码:**

1170 1171
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

Z
zt147369 已提交
1172 1173
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
1174 1175 1176
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
| 9001006  | If the resource re-ref too much.            |
Z
zt147369 已提交
1177 1178 1179 1180

**示例:** 
  ```ts
  try {
1181 1182 1183 1184 1185 1186 1187
    this.context.resourceManager.getStringArrayByName("test", (error, value) => {
      if (error != null) {
        console.log("error is " + error);
      } else {
        let strArray = value;
      }
    });
Z
zt147369 已提交
1188
  } catch (error) {
1189
    console.error(`callback getStringArrayByName failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
1190 1191
  }
  ```
Z
zengyawen 已提交
1192

1193
### getStringArrayByName<sup>9+</sup>
Z
zengyawen 已提交
1194

1195
getStringArrayByName(resName: string): Promise&lt;Array&lt;string&gt;&gt;
Z
zengyawen 已提交
1196

1197
用户获取指定资源名称对应的字符串数组,使用Promise形式返回字符串数组。
Z
zengyawen 已提交
1198

V
VictoriaGuo 已提交
1199 1200
**系统能力**:SystemCapability.Global.ResourceManager

H
HelloCrease 已提交
1201
**参数:** 
H
huangjie 已提交
1202

1203 1204 1205
| 参数名     | 类型     | 必填   | 说明   |
| ------- | ------ | ---- | ---- |
| resName | string | 是    | 资源名称 |
Z
zengyawen 已提交
1206

H
huangjie 已提交
1207 1208
**返回值:**

1209 1210 1211
| 类型                                 | 说明           |
| ---------------------------------- | ------------ |
| Promise&lt;Array&lt;string&gt;&gt; | 资源名称对应的字符串数组 |
Z
zengyawen 已提交
1212

H
huangjie 已提交
1213 1214
**错误码:**

1215 1216
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
1217 1218
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
1219 1220 1221
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
| 9001006  | If the resource re-ref too much.            |
H
huangjie 已提交
1222

H
HelloCrease 已提交
1223
**示例:** 
H
HelloCrease 已提交
1224
  ```ts
F
fangyunzhong 已提交
1225 1226
  import { BusinessError } from '@ohos.base';

H
huangjie 已提交
1227
  try {
F
fangyunzhong 已提交
1228
    this.context.resourceManager.getStringArrayByName("test").then((value: Array<string>) => {
1229
      let strArray = value;
F
fangyunzhong 已提交
1230
    }).catch((error: BusinessError) => {
1231
      console.log("getStringArrayByName promise error is " + error);
H
huangjie 已提交
1232 1233
    });
  } catch (error) {
1234
    console.error(`promise getStringArrayByName failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
1235 1236 1237
  }
  ```

1238
### getPluralStringValueSync<sup>10+</sup>
Z
zt147369 已提交
1239

1240
getPluralStringValueSync(resId: number, num: number): string
Z
zt147369 已提交
1241

1242
根据指定数量获取指定ID字符串表示的单复数字符串,使用同步方式返回字符串。
Z
zt147369 已提交
1243 1244 1245 1246 1247 1248 1249 1250

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 

| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resId | number | 是    | 资源ID值 |
1251
| num   | number | 是    | 数量值   |
Z
zt147369 已提交
1252 1253 1254

**返回值:**

1255 1256 1257
| 类型                    | 说明          |
| -------- | ----------- |
| string   | 根据指定数量获取指定ID字符串表示的单复数字符串 |
Z
zt147369 已提交
1258 1259 1260

**错误码:**

1261 1262
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

Z
zt147369 已提交
1263 1264 1265 1266
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
1267
| 9001006  | If the resource re-ref too much.            |
Z
zt147369 已提交
1268 1269 1270 1271

**示例:** 
  ```ts
  try {
1272
    this.context.resourceManager.getPluralStringValueSync($r('app.plural.test').id, 1);
Z
zt147369 已提交
1273
  } catch (error) {
1274
    console.error(`getPluralStringValueSync failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
1275
  }
Z
zengyawen 已提交
1276 1277
  ```

1278
### getPluralStringValueSync<sup>10+</sup>
1279

1280
getPluralStringValueSync(resource: Resource, num: number): string
1281

1282
根据指定数量获取指定resource对象表示的单复数字符串,使用同步方式返回字符串。
1283 1284 1285

**系统能力**:SystemCapability.Global.ResourceManager

Z
zt147369 已提交
1286 1287
**模型约束**:此接口仅可在Stage模型下使用。

1288
**参数:** 
H
huangjie 已提交
1289

1290 1291 1292 1293 1294 1295 1296 1297 1298 1299
| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resource | [Resource](#resource9) | 是    | 资源信息 |
| num      | number                 | 是    | 数量值   |

**返回值:**

| 类型                    | 说明          |
| --------------------- | ----------- |
| string | 根据指定数量获取指定resource对象表示的单复数字符串 |
1300

H
huangjie 已提交
1301 1302
**错误码:**

1303 1304
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
1305 1306
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
H
huangjie 已提交
1307 1308
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
1309
| 9001006  | If the resource re-ref too much.            |
H
huangjie 已提交
1310

1311
**示例:** 
H
HelloCrease 已提交
1312
  ```ts
F
fangyunzhong 已提交
1313 1314 1315
  import resourceManager from '@ohos.resourceManager';

  let resource: resourceManager.Resource = {
1316 1317 1318
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.plural.test').id
1319
  };
H
huangjie 已提交
1320
  try {
1321
    this.context.resourceManager.getPluralStringValueSync(resource, 1);
H
huangjie 已提交
1322
  } catch (error) {
1323
    console.error(`getPluralStringValueSync failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
1324
  }
1325 1326
  ```

F
fangyunzhong 已提交
1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366
### getPluralStringByNameSync<sup>10+</sup>

getPluralStringByNameSync(resName: string, num: number): string

根据指定数量获取指定资源名称表示的单复数字符串,使用同步方式返回字符串。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 

| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resName | string | 是    | 资源名称 |
| num      | number                 | 是    | 数量值   |

**返回值:**

| 类型                    | 说明          |
| --------------------- | ----------- |
| string | 根据指定数量获取指定资源名称表示的单复数字符串 |

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                       |
| 9001004  | If the resource not found by resName.         |
| 9001006  | If the resource re-ref too much.            |

**示例:** 
  ```ts
  try {
    this.context.resourceManager.getPluralStringByNameSync("test", 1);
  } catch (error) {
    console.error(`getPluralStringByNameSync failed, error code: ${error.code}, message: ${error.message}.`);
  }
  ```

1367
### getPluralStringValue<sup>9+</sup>
Z
zt147369 已提交
1368

1369
getPluralStringValue(resId: number, num: number, callback: AsyncCallback&lt;string&gt;): void
Z
zt147369 已提交
1370

1371
根据指定数量获取指定ID字符串表示的单复数字符串,使用callback形式返回字符串。
Z
zt147369 已提交
1372 1373 1374

**系统能力**:SystemCapability.Global.ResourceManager

1375
**参数:** 
Z
zt147369 已提交
1376

1377 1378 1379 1380 1381
| 参数名      | 类型                          | 必填   | 说明                              |
| -------- | --------------------------- | ---- | ------------------------------- |
| resId    | number                      | 是    | 资源ID值                           |
| num      | number                      | 是    | 数量值                             |
| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,返回根据指定数量获取指定ID字符串表示的单复数字符串 |
Z
zt147369 已提交
1382 1383 1384

**错误码:**

1385 1386
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

Z
zt147369 已提交
1387 1388 1389 1390
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
1391
| 9001006  | If the resource re-ref too much.            |
Z
zt147369 已提交
1392 1393 1394 1395

**示例:** 
  ```ts
  try {
1396 1397 1398 1399 1400 1401
    this.context.resourceManager.getPluralStringValue($r("app.plural.test").id, 1, (error, value) => {
      if (error != null) {
        console.log("error is " + error);
      } else {
        let str = value;
      }
Z
zt147369 已提交
1402 1403
    });
  } catch (error) {
1404
    console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
1405 1406 1407
  }
  ```

1408
### getPluralStringValue<sup>9+</sup>
1409

1410
getPluralStringValue(resId: number, num: number): Promise&lt;string&gt;
1411

1412
根据指定数量获取对指定ID字符串表示的单复数字符串,使用Promise形式返回字符串。
1413 1414 1415 1416

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
1417

1418 1419 1420 1421
| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resId | number | 是    | 资源ID值 |
| num   | number | 是    | 数量值   |
1422

H
huangjie 已提交
1423 1424
**返回值:**

H
HelloCrease 已提交
1425 1426
| 类型                    | 说明                        |
| --------------------- | ------------------------- |
1427
| Promise&lt;string&gt; | 根据提供的数量获取对应ID字符串表示的单复数字符串 |
1428

H
huangjie 已提交
1429 1430
**错误码:**

1431 1432
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
1433 1434
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
H
huangjie 已提交
1435 1436
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
1437
| 9001006  | If the resource re-ref too much.            |
H
huangjie 已提交
1438

1439
**示例:** 
H
HelloCrease 已提交
1440
  ```ts
F
fangyunzhong 已提交
1441 1442
  import { BusinessError } from '@ohos.base';

H
huangjie 已提交
1443
  try {
F
fangyunzhong 已提交
1444
    this.context.resourceManager.getPluralStringValue($r("app.plural.test").id, 1).then((value: string) => {
1445
      let str = value;
F
fangyunzhong 已提交
1446
    }).catch((error: BusinessError) => {
1447
      console.log("getPluralStringValue promise error is " + error);
H
huangjie 已提交
1448 1449
    });
  } catch (error) {
1450
    console.error(`promise getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
1451
  }
1452 1453
  ```

1454
### getPluralStringValue<sup>9+</sup>
Z
zt147369 已提交
1455

1456
getPluralStringValue(resource: Resource, num: number, callback: AsyncCallback&lt;string&gt;): void
Z
zt147369 已提交
1457

1458
根据指定数量获取指定resource对象表示的单复数字符串,使用callback形式返回字符串。
Z
zt147369 已提交
1459 1460 1461

**系统能力**:SystemCapability.Global.ResourceManager

Z
zt147369 已提交
1462 1463
**模型约束**:此接口仅可在Stage模型下使用。

Z
zt147369 已提交
1464 1465
**参数:** 

1466 1467 1468 1469 1470
| 参数名      | 类型                          | 必填   | 说明                                   |
| -------- | --------------------------- | ---- | ------------------------------------ |
| resource | [Resource](#resource9)      | 是    | 资源信息                                 |
| num      | number                      | 是    | 数量值                                  |
| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,返回根据指定数量获取指定resource对象表示的单复数字符串 |
Z
zt147369 已提交
1471 1472 1473

**错误码:**

1474 1475
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

Z
zt147369 已提交
1476 1477 1478 1479
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
1480
| 9001006  | If the resource re-ref too much.            |
Z
zt147369 已提交
1481 1482 1483

**示例:** 
  ```ts
F
fangyunzhong 已提交
1484 1485 1486
  import resourceManager from '@ohos.resourceManager';

  let resource: resourceManager.Resource = {
1487 1488 1489
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.plural.test').id
Z
zt147369 已提交
1490 1491
  };
  try {
1492 1493 1494 1495 1496 1497
    this.context.resourceManager.getPluralStringValue(resource, 1, (error, value) => {
      if (error != null) {
        console.log("error is " + error);
      } else {
        let str = value;
      }
Z
zt147369 已提交
1498 1499
    });
  } catch (error) {
1500
    console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
1501 1502
  }
  ```
Z
zengyawen 已提交
1503

1504
### getPluralStringValue<sup>9+</sup>
Z
zengyawen 已提交
1505

1506
getPluralStringValue(resource: Resource, num: number): Promise&lt;string&gt;
Z
zengyawen 已提交
1507

1508
根据指定数量获取对指定resource对象表示的单复数字符串,使用Promise形式返回字符串。
Z
zengyawen 已提交
1509

V
VictoriaGuo 已提交
1510 1511
**系统能力**:SystemCapability.Global.ResourceManager

1512 1513
**模型约束**:此接口仅可在Stage模型下使用。

H
HelloCrease 已提交
1514
**参数:** 
H
huangjie 已提交
1515

1516 1517 1518 1519
| 参数名      | 类型                     | 必填   | 说明   |
| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | 是    | 资源信息 |
| num      | number                 | 是    | 数量值  |
Z
zengyawen 已提交
1520

1521
**返回值:**
Z
zengyawen 已提交
1522

1523 1524 1525
| 类型                    | 说明                             |
| --------------------- | ------------------------------ |
| Promise&lt;string&gt; | 根据提供的数量获取对应resource对象表示的单复数字符串 |
Z
zengyawen 已提交
1526

1527
**错误码:**
V
VictoriaGuo 已提交
1528

1529
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
H
huangjie 已提交
1530

1531 1532 1533 1534 1535
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |
Z
zengyawen 已提交
1536

H
HelloCrease 已提交
1537
**示例:** 
H
HelloCrease 已提交
1538
  ```ts
F
fangyunzhong 已提交
1539 1540 1541 1542
  import resourceManager from '@ohos.resourceManager';
  import { BusinessError } from '@ohos.base';

  let resource: resourceManager.Resource = {
1543 1544 1545 1546
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.plural.test').id
  };
Z
zt147369 已提交
1547
  try {
F
fangyunzhong 已提交
1548
    this.context.resourceManager.getPluralStringValue(resource, 1).then((value: string) => {
1549
      let str = value;
F
fangyunzhong 已提交
1550
    }).catch((error: BusinessError) => {
1551
      console.log("getPluralStringValue promise error is " + error);
Z
zt147369 已提交
1552 1553
    });
  } catch (error) {
1554
    console.error(`promise getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
1555
  }
Z
zengyawen 已提交
1556
  ```
Z
zengyawen 已提交
1557

1558
### getPluralStringByName<sup>9+</sup>
Z
zengyawen 已提交
1559

1560
getPluralStringByName(resName: string, num: number, callback: AsyncCallback&lt;string&gt;): void
Z
zengyawen 已提交
1561

1562
根据传入的数量值,获取资源名称对应的字符串资源,使用callback形式返回字符串。
Z
zengyawen 已提交
1563

V
VictoriaGuo 已提交
1564 1565
**系统能力**:SystemCapability.Global.ResourceManager

H
HelloCrease 已提交
1566
**参数:** 
H
huangjie 已提交
1567

1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582
| 参数名      | 类型                          | 必填   | 说明                            |
| -------- | --------------------------- | ---- | ----------------------------- |
| resName  | string                      | 是    | 资源名称                          |
| num      | number                      | 是    | 数量值                           |
| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,返回根据传入的数量值获取资源名称对应的字符串资源 |

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
| 9001006  | If the resource re-ref too much.            |
Z
zengyawen 已提交
1583

H
HelloCrease 已提交
1584
**示例:** 
H
HelloCrease 已提交
1585
  ```ts
Z
zt147369 已提交
1586
  try {
1587
    this.context.resourceManager.getPluralStringByName("test", 1, (error, value) => {
Z
zt147369 已提交
1588
      if (error != null) {
1589
        console.log("error is " + error);
Z
zt147369 已提交
1590
      } else {
1591
        let str = value;
Z
zt147369 已提交
1592 1593 1594
      }
    });
  } catch (error) {
1595
    console.error(`callback getPluralStringByName failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
1596
  }
Z
zengyawen 已提交
1597
  ```
Z
zengyawen 已提交
1598

1599
### getPluralStringByName<sup>9+</sup>
Z
zengyawen 已提交
1600

1601
getPluralStringByName(resName: string, num: number): Promise&lt;string&gt;
Z
zengyawen 已提交
1602

1603
根据传入的数量值,获取资源名称对应的字符串资源,使用Promise形式返回字符串。
Z
zengyawen 已提交
1604

V
VictoriaGuo 已提交
1605 1606
**系统能力**:SystemCapability.Global.ResourceManager

1607
**参数:** 
Z
zengyawen 已提交
1608

1609 1610 1611 1612
| 参数名     | 类型     | 必填   | 说明   |
| ------- | ------ | ---- | ---- |
| resName | string | 是    | 资源名称 |
| num     | number | 是    | 数量值  |
V
VictoriaGuo 已提交
1613

1614
**返回值:**
H
huangjie 已提交
1615

1616 1617 1618
| 类型                    | 说明                     |
| --------------------- | ---------------------- |
| Promise&lt;string&gt; | 根据传入的数量值获取资源名称对应的字符串资源 |
Z
zengyawen 已提交
1619

H
huangjie 已提交
1620 1621
**错误码:**

1622 1623
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
1624 1625
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
1626 1627
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
H
huangjie 已提交
1628
| 9001006  | If the resource re-ref too much.            |
H
huangjie 已提交
1629

H
HelloCrease 已提交
1630
**示例:** 
H
HelloCrease 已提交
1631
  ```ts
F
fangyunzhong 已提交
1632 1633
  import { BusinessError } from '@ohos.base';

H
huangjie 已提交
1634
  try {
F
fangyunzhong 已提交
1635
    this.context.resourceManager.getPluralStringByName("test", 1).then((value: string) => {
1636
      let str = value;
F
fangyunzhong 已提交
1637
    }).catch((error: BusinessError) => {
1638
      console.log("getPluralStringByName promise error is " + error);
H
huangjie 已提交
1639 1640
    });
  } catch (error) {
1641
    console.error(`promise getPluralStringByName failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
1642
  }
Z
zengyawen 已提交
1643
  ```
Z
zengyawen 已提交
1644

1645
### getMediaContentSync<sup>10+</sup>
Z
zengyawen 已提交
1646

1647
getMediaContentSync(resId: number, density?: number): Uint8Array
Z
zengyawen 已提交
1648

1649
用户获取指定资源ID对应的默认或指定的屏幕密度媒体文件内容,使用同步方式返回字节数组。
Z
zengyawen 已提交
1650

V
VictoriaGuo 已提交
1651 1652
**系统能力**:SystemCapability.Global.ResourceManager

1653
**参数:**
H
huangjie 已提交
1654

H
HelloCrease 已提交
1655 1656 1657
| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resId | number | 是    | 资源ID值 |
1658
| [density](#screendensity) | number | 否    | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度 |
Z
zengyawen 已提交
1659

H
huangjie 已提交
1660 1661
**返回值:**

1662 1663 1664
| 类型                    | 说明          |
| -------- | ----------- |
| Uint8Array   | 资源ID对应的媒体文件内容 |
Z
zengyawen 已提交
1665

H
huangjie 已提交
1666 1667
**错误码:**

1668 1669
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
1670 1671
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
H
huangjie 已提交
1672 1673
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
H
huangjie 已提交
1674

1675
**示例:**
H
HelloCrease 已提交
1676
  ```ts
H
huangjie 已提交
1677
  try {
1678
    this.context.resourceManager.getMediaContentSync($r('app.media.test').id); // 默认屏幕密度
H
huangjie 已提交
1679
  } catch (error) {
1680 1681 1682 1683 1684 1685 1686
    console.error(`getMediaContentSync failed, error code: ${error.code}, message: ${error.message}.`);
  }

  try {
    this.context.resourceManager.getMediaContentSync($r('app.media.test').id, 120); // 指定屏幕密度
  } catch (error) {
    console.error(`getMediaContentSync failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
1687
  }
Z
zengyawen 已提交
1688
  ```
Z
zengyawen 已提交
1689

1690
### getMediaContentSync<sup>10+</sup>
1691

1692
getMediaContentSync(resource: Resource, density?: number): Uint8Array
1693

1694
用户获取指定resource对象对应的默认或指定的屏幕密度媒体文件内容,使用同步方式返回字节数组。
1695 1696 1697

**系统能力**:SystemCapability.Global.ResourceManager

Z
zt147369 已提交
1698 1699
**模型约束**:此接口仅可在Stage模型下使用。

1700
**参数:**
H
huangjie 已提交
1701

1702 1703 1704 1705 1706 1707 1708 1709 1710 1711
| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resource | [Resource](#resource9) | 是    | 资源信息 |
| [density](#screendensity) | number | 否    | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度 |

**返回值:**

| 类型                    | 说明          |
| --------------------- | ----------- |
| Uint8Array | resource对象对应的媒体文件内容 |
1712

H
huangjie 已提交
1713 1714
**错误码:**

1715 1716
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
1717 1718
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
H
huangjie 已提交
1719 1720
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
H
huangjie 已提交
1721

1722
**示例:**
H
HelloCrease 已提交
1723
  ```ts
F
fangyunzhong 已提交
1724 1725 1726
  import resourceManager from '@ohos.resourceManager';

  let resource: resourceManager.Resource = {
1727 1728 1729
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.media.test').id
1730
  };
H
huangjie 已提交
1731
  try {
1732
    this.context.resourceManager.getMediaContentSync(resource); // 默认屏幕密度
H
huangjie 已提交
1733
  } catch (error) {
1734 1735 1736 1737 1738 1739 1740
    console.error(`getMediaContentSync failed, error code: ${error.code}, message: ${error.message}.`);
  }

  try {
    this.context.resourceManager.getMediaContentSync(resource, 120); // 指定屏幕密度
  } catch (error) {
    console.error(`getMediaContentSync failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
1741
  }
1742 1743
  ```

F
fangyunzhong 已提交
1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788
### getMediaByNameSync<sup>10+</sup>

getMediaByNameSync(resName: string, density?: number): Uint8Array

用户获取指定资源名称对应的默认或指定的屏幕密度媒体文件内容,使用同步方式返回字节数组。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:**

| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resName | string | 是    | 资源名称 |
| [density](#screendensity) | number | 否    | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度 |

**返回值:**

| 类型                    | 说明          |
| --------------------- | ----------- |
| Uint8Array | 对应资源名称的媒体文件内容 |

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                       |
| 9001004  | If the resource not found by resName.         |

**示例:**
  ```ts
  try {
    this.context.resourceManager.getMediaByNameSync("test"); // 默认屏幕密度
  } catch (error) {
    console.error(`getMediaByNameSync failed, error code: ${error.code}, message: ${error.message}.`);
  }

  try {
    this.context.resourceManager.getMediaByNameSync("test", 120); // 指定屏幕密度
  } catch (error) {
    console.error(`getMediaByNameSync failed, error code: ${error.code}, message: ${error.message}.`);
  }
  ```

1789
### getMediaContent<sup>9+</sup>
1790

1791
getMediaContent(resId: number, callback: AsyncCallback&lt;Uint8Array&gt;): void
1792

1793
用户获取指定资源ID对应的媒体文件内容,使用callback形式返回字节数组。
1794 1795 1796 1797

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
1798

1799 1800 1801 1802
| 参数名      | 类型                              | 必填   | 说明                 |
| -------- | ------------------------------- | ---- | ------------------ |
| resId    | number                          | 是    | 资源ID值              |
| callback | AsyncCallback&lt;Uint8Array&gt; | 是    | 异步回调,用于返回获取的媒体文件内容 |
1803

H
huangjie 已提交
1804 1805
**错误码:**

1806 1807
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
1808 1809
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
H
huangjie 已提交
1810 1811
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
H
huangjie 已提交
1812

1813
**示例:** 
H
HelloCrease 已提交
1814
  ```ts
H
huangjie 已提交
1815
  try {
1816 1817 1818 1819 1820 1821
    this.context.resourceManager.getMediaContent($r('app.media.test').id, (error, value) => {
      if (error != null) {
        console.log("error is " + error);
      } else {
        let media = value;
      }
H
huangjie 已提交
1822 1823
    });
  } catch (error) {
1824
    console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
1825
  }
1826 1827
  ```

1828
### getMediaContent<sup>10+</sup>
Z
zengyawen 已提交
1829

1830
getMediaContent(resId: number, density: number, callback: AsyncCallback&lt;Uint8Array&gt;): void
Z
zengyawen 已提交
1831

1832
用户获取指定资源ID对应的指定屏幕密度媒体文件内容,使用callback形式返回字节数组。
Z
zengyawen 已提交
1833

V
VictoriaGuo 已提交
1834 1835
**系统能力**:SystemCapability.Global.ResourceManager

H
HelloCrease 已提交
1836
**参数:** 
H
huangjie 已提交
1837

1838 1839 1840 1841 1842
| 参数名      | 类型                              | 必填   | 说明                 |
| -------- | ------------------------------- | ---- | ------------------ |
| resId    | number                          | 是    | 资源ID值              |
| [density](#screendensity)  | number                          | 是    | 资源获取需要的屏幕密度,0表示默认屏幕密度    |
| callback | AsyncCallback&lt;Uint8Array&gt; | 是    | 异步回调,用于返回获取的媒体文件内容 |
Z
zengyawen 已提交
1843

H
huangjie 已提交
1844 1845
**错误码:**

1846 1847
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
1848 1849
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
1850 1851
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
H
huangjie 已提交
1852

H
HelloCrease 已提交
1853
**示例:** 
H
HelloCrease 已提交
1854
  ```ts
H
huangjie 已提交
1855
  try {
1856 1857 1858 1859 1860 1861
    this.context.resourceManager.getMediaContent($r('app.media.test').id, 120, (error, value) => {
      if (error != null) {
        console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
      } else {
        let media = value;
      }
H
huangjie 已提交
1862 1863
    });
  } catch (error) {
1864
    console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
1865
  }
Z
zengyawen 已提交
1866 1867
  ```

1868
### getMediaContent<sup>9+</sup>
Z
zengyawen 已提交
1869

1870
getMediaContent(resId: number): Promise&lt;Uint8Array&gt;
Z
zengyawen 已提交
1871

1872
用户获取指定资源ID对应的媒体文件内容,使用Promise形式返回字节数组。
Z
zengyawen 已提交
1873

V
VictoriaGuo 已提交
1874 1875
**系统能力**:SystemCapability.Global.ResourceManager

H
HelloCrease 已提交
1876
**参数:** 
H
huangjie 已提交
1877

1878 1879 1880 1881
| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resId | number | 是    | 资源ID值 |

H
huangjie 已提交
1882 1883
**返回值:**

1884 1885 1886
| 类型                        | 说明             |
| ------------------------- | -------------- |
| Promise&lt;Uint8Array&gt; | 资源ID值对应的媒体文件内容 |
Z
zengyawen 已提交
1887

H
huangjie 已提交
1888 1889
**错误码:**

1890 1891
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
1892 1893
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
1894 1895
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
H
huangjie 已提交
1896

H
HelloCrease 已提交
1897
**示例:** 
H
HelloCrease 已提交
1898
  ```ts
F
fangyunzhong 已提交
1899 1900
  import { BusinessError } from '@ohos.base';

H
huangjie 已提交
1901
  try {
F
fangyunzhong 已提交
1902
    this.context.resourceManager.getMediaContent($r('app.media.test').id).then((value: Uint8Array) => {
1903
      let media = value;
F
fangyunzhong 已提交
1904
    }).catch((error: BusinessError) => {
1905
      console.log("getMediaContent promise error is " + error);
H
huangjie 已提交
1906 1907
    });
  } catch (error) {
1908
    console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
1909
  }
Z
zengyawen 已提交
1910
  ```
W
wplan1 已提交
1911

1912
### getMediaContent<sup>10+</sup>
W
wplan1 已提交
1913

1914
getMediaContent(resId: number, density: number): Promise&lt;Uint8Array&gt;
W
wplan1 已提交
1915

1916
用户获取指定资源ID对应的指定屏幕密度媒体文件内容,使用Promise形式返回字节数组。
W
wplan1 已提交
1917 1918 1919

**系统能力**:SystemCapability.Global.ResourceManager

H
HelloCrease 已提交
1920
**参数:** 
H
huangjie 已提交
1921

1922 1923 1924 1925 1926 1927 1928 1929 1930 1931
| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resId | number | 是    | 资源ID值 |
| [density](#screendensity)  | number                          | 是    | 资源获取需要的屏幕密度,0表示默认屏幕密度    |

**返回值:**

| 类型                        | 说明             |
| ------------------------- | -------------- |
| Promise&lt;Uint8Array&gt; | 资源ID值对应的媒体文件内容 |
H
huangjie 已提交
1932

H
huangjie 已提交
1933 1934
**错误码:**

1935 1936
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
1937 1938
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
1939 1940
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
W
wplan1 已提交
1941

H
HelloCrease 已提交
1942
**示例:** 
H
HelloCrease 已提交
1943
  ```ts
F
fangyunzhong 已提交
1944 1945
  import { BusinessError } from '@ohos.base';

H
huangjie 已提交
1946
  try {
F
fangyunzhong 已提交
1947
    this.context.resourceManager.getMediaContent($r('app.media.test').id, 120).then((value: Uint8Array) => {
1948
      let media = value;
F
fangyunzhong 已提交
1949
    }).catch((error: BusinessError) => {
1950
      console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
1951 1952
    });
  } catch (error) {
1953
    console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
1954
  }
W
wplan1 已提交
1955 1956
  ```

1957
### getMediaContent<sup>9+</sup>
W
wplan1 已提交
1958

1959
getMediaContent(resource: Resource, callback: AsyncCallback&lt;Uint8Array&gt;): void
W
wplan1 已提交
1960

1961
用户获取指定resource对象对应的媒体文件内容,使用callback形式返回字节数组。
W
wplan1 已提交
1962 1963 1964

**系统能力**:SystemCapability.Global.ResourceManager

1965
**模型约束**:此接口仅可在Stage模型下使用。
W
wplan1 已提交
1966

1967
**参数:** 
H
huangjie 已提交
1968

1969 1970 1971 1972
| 参数名      | 类型                              | 必填   | 说明                 |
| -------- | ------------------------------- | ---- | ------------------ |
| resource | [Resource](#resource9)          | 是    | 资源信息               |
| callback | AsyncCallback&lt;Uint8Array&gt; | 是    | 异步回调,用于返回获取的媒体文件内容 |
H
huangjie 已提交
1973

H
huangjie 已提交
1974 1975
**错误码:**

1976 1977
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
1978 1979
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
1980 1981
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
W
wplan1 已提交
1982

H
HelloCrease 已提交
1983
**示例:** 
H
HelloCrease 已提交
1984
  ```ts
F
fangyunzhong 已提交
1985 1986 1987
  import resourceManager from '@ohos.resourceManager';

  let resource: resourceManager.Resource = {
1988 1989 1990 1991
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.media.test').id
  };
H
huangjie 已提交
1992
  try {
1993 1994 1995 1996 1997 1998
    this.context.resourceManager.getMediaContent(resource, (error, value) => {
      if (error != null) {
        console.log("error is " + error);
      } else {
        let media = value;
      }
H
huangjie 已提交
1999 2000
    });
  } catch (error) {
2001
    console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
2002
  }
W
wplan1 已提交
2003 2004
  ```

2005
### getMediaContent<sup>10+</sup>
2006

2007
getMediaContent(resource: Resource, density: number, callback: AsyncCallback&lt;Uint8Array&gt;): void
2008

2009
用户获取指定resource对象对应的指定屏幕密度媒体文件内容,使用callback形式返回字节数组。
2010 2011 2012

**系统能力**:SystemCapability.Global.ResourceManager

2013 2014
**模型约束**:此接口仅可在Stage模型下使用。

2015 2016
**参数:** 

2017 2018 2019 2020 2021
| 参数名      | 类型                              | 必填   | 说明                 |
| -------- | ------------------------------- | ---- | ------------------ |
| resource | [Resource](#resource9)          | 是    | 资源信息               |
| [density](#screendensity)  | number        | 是    | 资源获取需要的屏幕密度,0表示默认屏幕密度    |
| callback | AsyncCallback&lt;Uint8Array&gt; | 是    | 异步回调,用于返回获取的媒体文件内容 |
2022 2023 2024 2025 2026 2027 2028

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
2029 2030
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
2031 2032 2033

**示例:** 
  ```ts
F
fangyunzhong 已提交
2034 2035 2036
  import resourceManager from '@ohos.resourceManager';

  let resource: resourceManager.Resource = {
2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.media.test').id
  };
  try {
    this.context.resourceManager.getMediaContent(resource, 120, (error, value) => {
      if (error != null) {
        console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
      } else {
        let media = value;
      }
2048 2049
    });
  } catch (error) {
2050
    console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
2051 2052 2053
  }
  ```

2054
### getMediaContent<sup>9+</sup>
2055

2056
getMediaContent(resource: Resource): Promise&lt;Uint8Array&gt;
2057

2058
用户获取指定resource对象对应的媒体文件内容,使用Promise形式返回字节数组。
2059 2060 2061

**系统能力**:SystemCapability.Global.ResourceManager

2062 2063
**模型约束**:此接口仅可在Stage模型下使用。

2064 2065
**参数:** 

2066 2067 2068
| 参数名      | 类型                     | 必填   | 说明   |
| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | 是    | 资源信息 |
2069 2070 2071

**返回值:**

2072 2073 2074
| 类型                        | 说明                  |
| ------------------------- | ------------------- |
| Promise&lt;Uint8Array&gt; | resource对象对应的媒体文件内容 |
2075 2076 2077 2078 2079 2080 2081

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
2082 2083
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
2084 2085 2086

**示例:** 
  ```ts
F
fangyunzhong 已提交
2087 2088 2089 2090
  import resourceManager from '@ohos.resourceManager';
  import { BusinessError } from '@ohos.base';

  let resource: resourceManager.Resource = {
2091 2092 2093 2094 2095
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.media.test').id
  };
  try {
F
fangyunzhong 已提交
2096
    this.context.resourceManager.getMediaContent(resource).then((value: Uint8Array) => {
2097
      let media = value;
F
fangyunzhong 已提交
2098
    }).catch((error: BusinessError) => {
2099
      console.log("getMediaContent promise error is " + error);
2100 2101
    });
  } catch (error) {
2102
    console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
2103 2104 2105
  }
  ```

2106
### getMediaContent<sup>10+</sup>
W
wplan1 已提交
2107

2108
getMediaContent(resource: Resource, density: number): Promise&lt;Uint8Array&gt;
H
huangjie 已提交
2109

2110
用户获取指定resource对象对应的指定屏幕密度媒体文件内容,使用Promise形式返回字节数组。
H
huangjie 已提交
2111

H
huangjie 已提交
2112
**系统能力**:SystemCapability.Global.ResourceManager
H
huangjie 已提交
2113

2114 2115
**模型约束**:此接口仅可在Stage模型下使用。

H
huangjie 已提交
2116
**参数:** 
H
huangjie 已提交
2117

2118 2119 2120 2121 2122 2123 2124 2125 2126 2127
| 参数名      | 类型                     | 必填   | 说明   |
| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | 是    | 资源信息 |
| [density](#screendensity)  | number                          | 是    | 资源获取需要的屏幕密度,0表示默认屏幕密度    |

**返回值:**

| 类型                        | 说明                  |
| ------------------------- | ------------------- |
| Promise&lt;Uint8Array&gt; | resource对象对应的媒体文件内容 |
H
huangjie 已提交
2128

H
huangjie 已提交
2129 2130
**错误码:**

2131 2132
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
2133 2134
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
2135 2136
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
H
huangjie 已提交
2137

H
huangjie 已提交
2138
**示例:** 
H
HelloCrease 已提交
2139
  ```ts
F
fangyunzhong 已提交
2140 2141 2142 2143
  import resourceManager from '@ohos.resourceManager';
  import { BusinessError } from '@ohos.base';

  let resource: resourceManager.Resource = {
2144 2145 2146 2147
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.media.test').id
  };
H
huangjie 已提交
2148
  try {
F
fangyunzhong 已提交
2149
    this.context.resourceManager.getMediaContent(resource, 120).then((value: Uint8Array) => {
2150
      let media = value;
F
fangyunzhong 已提交
2151
    }).catch((error: BusinessError) => {
2152
      console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
2153 2154
    });
  } catch (error) {
2155
    console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
2156
  }
H
huangjie 已提交
2157 2158
  ```

2159
### getMediaByName<sup>9+</sup>
H
huangjie 已提交
2160

2161
getMediaByName(resName: string, callback: AsyncCallback&lt;Uint8Array&gt;): void
H
huangjie 已提交
2162

2163
用户获取指定资源ID对应的媒体文件内容,使用callback形式返回字节数组。
H
huangjie 已提交
2164 2165 2166 2167

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
2168

2169 2170 2171 2172
| 参数名      | 类型                              | 必填   | 说明                 |
| -------- | ------------------------------- | ---- | ------------------ |
| resName  | string                          | 是    | 资源名称               |
| callback | AsyncCallback&lt;Uint8Array&gt; | 是    | 异步回调,用于返回获取的媒体文件内容 |
H
huangjie 已提交
2173

H
huangjie 已提交
2174 2175
**错误码:**

2176 2177
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
2178 2179
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
2180 2181
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
H
huangjie 已提交
2182 2183 2184 2185

**示例:** 
  ```ts
  try {
2186 2187 2188 2189 2190 2191
    this.context.resourceManager.getMediaByName("test", (error, value) => {
      if (error != null) {
        console.log("error is " + error);
      } else {
        let media = value;
      }
H
huangjie 已提交
2192 2193
    });
  } catch (error) {
2194
    console.error(`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
2195
  }
H
huangjie 已提交
2196 2197
  ```

2198
### getMediaByName<sup>10+</sup>
H
huangjie 已提交
2199

2200
getMediaByName(resName: string, density: number, callback: AsyncCallback&lt;Uint8Array&gt;): void
H
huangjie 已提交
2201

2202
用户获取指定资源ID对应的指定屏幕密度媒体文件内容,使用callback形式返回字节数组。
H
huangjie 已提交
2203 2204 2205

**系统能力**:SystemCapability.Global.ResourceManager

2206
**参数:** 
H
huangjie 已提交
2207

2208 2209 2210 2211 2212
| 参数名      | 类型                              | 必填   | 说明                 |
| -------- | ------------------------------- | ---- | ------------------ |
| resName  | string                          | 是    | 资源名称               |
| [density](#screendensity)  | number        | 是    | 资源获取需要的屏幕密度,0表示默认屏幕密度    |
| callback | AsyncCallback&lt;Uint8Array&gt; | 是    | 异步回调,用于返回获取的媒体文件内容 |
H
huangjie 已提交
2213

H
huangjie 已提交
2214 2215
**错误码:**

2216 2217
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
2218 2219
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
H
huangjie 已提交
2220 2221
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
H
huangjie 已提交
2222

2223
**示例:** 
H
huangjie 已提交
2224 2225
  ```ts
  try {
2226 2227 2228 2229 2230 2231 2232
    this.context.resourceManager.getMediaByName("test", 120, (error, value) => {
      if (error != null) {
        console.error(`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`);
      } else {
        let media = value;
      }
    });
H
huangjie 已提交
2233
  } catch (error) {
2234
    console.error(`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
2235 2236 2237
  }
  ```

2238
### getMediaByName<sup>9+</sup>
H
huangjie 已提交
2239

2240
getMediaByName(resName: string): Promise&lt;Uint8Array&gt;
H
huangjie 已提交
2241

2242
用户获取指定资源名称对应的媒体文件内容,使用Promise形式返回字节数组。
H
huangjie 已提交
2243 2244 2245

**系统能力**:SystemCapability.Global.ResourceManager

2246
**参数:** 
H
huangjie 已提交
2247

H
HelloCrease 已提交
2248
| 参数名     | 类型     | 必填   | 说明   |
H
huangjie 已提交
2249
| ------- | ------ | ---- | ---- |
H
HelloCrease 已提交
2250
| resName | string | 是    | 资源名称 |
H
huangjie 已提交
2251 2252

**返回值:**
H
huangjie 已提交
2253

2254 2255 2256
| 类型                        | 说明            |
| ------------------------- | ------------- |
| Promise&lt;Uint8Array&gt; | 资源名称对应的媒体文件内容 |
H
huangjie 已提交
2257

H
huangjie 已提交
2258 2259
**错误码:**

2260 2261
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
2262 2263
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
H
huangjie 已提交
2264 2265
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
H
huangjie 已提交
2266

2267
**示例:** 
H
HelloCrease 已提交
2268
  ```ts
F
fangyunzhong 已提交
2269 2270
  import { BusinessError } from '@ohos.base';

H
huangjie 已提交
2271
  try {
F
fangyunzhong 已提交
2272
    this.context.resourceManager.getMediaByName("test").then((value: Uint8Array) => {
2273
      let media = value;
F
fangyunzhong 已提交
2274
    }).catch((error: BusinessError) => {
2275
      console.log("getMediaByName promise error is " + error);
H
huangjie 已提交
2276 2277
    });
  } catch (error) {
2278
    console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`)
H
huangjie 已提交
2279
  }
H
huangjie 已提交
2280 2281
  ```

2282
### getMediaByName<sup>10+</sup>
H
huangjie 已提交
2283

2284
getMediaByName(resName: string, density: number): Promise&lt;Uint8Array&gt;
H
huangjie 已提交
2285

2286
用户获取指定资源名称对应的指定屏幕密度媒体文件内容,使用Promise形式返回字节数组。
H
huangjie 已提交
2287 2288 2289

**系统能力**:SystemCapability.Global.ResourceManager

2290
**参数:** 
H
huangjie 已提交
2291

2292 2293 2294 2295 2296 2297 2298 2299 2300 2301
| 参数名     | 类型     | 必填   | 说明   |
| ------- | ------ | ---- | ---- |
| resName | string | 是    | 资源名称 |
| [density](#screendensity)  | number                          | 是    | 资源获取需要的屏幕密度,0表示默认屏幕密度    |

**返回值:**

| 类型                        | 说明            |
| ------------------------- | ------------- |
| Promise&lt;Uint8Array&gt; | 资源名称对应的媒体文件内容 |
H
huangjie 已提交
2302

H
huangjie 已提交
2303 2304
**错误码:**

2305 2306
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
2307 2308
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
H
huangjie 已提交
2309 2310
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
H
huangjie 已提交
2311

H
huangjie 已提交
2312
**示例:** 
H
HelloCrease 已提交
2313
  ```ts
F
fangyunzhong 已提交
2314 2315
  import { BusinessError } from '@ohos.base';

H
huangjie 已提交
2316
  try {
F
fangyunzhong 已提交
2317
    this.context.resourceManager.getMediaByName("test", 120).then((value: Uint8Array) => {
2318
      let media = value;
F
fangyunzhong 已提交
2319
    }).catch((error: BusinessError) => {
2320
      console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
2321 2322
    });
  } catch (error) {
2323
    console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
2324
  }
H
huangjie 已提交
2325 2326
  ```

2327
### getMediaContentBase64Sync<sup>10+</sup>
H
huangjie 已提交
2328

2329
getMediaContentBase64Sync(resId: number, density?: number): string
H
huangjie 已提交
2330

2331
用户获取指定资源ID对应的默认或指定的屏幕密度图片资源Base64编码,使用同步方式返回字符串。
H
huangjie 已提交
2332 2333 2334 2335

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
2336

2337 2338 2339 2340
| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resId | number | 是    | 资源ID值 |
| [density](#screendensity) | number | 否    | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度 |
H
huangjie 已提交
2341

H
huangjie 已提交
2342 2343
**返回值:**

2344 2345 2346
| 类型                    | 说明          |
| -------- | ----------- |
| string   | 资源ID对应的图片资源Base64编码 |
H
huangjie 已提交
2347

H
huangjie 已提交
2348 2349
**错误码:**

2350 2351
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
2352 2353
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
2354 2355
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
H
huangjie 已提交
2356

H
huangjie 已提交
2357
**示例:** 
H
HelloCrease 已提交
2358
  ```ts
H
huangjie 已提交
2359
  try {
2360
    this.context.resourceManager.getMediaContentBase64Sync($r('app.media.test').id); // 默认屏幕密度
H
huangjie 已提交
2361
  } catch (error) {
2362 2363 2364 2365 2366 2367 2368
    console.error(`getMediaContentBase64Sync failed, error code: ${error.code}, message: ${error.message}.`);
  }

  try {
    this.context.resourceManager.getMediaContentBase64Sync($r('app.media.test').id, 120); // 指定屏幕密度
  } catch (error) {
    console.error(`getMediaContentBase64Sync failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
2369
  }
H
huangjie 已提交
2370 2371
  ```

2372
### getMediaContentBase64Sync<sup>10+</sup>
H
huangjie 已提交
2373

2374
getMediaContentBase64Sync(resource: Resource, density?: number): string
H
huangjie 已提交
2375

2376
用户获取指定resource对象对应的默认或指定的屏幕密度图片资源Base64编码,使用同步方式返回字符串。
H
huangjie 已提交
2377 2378 2379

**系统能力**:SystemCapability.Global.ResourceManager

2380 2381
**模型约束**:此接口仅可在Stage模型下使用。

H
huangjie 已提交
2382
**参数:** 
H
huangjie 已提交
2383

2384 2385 2386 2387 2388 2389 2390 2391 2392 2393
| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resource | [Resource](#resource9) | 是    | 资源信息 |
| [density](#screendensity) | number | 否    | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度 |

**返回值:**

| 类型                    | 说明          |
| --------------------- | ----------- |
| string | resource对象对应的图片资源Base64编码 |
H
huangjie 已提交
2394

H
huangjie 已提交
2395 2396
**错误码:**

2397 2398
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
2399 2400
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
2401 2402
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
H
huangjie 已提交
2403

H
huangjie 已提交
2404
**示例:** 
H
HelloCrease 已提交
2405
  ```ts
F
fangyunzhong 已提交
2406 2407 2408
  import resourceManager from '@ohos.resourceManager';

  let resource: resourceManager.Resource = {
2409 2410 2411 2412
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.media.test').id
  };
H
huangjie 已提交
2413
  try {
2414
    this.context.resourceManager.getMediaContentBase64Sync(resource); // 默认屏幕密度
H
huangjie 已提交
2415
  } catch (error) {
2416 2417 2418 2419 2420 2421 2422
    console.error(`getMediaContentBase64Sync failed, error code: ${error.code}, message: ${error.message}.`);
  }

  try {
    this.context.resourceManager.getMediaContentBase64Sync(resource, 120); // 指定屏幕密度
  } catch (error) {
    console.error(`getMediaContentBase64Sync failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
2423
  }
H
huangjie 已提交
2424 2425
  ```

F
fangyunzhong 已提交
2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470
### getMediaBase64ByNameSync<sup>10+</sup>

getMediaBase64ByNameSync(resName: string, density?: number): string

用户获取指定资源名称对应的默认或指定的屏幕密度图片资源Base64编码,使用同步方式返回字符串。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 

| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resName | string | 是    | 资源名称 |
| [density](#screendensity) | number | 否    | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度 |

**返回值:**

| 类型                    | 说明          |
| --------------------- | ----------- |
| string | 资源名称对应的图片资源Base64编码 |

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                       |
| 9001004  | If the resource not found by resName.         |

**示例:** 
  ```ts
  try {
    this.context.resourceManager.getMediaBase64ByNameSync("test"); // 默认屏幕密度
  } catch (error) {
    console.error(`getMediaBase64ByNameSync failed, error code: ${error.code}, message: ${error.message}.`);
  }

  try {
    this.context.resourceManager.getMediaBase64ByNameSync("test", 120); // 指定屏幕密度
  } catch (error) {
    console.error(`getMediaBase64ByNameSync failed, error code: ${error.code}, message: ${error.message}.`);
  }
  ```

2471
### getMediaContentBase64<sup>9+</sup>
Z
zt147369 已提交
2472

2473
getMediaContentBase64(resId: number, callback: AsyncCallback&lt;string&gt;): void
Z
zt147369 已提交
2474

2475
用户获取指定资源ID对应的图片资源Base64编码,使用callback形式返回字符串。
Z
zt147369 已提交
2476 2477 2478

**系统能力**:SystemCapability.Global.ResourceManager

2479
**参数:** Content
Z
zt147369 已提交
2480

2481 2482 2483 2484
| 参数名      | 类型                          | 必填   | 说明                       |
| -------- | --------------------------- | ---- | ------------------------ |
| resId    | number                      | 是    | 资源ID值                    |
| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,用于返回获取的图片资源Base64编码 |
Z
zt147369 已提交
2485 2486 2487

**错误码:**

2488 2489
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

Z
zt147369 已提交
2490 2491
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
2492 2493
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
Z
zt147369 已提交
2494 2495 2496 2497

**示例:** 
  ```ts
  try {
2498 2499 2500 2501 2502 2503
    this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, (error, value) => {
      if (error != null) {
        console.log("error is " + error);
      } else {
        let media = value;
      }
Z
zt147369 已提交
2504 2505
    });
  } catch (error) {
2506
    console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
2507 2508 2509
  }
  ```

2510
### getMediaContentBase64<sup>10+</sup>
H
huangjie 已提交
2511

2512
getMediaContentBase64(resId: number, density: number, callback: AsyncCallback&lt;string&gt;): void
H
huangjie 已提交
2513

2514
用户获取指定资源ID对应的指定屏幕密度图片资源Base64编码,使用callback形式返回字符串。
H
huangjie 已提交
2515 2516 2517 2518

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
2519

2520 2521 2522 2523 2524
| 参数名      | 类型                          | 必填   | 说明                       |
| -------- | --------------------------- | ---- | ------------------------ |
| resId    | number                      | 是    | 资源ID值                    |
| [density](#screendensity)  | number        | 是    | 资源获取需要的屏幕密度,0表示默认屏幕密度    |
| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,用于返回获取的图片资源Base64编码 |
H
huangjie 已提交
2525

H
huangjie 已提交
2526 2527
**错误码:**

2528 2529
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
2530 2531
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
2532 2533
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
H
huangjie 已提交
2534

H
huangjie 已提交
2535
**示例:** 
H
HelloCrease 已提交
2536
  ```ts
H
huangjie 已提交
2537
  try {
2538 2539 2540 2541
    this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, 120, (error, value) => {
      if (error != null) {
        console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
      } else {
H
huangjie 已提交
2542
        let media = value;
2543
      }
H
huangjie 已提交
2544 2545
    });
  } catch (error) {
2546
    console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
2547
  }
H
huangjie 已提交
2548 2549
  ```

2550
### getMediaContentBase64<sup>9+</sup>
Z
zt147369 已提交
2551

2552
getMediaContentBase64(resId: number): Promise&lt;string&gt;
Z
zt147369 已提交
2553

2554
用户获取指定资源ID对应的图片资源Base64编码,使用Promise形式返回字符串。
Z
zt147369 已提交
2555 2556 2557 2558 2559

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 

2560 2561 2562
| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resId | number | 是    | 资源ID值 |
Z
zt147369 已提交
2563 2564 2565

**返回值:**

2566 2567 2568
| 类型                    | 说明                   |
| --------------------- | -------------------- |
| Promise&lt;string&gt; | 资源ID值对应的图片资源Base64编码 |
Z
zt147369 已提交
2569 2570 2571

**错误码:**

2572 2573
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

Z
zt147369 已提交
2574 2575
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
2576 2577
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
Z
zt147369 已提交
2578 2579 2580

**示例:** 
  ```ts
F
fangyunzhong 已提交
2581 2582
  import { BusinessError } from '@ohos.base';

Z
zt147369 已提交
2583
  try {
F
fangyunzhong 已提交
2584
    this.context.resourceManager.getMediaContentBase64($r('app.media.test').id).then((value: string) => {
2585
      let media = value;
F
fangyunzhong 已提交
2586
    }).catch((error: BusinessError) => {
2587
      console.log("getMediaContentBase64 promise error is " + error);
Z
zt147369 已提交
2588 2589
    });
  } catch (error) {
2590
    console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
2591 2592 2593
  }
  ```

2594
### getMediaContentBase64<sup>10+</sup>
H
huangjie 已提交
2595

2596
getMediaContentBase64(resId: number, density: number): Promise&lt;string&gt;
H
huangjie 已提交
2597

2598
用户获取指定资源ID对应的指定屏幕密度图片资源Base64编码,使用Promise形式返回字符串。
H
huangjie 已提交
2599 2600 2601 2602

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
2603

2604 2605 2606 2607 2608 2609 2610 2611 2612 2613
| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resId | number | 是    | 资源ID值 |
| [density](#screendensity)  | number                          | 是    | 资源获取需要的屏幕密度,0表示默认屏幕密度    |

**返回值:**

| 类型                    | 说明                   |
| --------------------- | -------------------- |
| Promise&lt;string&gt; | 资源ID值对应的图片资源Base64编码 |
H
huangjie 已提交
2614

H
huangjie 已提交
2615 2616
**错误码:**

2617 2618
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
2619 2620
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
2621 2622
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
H
huangjie 已提交
2623

H
huangjie 已提交
2624
**示例:** 
H
HelloCrease 已提交
2625
  ```ts
F
fangyunzhong 已提交
2626 2627
  import { BusinessError } from '@ohos.base';

H
huangjie 已提交
2628
  try {
F
fangyunzhong 已提交
2629
    this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, 120).then((value: string) => {
2630
      let media = value;
F
fangyunzhong 已提交
2631
    }).catch((error: BusinessError) => {
2632
      console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
2633 2634
    });
  } catch (error) {
2635
    console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
2636
  }
H
huangjie 已提交
2637 2638
  ```

2639
### getMediaContentBase64<sup>9+</sup>
Z
zt147369 已提交
2640

2641
getMediaContentBase64(resource: Resource, callback: AsyncCallback&lt;string&gt;): void
Z
zt147369 已提交
2642

2643
用户获取指定resource对象对应的图片资源Base64编码,使用callback形式返回字符串。
Z
zt147369 已提交
2644 2645 2646

**系统能力**:SystemCapability.Global.ResourceManager

2647 2648 2649
**模型约束**:此接口仅可在Stage模型下使用。

**参数:**
Z
zt147369 已提交
2650 2651 2652

| 参数名      | 类型                          | 必填   | 说明                       |
| -------- | --------------------------- | ---- | ------------------------ |
2653
| resource | [Resource](#resource9)      | 是    | 资源信息                     |
Z
zt147369 已提交
2654 2655 2656 2657
| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,用于返回获取的图片资源Base64编码 |

**错误码:**

2658 2659
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

Z
zt147369 已提交
2660 2661
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
2662 2663
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
Z
zt147369 已提交
2664 2665 2666

**示例:** 
  ```ts
F
fangyunzhong 已提交
2667 2668 2669
  import resourceManager from '@ohos.resourceManager';

  let resource: resourceManager.Resource = {
2670 2671 2672 2673
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.media.test').id
  };
Z
zt147369 已提交
2674
  try {
2675 2676 2677 2678 2679 2680
    this.context.resourceManager.getMediaContentBase64(resource, (error, value) => {
      if (error != null) {
        console.log("error is " + error);
      } else {
        let media = value;
      }
Z
zt147369 已提交
2681 2682
    });
  } catch (error) {
2683
    console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
2684 2685 2686
  }
  ```

2687
### getMediaContentBase64<sup>10+</sup>
H
huangjie 已提交
2688

2689
getMediaContentBase64(resource: Resource, density: number, callback: AsyncCallback&lt;string&gt;): void
H
huangjie 已提交
2690

2691
用户获取指定resource对象对应的指定屏幕密度图片资源Base64编码,使用callback形式返回字符串。
H
huangjie 已提交
2692 2693 2694

**系统能力**:SystemCapability.Global.ResourceManager

2695
**模型约束**:此接口仅可在Stage模型下使用。
H
huangjie 已提交
2696

2697
**参数:**
H
huangjie 已提交
2698

2699 2700 2701 2702 2703
| 参数名      | 类型                          | 必填   | 说明                       |
| -------- | --------------------------- | ---- | ------------------------ |
| resource | [Resource](#resource9)      | 是    | 资源信息                     |
| [density](#screendensity)  | number        | 是    | 资源获取需要的屏幕密度,0表示默认屏幕密度    |
| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,用于返回获取的图片资源Base64编码 |
H
huangjie 已提交
2704

H
huangjie 已提交
2705 2706
**错误码:**

2707 2708
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
2709 2710
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
2711 2712
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
H
huangjie 已提交
2713

H
huangjie 已提交
2714
**示例:** 
H
HelloCrease 已提交
2715
  ```ts
F
fangyunzhong 已提交
2716 2717 2718
  import resourceManager from '@ohos.resourceManager';

  let resource: resourceManager.Resource = {
2719 2720 2721 2722
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.media.test').id
  };
H
huangjie 已提交
2723
  try {
2724 2725 2726 2727
    this.context.resourceManager.getMediaContentBase64(resource, 120, (error, value) => {
      if (error != null) {
        console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
      } else {
H
huangjie 已提交
2728
        let media = value;
2729
      }
H
huangjie 已提交
2730 2731
    });
  } catch (error) {
2732
    console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
2733
  }
H
huangjie 已提交
2734 2735
  ```

2736
### getMediaContentBase64<sup>9+</sup>
Z
zt147369 已提交
2737

2738
getMediaContentBase64(resource: Resource): Promise&lt;string&gt;
Z
zt147369 已提交
2739

2740
用户获取指定resource对象对应的图片资源Base64编码,使用Promise形式返回字符串。
Z
zt147369 已提交
2741 2742 2743

**系统能力**:SystemCapability.Global.ResourceManager

2744 2745
**模型约束**:此接口仅可在Stage模型下使用。

Z
zt147369 已提交
2746 2747
**参数:** 

2748 2749 2750
| 参数名      | 类型                     | 必填   | 说明   |
| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | 是    | 资源信息 |
Z
zt147369 已提交
2751 2752 2753

**返回值:**

2754 2755 2756
| 类型                    | 说明                        |
| --------------------- | ------------------------- |
| Promise&lt;string&gt; | resource对象对应的图片资源Base64编码 |
Z
zt147369 已提交
2757 2758 2759

**错误码:**

2760 2761
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

Z
zt147369 已提交
2762 2763
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
2764 2765
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
Z
zt147369 已提交
2766 2767 2768

**示例:** 
  ```ts
F
fangyunzhong 已提交
2769 2770 2771 2772
  import resourceManager from '@ohos.resourceManager';
  import { BusinessError } from '@ohos.base';

  let resource: resourceManager.Resource = {
2773 2774 2775 2776
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.media.test').id
  };
Z
zt147369 已提交
2777
  try {
F
fangyunzhong 已提交
2778
    this.context.resourceManager.getMediaContentBase64(resource).then((value: string) => {
2779
      let media = value;
F
fangyunzhong 已提交
2780
    }).catch((error: BusinessError) => {
2781
      console.log("getMediaContentBase64 promise error is " + error);
Z
zt147369 已提交
2782 2783
    });
  } catch (error) {
2784
    console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
2785 2786 2787
  }
  ```

2788
### getMediaContentBase64<sup>10+</sup>
H
huangjie 已提交
2789

2790
getMediaContentBase64(resource: Resource, density: number): Promise&lt;string&gt;
H
huangjie 已提交
2791

2792
用户获取指定resource对象对应的指定屏幕密度图片资源Base64编码,使用Promise形式返回字符串。
H
huangjie 已提交
2793 2794 2795

**系统能力**:SystemCapability.Global.ResourceManager

2796 2797
**模型约束**:此接口仅可在Stage模型下使用。

H
huangjie 已提交
2798
**参数:** 
H
huangjie 已提交
2799

2800 2801 2802 2803 2804 2805 2806 2807 2808 2809
| 参数名      | 类型                     | 必填   | 说明   |
| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | 是    | 资源信息 |
| [density](#screendensity)  | number                          | 是    | 资源获取需要的屏幕密度,0表示默认屏幕密度    |

**返回值:**

| 类型                    | 说明                        |
| --------------------- | ------------------------- |
| Promise&lt;string&gt; | resource对象对应的图片资源Base64编码 |
H
huangjie 已提交
2810

H
huangjie 已提交
2811 2812
**错误码:**

2813 2814
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
2815 2816
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
2817 2818
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
H
huangjie 已提交
2819

H
huangjie 已提交
2820
**示例:** 
H
HelloCrease 已提交
2821
  ```ts
F
fangyunzhong 已提交
2822 2823 2824 2825
  import resourceManager from '@ohos.resourceManager';
  import { BusinessError } from '@ohos.base';

  let resource: resourceManager.Resource = {
2826 2827 2828 2829
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.media.test').id
  };
H
huangjie 已提交
2830
  try {
F
fangyunzhong 已提交
2831
    this.context.resourceManager.getMediaContentBase64(resource, 120).then((value: string) => {
2832
      let media = value;
F
fangyunzhong 已提交
2833
    }).catch((error: BusinessError) => {
2834
      console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
2835 2836
    });
  } catch (error) {
2837
    console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
2838
  }
H
huangjie 已提交
2839 2840
  ```

2841
### getMediaBase64ByName<sup>9+</sup>
H
huangjie 已提交
2842

2843
getMediaBase64ByName(resName: string, callback: AsyncCallback&lt;string&gt;): void
H
huangjie 已提交
2844

2845
用户获取指定资源名称对应的图片资源Base64编码,使用callback形式返回字符串。
H
huangjie 已提交
2846 2847 2848 2849

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
2850

2851 2852 2853 2854
| 参数名      | 类型                          | 必填   | 说明                       |
| -------- | --------------------------- | ---- | ------------------------ |
| resName  | string                      | 是    | 资源名称                     |
| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,用于返回获取的图片资源Base64编码 |
H
huangjie 已提交
2855

H
huangjie 已提交
2856 2857
**错误码:**

2858 2859
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
2860 2861
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
H
huangjie 已提交
2862 2863
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
H
huangjie 已提交
2864

H
huangjie 已提交
2865
**示例:** 
H
HelloCrease 已提交
2866
  ```ts
H
huangjie 已提交
2867
  try {
2868 2869 2870 2871 2872 2873
    this.context.resourceManager.getMediaBase64ByName("test", (error, value) => {
      if (error != null) {
        console.log("error is " + error);
      } else {
        let media = value;
      }
H
huangjie 已提交
2874 2875
    });
  } catch (error) {
2876
    console.error(`callback getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
2877
  }
H
huangjie 已提交
2878 2879
  ```

2880
### getMediaBase64ByName<sup>10+</sup>
H
huangjie 已提交
2881

2882
getMediaBase64ByName(resName: string, density: number, callback: AsyncCallback&lt;string&gt;): void
H
huangjie 已提交
2883

2884
用户获取指定资源名称对应的指定屏幕密度图片资源Base64编码,使用callback形式返回字符串。
H
huangjie 已提交
2885 2886 2887 2888

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
2889

2890 2891 2892 2893 2894
| 参数名      | 类型                          | 必填   | 说明                       |
| -------- | --------------------------- | ---- | ------------------------ |
| resName  | string                      | 是    | 资源名称                     |
| [density](#screendensity)  | number        | 是    | 资源获取需要的屏幕密度,0表示默认屏幕密度    |
| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,用于返回获取的图片资源Base64编码 |
H
huangjie 已提交
2895

H
huangjie 已提交
2896 2897
**错误码:**

2898 2899
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
2900 2901
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
2902 2903
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
H
huangjie 已提交
2904

H
huangjie 已提交
2905
**示例:** 
H
HelloCrease 已提交
2906
  ```ts
H
huangjie 已提交
2907
  try {
2908 2909 2910 2911 2912 2913 2914
    this.context.resourceManager.getMediaBase64ByName("test", 120, (error, value) => {
      if (error != null) {
        console.error(`callback getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`);
      } else {
        let media = value;
      }
    });
H
huangjie 已提交
2915
  } catch (error) {
2916
    console.error(`callback getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
2917
  }
H
huangjie 已提交
2918 2919
  ```

2920
### getMediaBase64ByName<sup>9+</sup>
Z
zt147369 已提交
2921

2922
getMediaBase64ByName(resName: string): Promise&lt;string&gt;
Z
zt147369 已提交
2923

2924
用户获取指定资源名称对应的图片资源Base64编码,使用Promise形式返回字符串。
Z
zt147369 已提交
2925 2926 2927 2928 2929

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 

2930 2931 2932
| 参数名     | 类型     | 必填   | 说明   |
| ------- | ------ | ---- | ---- |
| resName | string | 是    | 资源名称 |
Z
zt147369 已提交
2933 2934 2935

**返回值:**

2936 2937 2938
| 类型                    | 说明                  |
| --------------------- | ------------------- |
| Promise&lt;string&gt; | 资源名称对应的图片资源Base64编码 |
Z
zt147369 已提交
2939 2940 2941

**错误码:**

2942 2943
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

Z
zt147369 已提交
2944
| 错误码ID | 错误信息 |
2945 2946 2947
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
Z
zt147369 已提交
2948 2949 2950

**示例:** 
  ```ts
F
fangyunzhong 已提交
2951 2952
  import { BusinessError } from '@ohos.base';

Z
zt147369 已提交
2953
  try {
F
fangyunzhong 已提交
2954
    this.context.resourceManager.getMediaBase64ByName("test").then((value: string) => {
2955
      let media = value;
F
fangyunzhong 已提交
2956
    }).catch((error: BusinessError) => {
2957 2958
      console.log("getMediaBase64ByName promise error is " + error);
    });
Z
zt147369 已提交
2959
  } catch (error) {
2960
    console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
2961 2962 2963
  }
  ```

2964
### getMediaBase64ByName<sup>10+</sup>
2965

2966
getMediaBase64ByName(resName: string, density: number): Promise&lt;string&gt;
2967

2968
用户获取指定资源名称对应的指定屏幕密度图片资源Base64编码,使用Promise形式返回字符串。
2969 2970 2971 2972

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
2973

2974 2975 2976 2977
| 参数名     | 类型     | 必填   | 说明   |
| ------- | ------ | ---- | ---- |
| resName | string | 是    | 资源名称 |
| [density](#screendensity)  | number                          | 是    | 资源获取需要的屏幕密度,0表示默认屏幕密度    |
2978

H
huangjie 已提交
2979 2980
**返回值:**

2981 2982 2983
| 类型                    | 说明                  |
| --------------------- | ------------------- |
| Promise&lt;string&gt; | 资源名称对应的图片资源Base64编码 |
2984

H
huangjie 已提交
2985 2986
**错误码:**

2987 2988
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
2989 2990
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
2991 2992
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
H
huangjie 已提交
2993

2994
**示例:** 
H
HelloCrease 已提交
2995
  ```ts
F
fangyunzhong 已提交
2996 2997
  import { BusinessError } from '@ohos.base';

H
huangjie 已提交
2998
  try {
F
fangyunzhong 已提交
2999
    this.context.resourceManager.getMediaBase64ByName("test", 120).then((value: string) => {
3000
      let media = value;
F
fangyunzhong 已提交
3001
    }).catch((error: BusinessError) => {
3002 3003
      console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`);
    });
H
huangjie 已提交
3004
  } catch (error) {
3005
    console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
3006
  }
3007 3008
  ```

3009
### getDrawableDescriptor<sup>10+</sup>
Z
zt147369 已提交
3010

3011
getDrawableDescriptor(resId: number, density?: number): DrawableDescriptor;
Z
zt147369 已提交
3012

3013
用户获取指定资源ID对应的DrawableDescriptor对象,使用同步方式返回资源对应的DrawableDescriptor,用于图标的显示。
Z
zt147369 已提交
3014 3015 3016

**系统能力**:SystemCapability.Global.ResourceManager

3017
**参数:**
Z
zt147369 已提交
3018

3019 3020 3021 3022
| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resId | number | 是    | 资源ID值 |
| [density](#screendensity) | number | 否    | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度 |
Z
zt147369 已提交
3023 3024 3025

**返回值:**

3026 3027 3028
| 类型     | 说明         |
| ------ | ---------- |
| DrawableDescriptor | 资源ID值对应的DrawableDescriptor对象 |
Z
zt147369 已提交
3029 3030 3031

**错误码:**

3032 3033
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

Z
zt147369 已提交
3034 3035 3036 3037 3038
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |

3039
**示例:**
Z
zt147369 已提交
3040 3041
  ```ts
  try {
3042
    this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id);
Z
zt147369 已提交
3043
  } catch (error) {
3044
    console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
3045
  }
3046 3047 3048 3049 3050 3051
  try {
    this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id, 120);
  } catch (error) {
    console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`);
  }
  ```
Z
zt147369 已提交
3052

3053
### getDrawableDescriptor<sup>10+</sup>
H
huangjie 已提交
3054

3055
getDrawableDescriptor(resource: Resource, density?: number): DrawableDescriptor;
H
huangjie 已提交
3056

3057
用户获取指定resource对应的DrawableDescriptor对象,使用同步方式返回资源对应的DrawableDescriptor,用于图标的显示。
H
huangjie 已提交
3058 3059 3060

**系统能力**:SystemCapability.Global.ResourceManager

3061
**模型约束**:此接口仅可在Stage模型下使用。
H
huangjie 已提交
3062

3063 3064 3065 3066 3067 3068
**参数:**

| 参数名      | 类型                     | 必填   | 说明   |
| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | 是    | 资源信息 |
| [density](#screendensity) | number | 否    | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度 |
H
huangjie 已提交
3069

H
huangjie 已提交
3070 3071
**返回值:**

3072 3073 3074
| 类型      | 说明                |
| ------- | ----------------- |
| DrawableDescriptor | 资源ID值对应的DrawableDescriptor对象 |
H
huangjie 已提交
3075

H
huangjie 已提交
3076 3077
**错误码:**

3078 3079
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
3080 3081
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
3082 3083
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
H
huangjie 已提交
3084

3085
**示例:**
H
HelloCrease 已提交
3086
  ```ts
F
fangyunzhong 已提交
3087 3088 3089
  import resourceManager from '@ohos.resourceManager';

  let resource: resourceManager.Resource = {
3090 3091 3092 3093
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.media.icon').id
  };
H
huangjie 已提交
3094
  try {
3095
    this.context.resourceManager.getDrawableDescriptor(resource);
H
huangjie 已提交
3096
  } catch (error) {
3097 3098 3099 3100 3101 3102
    console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`);
  }
  try {
    this.context.resourceManager.getDrawableDescriptor(resource, 120);
  } catch (error) {
    console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
3103
  }
H
huangjie 已提交
3104 3105
  ```

3106
### getDrawableDescriptorByName<sup>10+</sup>
Z
zt147369 已提交
3107

3108
getDrawableDescriptorByName(resName: string, density?: number): DrawableDescriptor;
Z
zt147369 已提交
3109

3110
用户获取指定资源名称对应的DrawableDescriptor对象,使用同步方式返回资源对应的DrawableDescriptor,用于图标的显示。
Z
zt147369 已提交
3111 3112 3113

**系统能力**:SystemCapability.Global.ResourceManager

3114
**参数:**
Z
zt147369 已提交
3115 3116 3117 3118

| 参数名     | 类型     | 必填   | 说明   |
| ------- | ------ | ---- | ---- |
| resName | string | 是    | 资源名称 |
3119
| [density](#screendensity) | number | 否    | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度 |
Z
zt147369 已提交
3120 3121 3122

**返回值:**

3123 3124 3125
| 类型     | 说明        |
| ------ | --------- |
| DrawableDescriptor | 资源ID值对应的DrawableDescriptor对象 |
Z
zt147369 已提交
3126 3127 3128

**错误码:**

3129 3130
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

Z
zt147369 已提交
3131 3132 3133 3134 3135
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |

3136
**示例:**
Z
zt147369 已提交
3137 3138
  ```ts
  try {
3139
    this.context.resourceManager.getDrawableDescriptorByName('icon');
Z
zt147369 已提交
3140
  } catch (error) {
3141
    console.error(`getDrawableDescriptorByName failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
3142
  }
3143 3144 3145 3146 3147 3148
  try {
    this.context.resourceManager.getDrawableDescriptorByName('icon', 120);
  } catch (error) {
    console.error(`getDrawableDescriptorByName failed, error code: ${error.code}, message: ${error.message}.`);
  }
  ```
Z
zt147369 已提交
3149

H
huangjie 已提交
3150
### getBoolean<sup>9+</sup>
H
huangjie 已提交
3151 3152 3153 3154 3155 3156 3157 3158

getBoolean(resId: number): boolean

使用同步方式,返回获取指定资源ID对应的布尔结果。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
3159

H
huangjie 已提交
3160 3161 3162 3163
| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resId | number | 是    | 资源ID值 |

H
huangjie 已提交
3164 3165
**返回值:**

H
HelloCrease 已提交
3166 3167
| 类型      | 说明           |
| ------- | ------------ |
H
huangjie 已提交
3168 3169
| boolean | 资源ID值对应的布尔结果 |

H
huangjie 已提交
3170 3171
**错误码:**

3172 3173
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
3174 3175
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
H
huangjie 已提交
3176 3177 3178
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |
H
huangjie 已提交
3179

H
huangjie 已提交
3180
**示例:** 
H
HelloCrease 已提交
3181
  ```ts
H
huangjie 已提交
3182 3183 3184
  try {
    this.context.resourceManager.getBoolean($r('app.boolean.boolean_test').id);
  } catch (error) {
Z
zt147369 已提交
3185
    console.error(`getBoolean failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
3186
  }
H
huangjie 已提交
3187
  ```
3188 3189 3190 3191 3192 3193 3194 3195
### getBoolean<sup>9+</sup>

getBoolean(resource: Resource): boolean

使用同步方式,返回获取指定resource对象对应的布尔结果。

**系统能力**:SystemCapability.Global.ResourceManager

Z
zt147369 已提交
3196 3197
**模型约束**:此接口仅可在Stage模型下使用。

3198
**参数:** 
H
huangjie 已提交
3199

H
HelloCrease 已提交
3200 3201
| 参数名      | 类型                     | 必填   | 说明   |
| -------- | ---------------------- | ---- | ---- |
3202
| resource | [Resource](#resource9) | 是    | 资源信息 |
3203

H
huangjie 已提交
3204 3205
**返回值:**

H
HelloCrease 已提交
3206 3207
| 类型      | 说明                |
| ------- | ----------------- |
3208 3209
| boolean | resource对象对应的布尔结果 |

H
huangjie 已提交
3210 3211
**错误码:**

3212 3213
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
3214 3215
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
H
huangjie 已提交
3216 3217 3218
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |
H
huangjie 已提交
3219

3220
**示例:** 
H
HelloCrease 已提交
3221
  ```ts
F
fangyunzhong 已提交
3222 3223 3224
  import resourceManager from '@ohos.resourceManager';

  let resource: resourceManager.Resource = {
3225 3226 3227
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.boolean.boolean_test').id
3228
  };
H
huangjie 已提交
3229 3230 3231
  try {
    this.context.resourceManager.getBoolean(resource);
  } catch (error) {
Z
zt147369 已提交
3232
    console.error(`getBoolean failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
3233
  }
3234
  ```
H
huangjie 已提交
3235 3236 3237 3238 3239 3240 3241 3242 3243 3244

### getBooleanByName<sup>9+</sup>

getBooleanByName(resName: string): boolean

使用同步方式,返回获取指定资源名称对应的布尔结果

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
3245

H
HelloCrease 已提交
3246 3247 3248
| 参数名     | 类型     | 必填   | 说明   |
| ------- | ------ | ---- | ---- |
| resName | string | 是    | 资源名称 |
H
huangjie 已提交
3249

H
huangjie 已提交
3250 3251
**返回值:**

H
HelloCrease 已提交
3252 3253
| 类型      | 说明          |
| ------- | ----------- |
H
huangjie 已提交
3254 3255
| boolean | 资源名称对应的布尔结果 |

H
huangjie 已提交
3256 3257
**错误码:**

3258 3259
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
3260 3261
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
H
huangjie 已提交
3262 3263 3264
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
| 9001006  | If the resource re-ref too much.            |
H
huangjie 已提交
3265

H
huangjie 已提交
3266
**示例:** 
H
HelloCrease 已提交
3267
  ```ts
H
huangjie 已提交
3268 3269 3270
  try {
    this.context.resourceManager.getBooleanByName("boolean_test");
  } catch (error) {
Z
zt147369 已提交
3271
    console.error(`getBooleanByName failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
3272
  }
H
huangjie 已提交
3273 3274
  ```

H
huangjie 已提交
3275
### getNumber<sup>9+</sup>
H
huangjie 已提交
3276 3277 3278 3279 3280 3281 3282 3283

getNumber(resId: number): number

用户获取指定资源ID对应的integer数值或者float数值,使用同步方式返回资源对应的数值。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
3284

H
huangjie 已提交
3285 3286 3287 3288
| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resId | number | 是    | 资源ID值 |

H
huangjie 已提交
3289 3290
**返回值:**

H
HelloCrease 已提交
3291
| 类型     | 说明         |
H
huangjie 已提交
3292
| ------ | ---------- | 
H
huangjie 已提交
3293
| number | 资源ID值对应的数值。Integer对应的是原数值,float对应的是真实像素点值,具体参考示例代码 |
H
huangjie 已提交
3294

H
huangjie 已提交
3295 3296
**错误码:**

3297 3298
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
3299 3300
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
H
huangjie 已提交
3301 3302 3303
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |
H
huangjie 已提交
3304

H
huangjie 已提交
3305
**示例:** 
H
HelloCrease 已提交
3306
  ```ts
H
huangjie 已提交
3307
  try {
H
huangjie 已提交
3308
    this.context.resourceManager.getNumber($r('app.integer.integer_test').id); // integer对应返回的是原数值
H
huangjie 已提交
3309
  } catch (error) {
Z
zt147369 已提交
3310
    console.error(`getNumber failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
3311 3312 3313
  }

  try {
H
huangjie 已提交
3314
    this.context.resourceManager.getNumber($r('app.float.float_test').id); // float对应返回的是真实像素点值
H
huangjie 已提交
3315
  } catch (error) {
Z
zt147369 已提交
3316
    console.error(`getNumber failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
3317
  }
H
huangjie 已提交
3318 3319
  ```

3320 3321 3322 3323 3324 3325 3326 3327
### getNumber<sup>9+</sup>

getNumber(resource: Resource): number

用户获取指定resource对象对应的integer数值或者float数值,使用同步方式返回资源对应的数值。

**系统能力**:SystemCapability.Global.ResourceManager

Z
zt147369 已提交
3328 3329
**模型约束**:此接口仅可在Stage模型下使用。

3330
**参数:** 
H
huangjie 已提交
3331

H
HelloCrease 已提交
3332 3333
| 参数名      | 类型                     | 必填   | 说明   |
| -------- | ---------------------- | ---- | ---- |
3334
| resource | [Resource](#resource9) | 是    | 资源信息 |
3335

H
huangjie 已提交
3336 3337
**返回值:**

H
HelloCrease 已提交
3338 3339
| 类型     | 说明              |
| ------ | --------------- |
H
huangjie 已提交
3340
| number | resource对象对应的数值。Integer对应的是原数值,float对应的是真实像素点值, 具体参考示例代码 |
3341

H
huangjie 已提交
3342 3343
**错误码:**

3344 3345
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
3346 3347
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
H
huangjie 已提交
3348 3349 3350
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |
H
huangjie 已提交
3351

3352
**示例:** 
H
HelloCrease 已提交
3353
  ```ts
F
fangyunzhong 已提交
3354 3355 3356
  import resourceManager from '@ohos.resourceManager';

  let resource: resourceManager.Resource = {
3357 3358 3359
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.integer.integer_test').id
3360
  };
H
huangjie 已提交
3361
  try {
H
huangjie 已提交
3362
    this.context.resourceManager.getNumber(resource);// integer对应返回的是原数值, float对应返回的是真实像素点值
H
huangjie 已提交
3363
  } catch (error) {
Z
zt147369 已提交
3364
    console.error(`getNumber failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
3365
  }
3366 3367
  ```

H
huangjie 已提交
3368 3369 3370 3371 3372 3373 3374 3375 3376
### getNumberByName<sup>9+</sup>

getNumberByName(resName: string): number

用户获取指定资源名称对应的integer数值或者float数值,使用同步方式资源对应的数值。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
3377

H
HelloCrease 已提交
3378 3379
| 参数名     | 类型     | 必填   | 说明   |
| ------- | ------ | ---- | ---- |
H
huangjie 已提交
3380 3381
| resName | string | 是    | 资源名称 |

H
huangjie 已提交
3382 3383
**返回值:**

H
HelloCrease 已提交
3384 3385
| 类型     | 说明        |
| ------ | --------- |
H
huangjie 已提交
3386 3387
| number | 资源名称对应的数值 |

H
huangjie 已提交
3388 3389
**错误码:**

3390 3391
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
3392 3393
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
H
huangjie 已提交
3394 3395 3396
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
| 9001006  | If the resource re-ref too much.            |
H
huangjie 已提交
3397 3398 3399 3400 3401 3402

**示例:** 
  ```ts
  try {
    this.context.resourceManager.getNumberByName("integer_test");
  } catch (error) {
Z
zt147369 已提交
3403
    console.error(`getNumberByName failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
3404 3405 3406 3407 3408
  }

  try {
    this.context.resourceManager.getNumberByName("float_test");
  } catch (error) {
Z
zt147369 已提交
3409
    console.error(`getNumberByName failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
3410 3411 3412
  }
  ```

3413
### getColorSync<sup>10+</sup>
H
huangjie 已提交
3414

3415
getColorSync(resId: number) : number;
H
huangjie 已提交
3416

3417
用户获取指定资源ID对应的颜色值,使用同步方式返回其对应的颜色值。
H
huangjie 已提交
3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428

**系统能力**:SystemCapability.Global.ResourceManager

**参数:**

| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resId | number | 是    | 资源ID值 |

**返回值:**

3429 3430 3431
| 类型     | 说明          |
| ------ | ----------- |
| number | 资源ID值对应的颜色值(十进制) |
H
huangjie 已提交
3432 3433 3434

**错误码:**

3435 3436
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
3437 3438 3439 3440
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
3441
| 9001006  | If the resource re-ref too much.            |
H
huangjie 已提交
3442 3443 3444 3445

**示例:**
  ```ts
  try {
3446
    this.context.resourceManager.getColorSync($r('app.color.test').id);
H
huangjie 已提交
3447
  } catch (error) {
3448
    console.error(`getColorSync failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
3449 3450 3451
  }
  ```

3452
### getColorSync<sup>10+</sup>
H
huangjie 已提交
3453

3454
getColorSync(resource: Resource): number
H
huangjie 已提交
3455

3456
用户获取指定resource对象对应的颜色值,使用同步方式返回其对应的颜色值。
H
huangjie 已提交
3457 3458 3459

**系统能力**:SystemCapability.Global.ResourceManager

Z
zt147369 已提交
3460 3461
**模型约束**:此接口仅可在Stage模型下使用。

H
huangjie 已提交
3462 3463 3464 3465 3466 3467 3468 3469
**参数:**

| 参数名      | 类型                     | 必填   | 说明   |
| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | 是    | 资源信息 |

**返回值:**

3470 3471 3472
| 类型     | 说明               |
| ------ | ---------------- |
| number | resource对象对应的颜色值(十进制) |
H
huangjie 已提交
3473 3474 3475

**错误码:**

3476 3477
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
3478 3479 3480 3481
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
3482
| 9001006  | If the resource re-ref too much.            |
H
huangjie 已提交
3483 3484 3485

**示例:**
  ```ts
F
fangyunzhong 已提交
3486 3487 3488
  import resourceManager from '@ohos.resourceManager';

  let resource: resourceManager.Resource = {
3489 3490 3491
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.color.test').id
H
huangjie 已提交
3492 3493
  };
  try {
3494
    this.context.resourceManager.getColorSync(resource);
H
huangjie 已提交
3495
  } catch (error) {
3496
    console.error(`getColorSync failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
3497 3498 3499
  }
  ```

3500
### getColorByNameSync<sup>10+</sup>
H
huangjie 已提交
3501

3502
getColorByNameSync(resName: string) : number;
H
huangjie 已提交
3503

3504
用户获取指定资源名称对应的颜色值,使用同步方式返回其对应的颜色值。
H
huangjie 已提交
3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515

**系统能力**:SystemCapability.Global.ResourceManager

**参数:**

| 参数名     | 类型     | 必填   | 说明   |
| ------- | ------ | ---- | ---- |
| resName | string | 是    | 资源名称 |

**返回值:**

3516 3517 3518
| 类型     | 说明         |
| ------ | ---------- |
| number | 资源名称对应的颜色值(十进制) |
H
huangjie 已提交
3519 3520 3521

**错误码:**

3522 3523
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

H
huangjie 已提交
3524 3525 3526 3527
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
3528
| 9001006  | If the resource re-ref too much.            |
H
huangjie 已提交
3529 3530 3531 3532

**示例:**
  ```ts
  try {
3533
    this.context.resourceManager.getColorByNameSync("test");
H
huangjie 已提交
3534
  } catch (error) {
3535
    console.error(`getColorByNameSync failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
3536 3537
  }
  ```
H
huangjie 已提交
3538

H
huangjie 已提交
3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565
### getColor<sup>10+</sup>

getColor(resId: number, callback: AsyncCallback&lt;number&gt;): void;

用户获取指定资源ID对应的颜色值,使用callback形式返回其对应的颜色值。

**系统能力:** SystemCapability.Global.ResourceManager

**参数:**

| 参数名      | 类型                          | 必填   | 说明              |
| -------- | --------------------------- | ---- | --------------- |
| resId    | number                      | 是    | 资源ID值           |
| callback | AsyncCallback&lt;number&gt; | 是    | 异步回调,用于返回获取的颜色值(十进制) |

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001001  | If the module resId invalid.             |
| 9001002  | If the resource not found by resId.      |
| 9001006  | If the resource re-ref too much.         |

**示例Stage:**
  ```ts
3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576
  try {
    this.context.resourceManager.getColor($r('app.color.test').id, (error, value) => {
      if (error != null) {
        console.log("error is " + error);
      } else {
        let str = value;
      }
    });
  } catch (error) {
    console.error(`callback getColor failed, error code: ${error.code}, message: ${error.message}.`);
  }
H
huangjie 已提交
3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610
  ```

### getColor<sup>10+</sup>

getColor(resId: number): Promise&lt;number&gt;

用户获取指定资源ID对应的颜色值,使用Promise形式返回对应其对应的颜色值。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:**

| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resId | number | 是    | 资源ID值 |

**返回值:**

| 类型                    | 说明          |
| --------------------- | ----------- |
| Promise&lt;number&gt; | 资源ID值对应的颜色值(十进制) |

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |

**示例:**
  ```ts
F
fangyunzhong 已提交
3611 3612
  import { BusinessError } from '@ohos.base';

H
huangjie 已提交
3613
  try {
F
fangyunzhong 已提交
3614
    this.context.resourceManager.getColor($r('app.color.test').id).then((value: number) => {
3615
      let str = value;
F
fangyunzhong 已提交
3616
    }).catch((error: BusinessError) => {
3617
      console.log("getColor promise error is " + error);
H
huangjie 已提交
3618 3619
    });
  } catch (error) {
Z
zt147369 已提交
3620
    console.error(`promise getColor failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631
  }
  ```

### getColor<sup>10+</sup>

getColor(resource: Resource, callback: AsyncCallback&lt;number&gt;): void;

用户获取指定resource对象对应的颜色值,使用callback形式返回其对应的颜色值。

**系统能力:** SystemCapability.Global.ResourceManager

Z
zt147369 已提交
3632 3633
**模型约束**:此接口仅可在Stage模型下使用。

H
huangjie 已提交
3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652
**参数:**

| 参数名      | 类型                          | 必填   | 说明              |
| -------- | --------------------------- | ---- | --------------- |
| resource | [Resource](#resource9)      | 是    | 资源信息            |
| callback | AsyncCallback&lt;number&gt; | 是    | 异步回调,用于返回获取的颜色值(十进制) |

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |

**示例:**
  ```ts
F
fangyunzhong 已提交
3653 3654 3655
  import resourceManager from '@ohos.resourceManager';

  let resource: resourceManager.Resource = {
3656 3657 3658
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.color.test').id
H
huangjie 已提交
3659 3660 3661
  };
  try {
    this.context.resourceManager.getColor(resource, (error, value) => {
3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706
      if (error != null) {
        console.log("error is " + error);
      } else {
        let str = value;
      }
    });
  } catch (error) {
    console.error(`callback getColor failed, error code: ${error.code}, message: ${error.message}.`);
  }
  ```

### getColor<sup>10+</sup>

getColor(resource: Resource): Promise&lt;number&gt;;

用户获取指定resource对象对应的颜色值,使用Promise形式返回其对应的颜色值。

**系统能力**:SystemCapability.Global.ResourceManager

**模型约束**:此接口仅可在Stage模型下使用。

**参数:**

| 参数名      | 类型                     | 必填   | 说明   |
| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | 是    | 资源信息 |

**返回值:**

| 类型                    | 说明               |
| --------------------- | ---------------- |
| Promise&lt;number&gt; | resource对象对应的颜色值(十进制) |

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |

**示例:**
  ```ts
F
fangyunzhong 已提交
3707 3708 3709 3710
  import resourceManager from '@ohos.resourceManager';
  import { BusinessError } from '@ohos.base';

  let resource: resourceManager.Resource = {
3711 3712 3713 3714 3715
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.color.test').id
  };
  try {
F
fangyunzhong 已提交
3716
    this.context.resourceManager.getColor(resource).then((value: number) => {
3717
      let str = value;
F
fangyunzhong 已提交
3718
    }).catch((error: BusinessError) => {
3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797
      console.log("getColor promise error is " + error);
    });
  } catch (error) {
    console.error(`promise getColor failed, error code: ${error.code}, message: ${error.message}.`);
  }
  ```

### getColorByName<sup>10+</sup>

getColorByName(resName: string, callback: AsyncCallback&lt;number&gt;): void

用户获取指定资源名称对应的颜色值,使用callback形式返回其对应的颜色值。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:**

| 参数名      | 类型                          | 必填   | 说明              |
| -------- | --------------------------- | ---- | --------------- |
| resName  | string                      | 是    | 资源名称            |
| callback | AsyncCallback&lt;number&gt; | 是    | 异步回调,用于返回获取的颜色值(十进制) |

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
| 9001006  | If the resource re-ref too much.            |

**示例:**
  ```ts
  try {
    this.context.resourceManager.getColorByName("test", (error, value) => {
      if (error != null) {
        console.log("error is " + error);
      } else {
        let string = value;
      }
    });
  } catch (error) {
    console.error(`callback getColorByName failed, error code: ${error.code}, message: ${error.message}.`);
  }
  ```

### getColorByName<sup>10+</sup>

getColorByName(resName: string): Promise&lt;number&gt;

用户获取指定资源名称对应的颜色值,使用Promise形式返回其对应的颜色值。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:**

| 参数名     | 类型     | 必填   | 说明   |
| ------- | ------ | ---- | ---- |
| resName | string | 是    | 资源名称 |

**返回值:**

| 类型                    | 说明         |
| --------------------- | ---------- |
| Promise&lt;number&gt; | 资源名称对应的颜色值(十进制) |

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
| 9001006  | If the resource re-ref too much.            |

**示例:**
  ```ts
F
fangyunzhong 已提交
3798 3799
  import { BusinessError } from '@ohos.base';

3800
  try {
F
fangyunzhong 已提交
3801
    this.context.resourceManager.getColorByName("test").then((value: number) => {
3802
      let string = value;
F
fangyunzhong 已提交
3803
    }).catch((error: BusinessError) => {
3804 3805 3806 3807 3808 3809 3810
      console.log("getColorByName promise error is " + error);
    });
  } catch (error) {
    console.error(`promise getColorByName failed, error code: ${error.code}, message: ${error.message}.`);
  }
  ```

3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847
### getRawFileContentSync<sup>10+</sup>

getRawFileContentSync(path: string): Uint8Array

用户获取resources/rawfile目录下对应的rawfile文件内容,使用同步形式返回字节数组。

**系统能力:** SystemCapability.Global.ResourceManager

**参数:**

| 参数名      | 类型                              | 必填   | 说明                      |
| -------- | ------------------------------- | ---- | ----------------------- |
| path     | string                          | 是    | rawfile文件路径             |

**返回值:**

| 类型                    | 说明         |
| --------------------- | ---------- |
| Uint8Array | 返回获取的rawfile文件内容 |

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001005  | If the resource not found by path.          |

**示例:**
  ```ts
  try {
    this.context.resourceManager.getRawFileContentSync("test.txt");
  } catch (error) {
    console.error(`getRawFileContentSync failed, error code: ${error.code}, message: ${error.message}.`);
  }
  ```

3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873
### getRawFileContent<sup>9+</sup>

getRawFileContent(path: string, callback: AsyncCallback&lt;Uint8Array&gt;): void

用户获取resources/rawfile目录下对应的rawfile文件内容,使用callback形式返回字节数组。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 

| 参数名      | 类型                              | 必填   | 说明                      |
| -------- | ------------------------------- | ---- | ----------------------- |
| path     | string                          | 是    | rawfile文件路径             |
| callback | AsyncCallback&lt;Uint8Array&gt; | 是    | 异步回调,用于返回获取的rawfile文件内容 |

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001005  | If the resource not found by path.          |

**示例:** 
  ```ts
  try {
F
fangyunzhong 已提交
3874
    this.context.resourceManager.getRawFileContent("test.txt", (error, value) => {
3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915
      if (error != null) {
        console.log("error is " + error);
      } else {
        let rawFile = value;
      }
    });
  } catch (error) {
    console.error(`callback getRawFileContent failed, error code: ${error.code}, message: ${error.message}.`);
  }
  ```

### getRawFileContent<sup>9+</sup>

getRawFileContent(path: string): Promise&lt;Uint8Array&gt;

用户获取resources/rawfile目录下对应的rawfile文件内容,使用Promise形式返回字节数组。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 

| 参数名  | 类型     | 必填   | 说明          |
| ---- | ------ | ---- | ----------- |
| path | string | 是    | rawfile文件路径 |

**返回值:**

| 类型                        | 说明          |
| ------------------------- | ----------- |
| Promise&lt;Uint8Array&gt; | rawfile文件内容 |

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001005  | If the resource not found by path.          |

**示例:** 
  ```ts
F
fangyunzhong 已提交
3916 3917
  import { BusinessError } from '@ohos.base';

3918
  try {
F
fangyunzhong 已提交
3919
    this.context.resourceManager.getRawFileContent("test.txt").then((value: Uint8Array) => {
3920
      let rawFile = value;
F
fangyunzhong 已提交
3921
    }).catch((error: BusinessError) => {
3922 3923 3924 3925 3926 3927 3928
      console.log("getRawFileContent promise error is " + error);
    });
  } catch (error) {
    console.error(`promise getRawFileContent failed, error code: ${error.code}, message: ${error.message}.`);
  }
  ```

3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965
### getRawFileListSync<sup>10+</sup>

getRawFileListSync(path: string): Array\<string\>

用户获取resources/rawfile目录下文件夹及文件列表,使用同步形式返回文件列表的字符串数组。

**系统能力:** SystemCapability.Global.ResourceManager

**参数:**

| 参数名      | 类型                              | 必填   | 说明                      |
| -------- | ------------------------------- | ---- | ----------------------- |
| path     | string                          | 是    | rawfile文件夹路径             |

**返回值:**

| 类型                        | 说明          |
| ------------------------- | ----------- |
| Array\<string\> | rawfile文件夹下的列表(包含子文件夹和文件) |

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001005  | If the resource not found by path.       |

**示例:**
  ```ts
  try { // 传入""表示获取rawfile根目录下的文件列表
    this.context.resourceManager.getRawFileListSync("")
  } catch (error) {
    console.error(`getRawFileListSync failed, error code: ${error.code}, message: ${error.message}.`);
  }
  ```

3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033
### getRawFileList<sup>10+</sup>

getRawFileList(path: string, callback: AsyncCallback&lt;Array\<string\>&gt;): void;

用户获取resources/rawfile目录下文件夹及文件列表,使用callback形式返回文件列表的字符串数组。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 

| 参数名      | 类型                              | 必填   | 说明                      |
| -------- | ------------------------------- | ---- | ----------------------- |
| path     | string                          | 是    | rawfile文件夹路径             |
| callback | AsyncCallback&lt;Array\<string\>&gt; | 是 | 异步回调,用于返回获取rawfile文件目录下的文件列表 |

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001005  | If the resource not found by path.       |

**示例:** 
  ```ts
  try { // 传入""表示获取rawfile根目录下的文件列表
    this.context.resourceManager.getRawFileList("", (error, value) => {
      if (error != null) {
        console.error(`callback getRawFileList failed, error code: ${error.code}, message: ${error.message}.`);
      } else {
        let rawFile = value;
      }
    });
  } catch (error) {
    console.error(`callback getRawFileList failed, error code: ${error.code}, message: ${error.message}.`);
  }
  ```

### getRawFileList<sup>10+</sup>

getRawFileList(path: string): Promise&lt;Array\<string\>&gt;

用户获取resources/rawfile目录下文件夹及文件列表,使用Promise形式返回文件列表字符串数组。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 

| 参数名  | 类型     | 必填   | 说明          |
| ---- | ------ | ---- | ----------- |
| path | string | 是    | rawfile文件夹路径 |

**返回值:**

| 类型                        | 说明          |
| ------------------------- | ----------- |
| Promise&lt;Array\<string\>&gt; | rawfile文件目录下的文件列表 |

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001005  | If the resource not found by path.          |

**示例:** 
  ```ts
F
fangyunzhong 已提交
4034 4035
  import { BusinessError } from '@ohos.base';

4036
  try { // 传入""表示获取rawfile根目录下的文件列表
F
fangyunzhong 已提交
4037
    this.context.resourceManager.getRawFileList("").then((value: Array<string>) => {
4038
      let rawFile = value;
F
fangyunzhong 已提交
4039
    }).catch((error: BusinessError) => {
4040 4041 4042 4043 4044 4045 4046
      console.error(`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`);
    });
  } catch (error) {
    console.error(`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`);
  }
  ```

4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083
### getRawFdSync<sup>10+</sup>

getRawFdSync(path: string): RawFileDescriptor

用户获取resources/rawfile目录下对应rawfile文件的descriptor。

**系统能力:** SystemCapability.Global.ResourceManager

**参数:**

| 参数名      | 类型                                       | 必填   | 说明                               |
| -------- | ---------------------------------------- | ---- | -------------------------------- |
| path     | string                                   | 是    | rawfile文件路径                      |

**返回值:**

| 类型                        | 说明          |
| ------------------------- | ----------- |
| [RawFileDescriptor](#rawfiledescriptor8) | rawfile文件的descriptor |

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001005  | If the resource not found by path.          |

**示例:**
  ```ts
  try {
    this.context.resourceManager.getRawFdSync("test.txt");
  } catch (error) {
    console.error(`getRawFdSync failed, error code: ${error.code}, message: ${error.message}.`);
  }
  ```

4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109
### getRawFd<sup>9+</sup>

getRawFd(path: string, callback: AsyncCallback&lt;RawFileDescriptor&gt;): void

用户获取resources/rawfile目录下对应rawfile文件的descriptor,使用callback形式返回。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 

| 参数名      | 类型                                       | 必填   | 说明                               |
| -------- | ---------------------------------------- | ---- | -------------------------------- |
| path     | string                                   | 是    | rawfile文件路径                      |
| callback | AsyncCallback&lt;[RawFileDescriptor](#rawfiledescriptor8)&gt; | 是    | 异步回调,用于返回获取的rawfile文件的descriptor |

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001005  | If the resource not found by path.          |

**示例:** 
  ```ts
  try {
F
fangyunzhong 已提交
4110
    this.context.resourceManager.getRawFd("test.txt", (error, value) => {
4111 4112 4113 4114 4115 4116 4117
      if (error != null) {
        console.log(`callback getRawFd failed error code: ${error.code}, message: ${error.message}.`);
      } else {
        let fd = value.fd;
        let offset = value.offset;
        let length = value.length;
      }
H
huangjie 已提交
4118 4119
    });
  } catch (error) {
4120
    console.error(`callback getRawFd failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
4121 4122 4123
  }
  ```

4124
### getRawFd<sup>9+</sup>
H
huangjie 已提交
4125

4126
getRawFd(path: string): Promise&lt;RawFileDescriptor&gt;
H
huangjie 已提交
4127

4128
用户获取resources/rawfile目录下对应rawfile文件的descriptor,使用Promise形式返回。
H
huangjie 已提交
4129 4130 4131

**系统能力**:SystemCapability.Global.ResourceManager

4132
**参数:** 
H
huangjie 已提交
4133

4134 4135 4136
| 参数名  | 类型     | 必填   | 说明          |
| ---- | ------ | ---- | ----------- |
| path | string | 是    | rawfile文件路径 |
H
huangjie 已提交
4137 4138 4139

**返回值:**

4140 4141 4142
| 类型                                       | 说明                  |
| ---------------------------------------- | ------------------- |
| Promise&lt;[RawFileDescriptor](#rawfiledescriptor8)&gt; | rawfile文件descriptor |
H
huangjie 已提交
4143 4144 4145 4146 4147 4148 4149

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
4150
| 9001005  | If the resource not found by path.          |
H
huangjie 已提交
4151

4152
**示例:** 
H
huangjie 已提交
4153
  ```ts
F
fangyunzhong 已提交
4154 4155
  import { BusinessError } from '@ohos.base';

H
huangjie 已提交
4156
  try {
F
fangyunzhong 已提交
4157
    this.context.resourceManager.getRawFd("test.txt").then((value: resourceManager.RawFileDescriptor) => {
4158 4159 4160
      let fd = value.fd;
      let offset = value.offset;
      let length = value.length;
F
fangyunzhong 已提交
4161
    }).catch((error: BusinessError) => {
4162
      console.log(`promise getRawFd error error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
4163 4164
    });
  } catch (error) {
4165
    console.error(`promise getRawFd failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
4166 4167 4168
  }
  ```

4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199
### closeRawFdSync<sup>10+</sup>

closeRawFdSync(path: string): void

用户关闭resources/rawfile目录下rawfile文件的descriptor。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:**

| 参数名      | 类型                        | 必填   | 说明          |
| -------- | ------------------------- | ---- | ----------- |
| path     | string                    | 是    | rawfile文件路径 |

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001005  | The resource not found by path.          |

**示例:**
  ```ts
  try {
    this.context.resourceManager.closeRawFdSync("test.txt");
  } catch (error) {
    console.error(`closeRawFd failed, error code: ${error.code}, message: ${error.message}.`);
  }
  ```

4200
### closeRawFd<sup>9+</sup>
H
huangjie 已提交
4201

4202
closeRawFd(path: string, callback: AsyncCallback&lt;void&gt;): void
H
huangjie 已提交
4203

4204
用户关闭resources/rawfile目录下rawfile文件的descriptor,使用callback形式返回。
H
huangjie 已提交
4205 4206 4207

**系统能力**:SystemCapability.Global.ResourceManager

4208
**参数:** 
H
huangjie 已提交
4209

4210 4211 4212 4213
| 参数名      | 类型                        | 必填   | 说明          |
| -------- | ------------------------- | ---- | ----------- |
| path     | string                    | 是    | rawfile文件路径 |
| callback | AsyncCallback&lt;void&gt; | 是    | 异步回调        |
H
huangjie 已提交
4214 4215 4216 4217 4218 4219 4220

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
4221
| 9001005  | The resource not found by path.          |
H
huangjie 已提交
4222

4223
**示例:** 
H
huangjie 已提交
4224 4225
  ```ts
  try {
F
fangyunzhong 已提交
4226
    this.context.resourceManager.closeRawFd("test.txt", (error, value) => {
4227 4228 4229
      if (error != null) {
        console.log("error is " + error);
      }
H
huangjie 已提交
4230 4231
    });
  } catch (error) {
4232
    console.error(`callback closeRawFd failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
4233 4234 4235
  }
  ```

4236
### closeRawFd<sup>9+</sup>
H
huangjie 已提交
4237

4238
closeRawFd(path: string): Promise&lt;void&gt;
H
huangjie 已提交
4239

4240
用户关闭resources/rawfile目录下rawfile文件的descriptor,使用Promise形式返回。
H
huangjie 已提交
4241 4242 4243

**系统能力**:SystemCapability.Global.ResourceManager

4244
**参数:** 
H
huangjie 已提交
4245

4246 4247 4248
| 参数名  | 类型     | 必填   | 说明          |
| ---- | ------ | ---- | ----------- |
| path | string | 是    | rawfile文件路径 |
H
huangjie 已提交
4249 4250 4251

**返回值:**

4252 4253 4254
| 类型                  | 说明   |
| ------------------- | ---- |
| Promise&lt;void&gt; | 无返回值 |
H
huangjie 已提交
4255 4256 4257 4258 4259 4260 4261

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
4262
| 9001005  | If the resource not found by path.          |
H
huangjie 已提交
4263

4264
**示例:** 
H
huangjie 已提交
4265 4266
  ```ts
  try {
F
fangyunzhong 已提交
4267
    this.context.resourceManager.closeRawFd("test.txt");
H
huangjie 已提交
4268
  } catch (error) {
4269
    console.error(`promise closeRawFd failed, error code: ${error.code}, message: ${error.message}.`);
H
huangjie 已提交
4270 4271 4272
  }
  ```

F
fangyunzhong 已提交
4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297
### getConfigurationSync

getConfigurationSync(): Configuration

用户获取设备的Configuration,使用同步形式返回Configuration对象。

**系统能力**:SystemCapability.Global.ResourceManager

**返回值:**

| 类型                                       | 说明               |
| ---------------------------------------- | ---------------- |
| Promise&lt;[Configuration](#configuration)&gt; | 设备的Configuration |

**示例:** 
  ```ts
  try {
    let value = this.context.resourceManager.getConfigurationSync();
    let direction = value.direction;
    let locale = value.locale;
  } catch (error) {
    console.error("getConfigurationSync error is " + error);
  }
  ```

4298
### getConfiguration
H
huangjie 已提交
4299

4300
getConfiguration(callback: AsyncCallback&lt;Configuration&gt;): void
H
huangjie 已提交
4301

4302
用户获取设备的Configuration,使用callback形式返回Configuration对象。
H
huangjie 已提交
4303 4304 4305

**系统能力**:SystemCapability.Global.ResourceManager

4306
**参数:** 
H
huangjie 已提交
4307

4308 4309 4310
| 参数名      | 类型                                       | 必填   | 说明                        |
| -------- | ---------------------------------------- | ---- | ------------------------- |
| callback | AsyncCallback&lt;[Configuration](#configuration)&gt; | 是    | 异步回调,用于返回设备的Configuration |
H
huangjie 已提交
4311

4312
**示例:** 
H
huangjie 已提交
4313 4314
  ```ts
  try {
4315 4316 4317 4318 4319 4320 4321 4322
    this.context.resourceManager.getConfiguration((error, value) => {
      if (error != null) {
        console.error("getConfiguration callback error is " + error);
      } else {
        let direction = value.direction;
        let locale = value.locale;
      }
    });
H
huangjie 已提交
4323
  } catch (error) {
4324
    console.error("getConfiguration callback error is " + error);
H
huangjie 已提交
4325 4326 4327
  }
  ```

4328
### getConfiguration
H
huangjie 已提交
4329

4330
getConfiguration(): Promise&lt;Configuration&gt;
H
huangjie 已提交
4331

4332
用户获取设备的Configuration,使用Promise形式返回Configuration对象。
H
huangjie 已提交
4333 4334 4335

**系统能力**:SystemCapability.Global.ResourceManager

4336
**返回值:**
Z
zt147369 已提交
4337

4338 4339 4340
| 类型                                       | 说明               |
| ---------------------------------------- | ---------------- |
| Promise&lt;[Configuration](#configuration)&gt; | 设备的Configuration |
H
huangjie 已提交
4341

4342 4343
**示例:** 
  ```ts
F
fangyunzhong 已提交
4344 4345
  import { BusinessError } from '@ohos.base';

4346
  try {
F
fangyunzhong 已提交
4347
    this.context.resourceManager.getConfiguration().then((value: resourceManager.Configuration) => {
4348 4349
      let direction = value.direction;
      let locale = value.locale;
F
fangyunzhong 已提交
4350
    }).catch((error: BusinessError) => {
4351 4352 4353 4354 4355 4356
      console.error("getConfiguration promise error is " + error);
    });
  } catch (error) {
    console.error("getConfiguration promise error is " + error);
  }
  ```
H
huangjie 已提交
4357

F
fangyunzhong 已提交
4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382
### getDeviceCapabilitySync

getDeviceCapabilitySync(): DeviceCapability

用户获取设备的DeviceCapability,使用同步形式返回DeviceCapability对象。

**系统能力**:SystemCapability.Global.ResourceManager

**返回值:**

| 类型                                       | 说明                  |
| ---------------------------------------- | ------------------- |
| DeviceCapability | 设备的DeviceCapability |

**示例:** 
  ```ts
  try {
    let value = this.context.resourceManager.getDeviceCapabilitySync();
    let screenDensity = value.screenDensity;
    let deviceType = value.deviceType;
  } catch (error) {
    console.error("getDeviceCapabilitySync error is " + error);
  }
  ```

4383
### getDeviceCapability
H
huangjie 已提交
4384

4385
getDeviceCapability(callback: AsyncCallback&lt;DeviceCapability&gt;): void
H
huangjie 已提交
4386

4387
用户获取设备的DeviceCapability,使用callback形式返回DeviceCapability对象。
H
huangjie 已提交
4388

4389
**系统能力**:SystemCapability.Global.ResourceManager
H
huangjie 已提交
4390

4391
**参数:** 
H
huangjie 已提交
4392

4393 4394 4395 4396 4397
| 参数名      | 类型                                       | 必填   | 说明                           |
| -------- | ---------------------------------------- | ---- | ---------------------------- |
| callback | AsyncCallback&lt;[DeviceCapability](#devicecapability)&gt; | 是    | 异步回调,用于返回设备的DeviceCapability |

**示例:** 
H
huangjie 已提交
4398 4399
  ```ts
  try {
4400 4401 4402 4403 4404 4405 4406 4407
    this.context.resourceManager.getDeviceCapability((error, value) => {
      if (error != null) {
        console.error("getDeviceCapability callback error is " + error);
      } else {
        let screenDensity = value.screenDensity;
        let deviceType = value.deviceType;
      }
    });
H
huangjie 已提交
4408
  } catch (error) {
4409
    console.error("getDeviceCapability callback error is " + error);
H
huangjie 已提交
4410 4411 4412
  }
  ```

4413
### getDeviceCapability
H
huangjie 已提交
4414

4415
getDeviceCapability(): Promise&lt;DeviceCapability&gt;
H
huangjie 已提交
4416

4417
用户获取设备的DeviceCapability,使用Promise形式返回DeviceCapability对象。
H
huangjie 已提交
4418 4419 4420

**系统能力**:SystemCapability.Global.ResourceManager

4421
**返回值:**
H
huangjie 已提交
4422

4423 4424 4425
| 类型                                       | 说明                  |
| ---------------------------------------- | ------------------- |
| Promise&lt;[DeviceCapability](#devicecapability)&gt; | 设备的DeviceCapability |
H
huangjie 已提交
4426

4427 4428
**示例:** 
  ```ts
F
fangyunzhong 已提交
4429 4430
  import { BusinessError } from '@ohos.base';

4431
  try {
F
fangyunzhong 已提交
4432
    this.context.resourceManager.getDeviceCapability().then((value: resourceManager.DeviceCapability) => {
4433 4434
      let screenDensity = value.screenDensity;
      let deviceType = value.deviceType;
F
fangyunzhong 已提交
4435
    }).catch((error: BusinessError) => {
4436 4437 4438 4439 4440 4441
      console.error("getDeviceCapability promise error is " + error);
    });
  } catch (error) {
    console.error("getDeviceCapability promise error is " + error);
  }
  ```
H
huangjie 已提交
4442

4443
### release<sup>7+</sup>
H
huangjie 已提交
4444

4445
release()
H
huangjie 已提交
4446

4447
用户释放创建的resourceManager。
H
huangjie 已提交
4448

4449
**系统能力**:SystemCapability.Global.ResourceManager
H
huangjie 已提交
4450

4451
**示例:** 
H
huangjie 已提交
4452 4453
  ```ts
  try {
4454
    this.context.resourceManager.release();
H
huangjie 已提交
4455
  } catch (error) {
4456
    console.error("release error is " + error);
H
huangjie 已提交
4457 4458 4459
  }
  ```

4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485
### addResource<sup>10+</sup>

addResource(path: string) : void;

应用运行时,加载指定的资源路径,实现资源覆盖。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:**

| 参数名      | 类型                     | 必填   | 说明   |
| -------- | ---------------------- | ---- | ---- |
| path | string | 是    | 资源路径 |

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001010  | If the overlay path is invalid.            |

**示例:**
  ```ts
  let path = getContext().bundleCodeDir + "/library1-default-signed.hsp";
  try {
4486
    this.context.resourceManager.addResource(path);
4487
  } catch (error) {
4488
    console.error(`addResource failed, error code: ${error.code}, message: ${error.message}.`);
Z
zt147369 已提交
4489
  }
4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517
  ```

### removeResource<sup>10+</sup>

removeResource(path: string) : void;

用户运行时,移除指定的资源路径,还原被覆盖前的资源。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:**

| 参数名      | 类型            | 必填   | 说明   |
| -------- | ---------------------- | ---- | ---- |
| path | string | 是    | 资源路径 |

**错误码:**

以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。

| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001010  | If the overlay path is invalid.            |

**示例:**
  ```ts
  let path = getContext().bundleCodeDir + "/library1-default-signed.hsp";
  try {
F
fangyunzhong 已提交
4518
    this.context.resourceManager.removeResource(path);
4519
  } catch (error) {
4520
    console.error(`removeResource failed, error code: ${error.code}, message: ${error.message}.`);
4521 4522 4523
  }
  ```

H
huangjie 已提交
4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534
### getString<sup>(deprecated)</sup>

getString(resId: number, callback: AsyncCallback&lt;string&gt;): void

用户获取指定资源ID对应的字符串,使用callback形式返回字符串。

从API version 9开始不再维护,建议使用[getStringValue](#getstringvalue9)代替。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
4535

H
huangjie 已提交
4536 4537 4538 4539 4540
| 参数名      | 类型                          | 必填   | 说明              |
| -------- | --------------------------- | ---- | --------------- |
| resId    | number                      | 是    | 资源ID值           |
| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,用于返回获取的字符串 |

4541
**示例:**
H
huangjie 已提交
4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565
  ```ts
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getString($r('app.string.test').id, (error, value) => {
          if (error != null) {
              console.log("error is " + error);
          } else {
              let str = value;
          }
      });
  });
  ```


### getString<sup>(deprecated)</sup>

getString(resId: number): Promise&lt;string&gt;

用户获取指定资源ID对应的字符串,使用Promise形式返回字符串。

从API version 9开始不再维护,建议使用[getStringValue](#getstringvalue9-1)代替。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
4566

H
huangjie 已提交
4567 4568 4569 4570
| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resId | number | 是    | 资源ID值 |

H
huangjie 已提交
4571 4572
**返回值:**

H
huangjie 已提交
4573 4574 4575 4576 4577 4578
| 类型                    | 说明          |
| --------------------- | ----------- |
| Promise&lt;string&gt; | 资源ID值对应的字符串 |

**示例:** 
  ```ts
F
fangyunzhong 已提交
4579 4580
  import { BusinessError } from '@ohos.base';

H
huangjie 已提交
4581
  resourceManager.getResourceManager((error, mgr) => {
F
fangyunzhong 已提交
4582
      mgr.getString($r('app.string.test').id).then((value: string) => {
H
huangjie 已提交
4583
          let str = value;
F
fangyunzhong 已提交
4584
      }).catch((error: BusinessError) => {
H
huangjie 已提交
4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601
          console.log("getstring promise error is " + error);
      });
  });
  ```


### getStringArray<sup>(deprecated)</sup>

getStringArray(resId: number, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void

用户获取指定资源ID对应的字符串数组,使用callback形式返回字符串数组。

从API version 9开始不再维护,建议使用[getStringArrayValue](#getstringarrayvalue9)代替。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
4602

H
huangjie 已提交
4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632
| 参数名      | 类型                                       | 必填   | 说明                |
| -------- | ---------------------------------------- | ---- | ----------------- |
| resId    | number                                   | 是    | 资源ID值             |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | 是    | 异步回调,用于返回获取的字符串数组 |

**示例:** 
  ```ts
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getStringArray($r('app.strarray.test').id, (error, value) => {
          if (error != null) {
              console.log("error is " + error);
          } else {
              let strArray = value;
          }
      });
  });
  ```


### getStringArray<sup>(deprecated)</sup>

getStringArray(resId: number): Promise&lt;Array&lt;string&gt;&gt;

用户获取指定资源ID对应的字符串数组,使用Promise形式返回字符串数组。

从API version 9开始不再维护,建议使用[getStringArrayValue](#getstringarrayvalue9-1)代替。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
4633

H
huangjie 已提交
4634 4635 4636 4637
| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resId | number | 是    | 资源ID值 |

H
huangjie 已提交
4638 4639
**返回值:**

H
huangjie 已提交
4640 4641 4642 4643
| 类型                                 | 说明            |
| ---------------------------------- | ------------- |
| Promise&lt;Array&lt;string&gt;&gt; | 资源ID值对应的字符串数组 |

H
huangjie 已提交
4644
**示例:** 
H
HelloCrease 已提交
4645
  ```ts
F
fangyunzhong 已提交
4646 4647
  import { BusinessError } from '@ohos.base';

H
huangjie 已提交
4648
  resourceManager.getResourceManager((error, mgr) => {
F
fangyunzhong 已提交
4649
       mgr.getStringArray($r('app.strarray.test').id).then((value: Array<string>) => {
H
huangjie 已提交
4650
          let strArray = value;
F
fangyunzhong 已提交
4651
      }).catch((error: BusinessError) => {
H
huangjie 已提交
4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663
          console.log("getStringArray promise error is " + error);
      });
  });
  ```


### getMedia<sup>(deprecated)</sup>

getMedia(resId: number, callback: AsyncCallback&lt;Uint8Array&gt;): void

用户获取指定资源ID对应的媒体文件内容,使用callback形式返回字节数组。

H
huangjie 已提交
4664
从API version 9开始不再维护,建议使用[getMediaContent](#getmediacontent9)代替。
H
huangjie 已提交
4665 4666 4667 4668

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
4669

H
huangjie 已提交
4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694
| 参数名      | 类型                              | 必填   | 说明                 |
| -------- | ------------------------------- | ---- | ------------------ |
| resId    | number                          | 是    | 资源ID值              |
| callback | AsyncCallback&lt;Uint8Array&gt; | 是    | 异步回调,用于返回获取的媒体文件内容 |

**示例:** 
  ```ts
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getMedia($r('app.media.test').id, (error, value) => {
          if (error != null) {
              console.log("error is " + error);
          } else {
              let media = value;
          }
      });
  });
  ```


### getMedia<sup>(deprecated)</sup>

getMedia(resId: number): Promise&lt;Uint8Array&gt;

用户获取指定资源ID对应的媒体文件内容,使用Promise形式返回字节数组。

H
huangjie 已提交
4695
从API version 9开始不再维护,建议使用[getMediaContent](#getmediacontent9-1)代替。
H
huangjie 已提交
4696 4697 4698 4699

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
4700

H
huangjie 已提交
4701 4702 4703 4704
| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resId | number | 是    | 资源ID值 |

H
huangjie 已提交
4705 4706
**返回值:**

H
huangjie 已提交
4707 4708 4709 4710 4711 4712
| 类型                        | 说明             |
| ------------------------- | -------------- |
| Promise&lt;Uint8Array&gt; | 资源ID值对应的媒体文件内容 |

**示例:** 
  ```ts
F
fangyunzhong 已提交
4713 4714
  import { BusinessError } from '@ohos.base';

H
huangjie 已提交
4715
  resourceManager.getResourceManager((error, mgr) => {
F
fangyunzhong 已提交
4716
      mgr.getMedia($r('app.media.test').id).then((value: Uint8Array) => {
H
huangjie 已提交
4717
          let media = value;
F
fangyunzhong 已提交
4718
      }).catch((error: BusinessError) => {
H
huangjie 已提交
4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730
          console.log("getMedia promise error is " + error);
      });
  });
  ```


### getMediaBase64<sup>(deprecated)</sup>

getMediaBase64(resId: number, callback: AsyncCallback&lt;string&gt;): void

用户获取指定资源ID对应的图片资源Base64编码,使用callback形式返回字符串。

H
huangjie 已提交
4731
从API version 9开始不再维护,建议使用[getMediaContentBase64](#getmediacontentbase649)代替。
H
huangjie 已提交
4732 4733 4734 4735

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
4736

H
huangjie 已提交
4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761
| 参数名      | 类型                          | 必填   | 说明                       |
| -------- | --------------------------- | ---- | ------------------------ |
| resId    | number                      | 是    | 资源ID值                    |
| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,用于返回获取的图片资源Base64编码 |

**示例:** 
  ```ts
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getMediaBase64($r('app.media.test').id, (error, value) => {
          if (error != null) {
              console.log("error is " + error);
          } else {
              let media = value;
          }
      });
  });
  ```


### getMediaBase64<sup>(deprecated)</sup>

getMediaBase64(resId: number): Promise&lt;string&gt;

用户获取指定资源ID对应的图片资源Base64编码,使用Promise形式返回字符串。

H
huangjie 已提交
4762
从API version 9开始不再维护,建议使用[getMediaContentBase64](#getmediacontentbase649-1)代替。
H
huangjie 已提交
4763 4764 4765 4766

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
4767

H
huangjie 已提交
4768 4769 4770 4771
| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resId | number | 是    | 资源ID值 |

H
huangjie 已提交
4772 4773
**返回值:**

H
huangjie 已提交
4774 4775 4776 4777 4778 4779
| 类型                    | 说明                   |
| --------------------- | -------------------- |
| Promise&lt;string&gt; | 资源ID值对应的图片资源Base64编码 |

**示例:** 
  ```ts
F
fangyunzhong 已提交
4780 4781
  import { BusinessError } from '@ohos.base';

H
huangjie 已提交
4782
  resourceManager.getResourceManager((error, mgr) => {
F
fangyunzhong 已提交
4783
      mgr.getMediaBase64($r('app.media.test').id).then((value: string) => {
H
huangjie 已提交
4784
          let media = value;
F
fangyunzhong 已提交
4785
      }).catch((error: BusinessError) => {
H
huangjie 已提交
4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797
          console.log("getMediaBase64 promise error is " + error);
      });
  });
  ```


### getPluralString<sup>(deprecated)</sup>

getPluralString(resId: number, num: number): Promise&lt;string&gt;

根据指定数量获取对指定ID字符串表示的单复数字符串,使用Promise形式返回字符串。

H
huangjie 已提交
4798
从API version 9开始不再维护,建议使用[getPluralStringValue](#getpluralstringvalue9)代替。
H
huangjie 已提交
4799 4800 4801 4802

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
4803

H
huangjie 已提交
4804 4805 4806 4807 4808
| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| resId | number | 是    | 资源ID值 |
| num   | number | 是    | 数量值   |

H
huangjie 已提交
4809 4810
**返回值:**

H
huangjie 已提交
4811 4812 4813 4814 4815 4816
| 类型                    | 说明                        |
| --------------------- | ------------------------- |
| Promise&lt;string&gt; | 根据提供的数量获取对应ID字符串表示的单复数字符串 |

**示例:** 
  ```ts
F
fangyunzhong 已提交
4817 4818
  import { BusinessError } from '@ohos.base';

H
huangjie 已提交
4819
  resourceManager.getResourceManager((error, mgr) => {
F
fangyunzhong 已提交
4820
      mgr.getPluralString($r("app.plural.test").id, 1).then((value: string) => {
H
huangjie 已提交
4821
          let str = value;
F
fangyunzhong 已提交
4822
      }).catch((error: BusinessError) => {
H
huangjie 已提交
4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834
          console.log("getPluralString promise error is " + error);
      });
  });
  ```


### getPluralString<sup>(deprecated)</sup>

getPluralString(resId: number, num: number, callback: AsyncCallback&lt;string&gt;): void

根据指定数量获取指定ID字符串表示的单复数字符串,使用callback形式返回字符串。

H
huangjie 已提交
4835
从API version 9开始不再维护,建议使用[getPluralStringValue](#getpluralstringvalue9-1)代替。
H
huangjie 已提交
4836 4837 4838 4839

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
4840

H
huangjie 已提交
4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871
| 参数名      | 类型                          | 必填   | 说明                              |
| -------- | --------------------------- | ---- | ------------------------------- |
| resId    | number                      | 是    | 资源ID值                           |
| num      | number                      | 是    | 数量值                             |
| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,返回根据指定数量获取指定ID字符串表示的单复数字符串 |

**示例:** 
  ```ts
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getPluralString($r("app.plural.test").id, 1, (error, value) => {
          if (error != null) {
              console.log("error is " + error);
          } else {
              let str = value;
          }
      });
  });
  ```


### getRawFile<sup>(deprecated)</sup>

getRawFile(path: string, callback: AsyncCallback&lt;Uint8Array&gt;): void

用户获取resources/rawfile目录下对应的rawfile文件内容,使用callback形式返回字节数组。

从API version 9开始不再维护,建议使用[getRawFileContent](#getrawfilecontent9)代替。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
4872

H
huangjie 已提交
4873 4874 4875 4876 4877 4878 4879 4880
| 参数名      | 类型                              | 必填   | 说明                      |
| -------- | ------------------------------- | ---- | ----------------------- |
| path     | string                          | 是    | rawfile文件路径             |
| callback | AsyncCallback&lt;Uint8Array&gt; | 是    | 异步回调,用于返回获取的rawfile文件内容 |

**示例:** 
  ```ts
  resourceManager.getResourceManager((error, mgr) => {
F
fangyunzhong 已提交
4881
      mgr.getRawFile("test.txt", (error, value) => {
H
huangjie 已提交
4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902
          if (error != null) {
              console.log("error is " + error);
          } else {
              let rawFile = value;
          }
      });
  });
  ```


### getRawFile<sup>(deprecated)</sup>

getRawFile(path: string): Promise&lt;Uint8Array&gt;

用户获取resources/rawfile目录下对应的rawfile文件内容,使用Promise形式返回字节数组。

从API version 9开始不再维护,建议使用[getRawFileContent](#getrawfilecontent9-1)代替。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
4903

H
huangjie 已提交
4904 4905 4906 4907
| 参数名  | 类型     | 必填   | 说明          |
| ---- | ------ | ---- | ----------- |
| path | string | 是    | rawfile文件路径 |

H
huangjie 已提交
4908 4909
**返回值:**

H
huangjie 已提交
4910 4911 4912 4913 4914 4915
| 类型                        | 说明          |
| ------------------------- | ----------- |
| Promise&lt;Uint8Array&gt; | rawfile文件内容 |

**示例:** 
  ```ts
F
fangyunzhong 已提交
4916 4917
  import { BusinessError } from '@ohos.base';

H
huangjie 已提交
4918
  resourceManager.getResourceManager((error, mgr) => {
F
fangyunzhong 已提交
4919
      mgr.getRawFile("test.txt").then((value: Uint8Array) => {
H
huangjie 已提交
4920
          let rawFile = value;
F
fangyunzhong 已提交
4921
      }).catch((error: BusinessError) => {
H
huangjie 已提交
4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938
          console.log("getRawFile promise error is " + error);
      });
  });
  ```


### getRawFileDescriptor<sup>(deprecated)</sup>

getRawFileDescriptor(path: string, callback: AsyncCallback&lt;RawFileDescriptor&gt;): void

用户获取resources/rawfile目录下对应rawfile文件的descriptor,使用callback形式返回。

从API version 9开始不再维护,建议使用[getRawFd](#getrawfd9)代替。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
4939

H
huangjie 已提交
4940 4941 4942 4943 4944 4945 4946 4947
| 参数名      | 类型                                       | 必填   | 说明                               |
| -------- | ---------------------------------------- | ---- | -------------------------------- |
| path     | string                                   | 是    | rawfile文件路径                      |
| callback | AsyncCallback&lt;[RawFileDescriptor](#rawfiledescriptor8)&gt; | 是    | 异步回调,用于返回获取的rawfile文件的descriptor |

**示例:** 
  ```ts
  resourceManager.getResourceManager((error, mgr) => {
F
fangyunzhong 已提交
4948
      mgr.getRawFileDescriptor("test.txt", (error, value) => {
H
huangjie 已提交
4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970
          if (error != null) {
              console.log("error is " + error);
          } else {
              let fd = value.fd;
              let offset = value.offset;
              let length = value.length;
          }
      });
  });
  ```

### getRawFileDescriptor<sup>(deprecated)</sup>

getRawFileDescriptor(path: string): Promise&lt;RawFileDescriptor&gt;

用户获取resources/rawfile目录下对应rawfile文件的descriptor,使用Promise形式返回。

从API version 9开始不再维护,建议使用[getRawFd](#getrawfd9-1)代替。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 
H
huangjie 已提交
4971

H
huangjie 已提交
4972 4973 4974 4975
| 参数名  | 类型     | 必填   | 说明          |
| ---- | ------ | ---- | ----------- |
| path | string | 是    | rawfile文件路径 |

H
huangjie 已提交
4976 4977
**返回值:**

H
huangjie 已提交
4978 4979 4980 4981 4982 4983
| 类型                                       | 说明                  |
| ---------------------------------------- | ------------------- |
| Promise&lt;[RawFileDescriptor](#rawfiledescriptor8)&gt; | rawfile文件descriptor |

**示例:** 
  ```ts
F
fangyunzhong 已提交
4984 4985
  import { BusinessError } from '@ohos.base';

H
huangjie 已提交
4986
  resourceManager.getResourceManager((error, mgr) => {
F
fangyunzhong 已提交
4987
      mgr.getRawFileDescriptor("test.txt").then((value: resourceManager.RawFileDescriptor) => {
H
huangjie 已提交
4988 4989 4990
          let fd = value.fd;
          let offset = value.offset;
          let length = value.length;
F
fangyunzhong 已提交
4991
      }).catch((error: BusinessError) => {
H
huangjie 已提交
4992 4993 4994
          console.log("getRawFileDescriptor promise error is " + error);
      });
  });
Z
zt147369 已提交
4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016
  ```

### closeRawFileDescriptor<sup>(deprecated)</sup>

closeRawFileDescriptor(path: string, callback: AsyncCallback&lt;void&gt;): void

用户关闭resources/rawfile目录下rawfile文件的descriptor,使用callback形式返回。

从API version 9开始不再维护,建议使用[closeRawFd](#closerawfd9)代替。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 

| 参数名      | 类型                        | 必填   | 说明          |
| -------- | ------------------------- | ---- | ----------- |
| path     | string                    | 是    | rawfile文件路径 |
| callback | AsyncCallback&lt;void&gt; | 是    | 异步回调        |

**示例:** 
  ```ts
  resourceManager.getResourceManager((error, mgr) => {
F
fangyunzhong 已提交
5017
      mgr.closeRawFileDescriptor("test.txt", (error, value) => {
Z
zt147369 已提交
5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049
          if (error != null) {
              console.log("error is " + error);
          }
      });
  });
  ```

### closeRawFileDescriptor<sup>(deprecated)</sup>

closeRawFileDescriptor(path: string): Promise&lt;void&gt;

用户关闭resources/rawfile目录下rawfile文件的descriptor,使用Promise形式返回。

从API version 9开始不再维护,建议使用[closeRawFd](#closerawfd9-1)代替。

**系统能力**:SystemCapability.Global.ResourceManager

**参数:** 

| 参数名  | 类型     | 必填   | 说明          |
| ---- | ------ | ---- | ----------- |
| path | string | 是    | rawfile文件路径 |

**返回值:**

| 类型                  | 说明   |
| ------------------- | ---- |
| Promise&lt;void&gt; | 无返回值 |

**示例:** 
  ```ts
  resourceManager.getResourceManager((error, mgr) => {
F
fangyunzhong 已提交
5050
      mgr.closeRawFileDescriptor("test.txt");
Z
zt147369 已提交
5051
  });
H
huangjie 已提交
5052
  ```