• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Resource Manager Changelog
2
3## cl.resourceManager.1 Name Change of Multi-Project APIs in API Version 9
4
5The Resource Manager module can return error codes and error information for APIs in API version 9 and later. Some multi-project APIs in API version 9 need to be adapted. The following changes are made in API version 9:
6
7Some multi-project APIs of the Resource Manager are replaced with new APIs, but the parameters remain unchanged.
8
9**Change Impact**
10
11For applications developed based on earlier versions, relevant JavaScript multi-project APIs need to be replaced with new APIs.
12
13**Key API/Component Changes**
14
15| **Original API**                           | **New API**|
16| ----------------                         | ------------ |
17| getString(resource: Resource, <br>callback: AsyncCallback\<string>): void;   | getStringValue(resource: Resource, <br>callback: AsyncCallback\<string>): void;       |
18| getString(resource: Resource): Promise\<string>;   | getStringValue(resource: Resource): Promise\<string>;       |
19| getStringArray(resource: Resource, <br>callback: AsyncCallback\<Array\<string>>): void;    | getStringArrayValue(resource: Resource, <br>callback: AsyncCallback\<Array\<string>>): void;       |
20| getStringArray(resource: Resource): Promise\<Array\<string>>;    | getStringArrayValue(resource: Resource): Promise\<Array\<string>>;       |
21| getMedia(resource: Resource, <br>callback: AsyncCallback\<Uint8Array>): void;    | getMediaContent(resource: Resource, <br>callback: AsyncCallback\<Uint8Array>): void;       |
22| getMedia(resource: Resource): Promise\<Uint8Array>;   | getMediaContent(resource: Resource): Promise\<Uint8Array>;       |
23| getMediaBase64(resource: Resource, <br>callback: AsyncCallback\<string>): void;   | getMediaContentBase64(resource: Resource, <br>callback: AsyncCallback\<string>): void;       |
24| getMediaBase64(resource: Resource): Promise\<string>;  | getMediaContentBase64(resource: Resource): Promise\<string>;       |
25| getPluralString(resource: Resource, num: number, <br>callback: AsyncCallback<string>): void;   | getPluralStringValue(resource: Resource, num: number, <br>callback: AsyncCallback\<string>): void;       |
26| getPluralString(resource: Resource, num: number): Promise\<string>;   | getPluralStringValue(resource: Resource, num: number): Promise\<string>;       |
27
28**Adaptation Guide**
29
30The following describes how to change **getMedia** to **getMediaContent** in callback mode. The promise mode is similar. You only need to change the function name, add the error code and error information, and keep other information unchanged. Example:
31
32- Before the change: **getMedia(resource: Resource, callback: AsyncCallback<Uint8Array>): void;**
33```ts
34let resource = {
35    bundleName: "com.example.myapplication",
36    moduleName: "entry",
37    id: $r('app.media.test').id
38};
39this.context.resourceManager.getMedia(resource, (error, value) => {
40    if (error != null) {
41      console.log("error is " + error);
42    } else {
43      let media = value;
44    }
45});
46```
47
48- After the change: **getMediaContent(resource: Resource, callback: AsyncCallback<Uint8Array>): void;**
49```ts
50let resource = {
51    bundleName: "com.example.myapplication",
52    moduleName: "entry",
53    id: $r('app.media.test').id
54};
55try {
56  this.context.resourceManager.getMediaContent(resource, (error, value) => {
57      if (error != null) {
58        console.log("error is " + error);
59      } else {
60        let media = value;
61      }
62  });
63} catch (error) {
64  console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`)
65}
66```
67