diff --git a/zh-cn/application-dev/reference/apis/js-apis-resource-manager.md b/zh-cn/application-dev/reference/apis/js-apis-resource-manager.md index 13a31f5ca0cfa14442f1d65351c6fbe565bc70d1..d46da1226a142fed8522cf4b10e8049107565668 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-resource-manager.md +++ b/zh-cn/application-dev/reference/apis/js-apis-resource-manager.md @@ -238,6 +238,18 @@ resourceManager.getResourceManager((error, mgr) => { | offset | number | rawfile的起始偏移量 | | length | number | rawfile的文件长度 | +## Resource + +表示的资源信息。 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Global.ResourceManager + +| 名称 | 类型 | 说明 | +| ------ | ------ | ------------------ | +| bundleName | string | 应用的bundle名称 | +| moduleName | string | 应用的module名称 | +| id | number | 资源的id值 | + ## ResourceManager @@ -307,6 +319,68 @@ getString(resId: number): Promise<string> ``` +### getString9+ + +getString(resource: Resource, callback: AsyncCallback<string>): void + +用户获取指定resource对象对应的字符串,使用callback形式返回字符串。 + +**系统能力**:SystemCapability.Global.ResourceManager + +**参数:** +| 参数名 | 类型 | 必填 | 说明 | +| -------- | --------------------------- | ---- | --------------- | +| resource | [Resource](#resource) | 是 | 资源信息 | +| callback | AsyncCallback<string> | 是 | 异步回调,用于返回获取的字符串 | + +**示例:** + ``` + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.string.test').id + }; + this.context.resourceManager.getString(resource, (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let str = value; + } + }); + ``` + +### getString9+ + +getString(resource: Resource): Promise<string> + +用户获取指定resource对象对应的字符串,使用Promise形式返回字符串。 + +**系统能力**:SystemCapability.Global.ResourceManager + +**参数:** +| 参数名 | 类型 | 必填 | 说明 | +| ----- | ------ | ---- | ----- | +| resource | [Resource](#resource) | 是 | 资源信息 | + +**返回值:** +| 类型 | 说明 | +| --------------------- | ----------- | +| Promise<string> | resource对象对应的字符串 | + +**示例:** + ``` + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.string.test').id + }; + this.context.resourceManager.getString(resource).then(value => { + let str = value; + }).catch(error => { + console.log("getstring promise error is " + error); + }); + ``` + ### getStringArray getStringArray(resId: number, callback: AsyncCallback<Array<string>>): void @@ -364,6 +438,67 @@ getStringArray(resId: number): Promise<Array<string>> }); ``` +### getStringArray9+ + +getStringArray(resource: Resource, callback: AsyncCallback<Array<string>>): void + +用户获取指定resource对象对应的字符串数组,使用callback形式返回回字符串数组。 + +**系统能力**:SystemCapability.Global.ResourceManager + +**参数:** +| 参数名 | 类型 | 必填 | 说明 | +| -------- | --------------------------- | ---- | --------------- | +| resource | [Resource](#resource) | 是 | 资源信息 | +| callback | AsyncCallback<Array<string>> | 是 | 异步回调,用于返回获取的字符串数组 | + +**示例:** + ``` + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.strarray.test').id + }; + this.context.resourceManager.getStringArray(resource, (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let strArray = value; + } + }); + ``` + +### getStringArray9+ + +getStringArray(resource: Resource): Promise<Array<string>> + +用户获取指定resource对象对应的字符串数组,使用Promise形式返回字符串数组。 + +**系统能力**:SystemCapability.Global.ResourceManager + +**参数:** +| 参数名 | 类型 | 必填 | 说明 | +| ----- | ------ | ---- | ----- | +| resource | [Resource](#resource) | 是 | 资源信息 | + +**返回值:** +| 类型 | 说明 | +| --------------------- | ----------- | +| Promise<Array<string>> | resource对象对应的字符串数组 | + +**示例:** + ``` + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.strarray.test').id + }; + this.context.resourceManager.getStringArray(resource).then(value => { + let strArray = value; + }).catch(error => { + console.log("getStringArray promise error is " + error); + }); + ``` ### getMedia @@ -422,6 +557,67 @@ getMedia(resId: number): Promise<Uint8Array> }); ``` +### getMedia9+ + +getMedia(resource: Resource, callback: AsyncCallback<Uint8Array>): void + +用户获取指定resource对象对应的媒体文件内容,使用callback形式返回字节数组。 + +**系统能力**:SystemCapability.Global.ResourceManager + +**参数:** +| 参数名 | 类型 | 必填 | 说明 | +| -------- | --------------------------- | ---- | --------------- | +| resource | [Resource](#resource) | 是 | 资源信息 | +| callback | AsyncCallback<Uint8Array> | 是 | 异步回调,用于返回获取的媒体文件内容 | + +**示例:** + ``` + 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; + } + }); + ``` + +### getMedia9+ + +getMedia(resource: Resource): Promise<Uint8Array> + +用户获取指定resource对象对应的媒体文件内容,使用Promise形式返回字节数组。 + +**系统能力**:SystemCapability.Global.ResourceManager + +**参数:** +| 参数名 | 类型 | 必填 | 说明 | +| ----- | ------ | ---- | ----- | +| resource | [Resource](#resource) | 是 | 资源信息 | + +**返回值:** +| 类型 | 说明 | +| --------------------- | ----------- | +| Promise<Uint8Array> | resource对象对应的媒体文件内容 | + +**示例:** + ``` + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.media.test').id + }; + this.context.resourceManager.getMedia(resource).then(value => { + let media = value; + }).catch(error => { + console.log("getMedia promise error is " + error); + }); + ``` ### getMediaBase64 @@ -480,6 +676,68 @@ getMediaBase64(resId: number): Promise<string> }); ``` +### getMediaBase649+ + +getMediaBase64(resource: Resource, callback: AsyncCallback<string>): void + +用户获取指定resource对象对应的图片资源Base64编码,使用callback形式返回字符串。 + +**系统能力**:SystemCapability.Global.ResourceManager + +**参数:** +| 参数名 | 类型 | 必填 | 说明 | +| -------- | --------------------------- | ---- | ------------------------ | +| resource | [Resource](#resource) | 是 | 资源信息 | +| callback | AsyncCallback<string> | 是 | 异步回调,用于返回获取的图片资源Base64编码 | + +**示例:** + ``` + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.media.test').id + }; + this.context.resourceManager.getMediaBase64(resource, (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let media = value; + } + }); + ``` + +### getMediaBase649+ + +getMediaBase64(resource: Resource): Promise<string> + +用户获取指定resource对象对应的图片资源Base64编码,使用Promise形式返回字符串。 + +**系统能力**:SystemCapability.Global.ResourceManager + +**参数:** +| 参数名 | 类型 | 必填 | 说明 | +| ----- | ------ | ---- | ----- | +| resource | [Resource](#resource) | 是 | 资源信息 | + +**返回值:** +| 类型 | 说明 | +| --------------------- | -------------------- | +| Promise<string> | resource对象对应的图片资源Base64编码 | + +**示例:** + ``` + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.media.test').id + }; + this.context.resourceManager.getMediaBase64(resource).then(value => { + let media = value; + }).catch(error => { + console.log("getMediaBase64 promise error is " + error); + }); + ``` + ### getConfiguration @@ -648,6 +906,70 @@ getPluralString(resId: number, num: number): Promise<string> }); ``` +### getPluralString9+ + +getPluralString(resource: Resource, num: number, callback: AsyncCallback<string>): void + +根据指定数量获取指定resource对象表示的单复数字符串,使用callback形式返回字符串。 + +**系统能力**:SystemCapability.Global.ResourceManager + +**参数:** +| 参数名 | 类型 | 必填 | 说明 | +| -------- | --------------------------- | ---- | ------------------------------- | +| resource | [Resource](#resource) | 是 | 资源信息 | +| num | number | 是 | 数量值 | +| callback | AsyncCallback<string> | 是 | 异步回调,返回根据指定数量获取指定resource对象表示的单复数字符串 | + +**示例:** + ``` + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.plural.test').id + }; + this.context.resourceManager.getPluralString(resource, 1, (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let str = value; + } + }); + ``` + +### getPluralString9+ + +getPluralString(resource: Resource, num: number): Promise<string> + +根据指定数量获取对指定resource对象表示的单复数字符串,使用Promise形式返回字符串。 + +**系统能力**:SystemCapability.Global.ResourceManager + +**参数:** +| 参数名 | 类型 | 必填 | 说明 | +| ----- | ------ | ---- | ----- | +| resource | [Resource](#resource) | 是 | 资源信息 | +| num | number | 是 | 数量值 | + +**返回值:** +| 类型 | 说明 | +| --------------------- | ------------------------- | +| Promise<string> | 根据提供的数量获取对应resource对象表示的单复数字符串 | + +**示例:** + ``` + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.plural.test').id + }; + this.context.resourceManager.getPluralString(resource, 1).then(value => { + let str = value; + }).catch(error => { + console.log("getPluralString promise error is " + error); + }); + ``` + ### getRawFile8+ getRawFile(path: string, callback: AsyncCallback<Uint8Array>): void @@ -1118,6 +1440,34 @@ getStringSync(resId: number): string resourceManager.getStringSync($r('app.string.test').id); ``` +### getStringSync9+ + +getStringSync(resource: Resource): string + +用户获取指定resource对象对应的字符串,使用同步方式返回字符串。 + +**系统能力**:SystemCapability.Global.ResourceManager + +**参数:** +| 参数名 | 类型 | 必填 | 说明 | +| ----- | ------ | ---- | ----- | +| resource | [Resource](#resource) | 是 | 资源信息 | + +**返回值:** +| 类型 | 说明 | +| --------------------- | ----------- | +| string | resource对象对应的字符串 | + +**示例:** + ``` + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.string.test').id + }; + this.context.resourceManager.getStringSync(resource); + ``` + ### getStringByNameSync9+ getStringByNameSync(resName: string): string @@ -1163,6 +1513,33 @@ getBoolean(resId: number): boolean ``` resourceManager.getBoolean($r('app.boolean.boolean_test').id); ``` +### getBoolean9+ + +getBoolean(resource: Resource): boolean + +使用同步方式,返回获取指定resource对象对应的布尔结果。 + +**系统能力**:SystemCapability.Global.ResourceManager + +**参数:** +| 参数名 | 类型 | 必填 | 说明 | +| ----- | ------ | ---- | ----- | +| resource | [Resource](#resource) | 是 | 资源信息 | + +**返回值:** +| 类型 | 说明 | +| --------------------- | ----------- | +| boolean | resource对象对应的布尔结果 | + +**示例:** + ``` + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.boolean.boolean_test').id + }; + this.context.resourceManager.getBoolean(resource); + ``` ### getBooleanByName9+ @@ -1211,6 +1588,34 @@ getNumber(resId: number): number resourceManager.getNumber($r('app.float.float_test').id); ``` +### getNumber9+ + +getNumber(resource: Resource): number + +用户获取指定resource对象对应的integer数值或者float数值,使用同步方式返回资源对应的数值。 + +**系统能力**:SystemCapability.Global.ResourceManager + +**参数:** +| 参数名 | 类型 | 必填 | 说明 | +| ----- | ------ | ---- | ----- | +| resource | [Resource](#resource) | 是 | 资源信息 | + +**返回值:** +| 类型 | 说明 | +| --------------------- | ----------- | +| number | resource对象对应的数值 | + +**示例:** + ``` + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.integer.integer_test').id + }; + this.context.resourceManager.getNumber(resource); + ``` + ### getNumberByName9+ getNumberByName(resName: string): number