diff --git a/en/application-dev/reference/apis/js-apis-i18n.md b/en/application-dev/reference/apis/js-apis-i18n.md index b5bc89099f57b1f56b65859e6d4b0422d483df23..7d7ec04c6ca3bcbaf5cb8d1f314d256f15efbef8 100644 --- a/en/application-dev/reference/apis/js-apis-i18n.md +++ b/en/application-dev/reference/apis/js-apis-i18n.md @@ -702,7 +702,7 @@ Defines the measurement unit information. ### unitConvert8+ -unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string +static unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string Converts one measurement unit into another and formats the unit based on the specified locale and style. @@ -825,7 +825,7 @@ Obtains the index of a text object. ### isDigit8+ -isDigit(char: string): boolean +static isDigit(char: string): boolean Checks whether the input character string is composed of digits. @@ -849,7 +849,7 @@ Checks whether the input character string is composed of digits. ### isSpaceChar8+ -isSpaceChar(char: string): boolean +static isSpaceChar(char: string): boolean Checks whether the input character is a space. @@ -873,7 +873,7 @@ Checks whether the input character is a space. ### isWhitespace8+ -isWhitespace(char: string): boolean +static isWhitespace(char: string): boolean Checks whether the input character is a white space. @@ -897,7 +897,7 @@ Checks whether the input character is a white space. ### isRTL8+ -isRTL(char: string): boolean +static isRTL(char: string): boolean Checks whether the input character is of the right to left (RTL) language. @@ -921,7 +921,7 @@ Checks whether the input character is of the right to left (RTL) language. ### isIdeograph8+ -isIdeograph(char: string): boolean +static isIdeograph(char: string): boolean Checks whether the input character is an ideographic character. @@ -945,7 +945,7 @@ Checks whether the input character is an ideographic character. ### isLetter8+ -isLetter(char: string): boolean +static isLetter(char: string): boolean Checks whether the input character is a letter. @@ -969,7 +969,7 @@ Checks whether the input character is a letter. ### isLowerCase8+ -isLowerCase(char: string): boolean +static isLowerCase(char: string): boolean Checks whether the input character is a lowercase letter. @@ -993,7 +993,7 @@ Checks whether the input character is a lowercase letter. ### isUpperCase8+ -isUpperCase(char: string): boolean +static isUpperCase(char: string): boolean Checks whether the input character is an uppercase letter. @@ -1017,7 +1017,7 @@ Checks whether the input character is an uppercase letter. ### getType8+ -getType(char: string): string +static getType(char: string): string Obtains the type of the input character string. @@ -1124,7 +1124,7 @@ Obtains the position of the [BreakIterator](#breakiterator8) object in the text ``` var iterator = i18n.getLineInstance("en"); iterator.setLineBreakText("Apple is my favorite fruit."); - breakIter.current(); // 0 + iterator.current(); // 0 ``` @@ -1145,7 +1145,7 @@ Puts the [BreakIterator](#breakiterator8) object to the first text boundary, whi ``` var iterator = i18n.getLineInstance("en"); iterator.setLineBreakText("Apple is my favorite fruit."); - breakIter.first(); // 0 + iterator.first(); // 0 ``` diff --git a/en/application-dev/reference/apis/js-apis-resource-manager.md b/en/application-dev/reference/apis/js-apis-resource-manager.md index 2effb8b20a713c2c1f9a27baa8c12cabdcd37cda..335e31cdb21bacd975db26b726f503c0a44e431d 100644 --- a/en/application-dev/reference/apis/js-apis-resource-manager.md +++ b/en/application-dev/reference/apis/js-apis-resource-manager.md @@ -2,7 +2,7 @@ The resource management module provides APIs to obtain information about the current device configuration (including the language, region, screen direction, and MCC/MNC) and device capability (including the device type and resolution). -> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
+> **NOTE**
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. @@ -12,31 +12,41 @@ The resource management module provides APIs to obtain information about the cur import resourceManager from '@ohos.resourceManager'; ``` +## Usage + +Since API version 9, the stage model allows an application to obtain a **ResourceManager** object based on **context** and call its APIs without first importing the required bundle. This method, however, is not applicable to the FA model. + +``` +this.context.resourceManager; +``` + ## resourceManager.getResourceManager getResourceManager(callback: AsyncCallback<ResourceManager>): void -Obtains the **ResourceManager** object of this application. This API uses a callback to return the result. +Obtains the **ResourceManager** object of this application. This API uses an asynchronous callback to return the result. + +This API is used only in the FA model. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ----------------------------- | -| callback | AsyncCallback<[ResourceManager](#resourcemanager)> | Yes | Asynchronous callback used to return the **ResourceManager** object obtained.| +| callback | AsyncCallback<[ResourceManager](#resourcemanager)> | Yes | Asynchronous callback used to return the result.| **Example** ``` resourceManager.getResourceManager((error, mgr) => { if (error != null) { - console.log("error occurs" + error); + console.log("error is " + error); return; } mgr.getString(0x1000000, (error, value) => { if (error != null) { - console.log(value); + console.log("error is " + error); } else { - console.log(value); + let str = value; } }); }); @@ -47,7 +57,9 @@ Obtains the **ResourceManager** object of this application. This API uses a call getResourceManager(bundleName: string, callback: AsyncCallback<ResourceManager>): void -Obtains the **ResourceManager** object of an application. This API uses an asynchronous callback to return the result. +Obtains the **ResourceManager** object of an application based on the specified bundle name. This API uses an asynchronous callback to return the result. + +This API is used only in the FA model. **System capability**: SystemCapability.Global.ResourceManager @@ -55,7 +67,7 @@ Obtains the **ResourceManager** object of an application. This API uses an async | Name | Type | Mandatory | Description | | ---------- | ---------------------------------------- | ---- | ----------------------------- | | bundleName | string | Yes | Bundle name of the target application. | -| callback | AsyncCallback<[ResourceManager](#resourcemanager)> | Yes | Asynchronous callback used to return the **ResourceManager** object obtained.| +| callback | AsyncCallback<[ResourceManager](#resourcemanager)> | Yes | Asynchronous callback used to return the result.| **Example** ``` @@ -70,25 +82,27 @@ getResourceManager(): Promise<ResourceManager> Obtains the **ResourceManager** object of this application. This API uses a promise to return the result. +This API is used only in the FA model. + **System capability**: SystemCapability.Global.ResourceManager **Return value** | Type | Description | | ---------------------------------------- | ----------------- | -| Promise<[ResourceManager](#resourcemanager)> | Promise used to return the **ResourceManager** object obtained.| +| Promise<[ResourceManager](#resourcemanager)> | Promise used to return the result.| **Example** ``` resourceManager.getResourceManager().then(mgr => { mgr.getString(0x1000000, (error, value) => { if (error != null) { - console.log(value); + console.log("error is " + error); } else { - console.log(value); + let str = value; } }); }).catch(error => { - console.log(error); + console.log("error is " + error); }); ``` @@ -97,7 +111,9 @@ Obtains the **ResourceManager** object of this application. This API uses a prom getResourceManager(bundleName: string): Promise<ResourceManager> -Obtains the **ResourceManager** object of an application. This API uses a promise to return the result. +Obtains the **ResourceManager** object of an application based on the specified bundle name. This API uses a promise to return the result. + +This API is used only in the FA model. **System capability**: SystemCapability.Global.ResourceManager @@ -109,7 +125,7 @@ Obtains the **ResourceManager** object of an application. This API uses a promis **Return value** | Type | Description | | ---------------------------------------- | ------------------ | -| Promise<[ResourceManager](#resourcemanager)> | Promise used to return the **ResourceManager** object obtained.| +| Promise<[ResourceManager](#resourcemanager)> | Promise used to return the result.| **Example** ``` @@ -129,8 +145,8 @@ Enumerates the screen directions. | Name | Default Value | Description | | -------------------- | ---- | ---- | -| DIRECTION_VERTICAL | 0 | Portrait | -| DIRECTION_HORIZONTAL | 1 | Landscape | +| DIRECTION_VERTICAL | 0 | Portrait. | +| DIRECTION_HORIZONTAL | 1 | Landscape. | ## DeviceType @@ -141,12 +157,12 @@ Enumerates the device types. | Name | Default Value | Description | | -------------------- | ---- | ---- | -| DEVICE_TYPE_PHONE | 0x00 | Phone | -| DEVICE_TYPE_TABLET | 0x01 | Tablet | -| DEVICE_TYPE_CAR | 0x02 | Head unit | -| DEVICE_TYPE_PC | 0x03 | PC | -| DEVICE_TYPE_TV | 0x04 | TV | -| DEVICE_TYPE_WEARABLE | 0x06 | Wearable | +| DEVICE_TYPE_PHONE | 0x00 | Phone. | +| DEVICE_TYPE_TABLET | 0x01 | Tablet. | +| DEVICE_TYPE_CAR | 0x02 | Head unit. | +| DEVICE_TYPE_PC | 0x03 | PC. | +| DEVICE_TYPE_TV | 0x04 | TV. | +| DEVICE_TYPE_WEARABLE | 0x06 | Wearable. | ## ScreenDensity @@ -182,8 +198,8 @@ Defines the device configuration. ``` resourceManager.getResourceManager((error, mgr) => { mgr.getConfiguration((error, value) => { - console.log(value.direction); - console.log(value.locale); + let direction = value.direction; + let locale = value.locale; }); }); ``` @@ -205,8 +221,8 @@ Defines the device capability. ``` resourceManager.getResourceManager((error, mgr) => { mgr.getDeviceCapability((error, value) => { - console.log(value.screenDensity); - console.log(value.deviceType); + let screenDensity = value.screenDensity; + let deviceType = value.deviceType; }); }); ``` @@ -227,7 +243,7 @@ Defines the descriptor information of the raw file.
Defines the capability of accessing application resources. -> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
+> **NOTE**
> - The methods involved in **ResourceManager** are applicable only to the TypeScript-based declarative development paradigm. > > - Resource files are defined in the **resources** directory of the project. You can obtain the resource ID using **$r(resource address).id**, for example, **$r('app.string.test').id**. @@ -245,16 +261,16 @@ Obtains the string corresponding to the specified resource ID. This API uses an | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | --------------- | | resId | number | Yes | Resource ID. | -| callback | AsyncCallback<string> | Yes | Asynchronous callback used to return the obtained string.| +| callback | AsyncCallback<string> | Yes | Asynchronous callback used to return the result.| **Example** ``` resourceManager.getResourceManager((error, mgr) => { mgr.getString($r('app.string.test').id, (error, value) => { if (error != null) { - console.log(value); + console.log("error is " + error); } else { - console.log(value); + let str = value; } }); }); @@ -277,15 +293,15 @@ Obtains the string corresponding to the specified resource ID. This API uses a p **Return value** | Type | Description | | --------------------- | ----------- | -| Promise<string> | Promise used to return the string obtained.| +| Promise<string> | Promise used to return the result.| **Example** ``` resourceManager.getResourceManager((error, mgr) => { mgr.getString($r('app.string.test').id).then(value => { - console.log(value); + let str = value; }).catch(error => { - console.log("getstring promise " + error); + console.log("getstring promise error is " + error); }); }); ``` @@ -295,7 +311,7 @@ Obtains the string corresponding to the specified resource ID. This API uses a p getStringArray(resId: number, callback: AsyncCallback<Array<string>>): void -Obtains the array of strings corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. +Obtains the string array corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager @@ -303,16 +319,16 @@ Obtains the array of strings corresponding to the specified resource ID. This AP | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ----------------- | | resId | number | Yes | Resource ID. | -| callback | AsyncCallback<Array<string>> | Yes | Asynchronous callback used to return the obtained array of strings.| +| callback | AsyncCallback<Array<string>> | Yes | Asynchronous callback used to return the result.| **Example** ``` resourceManager.getResourceManager((error, mgr) => { mgr.getStringArray($r('app.strarray.test').id, (error, value) => { if (error != null) { - console.log(value); + console.log("error is " + error); } else { - console.log(value); + let strArray = value; } }); }); @@ -323,7 +339,7 @@ Obtains the array of strings corresponding to the specified resource ID. This AP getStringArray(resId: number): Promise<Array<string>> -Obtains the array of strings corresponding to the specified resource ID. This API uses a promise to return the result. +Obtains the string array corresponding to the specified resource ID. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager @@ -335,15 +351,15 @@ Obtains the array of strings corresponding to the specified resource ID. This AP **Return value** | Type | Description | | ---------------------------------- | ------------- | -| Promise<Array<string>> | Promise used to return the array of strings obtained.| +| Promise<Array<string>> | Promise used to return the result.| **Example** ``` resourceManager.getResourceManager((error, mgr) => { mgr.getStringArray($r('app.strarray.test').id).then(value => { - console.log(value); + let strArray = value; }).catch(error => { - console.log("getstring promise " + error); + console.log("getStringArray promise error is " + error); }); }); ``` @@ -361,16 +377,16 @@ Obtains the content of the media file corresponding to the specified resource ID | Name | Type | Mandatory | Description | | -------- | ------------------------------- | ---- | ------------------ | | resId | number | Yes | Resource ID. | -| callback | AsyncCallback<Uint8Array> | Yes | Asynchronous callback used to return the content of the media file obtained.| +| callback | AsyncCallback<Uint8Array> | Yes | Asynchronous callback used to return the result.| **Example** ``` resourceManager.getResourceManager((error, mgr) => { mgr.getMedia($r('app.media.test').id, (error, value) => { if (error != null) { - console.log(value); + console.log("error is " + error); } else { - console.log(value); + let media = value; } }); }); @@ -393,15 +409,15 @@ Obtains the content of the media file corresponding to the specified resource ID **Return value** | Type | Description | | ------------------------- | -------------- | -| Promise<Uint8Array> | Promise used to return the content of the media file obtained.| +| Promise<Uint8Array> | Promise used to return the result.| **Example** ``` resourceManager.getResourceManager((error, mgr) => { mgr.getMedia($r('app.media.test').id).then(value => { - console.log(value); + let media = value; }).catch(error => { - console.log("getstring promise " + error); + console.log("getMedia promise error is " + error); }); }); ``` @@ -419,16 +435,16 @@ Obtains the Base64 code of the image corresponding to the specified resource ID. | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | ------------------------ | | resId | number | Yes | Resource ID. | -| callback | AsyncCallback<string> | Yes | Asynchronous callback used to return the Base64 code of the image obtained.| +| callback | AsyncCallback<string> | Yes | Asynchronous callback used to return the result.| **Example** ``` resourceManager.getResourceManager((error, mgr) => { mgr.getMediaBase64($r('app.media.test').id, (error, value) => { if (error != null) { - console.log(value); + console.log("error is " + error); } else { - console.log(value); + let media = value; } }); }); @@ -451,15 +467,15 @@ Obtains the Base64 code of the image corresponding to the specified resource ID. **Return value** | Type | Description | | --------------------- | -------------------- | -| Promise<string> | Promise used to return the Base64 code of the image obtained.| +| Promise<string> | Promise used to return the result.| **Example** ``` resourceManager.getResourceManager((error, mgr) => { mgr.getMediaBase64($r('app.media.test').id).then(value => { - console.log(value); + let media = value; }).catch(error => { - console.log("getstring promise " + error); + console.log("getMediaBase64 promise error is " + error); }); }); ``` @@ -476,16 +492,17 @@ Obtains the device configuration. This API uses an asynchronous callback to retu **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ------------------------- | -| callback | AsyncCallback<[Configuration](#configuration)> | Yes | Asynchronous callback used to return the obtained device configuration.| +| callback | AsyncCallback<[Configuration](#configuration)> | Yes | Asynchronous callback used to return the result.| **Example** ``` resourceManager.getResourceManager((error, mgr) => { mgr.getConfiguration((error, value) => { if (error != null) { - console.log(value); + console.log("error is " + error); } else { - console.log(value); + let direction = value.direction; + let locale = value.locale; } }); }); @@ -503,15 +520,16 @@ Obtains the device configuration. This API uses a promise to return the result. **Return value** | Type | Description | | ---------------------------------------- | ---------------- | -| Promise<[Configuration](#configuration)> | Promise used to return the device configuration.| +| Promise<[Configuration](#configuration)> | Promise used to return the result.| **Example** ``` resourceManager.getResourceManager((error, mgr) => { mgr.getConfiguration().then(value => { - console.log(value); + let direction = value.direction; + let locale = value.locale; }).catch(error => { - console.log("getstring promise " + error); + console.log("getConfiguration promise error is " + error); }); }); ``` @@ -528,16 +546,17 @@ Obtains the device capability. This API uses an asynchronous callback to return **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ---------------------------- | -| callback | AsyncCallback<[DeviceCapability](#devicecapability)> | Yes | Asynchronous callback used to return the obtained device capability.| +| callback | AsyncCallback<[DeviceCapability](#devicecapability)> | Yes | Asynchronous callback used to return the result.| **Example** ``` resourceManager.getResourceManager((error, mgr) => { mgr.getDeviceCapability((error, value) => { if (error != null) { - console.log(value); + console.log("error is " + error); } else { - console.log(value); + let screenDensity = value.screenDensity; + let deviceType = value.deviceType; } }); }); @@ -555,15 +574,16 @@ Obtains the device capability. This API uses a promise to return the result. **Return value** | Type | Description | | ---------------------------------------- | ------------------- | -| Promise<[DeviceCapability](#devicecapability)> | Promise used to return the obtained device capability.| +| Promise<[DeviceCapability](#devicecapability)> | Promise used to return the result.| **Example** ``` resourceManager.getResourceManager((error, mgr) => { mgr.getDeviceCapability().then(value => { - console.log(value); + let screenDensity = value.screenDensity; + let deviceType = value.deviceType; }).catch(error => { - console.log("getstring promise " + error); + console.log("getDeviceCapability promise error is " + error); }); }); ``` @@ -582,16 +602,16 @@ Obtains the specified number of singular-plural strings corresponding to the spe | -------- | --------------------------- | ---- | ------------------------------- | | resId | number | Yes | Resource ID. | | num | number | Yes | Number that determines the plural or singular form. | -| callback | AsyncCallback<string> | Yes | Asynchronous callback used to return the singular-plural string obtained.| +| callback | AsyncCallback<string> | Yes | Asynchronous callback used to return the result.| **Example** ``` resourceManager.getResourceManager((error, mgr) => { mgr.getPluralString($r("app.plural.test").id, 1, (error, value) => { if (error != null) { - console.log(value); + console.log("error is " + error); } else { - console.log(value); + let str = value; } }); }); @@ -615,15 +635,15 @@ Obtains the specified number of singular-plural strings corresponding to the spe **Return value** | Type | Description | | --------------------- | ------------------------- | -| Promise<string> | Promise used to return the singular-plural string obtained.| +| Promise<string> | Promise used to return the result.| **Example** ``` resourceManager.getResourceManager((error, mgr) => { mgr.getPluralString($r("app.plural.test").id, 1).then(value => { - console.log(value); + let str = value; }).catch(error => { - console.log("getstring promise " + error); + console.log("getPluralString promise error is " + error); }); }); ``` @@ -632,7 +652,7 @@ Obtains the specified number of singular-plural strings corresponding to the spe getRawFile(path: string, callback: AsyncCallback<Uint8Array>): void -Obtains the content of rawfile in the specified path. This API uses an asynchronous callback to return the result. +Obtains the content of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager @@ -640,16 +660,16 @@ Obtains the content of rawfile in the specified path. This API uses an asynchron | Name | Type | Mandatory | Description | | -------- | ------------------------------- | ---- | ----------------------- | | path | string | Yes | Path of the raw file. | -| callback | AsyncCallback<Uint8Array> | Yes | Asynchronous callback used to return the raw file content, in byte arrays.| +| callback | AsyncCallback<Uint8Array> | Yes | Asynchronous callback used to return the result.| **Example** ``` resourceManager.getResourceManager((error, mgr) => { mgr.getRawFile("test.xml", (error, value) => { if (error != null) { - console.log(value); + console.log("error is " + error); } else { - console.log(value); + let rawFile = value; } }); }); @@ -659,7 +679,7 @@ Obtains the content of rawfile in the specified path. This API uses an asynchron getRawFile(path: string): Promise<Uint8Array> -Obtains the content of the raw file in the specified path. This API uses a promise to return the result. +Obtains the content of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager @@ -671,15 +691,15 @@ Obtains the content of the raw file in the specified path. This API uses a promi **Return value** | Type | Description | | ------------------------- | ----------- | -| Promise<Uint8Array> | Promise used to return the raw file content, in byte arrays.| +| Promise<Uint8Array> | Promise used to return the result.| **Example** ``` resourceManager.getResourceManager((error, mgr) => { mgr.getRawFile("test.xml").then(value => { - console.log(value); + let rawFile = value; }).catch(error => { - console.log("getrawfile promise " + error); + console.log("getRawFile promise error is " + error); }); }); ``` @@ -688,7 +708,7 @@ Obtains the content of the raw file in the specified path. This API uses a promi getRawFileDescriptor(path: string, callback: AsyncCallback<RawFileDescriptor>): void -Obtains the descriptor of the raw file in the specified path. This API uses an asynchronous callback to return the result. +Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager @@ -696,14 +716,14 @@ Obtains the descriptor of the raw file in the specified path. This API uses an a | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | -------------------------------- | | path | string | Yes | Path of the raw file. | -| callback | AsyncCallback<[RawFileDescriptor](#rawfiledescriptor8)> | Yes | Asynchronous callback used to return the raw file descriptor.| +| callback | AsyncCallback<[RawFileDescriptor](#rawfiledescriptor8)> | Yes | Asynchronous callback used to return the result.| **Example** ``` resourceManager.getResourceManager((error, mgr) => { mgr.getRawFileDescriptor("test.xml", (error, value) => { if (error != null) { - console.log(value); + console.log("error is " + error); } else { let fd = value.fd; let offset = value.offset; @@ -717,7 +737,7 @@ Obtains the descriptor of the raw file in the specified path. This API uses an a getRawFileDescriptor(path: string): Promise<RawFileDescriptor> -Obtains the descriptor of the raw file in the specified path. This API uses a promise to return the result. +Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager @@ -729,7 +749,7 @@ Obtains the descriptor of the raw file in the specified path. This API uses a pr **Return value** | Type | Description | | ---------------------------------------- | ------------------- | -| Promise<[RawFileDescriptor](#rawfiledescriptor8)> | Promise used to return the raw file descriptor.| +| Promise<[RawFileDescriptor](#rawfiledescriptor8)> | Promise used to return the result.| **Example** ``` @@ -739,7 +759,7 @@ Obtains the descriptor of the raw file in the specified path. This API uses a pr let offset = value.offset; let length = value.length; }).catch(error => { - console.log("getRawFileDescriptor promise " + error); + console.log("getRawFileDescriptor promise error is " + error); }); }); ``` @@ -748,7 +768,7 @@ Obtains the descriptor of the raw file in the specified path. This API uses a pr closeRawFileDescriptor(path: string, callback: AsyncCallback<void>): void -Closes the descriptor of the raw file in the specified path. This API uses an asynchronous callback to return the result. +Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager @@ -763,7 +783,7 @@ Closes the descriptor of the raw file in the specified path. This API uses an as resourceManager.getResourceManager((error, mgr) => { mgr.closeRawFileDescriptor("test.xml", (error, value) => { if (error != null) { - console.log(value); + console.log("error is " + error); } }); }); @@ -773,7 +793,7 @@ Closes the descriptor of the raw file in the specified path. This API uses an as closeRawFileDescriptor(path: string): Promise<void> -Closes the descriptor of the raw file in the specified path. This API uses a promise to return the result. +Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager @@ -791,9 +811,9 @@ Closes the descriptor of the raw file in the specified path. This API uses a pro ``` resourceManager.getResourceManager((error, mgr) => { mgr.closeRawFileDescriptor("test.xml").then(value => { - console.log(value); + let result = value; }).catch(error => { - console.log("closeRawFileDescriptor promise " + error); + console.log("closeRawFileDescriptor promise error is " + error); }); }); ``` @@ -809,10 +829,408 @@ Releases the created **resourceManager**. **Example** ``` resourceManager.getResourceManager((error, mgr) => { - mgr.release((error, value) => { - if (error != null) { - console.log(value); - } - }); + mgr.release(); + }); + ``` + +### getStringByName9+ + +getStringByName(resName: string, callback: AsyncCallback<string>): void + +Obtains the string corresponding to the specified resource name. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | --------------- | +| resName | string | Yes | Resource name. | +| callback | AsyncCallback<string> | Yes | Asynchronous callback used to return the result.| + +**Example** + ``` + resourceManager.getStringByName("test", (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let string = value; + } + }); + ``` + +### getStringByName9+ + +getStringByName(resName: string): Promise<string> + +Obtains the string corresponding to the specified resource name. This API uses a promise to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ---- | +| resName | string | Yes | Resource name.| + +**Return value** +| Type | Description | +| --------------------- | ----------- | +| Promise<string> | String corresponding to the resource name.| + +**Example** + ``` + resourceManager.getStringByName("test").then(value => { + let string = value; + }).catch(error => { + console.log("getStringByName promise error is " + error); + }); + ``` + +### getStringArrayByName9+ + +getStringArrayByName(resName: string, callback: AsyncCallback<Array<string>>): void + +Obtains the string array corresponding to the specified resource name. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | ----------------- | +| resName | string | Yes | Resource name. | +| callback | AsyncCallback<Array<string>> | Yes | Asynchronous callback used to return the result.| + +**Example** + ``` + resourceManager.getStringArrayByName("test", (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let strArray = value; + } + }); + ``` + +### getStringArrayByName9+ + +getStringArrayByName(resName: string): Promise<Array<string>> + +Obtains the string array corresponding to the specified resource name. This API uses a promise to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ----- | +| resName | string | Yes | Resource name.| + +**Return value** +| Type | Description | +| ---------------------------------- | ------------- | +| Promise<Array<string>> | Promise used to return the result.| + +**Example** + ``` + resourceManager.getStringArrayByName("test").then(value => { + let strArray = value; + }).catch(error => { + console.log("getStringArrayByName promise error is " + error); + }); + ``` + +### getMediaByName9+ + +getMediaByName(resName: string, callback: AsyncCallback<Uint8Array>): void + +Obtains the content of the media file corresponding to the specified resource name. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** +| Name | Type | Mandatory | Description | +| -------- | ------------------------------- | ---- | ------------------ | +| resName | string | Yes | Resource name. | +| callback | AsyncCallback<Uint8Array> | Yes | Asynchronous callback used to return the result.| + +**Example** + ``` + resourceManager.getMediaByName("test", (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let media = value; + } + }); + ``` + +### getMediaByName9+ + +getMediaByName(resName: string): Promise<Uint8Array> + +Obtains the content of the media file corresponding to the specified resource name. This API uses a promise to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----- | +| resName | string | Yes | Resource name.| + +**Return value** +| Type | Description | +| ------------------------- | -------------- | +| Promise<Uint8Array> | Promise used to return the result.| + +**Example** + ``` + resourceManager.getMediaByName("test").then(value => { + let media = value; + }).catch(error => { + console.log("getMediaByName promise error is " + error); + }); + ``` + +### getMediaBase64ByName9+ + +getMediaBase64ByName(resName: string, callback: AsyncCallback<string>): void + +Obtains the Base64 code of the image corresponding to the specified resource name. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | ------------------------ | +| resName | string | Yes | Resource name. | +| callback | AsyncCallback<string> | Yes | Asynchronous callback used to return the result.| + +**Example** + ``` + resourceManager.getMediaBase64ByName("test", (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let media = value; + } }); ``` + +### getMediaBase64ByName9+ + +getMediaBase64ByName(resName: string): Promise<string> + +Obtains the Base64 code of the image corresponding to the specified resource name. This API uses a promise to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ----- | +| resName | string | Yes | Resource name.| + +**Return value** +| Type | Description | +| --------------------- | -------------------- | +| Promise<string> | Promise used to return the result.| + +**Example** + ``` + resourceManager.getMediaByName("test").then(value => { + let media = value; + }).catch(error => { + console.log("getMediaBase64ByName promise error is " + error); + }); + ``` + +### getPluralStringByName9+ + +getPluralStringByName(resName: string, num: number, callback: AsyncCallback<string>): void + +Obtains the plural string corresponding to the specified resource name. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | ------------------------------- | +| resName | string | Yes | Resource name. | +| num | number | Yes | Number that determines the plural or singular form. | +| callback | AsyncCallback<string> | Yes | Asynchronous callback used to return the result.| + +**Example** + ``` + resourceManager.getPluralStringByName("test", 1, (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let str = value; + } + }); + ``` + +### getPluralStringByName9+ + +getPluralStringByName(resName: string, num: number): Promise<string> + +Obtains the plural string corresponding to the specified resource name. This API uses a promise to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ----- | +| resName | string | Yes | Resource name.| +| num | number | Yes | Number that determines the plural or singular form. | + +**Return value** +| Type | Description | +| --------------------- | ------------------------- | +| Promise<string> | Promise used to return the result.| + +**Example** + ``` + resourceManager.getPluralStringByName("test", 1).then(value => { + let str = value; + }).catch(error => { + console.log("getPluralStringByName promise error is " + error); + }); + ``` + +### getStringSync9+ + +getStringSync(resId: number): string + +Obtains the string corresponding to the specified resource ID. This API returns the result synchronously. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----- | +| resId | number | Yes | Resource ID.| + +**Return value** +| Type | Description | +| --------------------- | ----------- | +| string | String corresponding to the specified resource ID.| + +**Example** + ``` + resourceManager.getStringSync($r('app.string.test').id); + ``` + +### getStringByNameSync9+ + +getStringByNameSync(resName: string): string + +Obtains the string corresponding to the specified resource name. This API returns the result synchronously. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----- | +| resName | string | Yes | Resource name.| + +**Return value** +| Type | Description | +| --------------------- | ----------- | +| string | String corresponding to the resource name.| + +**Example** + ``` + resourceManager.getStringByNameSync("test"); + ``` + + ### getBoolean9+ + +getBoolean(resId: number): boolean + +Obtains the Boolean result corresponding to the specified resource ID. This API returns the result synchronously. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----- | +| resId | number | Yes | Resource ID.| + +**Return value** +| Type | Description | +| --------------------- | ----------- | +| boolean | Boolean result corresponding to the specified resource ID.| + +**Example** + ``` + resourceManager.getBoolean($r('app.boolean.boolean_test').id); + ``` + +### getBooleanByName9+ + +getBooleanByName(resName: string): boolean + +Obtains the Boolean result corresponding to the specified resource name. This API returns the result synchronously. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ----- | +| resName | string | Yes | Resource name.| + +**Return value** +| Type | Description | +| --------------------- | ----------- | +| boolean | Boolean result corresponding to the specified resource name.| + +**Example** + ``` + resourceManager.getBooleanByName("boolean_test"); + ``` + + ### getNumber9+ + +getNumber(resId: number): number + +Obtains the integer or float value corresponding to the specified resource ID. This API returns the result synchronously. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----- | +| resId | number | Yes | Resource ID.| + +**Return value** +| Type | Description | +| --------------------- | ----------- | +| number | Integer or float value corresponding to the specified resource ID.| + +**Example** + ``` + resourceManager.getNumber($r('app.integer.integer_test').id); + resourceManager.getNumber($r('app.float.float_test').id); + ``` + +### getNumberByName9+ + +getNumberByName(resName: string): number + +Obtains the integer or float value corresponding to the specified resource name. This API returns the result synchronously. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----- | +| resName | string | Yes | Resource name.| + +**Return value** +| Type | Description | +| --------------------- | ----------- | +| number | Integer or float value corresponding to the specified resource name.| + +**Example** + ``` + resourceManager.getNumberByName("integer_test"); + resourceManager.getNumberByName("float_test"); + ``` diff --git a/en/application-dev/reference/apis/js-apis-system-configuration.md b/en/application-dev/reference/apis/js-apis-system-configuration.md index d1564c4213f98d48187231dbdd960561b10f27c7..a46571ff7fc4caf83fface874c561e75529584c1 100644 --- a/en/application-dev/reference/apis/js-apis-system-configuration.md +++ b/en/application-dev/reference/apis/js-apis-system-configuration.md @@ -17,7 +17,7 @@ import configuration from '@system.configuration'; ## configuration.getLocale -getLocale(): LocaleResponse +static getLocale(): LocaleResponse Obtains the current locale of the application, which is the same as the system locale.