harmony 鸿蒙资源管理changeLog

  • 2022-12-22
  • 浏览 (623)

资源管理changeLog

cl.resourceManager.1 资源API9部分多工程接口命名变更

资源管理从API9开始提供接口的错误码和错误信息返回,涉及API9提供的部分多工程接口需要适配。从API9开始作以下变更:

资源API部分多工程接口需要用新的接口替换,参数不变。

变更影响

基于此前版本开发的应用,涉及下面多工程接口的JS接口需要替换为新的接口。

关键接口/组件变更

涉及接口 对应替换接口
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>;

适配指导

以getMedia修改为getMediaContent的callback调用为例,其promise方式类似,只需修改函数名,且增加错误码和错误信息返回,其它不变。示例代码如下:

  • 变更前: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;
    }
    });
    
  • 变更后: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}.`)
    }
    

你可能感兴趣的鸿蒙文章

harmony 鸿蒙帐号子系统changeLog

harmony 鸿蒙媒体子系统JS API变更Changelog

harmony 鸿蒙设备管理changeLog

harmony 鸿蒙USB管理 changeLog

harmony 鸿蒙软总线子系统Changelog

harmony 鸿蒙文件管理子系统ChangeLog

harmony 鸿蒙全球化子系统ChangeLog

harmony 鸿蒙输入法框架changeLog

harmony 鸿蒙多模输入changeLog

harmony 鸿蒙电源子系统ChangeLog

0  赞