Resource Manager Changelog

cl.resourceManager.1 Name Change of Multi-Project APIs in API Version 9

The 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:

Some multi-project APIs of the Resource Manager are replaced with new APIs, but the parameters remain unchanged.

Change Impact

For applications developed based on earlier versions, relevant JavaScript multi-project APIs need to be replaced with new APIs.

Key API/Component Changes

Original API New API
getString(resource: Resource,
callback: AsyncCallback<string>): void;
getStringValue(resource: Resource,
callback: AsyncCallback<string>): void;
getString(resource: Resource): Promise<string>; getStringValue(resource: Resource): Promise<string>;
getStringArray(resource: Resource,
callback: AsyncCallback<Array<string>>): void;
getStringArrayValue(resource: Resource,
callback: AsyncCallback<Array<string>>): void;
getStringArray(resource: Resource): Promise<Array<string>>; getStringArrayValue(resource: Resource): Promise<Array<string>>;
getMedia(resource: Resource,
callback: AsyncCallback<Uint8Array>): void;
getMediaContent(resource: Resource,
callback: AsyncCallback<Uint8Array>): void;
getMedia(resource: Resource): Promise<Uint8Array>; getMediaContent(resource: Resource): Promise<Uint8Array>;
getMediaBase64(resource: Resource,
callback: AsyncCallback<string>): void;
getMediaContentBase64(resource: Resource,
callback: AsyncCallback<string>): void;
getMediaBase64(resource: Resource): Promise<string>; getMediaContentBase64(resource: Resource): Promise<string>;
getPluralString(resource: Resource, num: number,
callback: AsyncCallback): void;
getPluralStringValue(resource: Resource, num: number,
callback: AsyncCallback<string>): void;
getPluralString(resource: Resource, num: number): Promise<string>; getPluralStringValue(resource: Resource, num: number): Promise<string>;

Adaptation Guide

The 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:

  • Before the change: getMedia(resource: Resource, callback: AsyncCallback): void;
let resource = {
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.media.test').id
};
this.context.resourceManager.getMedia(resource, (error, value) => {
    if (error != null) {
      console.log("error is " + error);
    } else {
      let media = value;
    }
});
  • After the change: getMediaContent(resource: Resource, callback: AsyncCallback): void;
let resource = {
    bundleName: "com.example.myapplication",
    moduleName: "entry",
    id: $r('app.media.test').id
};
try {
  this.context.resourceManager.getMediaContent(resource, (error, value) => {
      if (error != null) {
        console.log("error is " + error);
      } else {
        let media = value;
      }
  });
} catch (error) {
  console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`)
}