diff --git a/en/application-dev/dfx/apprecovery-guidelines.md b/en/application-dev/dfx/apprecovery-guidelines.md index 0e4e7c257cbde0853a36bd8a3729ee707a4b2391..b2992e7c9958f0a1ffd87db9e4549bf0187bad78 100644 --- a/en/application-dev/dfx/apprecovery-guidelines.md +++ b/en/application-dev/dfx/apprecovery-guidelines.md @@ -17,7 +17,7 @@ The application recovery APIs are provided by the **appRecovery** module, which | API | Description | | ------------------------------------------------------------ | ------------------------------------------------------------ | -| enableAppRecovery(restart?: RestartFlag, saveOccasion?: SaveOccasionFlag, saveMode?: SaveModeFlag) : void; | Enables the application recovery function. | +| enableAppRecovery(restart?: RestartFlag, saveOccasion?: SaveOccasionFlag, saveMode?: SaveModeFlag) : void; | Enables the application recovery function. | | saveAppState(): boolean; | Saves the ability status of an application. | | restartApp(): void; | Restarts the current process. If there is saved ability status, it will be passed to the **want** parameter's **wantParam** attribute of the **onCreate** lifecycle callback of the ability.| diff --git a/en/application-dev/faqs/faqs-dfx.md b/en/application-dev/faqs/faqs-dfx.md index ec1c8dbfedd5fa3c087c96d54c9c2aab73d75e8a..9fc12a1b1c26e109240702cca50e50b77495bdf5 100644 --- a/en/application-dev/faqs/faqs-dfx.md +++ b/en/application-dev/faqs/faqs-dfx.md @@ -6,7 +6,7 @@ Applicable to: OpenHarmony SDK 3.2.5.5 1. Locate the crash-related code based on the service log. -2. View the error information in the crash file. The crash file is located at **/data/log/faultlog/faultlogger/**. +2. View the error information in the crash file, which is located at **/data/log/faultlog/faultlogger/**. ## Why cannot access controls in the UiTest test framework? diff --git a/en/application-dev/faqs/faqs-language.md b/en/application-dev/faqs/faqs-language.md index 4c0a6cba384f4e94832a6a4a933aebeee4b2f364..db7e95d5ede5c3bead52e16bceb16e90c6188b79 100644 --- a/en/application-dev/faqs/faqs-language.md +++ b/en/application-dev/faqs/faqs-language.md @@ -51,9 +51,9 @@ build() { Applicable to: OpenHarmony SDK 3.2.2.5, stage model of API version 9 -1. Obtain data in Uint8Array format by calling the **RawFile** API of **resourceManager**. +1. Obtain Uint8Array data by calling the **RawFile** API of **resourceManager**. -2. Convert data in Uint8Array format to the string type by calling the **String.fromCharCode** API. +2. Convert the Uint8Array data to strings by calling the **String.fromCharCode** API. Reference: [Resource Manager](../reference/apis/js-apis-resource-manager.md) diff --git a/en/application-dev/media/image.md b/en/application-dev/media/image.md index 048716dfdcd76d0e35f4ed3ad70a5eeb266ac8cc..fb4e648b56839ef76cb0e5277443605734d7ab6f 100644 --- a/en/application-dev/media/image.md +++ b/en/application-dev/media/image.md @@ -19,112 +19,121 @@ const color = new ArrayBuffer(96); // Create a buffer to store image pixel data. let opts = { alphaType: 0, editable: true, pixelFormat: 4, scaleMode: 1, size: { height: 2, width: 3 } } // Image pixel data. // Create a PixelMap object. -const color = new ArrayBuffer(96); -let opts = { alphaType: 0, editable: true, pixelFormat: 4, scaleMode: 1, size: { height: 2, width: 3 } } image.createPixelMap(color, opts, (err, pixelmap) => { console.log('Succeeded in creating pixelmap.'); -}) - -// Read pixels. -const area = { - pixels: new ArrayBuffer(8), - offset: 0, - stride: 8, - region: { size: { height: 1, width: 2 }, x: 0, y: 0 } -} -pixelmap.readPixels(area,() => { - var bufferArr = new Uint8Array(area.pixels); - var res = true; - for (var i = 0; i < bufferArr.length; i++) { - console.info(' buffer ' + bufferArr[i]); - if(res) { - if(bufferArr[i] == 0) { - res = false; - console.log('readPixels end.'); - break; - } - } + // Failed to create the PixelMap object. + if (err) { + console.info('create pixelmap failed, err' + err); + return } -}) - -// Store pixels. -const readBuffer = new ArrayBuffer(96); -pixelmap.readPixelsToBuffer(readBuffer,() => { - var bufferArr = new Uint8Array(readBuffer); - var res = true; - for (var i = 0; i < bufferArr.length; i++) { - if(res) { - if (bufferArr[i] !== 0) { - res = false; - console.log('readPixelsToBuffer end.'); - break; - } - } + + // Read pixels. + const area = { + pixels: new ArrayBuffer(8), + offset: 0, + stride: 8, + region: { size: { height: 1, width: 2 }, x: 0, y: 0 } } -}) - -// Write pixels. -pixelmap.writePixels(area,() => { - const readArea = { pixels: new ArrayBuffer(20), offset: 0, stride: 8, region: { size: { height: 1, width: 2 }, x: 0, y: 0 }} - pixelmap.readPixels(readArea,() => { - var readArr = new Uint8Array(readArea.pixels); - var res = true; - for (var i = 0; i < readArr.length; i++) { + pixelmap.readPixels(area,() => { + let bufferArr = new Uint8Array(area.pixels); + let res = true; + for (let i = 0; i < bufferArr.length; i++) { + console.info(' buffer ' + bufferArr[i]); if(res) { - if (readArr[i] !== 0) { + if(bufferArr[i] == 0) { res = false; - console.log('readPixels end.please check buffer'); + console.log('readPixels end.'); break; } } } }) -}) - -// Write pixels to the buffer. -pixelmap.writeBufferToPixels(writeColor).then(() => { + + // Store pixels. const readBuffer = new ArrayBuffer(96); - pixelmap.readPixelsToBuffer(readBuffer).then (() => { - var bufferArr = new Uint8Array(readBuffer); - var res = true; - for (var i = 0; i < bufferArr.length; i++) { + pixelmap.readPixelsToBuffer(readBuffer,() => { + let bufferArr = new Uint8Array(readBuffer); + let res = true; + for (let i = 0; i < bufferArr.length; i++) { if(res) { - if (bufferArr[i] !== i) { + if (bufferArr[i] !== 0) { res = false; - console.log('readPixels end.please check buffer'); + console.log('readPixelsToBuffer end.'); break; } } } }) -}) + + // Write pixels. + pixelmap.writePixels(area,() => { + const readArea = { pixels: new ArrayBuffer(20), offset: 0, stride: 8, region: { size: { height: 1, width: 2 }, x: 0, y: 0 }} + pixelmap.readPixels(readArea,() => { + let readArr = new Uint8Array(readArea.pixels); + let res = true; + for (let i = 0; i < readArr.length; i++) { + if(res) { + if (readArr[i] !== 0) { + res = false; + console.log('readPixels end.please check buffer'); + break; + } + } + } + }) + }) -// Obtain image information. -pixelmap.getImageInfo((error, imageInfo) => { - if (imageInfo !== null) { - console.log('Succeeded in getting imageInfo'); - } -}) + const writeColor = new ArrayBuffer(96); // Pixel data of the image. + // Write pixels to the buffer. + pixelmap.writeBufferToPixels(writeColor).then(() => { + const readBuffer = new ArrayBuffer(96); + pixelmap.readPixelsToBuffer(readBuffer).then (() => { + let bufferArr = new Uint8Array(readBuffer); + let res = true; + for (let i = 0; i < bufferArr.length; i++) { + if(res) { + if (bufferArr[i] !== i) { + res = false; + console.log('readPixels end.please check buffer'); + break; + } + } + } + }) + }) -// Release the PixelMap object. -pixelmap.release(()=>{ - console.log('Succeeded in releasing pixelmap'); + // Obtain image information. + pixelmap.getImageInfo((err, imageInfo) => { + // Failed to obtain the image information. + if (err || imageInfo == null) { + console.info('getImageInfo failed, err' + err); + return + } + if (imageInfo !== null) { + console.log('Succeeded in getting imageInfo'); + } + }) + + // Release the PixelMap object. + pixelmap.release(()=>{ + console.log('Succeeded in releasing pixelmap'); + }) }) // Create an image source (uri). let path = '/data/local/tmp/test.jpg'; -const imageSourceApi = image.createImageSource(path); +const imageSourceApi1 = image.createImageSource(path); // Create an image source (fd). let fd = 29; -const imageSourceApi = image.createImageSource(fd); +const imageSourceApi2 = image.createImageSource(fd); // Create an image source (data). const data = new ArrayBuffer(96); -const imageSourceApi = image.createImageSource(data); +const imageSourceApi3 = image.createImageSource(data); // Release the image source. -imageSourceApi.release(() => { +imageSourceApi3.release(() => { console.log('Succeeded in releasing imagesource'); }) @@ -133,6 +142,10 @@ const imagePackerApi = image.createImagePacker(); const imageSourceApi = image.createImageSource(0); let packOpts = { format:"image/jpeg", quality:98 }; imagePackerApi.packing(imageSourceApi, packOpts, (err, data) => { + if (err) { + console.info('packing from imagePackerApi failed, err' + err); + return + } console.log('Succeeded in packing'); }) @@ -161,36 +174,33 @@ let decodingOptions = { // Create a pixel map in callback mode. imageSourceApi.createPixelMap(decodingOptions, (err, pixelmap) => { + // Failed to create the PixelMap object. + if (err) { + console.info('create pixelmap failed, err' + err); + return + } console.log('Succeeded in creating pixelmap.'); }) // Create a pixel map in promise mode. imageSourceApi.createPixelMap().then(pixelmap => { console.log('Succeeded in creating pixelmap.'); -}) - -// Capture error information when an exception occurs during function invoking. -catch(error => { - console.log('Failed in creating pixelmap.' + error); -}) -// Obtain the number of bytes in each line of pixels. -var num = pixelmap.getBytesNumberPerRow(); + // Obtain the number of bytes in each line of pixels. + let num = pixelmap.getBytesNumberPerRow(); -// Obtain the total number of pixel bytes. -var pixelSize = pixelmap.getPixelBytesNumber(); + // Obtain the total number of pixel bytes. + let pixelSize = pixelmap.getPixelBytesNumber(); -// Obtain the pixel map information. -pixelmap.getImageInfo().then( imageInfo => {}); + // Obtain the pixel map information. + pixelmap.getImageInfo().then( imageInfo => {}); -// Release the PixelMap object. -pixelmap.release(()=>{ - console.log('Succeeded in releasing pixelmap'); -}) - -// Capture release failure information. -catch(error => { - console.log('Failed in releasing pixelmap.' + error); + // Release the PixelMap object. + pixelmap.release(()=>{ + console.log('Succeeded in releasing pixelmap'); + }) +}).catch(error => { + console.log('Failed in creating pixelmap.' + error); }) ``` @@ -216,7 +226,7 @@ if (imagePackerApi == null) { } // Set encoding parameters if the image packer is successfully created. -let packOpts = { format:["image/jpeg"], // The supported encoding format is jpg. +let packOpts = { format:"image/jpeg", // The supported encoding format is jpg. quality:98 } // Image quality, which ranges from 0 to 100. // Encode the image. @@ -233,8 +243,9 @@ imageSourceApi.getImageInfo((err, imageInfo) => { console.log('Succeeded in getting imageInfo'); }) +const array = new ArrayBuffer(100); // Incremental data. // Update incremental data. -imageSourceIncrementalSApi.updateData(array, false, 0, 10,(error, data)=> {}) +imageSourceApi.updateData(array, false, 0, 10,(error, data)=> {}) ``` @@ -246,10 +257,15 @@ Example scenario: The camera functions as the client to transmit image data to t public async init(surfaceId: any) { // (Server code) Create an ImageReceiver object. - var receiver = image.createImageReceiver(8 * 1024, 8, image.ImageFormat.JPEG, 1); + let receiver = image.createImageReceiver(8 * 1024, 8, image.ImageFormat.JPEG, 1); // Obtain the surface ID. receiver.getReceivingSurfaceId((err, surfaceId) => { + // Failed to obtain the surface ID. + if (err) { + console.info('getReceivingSurfaceId failed, err' + err); + return + } console.info("receiver getReceivingSurfaceId success"); }); // Register a surface listener, which is triggered after the buffer of the surface is ready. diff --git a/en/application-dev/quick-start/arkts-basic-ui-description.md b/en/application-dev/quick-start/arkts-basic-ui-description.md index d20efe12859e944d9d78fb71688dc4aada729228..4ef7f97c280d7fcac0771a304359e58c26183d34 100644 --- a/en/application-dev/quick-start/arkts-basic-ui-description.md +++ b/en/application-dev/quick-start/arkts-basic-ui-description.md @@ -15,7 +15,7 @@ In ArkTS, you define a custom component by using decorators **@Component** and * } ``` -- **build** function: a function that complies with the **Builder** API definition and is used to define the declarative UI description of components. A **build** function must be defined for custom components, and custom constructors are prohibited for custom components. +- **build** function: A custom component must implement the **build** function and must implement no constructor. The **build** function meets the definition of the **Builder** API and is used to define the declarative UI description of components. ```ts interface Builder { @@ -49,9 +49,9 @@ Column() { } ``` -### Structs with Mandatory Parameters +### Structs with Parameters -A struct with mandatory parameters is a component whose API definition expects parameters enclosed in the parentheses. You can use constants to assign values to the parameters. +A struct with parameters is a component whose API definition expects parameters enclosed in the parentheses. You can use constants to assign values to the parameters. Sample code: @@ -61,7 +61,7 @@ Sample code: Image('https://xyz/test.jpg') ``` -- Set the mandatory parameter **content** of the **\** component as follows: +- Set the optional parameter **content** of the **\** component as follows: ```ts Text('test') @@ -83,35 +83,35 @@ Component attributes are configured using an attribute method, which follows the ```ts Text('test') - .fontSize(12) + .fontSize(12) ``` - Example of configuring multiple attributes at the same time by using the "**.**" operator to implement chain call: ```ts Image('test.jpg') - .alt('error.jpg') - .width(100) - .height(100) + .alt('error.jpg') + .width(100) + .height(100) ``` - Example of passing variables or expressions in addition to constants: ```ts Text('hello') - .fontSize(this.size) + .fontSize(this.size) Image('test.jpg') - .width(this.count % 2 === 0 ? 100 : 200) - .height(this.offset + 100) + .width(this.count % 2 === 0 ? 100 : 200) + .height(this.offset + 100) ``` - For attributes of built-in components, ArkUI also provides some predefined [enumeration types](../reference/arkui-ts/ts-appendix-enums.md), which you can pass as parameters to methods if they meet the parameter type requirements. For example, you can configure the font color and weight attributes of the **\** component as follows: ```ts Text('hello') - .fontSize(20) - .fontColor(Color.Red) - .fontWeight(FontWeight.Bold) + .fontSize(20) + .fontColor(Color.Red) + .fontWeight(FontWeight.Bold) ``` ### Event Configuration @@ -123,7 +123,7 @@ Events supported by components are configured using event methods, which each fo ```ts Button('add counter') .onClick(() => { - this.counter += 2 + this.counter += 2; }) ``` @@ -132,7 +132,7 @@ Events supported by components are configured using event methods, which each fo ```ts Button('add counter') .onClick(function () { - this.counter += 2 + this.counter += 2; }.bind(this)) ``` @@ -140,13 +140,13 @@ Events supported by components are configured using event methods, which each fo ```ts myClickHandler(): void { - this.counter += 2 + this.counter += 2; } ... - + Button('add counter') - .onClick(this.myClickHandler) + .onClick(this.myClickHandler.bind(this)) ``` ### Child Component Configuration @@ -158,11 +158,11 @@ For a component that supports child components, for example, a container compone ```ts Column() { Text('Hello') - .fontSize(100) + .fontSize(100) Divider() Text(this.myText) - .fontSize(100) - .fontColor(Color.Red) + .fontSize(100) + .fontColor(Color.Red) } ``` @@ -176,10 +176,10 @@ For a component that supports child components, for example, a container compone .height(100) Button('click +1') .onClick(() => { - console.info('+1 clicked!') + console.info('+1 clicked!'); }) } - + Divider() Row() { Image('test2.jpg') @@ -187,10 +187,10 @@ For a component that supports child components, for example, a container compone .height(100) Button('click +2') .onClick(() => { - console.info('+2 clicked!') + console.info('+2 clicked!'); }) } - + Divider() Row() { Image('test3.jpg') @@ -198,7 +198,7 @@ For a component that supports child components, for example, a container compone .height(100) Button('click +3') .onClick(() => { - console.info('+3 clicked!') + console.info('+3 clicked!'); }) } } diff --git a/en/application-dev/quick-start/resource-categories-and-access.md b/en/application-dev/quick-start/resource-categories-and-access.md index d1d342fe74eaed80516a7ca554cbe84f84ad927c..b79359a99ee1f7ecf434a7858a7ee1999b9af5d5 100644 --- a/en/application-dev/quick-start/resource-categories-and-access.md +++ b/en/application-dev/quick-start/resource-categories-and-access.md @@ -230,27 +230,27 @@ When referencing resources in the **rawfile** subdirectory, use the **"$rawfile( > > The return value of **$r** is a **Resource** object. You can obtain the corresponding string by using the [getStringValue](../reference/apis/js-apis-resource-manager.md) API. -In the **.ets** file, you can use the resources defined in the **resources** directory. +In the **.ets** file, you can use the resources defined in the **resources** directory. The following is a resource usage example based on the resource file examples in [Resource Group Sub-directories](#resource-group-subdirectories): ```ts Text($r('app.string.string_hello')) - .fontColor($r('app.color.color_hello')) - .fontSize($r('app.float.font_hello')) -} + .fontColor($r('app.color.color_hello')) + .fontSize($r('app.float.font_hello')) Text($r('app.string.string_world')) - .fontColor($r('app.color.color_world')) - .fontSize($r('app.float.font_world')) -} - -Text($r('app.string.message_arrive', "five of the clock")) // Reference string resources. The second parameter of $r is used to replace %s. - .fontColor($r('app.color.color_hello')) - .fontSize($r('app.float.font_hello')) -} - -Text($r('app.plural.eat_apple', 5, 5)) // Reference plural resources. The first parameter indicates the plural resource, the second parameter indicates the number of plural resources, and the third parameter indicates the substitute of %d. - .fontColor($r('app.color.color_world')) - .fontSize($r('app.float.font_world')) + .fontColor($r('app.color.color_world')) + .fontSize($r('app.float.font_world')) + +// Reference string resources. The second parameter of $r is used to replace %s, and value is "We will arrive at five'o clock". +Text($r('app.string.message_arrive', "five'o clock")) + .fontColor($r('app.color.color_hello')) + .fontSize($r('app.float.font_hello')) + +// Reference plural resources. The first parameter indicates the plural resource, the second parameter indicates the number of plural resources, and the third parameter indicates the substitute of %d. +// The value is "5 apple" in singular form and "5 apples" in plural form. +Text($r('app.plural.eat_apple', 5, 5)) + .fontColor($r('app.color.color_world')) + .fontSize($r('app.float.font_world')) } Image($r('app.media.my_background_image')) // Reference media resources. @@ -274,14 +274,20 @@ To reference a system resource, use the **"$r('sys.type.resource_id')"** format. ```ts Text('Hello') - .fontColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize($r('sys.float.ohos_id_text_size_headline1')) - .fontFamily($r('sys.string.ohos_id_text_font_family_medium')) - .backgroundColor($r('sys.color.ohos_id_color_palette_aux1')) + .fontColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize($r('sys.float.ohos_id_text_size_headline1')) + .fontFamily($r('sys.string.ohos_id_text_font_family_medium')) + .backgroundColor($r('sys.color.ohos_id_color_palette_aux1')) + Image($r('sys.media.ohos_app_icon')) - .border({color: $r('sys.color.ohos_id_color_palette_aux1'), radius: $r('sys.float.ohos_id_corner_radius_button'), width: 2}) - .margin({top: $r('sys.float.ohos_id_elements_margin_horizontal_m'), bottom: $r('sys.float.ohos_id_elements_margin_horizontal_l')}) - .height(200) - .width(300) + .border({ + color: $r('sys.color.ohos_id_color_palette_aux1'), + radius: $r('sys.float.ohos_id_corner_radius_button'), width: 2 + }) + .margin({ + top: $r('sys.float.ohos_id_elements_margin_horizontal_m'), + bottom: $r('sys.float.ohos_id_elements_margin_horizontal_l') + }) + .height(200) + .width(300) ``` - diff --git a/en/application-dev/reference/apis/js-apis-call.md b/en/application-dev/reference/apis/js-apis-call.md index 56596e1ffdb8e011627fa026240375ce1094d9ea..82741c1432d9d4fd9c5babef17548bb643cf2dd9 100644 --- a/en/application-dev/reference/apis/js-apis-call.md +++ b/en/application-dev/reference/apis/js-apis-call.md @@ -55,7 +55,7 @@ Initiates a call based on the specified options. This API uses an asynchronous c | Name | Type | Mandatory | Description | | ----------- | ---------------------------- | ---- | --------------------------------------- | | phoneNumber | string | Yes | Phone number. | -| options | [DialOptions](#dialoptions) | Yes | Call option, which indicates whether the call is a voice call or video call. | +| options | [DialOptions](#dialoptions) | No | Call option, which indicates whether the call is a voice call or video call. | | callback | AsyncCallback<boolean> | Yes | Callback used to return the result.
- **true**: success
- **false**: failure | **Example** @@ -313,7 +313,7 @@ Checks whether the called number is an emergency number based on the specified p | Name | Type | Mandatory | Description | | ----------- | -------------------------------------------------- | ---- | -------------------------------------------- | | phoneNumber | string | Yes | Phone number. | -| options | [EmergencyNumberOptions](#emergencynumberoptions7) | Yes | Phone number options. | +| options | [EmergencyNumberOptions](#emergencynumberoptions7) | No | Phone number options. | | callback | AsyncCallback<boolean> | Yes | Callback used to return the result.
- **true**: The called number is an emergency number.
- **false**: The called number is not an emergency number. | **Example** @@ -397,7 +397,7 @@ A formatted phone number is a standard numeric string, for example, 555 0100. | Name | Type | Mandatory | Description | | ----------- | -------------------------------------------- | ---- | ------------------------------------ | | phoneNumber | string | Yes | Phone number. | -| options | [NumberFormatOptions](#numberformatoptions7) | Yes | Number formatting options, for example, country code. | +| options | [NumberFormatOptions](#numberformatoptions7) | No | Number formatting options, for example, country code. | | callback | AsyncCallback<string> | Yes | Callback used to return the result. | **Example** @@ -566,33 +566,6 @@ promise.then(data => { }); ``` -## call.answer7+ - -answer\(callback: AsyncCallback\): void - -Answers a call. This API uses an asynchronous callback to return the result. - -This is a system API. - -**Required permission**: ohos.permission.ANSWER_CALL - -**System capability**: SystemCapability.Telephony.CallManager - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ------------------------- | ---- | ---------- | -| callback | AsyncCallback<void> | Yes | Callback used to return the result.| - -**Example** - -```js -call.answer((err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); -}); -``` - - ## call.answer7+ answer\(callId: number, callback: AsyncCallback\): void @@ -658,7 +631,7 @@ promise.then(data => { ## call.hangup7+ -hangup\(callback: AsyncCallback\): void +hangup\(callId: number, callback: AsyncCallback\): void Ends a call. This API uses an asynchronous callback to return the result. @@ -672,22 +645,23 @@ This is a system API. | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | +| callId | number | Yes | Call ID. You can obtain the value by subscribing to **callDetailsChange** events.| | callback | AsyncCallback<void> | Yes | Callback used to return the result.| **Example** ```js -call.hangup((err, data) => { +call.hangup(1, (err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); ``` -## call.hangup7+ +## call.answer9+ -hangup\(callId: number, callback: AsyncCallback\): void +answer\(callback: AsyncCallback\): void -Ends a call based on the specified call ID. This API uses an asynchronous callback to return the result. +Answers a call.This API uses an asynchronous callback to return the result. This is a system API. @@ -699,13 +673,12 @@ This is a system API. | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ----------------------------------------------- | -| callId | number | Yes | Call ID. You can obtain the value by subscribing to **callDetailsChange** events.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```js -call.hangup(1, (err, data) => { +call.answer((err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); ``` @@ -746,11 +719,11 @@ promise.then(data => { }); ``` -## call.reject7+ +## call.hangup9+ -reject\(callback: AsyncCallback\): void +hangup\(callback: AsyncCallback\): void -Rejects a call. This API uses an asynchronous callback to return the result. +Ends a call. This API uses an asynchronous callback to return the result. This is a system API. @@ -767,38 +740,7 @@ This is a system API. **Example** ```js -call.reject((err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); -}); -``` - - -## call.reject7+ - -reject\(options: RejectMessageOptions, callback: AsyncCallback\): void - -Rejects a call based on the specified options. This API uses an asynchronous callback to return the result. - -This is a system API. - -**Required permission**: ohos.permission.ANSWER_CALL - -**System capability**: SystemCapability.Telephony.CallManager - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ---------------------------------------------- | ---- | -------------- | -| options | [RejectMessageOptions](#rejectmessageoptions7) | Yes | Options for the call rejection message.| -| callback | AsyncCallback<void> | Yes | Callback used to return the result. | - -**Example** - -```js -let rejectMessageOptions={ - messageContent: "Unknown number blocked" -} -call.reject(rejectMessageOptions, (err, data) => { +call.hangup((err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); ``` @@ -903,6 +845,65 @@ promise.then(data => { }); ``` + +## call.reject9+ + +reject\(callback: AsyncCallback\): void + +Rejects a call. This API uses an asynchronous callback to return the result. + +This is a system API. + +**Required permission**: ohos.permission.ANSWER_CALL + +**System capability**: SystemCapability.Telephony.CallManager + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ---------- | +| callback | AsyncCallback<void> | Yes | Callback used to return the result.| + +**Example:** + +```js +call.reject((err, data) => { + console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +}); +``` + + +## call.reject9+ + +reject\(options: RejectMessageOptions, callback: AsyncCallback\): void + +Rejects a call. This API uses an asynchronous callback to return the result. + +This is a system API. + +**Required permission**: ohos.permission.ANSWER_CALL + +**System capability**: SystemCapability.Telephony.CallManager + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ---------------------------------------------- | ---- | -------------- | +| options | [RejectMessageOptions](#rejectmessageoptions7) | Yes | Options for the call rejection message.| +| callback | AsyncCallback<void> | Yes | Callback used to return the result. | + +**Example:** + +```js +let rejectMessageOptions={ + messageContent: "Unknown number blocked" +} +call.reject(rejectMessageOptions, (err, data) => { + console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +}); +``` + + ## call.holdCall7+ holdCall\(callId: number, callback: AsyncCallback\): void @@ -1344,8 +1345,8 @@ This is a system API. | Name | Type | Mandatory| Description | | -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | -| slotId | number | Yes | Card slot ID.
- **0**: card slot 1
- **1**: card slot 2 | -| callback | AsyncCallback<[CallWaitingStatus](#callwaitingstatus7)\> | Yes | Callback used to return the result.

- **0**: Call waiting is disabled.
- **1**: Call waiting is enabled.| +| slotId | number | Yes | Card slot ID.
- **0**: card slot 1
- **1**: card slot 2 | +| callback | AsyncCallback<[CallWaitingStatus](#callwaitingstatus7)\> | Yes | Callback used to return the result.
- **0**: Call waiting is disabled.
- **1**: Call waiting is enabled.| **Example** @@ -2399,7 +2400,7 @@ promise.then(data => { }); ``` -## call.setAudioDevice8+ +## call.setAudioDevice9+ setAudioDevice\(device: AudioDevice, callback: AsyncCallback\): void @@ -2425,7 +2426,7 @@ call.setAudioDevice(1, (err, data) => { ``` -## call.setAudioDevice8+ +## call.setAudioDevice9+ setAudioDevice\(device: AudioDevice, options: AudioDeviceOptions, callback: AsyncCallback\): void diff --git a/en/application-dev/reference/apis/js-apis-i18n.md b/en/application-dev/reference/apis/js-apis-i18n.md index e990ecf8126054b0de5ad52308c4f83843782d97..08bf0cfe66b40f46262765048463081b9c1a66a6 100644 --- a/en/application-dev/reference/apis/js-apis-i18n.md +++ b/en/application-dev/reference/apis/js-apis-i18n.md @@ -1,13 +1,10 @@ # Internationalization – I18N - This module provides system-related or enhanced I18N capabilities, such as locale management, phone number formatting, and calendar, through supplementary I18N APIs that are not defined in ECMA 402. +The I18N module provides system-related or enhanced I18N capabilities, such as locale management, phone number formatting, and calendar, through supplementary I18N APIs that are not defined in ECMA 402. The [Intl](js-apis-intl.md) module provides basic I18N capabilities through the standard I18N APIs defined in ECMA 402. It works with the I18N module to provide a complete suite of I18N capabilities. > **NOTE** -> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. -> -> - This module provides system-related or enhanced I18N capabilities, such as locale management, phone number formatting, and calendar, through supplementary I18N APIs that are not defined in ECMA 402. For details about the basic I18N capabilities, see [Intl](js-apis-intl.md). - +> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. ## Modules to Import @@ -247,9 +244,9 @@ This is a system API. **Parameters** -| Name | Type | Description | -| -------- | ------ | ----- | -| language | string | Language ID.| +| Name | Type | Mandatory | Description | +| -------- | ------ | ----- | ----- | +| language | string | Yes | Language ID.| **Error codes** @@ -313,9 +310,9 @@ This is a system API. **Parameters** -| Name | Type | Description | -| ------ | ------ | ----- | -| region | string | Region ID.| +| Name | Type | Mandatory | Description | +| -------- | ------ | ----- | ----- | +| region | string | Yes | Region ID.| **Error codes** @@ -379,9 +376,9 @@ This is a system API. **Parameters** -| Name | Type | Description | -| ------ | ------ | --------------- | -| locale | string | System locale ID, for example, **zh-CN**.| +| Name | Type | Mandatory | Description | +| -------- | ------ | ----- | ----- | +| locale | string | Yes | System locale ID, for example, **zh-CN**.| **Error codes** @@ -713,9 +710,9 @@ Checks whether the localized script for the specified language is displayed from **Parameters** -| Name | Type | Description | -| ------ | ------ | ------- | -| locale | string | Locale ID.| +| Name | Type | Mandatory | Description | +| -------- | ------ | ----- | ----- | +| locale | string | Yes | Locale ID.| **Return value** @@ -905,7 +902,7 @@ Sets the start day of a week for this **Calendar** object. | Name | Type | Mandatory | Description | | ----- | ------ | ---- | --------------------- | -| value | number | No | Start day of a week. The value **1** indicates Sunday, and the value **7** indicates Saturday.| +| value | number | Yes | Start day of a week. The value **1** indicates Sunday, and the value **7** indicates Saturday.| **Example** ```js @@ -947,7 +944,7 @@ Sets the minimum number of days in the first week of a year. | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ------------ | -| value | number | No | Minimum number of days in the first week of a year.| +| value | number | Yes | Minimum number of days in the first week of a year.| **Example** ```js diff --git a/en/application-dev/reference/apis/js-apis-inputmethod-subtype.md b/en/application-dev/reference/apis/js-apis-inputmethod-subtype.md index 3db933a52a6f940e8d25a324d0fef7131330bc9f..61ec49997ccb35b204f860e57b0985793598e071 100644 --- a/en/application-dev/reference/apis/js-apis-inputmethod-subtype.md +++ b/en/application-dev/reference/apis/js-apis-inputmethod-subtype.md @@ -1,6 +1,6 @@ -# Input Method Subtype +# @ohos.inputmethodsubtype -The **inputMethodEngine** module provides APIs for managing the attributes of input method subtypes. Different attribute settings result in different subtypes. +The **inputMethodSubtype** module provides APIs for managing the attributes of input method subtypes. Different attribute settings result in different subtypes. > **NOTE** > diff --git a/en/application-dev/reference/apis/js-apis-inputmethod.md b/en/application-dev/reference/apis/js-apis-inputmethod.md index 857bc3fd17b1fc4a29eda9c2e0185dfa11163702..424e48b357711a7ee94eb4b048f107d7ad4c7a3d 100644 --- a/en/application-dev/reference/apis/js-apis-inputmethod.md +++ b/en/application-dev/reference/apis/js-apis-inputmethod.md @@ -1,15 +1,15 @@ -# Input Method Framework +# @ohos.inputmethod The **inputMethod** module provides an input method framework, which can be used to hide the keyboard, obtain the list of installed input methods, display the dialog box for input method selection, and more. ->**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. +> 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. ## Modules to Import -``` +```js import inputMethod from '@ohos.inputmethod'; ``` @@ -31,14 +31,14 @@ Describes the input method application attributes. | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | -| name9+ | string | Yes| No| Internal name of the input method.| -| id9+ | string | Yes| No| Unique ID of the input method.| -| label9+ | string | Yes| No| External display name of the input method.| -| icon9+ | string | Yes| No| Icon of the input method.| -| iconId9+ | number | Yes| No| Icon ID of the input method.| -| extra9+ | object | Yes| No| Extra information about the input method.| -| packageName(deprecated) | string | Yes| No| Name of the input method package.
**NOTE**
This API is supported since API version 8 and deprecated since API version 9. You are advised to use **name**.| -| methodId(deprecated) | string | Yes| No| Unique ID of the input method.
**NOTE**
This API is supported since API version 8 and deprecated since API version 9. You are advised to use **id**.| +| name9+ | string | Yes| No| Internal name of the input method. Mandatory.| +| id9+ | string | Yes| No| Unique ID of the input method. Mandatory.| +| label9+ | string | Yes| No| External display name of the input method. Optional.| +| icon9+ | string | Yes| No| Icon of the input method. Optional.| +| iconId9+ | number | Yes| No| Icon ID of the input method. Optional.| +| extra9+ | object | Yes| Yes| Extra information about the input method. Mandatory.| +| packageName(deprecated) | string | Yes| No| Name of the input method package. Mandatory.
**NOTE**
This API is supported since API version 8 and deprecated since API version 9. You are advised to use **name**.| +| methodId(deprecated) | string | Yes| No| Unique ID of the input method. Mandatory.
**NOTE**
This API is supported since API version 8 and deprecated since API version 9. You are advised to use **id**.| ## inputMethod.getController9+ @@ -102,7 +102,7 @@ switchInputMethod(target: InputMethodProperty, callback: AsyncCallback<boolea Switches to another input method. This API uses an asynchronous callback to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -120,25 +120,33 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js +let im = inputMethod.getCurrentInputMethod(); +let prop = { + packageName: im.packageName, + methodId: im.methodId, + name: im.packageName, + id: im.methodId, + extra: {} +} try{ - inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard', extra: {}}, (err, result) => { - if (err) { - console.error('switchInputMethod err: ' + JSON.stringify(err)); + inputMethod.switchInputMethod(prop, (err, result) => { + if (err !== undefined) { + console.error('Failed to switchInputMethod: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to switchInputMethod.(callback)'); + console.info('Succeeded in switching inputmethod.'); } else { - console.error('Failed to switchInputMethod.(callback)'); + console.error('Failed to switchInputMethod.'); } }); } catch(err) { - console.error('switchInputMethod err: ' + JSON.stringify(err)); + console.error('Failed to switchInputMethod: ' + JSON.stringify(err)); } ``` ## inputMethod.switchInputMethod9+ @@ -146,7 +154,7 @@ switchInputMethod(target: InputMethodProperty): Promise<boolean> Switches to another input method. This API uses a promise to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -169,23 +177,31 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js +let im = inputMethod.getCurrentInputMethod(); +let prop = { + packageName: im.packageName, + methodId: im.methodId, + name: im.packageName, + id: im.methodId, + extra: {} +} try { - inputMethod.switchInputMethod({packageName:'com.example.kikakeyboard', methodId:'com.example.kikakeyboard', extra: {}}).then((result) => { + inputMethod.switchInputMethod(prop).then((result) => { if (result) { - console.info('Success to switchInputMethod.'); + console.info('Succeeded in switching inputmethod.'); } else { console.error('Failed to switchInputMethod.'); } }).catch((err) => { - console.error('switchInputMethod err: ' + JSON.stringify(err)); + console.error('Failed to switchInputMethod: ' + JSON.stringify(err)); }) } catch(err) { - console.error('switchInputMethod err: ' + JSON.stringify(err)); + console.error('Failed to switchInputMethod: ' + JSON.stringify(err)); } ``` @@ -215,7 +231,7 @@ switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallb Switches to another subtype of the current input method. This API uses an asynchronous callback to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -233,36 +249,35 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js -let inputMethodSubtype = { - id: "com.example.kikakeyboard", - label: "ServiceExtAbility", - name: "", - mode: "upper", - locale: "", - language: "", - icon: "", - iconId: 0, - extra: {} -} try { - inputMethod.switchCurrentInputMethodSubtype(inputMethodSubtype, (err, result) => { - if (err) { - console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err)); + inputMethod.switchCurrentInputMethodSubtype({ + id: "com.example.kikakeyboard", + label: "ServiceExtAbility", + name: "", + mode: "upper", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} + }, (err, result) => { + if (err !== undefined) { + console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to switchCurrentInputMethodSubtype.(callback)'); + console.info('Succeeded in switching currentInputMethodSubtype.'); } else { - console.error('Failed to switchCurrentInputMethodSubtype.(callback)'); + console.error('Failed to switchCurrentInputMethodSubtype'); } }); } catch(err) { - console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err)); + console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err)); } ``` @@ -272,7 +287,7 @@ switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise<boolean& Switches to another subtype of the current input method. This API uses a promise to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -295,34 +310,33 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js -let inputMethodSubtype = { - id: "com.example.kikakeyboard", - label: "ServiceExtAbility", - name: "", - mode: "upper", - locale: "", - language: "", - icon: "", - iconId: 0, - extra: {} -} try { - inputMethod.switchCurrentInputMethodSubtype(inputMethodSubtype).then((result) => { + inputMethod.switchCurrentInputMethodSubtype({ + id: "com.example.kikakeyboard", + label: "ServiceExtAbility", + name: "", + mode: "upper", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} + }).then((result) => { if (result) { - console.info('Success to switchCurrentInputMethodSubtype.'); + console.info('Succeeded in switching currentInputMethodSubtype.'); } else { console.error('Failed to switchCurrentInputMethodSubtype.'); } }).catch((err) => { - console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err)); + console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err)); }) } catch(err) { - console.error('switchCurrentInputMethodSubtype err: ' + JSON.stringify(err)); + console.error('Failed to switchCurrentInputMethodSubtype: ' + JSON.stringify(err)); } ``` @@ -352,7 +366,7 @@ switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inp Switches to a specified subtype of a specified input method. This API uses an asynchronous callback to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -371,41 +385,43 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js +let im = inputMethod.getCurrentInputMethod(); let inputMethodProperty = { - packageName: "com.example.kikakeyboard", - methodId: "ServiceExtAbility", - extra: {} -} -let inputMethodSubProperty = { - id: "com.example.kikakeyboard", - label: "ServiceExtAbility", - name: "", - mode: "upper", - locale: "", - language: "", - icon: "", - iconId: 0, + packageName: im.packageName, + methodId: im.methodId, + name: im.packageName, + id: im.methodId, extra: {} } try { - inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, inputMethodSubProperty, (err,result) => { - if (err) { - console.error('switchCurrentInputMethodAndSubtype err: ' + JSON.stringify(err)); + inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, { + id: "com.example.kikakeyboard", + label: "ServiceExtAbility", + name: "", + mode: "upper", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} + }, (err,result) => { + if (err !== undefined) { + console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to switchCurrentInputMethodAndSubtype.(callback)'); + console.info('Succeeded in switching currentInputMethodAndSubtype.'); } else { - console.error('Failed to switchCurrentInputMethodAndSubtype.(callback)'); + console.error('Failed to switchCurrentInputMethodAndSubtype.'); } }); } catch (err) { - console.error('switchCurrentInputMethodAndSubtype err: ' + JSON.stringify(err)); + console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err)); } ``` @@ -415,7 +431,7 @@ switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inp Switches to a specified subtype of a specified input method. This API uses a promise to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -439,39 +455,41 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800005 | Configuration persisting error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js +let im = inputMethod.getCurrentInputMethod(); let inputMethodProperty = { - packageName: "com.example.kikakeyboard", - methodId: "ServiceExtAbility", - extra: {} -} -let inputMethodSubProperty = { - id: "com.example.kikakeyboard", - label: "ServiceExtAbility", - name: "", - mode: "upper", - locale: "", - language: "", - icon: "", - iconId: 0, + packageName: im.packageName, + methodId: im.methodId, + name: im.packageName, + id: im.methodId, extra: {} } try { - inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, inputMethodSubProperty).then((result) => { + inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, { + id: im.packageName, + label: im.methodId, + name: "", + mode: "upper", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} + }).then((result) => { if (result) { - console.info('Success to switchCurrentInputMethodAndSubtype.'); + console.info('Succeeded in switching currentInputMethodAndSubtype.'); } else { console.error('Failed to switchCurrentInputMethodAndSubtype.'); } }).catch((err) => { - console.error('switchCurrentInputMethodAndSubtype err: ' + err); + console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err)); }) } catch(err) { - console.error('switchCurrentInputMethodAndSubtype err: ' + err); + console.error('Failed to switchCurrentInputMethodAndSubtype: ' + JSON.stringify(err)); } ``` @@ -548,25 +566,25 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800003 | Input method client error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js try { inputMethodController.stopInputSession((error, result) => { - if (error) { - console.error('stopInputSession err: ' + JSON.stringify(error)); + if (error !== undefined) { + console.error('Failed to stopInputSession: ' + JSON.stringify(error)); return; } if (result) { - console.info('Success to stopInputSession.(callback)'); + console.info('Succeeded in stopping inputSession.'); } else { - console.error('Failed to stopInputSession.(callback)'); + console.error('Failed to stopInputSession.'); } }); } catch(error) { - console.error('stopInputSession err: ' + JSON.stringify(error)); + console.error('Failed to stopInputSession: ' + JSON.stringify(error)); } ``` @@ -591,7 +609,7 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800003 | Input method client error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** @@ -599,15 +617,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e try { inputMethodController.stopInputSession().then((result) => { if (result) { - console.info('Success to stopInputSession.'); + console.info('Succeeded in stopping inputSession.'); } else { console.error('Failed to stopInputSession.'); } }).catch((err) => { - console.error('stopInputSession err: ' + JSON.stringify(err)); + console.error('Failed to stopInputSession: ' + JSON.stringify(err)); }) } catch(err) { - console.error('stopInputSession err: ' + JSON.stringify(err)); + console.error('Failed to stopInputSession: ' + JSON.stringify(err)); } ``` @@ -617,7 +635,7 @@ showSoftKeyboard(callback: AsyncCallback<void>): void Shows this soft keyboard. This API must be used with the input text box and works only when the input text box is activated. This API uses an asynchronous callback to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -634,16 +652,16 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800003 | Input method client error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js inputMethodController.showSoftKeyboard((err) => { if (err === undefined) { - console.info('showSoftKeyboard success'); + console.info('Succeeded in showing softKeyboard.'); } else { - console.error('showSoftKeyboard failed because : ' + JSON.stringify(err)); + console.error('Failed to showSoftKeyboard: ' + JSON.stringify(err)); } }) ``` @@ -654,7 +672,7 @@ showSoftKeyboard(): Promise<void> Shows this soft keyboard. This API must be used with the input text box and works only when the input text box is activated. This API uses a promise to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -671,15 +689,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800003 | Input method client error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js -inputMethodController.showSoftKeyboard().then(async (err) => { - console.log('showSoftKeyboard success'); +inputMethodController.showSoftKeyboard().then(() => { + console.log('Succeeded in showing softKeyboard.'); }).catch((err) => { - console.error('showSoftKeyboard err: ' + JSON.stringify(err)); + console.error('Failed to showSoftKeyboard: ' + JSON.stringify(err)); }); ``` @@ -689,7 +707,7 @@ hideSoftKeyboard(callback: AsyncCallback<void>): void Hides this soft keyboard. This API must be used with the input text box and works only when the input text box is activated. This API uses an asynchronous callback to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -706,16 +724,16 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800003 | Input method client error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js inputMethodController.hideSoftKeyboard((err) => { if (err === undefined) { - console.info('hideSoftKeyboard success'); + console.info('Succeeded in hiding softKeyboard.'); } else { - console.error('hideSoftKeyboard failed because : ' + JSON.stringify(err)); + console.error('Failed to hideSoftKeyboard: ' + JSON.stringify(err)); } }) ``` @@ -726,7 +744,7 @@ hideSoftKeyboard(): Promise<void> Hides this soft keyboard. This API must be used with the input text box and works only when the input text box is activated. This API uses a promise to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -743,15 +761,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800003 | Input method client error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js -inputMethodController.hideSoftKeyboard().then(async (err) => { - console.log('hideSoftKeyboard success'); +inputMethodController.hideSoftKeyboard().then(() => { + console.log('Succeeded in hiding softKeyboard.'); }).catch((err) => { - console.error('hideSoftKeyboard err: ' + JSON.stringify(err)); + console.error('Failed to hideSoftKeyboard: ' + JSON.stringify(err)); }); ``` @@ -777,14 +795,14 @@ Ends this input session. The invoking of this API takes effect only after the in ```js inputMethodController.stopInput((error, result) => { - if (error) { - console.error('failed to stopInput because: ' + JSON.stringify(error)); + if (error !== undefined) { + console.error('Failed to stopInput: ' + JSON.stringify(error)); return; } if (result) { - console.info('Success to stopInput.(callback)'); + console.info('Succeeded in stopping input.'); } else { - console.error('Failed to stopInput.(callback)'); + console.error('Failed to stopInput.'); } }); ``` @@ -812,12 +830,12 @@ Ends this input session. The invoking of this API takes effect only after the in ```js inputMethodController.stopInput().then((result) => { if (result) { - console.info('Success to stopInput.'); + console.info('Succeeded in stopping input.'); } else { console.error('Failed to stopInput.'); } }).catch((err) => { - console.error('stopInput err: ' + err); + console.error('Failed to stopInput: ' + err); }) ``` @@ -891,26 +909,28 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800001 | Package manager error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js let inputMethodProperty = { - packageName:'com.example.kikakeyboard', - methodId:'com.example.kikakeyboard', + packageName: 'com.example.kikakeyboard', + methodId: 'com.example.kikakeyboard', + name: 'com.example.kikakeyboard', + id: 'com.example.kikakeyboard', extra:{} } try { inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err,data) => { - if (err) { - console.error('listInputMethodSubtype failed: ' + JSON.stringify(err)); + if (err !== undefined) { + console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err)); return; } - console.log('listInputMethodSubtype success'); + console.log('Succeeded in listing inputMethodSubtype.'); }); } catch (err) { - console.error('listInputMethodSubtype failed: ' + JSON.stringify(err)); + console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err)); } ``` @@ -941,24 +961,26 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800001 | Package manager error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js let inputMethodProperty = { - packageName:'com.example.kikakeyboard', - methodId:'com.example.kikakeyboard', + packageName: 'com.example.kikakeyboard', + methodId: 'com.example.kikakeyboard', + name: 'com.example.kikakeyboard', + id: 'com.example.kikakeyboard', extra:{} } try { inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data) => { - console.info('listInputMethodSubtype success'); + console.info('Succeeded in listing inputMethodSubtype.'); }).catch((err) => { - console.error('listInputMethodSubtype err: ' + JSON.stringify(err)); + console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err)); }) } catch(err) { - console.error('listInputMethodSubtype err: ' + JSON.stringify(err)); + console.error('Failed to listInputMethodSubtype: ' + JSON.stringify(err)); } ``` @@ -983,21 +1005,21 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800001 | Package manager error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js try { inputMethodSetting.listCurrentInputMethodSubtype((err, data) => { - if (err) { - console.error('listCurrentInputMethodSubtype failed: ' + JSON.stringify(err)); + if (err !== undefined) { + console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err)); return; } - console.log('listCurrentInputMethodSubtype success'); + console.log('Succeeded in listing currentInputMethodSubtype.'); }); } catch(err) { - console.error('listCurrentInputMethodSubtype err: ' + JSON.stringify(err)); + console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err)); } ``` @@ -1022,19 +1044,19 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800001 | Package manager error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js try { inputMethodSetting.listCurrentInputMethodSubtype().then((data) => { - console.info('listCurrentInputMethodSubtype success'); + console.info('Succeeded in listing currentInputMethodSubtype.'); }).catch((err) => { - console.error('listCurrentInputMethodSubtype err: ' + err); + console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err)); }) } catch(err) { - console.error('listCurrentInputMethodSubtype err: ' + JSON.stringify(err)); + console.error('Failed to listCurrentInputMethodSubtype: ' + JSON.stringify(err)); } ``` @@ -1060,21 +1082,21 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800001 | Package manager error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js try { inputMethodSetting.getInputMethods(true, (err,data) => { - if (err) { - console.error('getInputMethods failed: ' + JSON.stringify(err)); + if (err !== undefined) { + console.error('Failed to getInputMethods: ' + JSON.stringify(err)); return; } - console.log('getInputMethods success'); + console.log('Succeeded in getting inputMethods.'); }); } catch (err) { - console.error('getInputMethods failed: ' + JSON.stringify(err)); + console.error('Failed to getInputMethods: ' + JSON.stringify(err)); } ``` @@ -1099,7 +1121,7 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | | 12800001 | Package manager error. | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Return value** @@ -1112,12 +1134,12 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js try { inputMethodSetting.getInputMethods(true).then((data) => { - console.info('getInputMethods success'); + console.info('Succeeded in getting inputMethods.'); }).catch((err) => { - console.error('getInputMethods err: ' + JSON.stringify(err)); + console.error('Failed to getInputMethods: ' + JSON.stringify(err)); }) } catch(err) { - console.error('getInputMethods err: ' + JSON.stringify(err)); + console.error('Failed to getInputMethods: ' + JSON.stringify(err)); } ``` @@ -1127,7 +1149,7 @@ showOptionalInputMethods(callback: AsyncCallback<boolean>): void Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -1143,21 +1165,21 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js try { inputMethodSetting.showOptionalInputMethods((err, data) => { - if (err) { - console.error('showOptionalInputMethods failed: ' + JSON.stringify(err)); + if (err !== undefined) { + console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err)); return; } - console.info('showOptionalInputMethods success'); + console.info('Succeeded in showing optionalInputMethods.'); }); } catch (err) { - console.error('showOptionalInputMethods failed: ' + JSON.stringify(err)); + console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err)); } ``` @@ -1167,7 +1189,7 @@ showOptionalInputMethods(): Promise<boolean> Displays a dialog box for selecting an input method. This API uses a promise to return the result. -**Required permissions**: ohos.permission.CONNECT_IME_ABILITY +**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (available only to system applications) **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -1183,15 +1205,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e | Error Code ID| Error Message | | -------- | -------------------------------------- | -| 12800008 | Input method settings extension error. | +| 12800008 | Input method manager service error. | **Example** ```js inputMethodSetting.showOptionalInputMethods().then((data) => { - console.info('displayOptionalInputMethod success.'); + console.info('Succeeded in showing optionalInputMethods.'); }).catch((err) => { - console.error('displayOptionalInputMethod err: ' + err); + console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err)); }) ``` @@ -1217,11 +1239,11 @@ Obtains a list of installed input methods. This API uses an asynchronous callbac ```js inputMethodSetting.listInputMethod((err,data) => { - if (err) { - console.error('listInputMethod failed because: ' + JSON.stringify(err)); + if (err !== undefined) { + console.error('Failed to listInputMethod: ' + JSON.stringify(err)); return; } - console.log('listInputMethod success'); + console.log('Succeeded in listing inputMethod.'); }); ``` @@ -1247,9 +1269,9 @@ Obtains a list of installed input methods. This API uses a promise to return the ```js inputMethodSetting.listInputMethod().then((data) => { - console.info('listInputMethod success'); + console.info('Succeeded in listing inputMethod.'); }).catch((err) => { - console.error('listInputMethod err: ' + JSON.stringify(err)); + console.error('Failed to listInputMethod: ' + JSON.stringify(err)); }) ``` @@ -1275,11 +1297,11 @@ Displays a dialog box for selecting an input method. This API uses an asynchrono ```js inputMethodSetting.displayOptionalInputMethod((err) => { - if (err) { - console.error('displayOptionalInputMethod failed because: ' + JSON.stringify(err)); + if (err !== undefined) { + console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err)); return; } - console.info('displayOptionalInputMethod success'); + console.info('Succeeded in displaying optionalInputMethod.'); }); ``` @@ -1305,8 +1327,8 @@ Displays a dialog box for selecting an input method. This API uses a promise to ```js inputMethodSetting.displayOptionalInputMethod().then(() => { - console.info('displayOptionalInputMethod success'); + console.info('Succeeded in displaying optionalInputMethod.'); }).catch((err) => { - console.error('displayOptionalInputMethod err: ' + err); + console.error('Failed to displayOptionalInputMethod: ' + JSON.stringify(err)); }) ``` diff --git a/en/application-dev/reference/apis/js-apis-inputmethodengine.md b/en/application-dev/reference/apis/js-apis-inputmethodengine.md index d0512b5904dc67fdde8d8c1f85c3b181cb771188..2c87f74698434a68279b5e1c627e2a7352819a38 100644 --- a/en/application-dev/reference/apis/js-apis-inputmethodengine.md +++ b/en/application-dev/reference/apis/js-apis-inputmethodengine.md @@ -1,4 +1,4 @@ -# Input Method Engine +# @ohos.inputmethodengine The **inputMethodEngine** module streamlines the interaction between input methods and applications. By calling APIs of this module, applications can be bound to input method services to accept text input through the input methods, request the keyboard to display or hide, listen for the input method status, and much more. @@ -137,7 +137,7 @@ Obtains a **KeyboardDelegate** instance. **Example** ```js -let KeyboardDelegate = inputMethodEngine.createKeyboardDelegate(); +let keyboardDelegate = inputMethodEngine.createKeyboardDelegate(); ``` ## InputMethodEngine @@ -162,9 +162,9 @@ Enables listening for the input method binding event. This API uses an asynchron **Example** ```js -inputMethodEngine.getInputMethodEngine().on('inputStart', (kbController, textInputClient) => { - KeyboardController = kbController; - TextInputClient = textInputClient; +inputMethodEngine.getInputMethodEngine().on('inputStart', (kbController, textClient) => { + let keyboardController = kbController; + let textInputClient = textClient; }); ``` @@ -229,18 +229,14 @@ Disables listening for a keyboard event. This API uses an asynchronous callback | Name | Type | Mandatory| Description | | -------- | ------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Listening type.
- The value **'keyboardShow'** indicates the keyboard display event.
- The value **'keyboardHide'** indicates the keyboard hiding event. | +| type | string | Yes | Listening type.
- The value **'keyboardShow'** indicates the keyboard display event.
- The value **'keyboardHide'** indicates the keyboard hiding event.| | callback | () => void | No | Callback used to return the result.| **Example** ```js -inputMethodEngine.getInputMethodEngine().off('keyboardShow', () => { - console.log('inputMethodEngine delete keyboardShow notification.'); -}); -inputMethodEngine.getInputMethodEngine().off('keyboardHide', () => { - console.log('inputMethodEngine delete keyboardHide notification.'); -}); +inputMethodEngine.getInputMethodEngine().off('keyboardShow'); +inputMethodEngine.getInputMethodEngine().off('keyboardHide'); ``` ## InputMethodAbility @@ -265,9 +261,9 @@ Enables listening for the input method binding event. This API uses an asynchron **Example** ```js -inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, inputClient) => { - KeyboardController = kbController; - InputClient = inputClient; +inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, client) => { + let keyboardController = kbController; + let inputClient = client; }); ``` @@ -289,9 +285,7 @@ Cancels listening for the input method binding event. This API uses an asynchron **Example** ```js -inputMethodEngine.getInputMethodAbility().off('inputStart', (kbController, inputClient) => { - console.log('delete inputStart notification.'); -}); +inputMethodEngine.getInputMethodAbility().off('inputStart'); ``` ### on('inputStop')9+ @@ -390,7 +384,7 @@ inputMethodEngine.getInputMethodAbility().off('setCallingWindow', () => { on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void -Enables listening for an input method event. This API uses an asynchronous callback to return the result. +Enables listening for a keyboard event. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -398,7 +392,7 @@ Enables listening for an input method event. This API uses an asynchronous callb | Name | Type | Mandatory| Description | | -------- | ------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Listening type.
- The value **'keyboardShow'** indicates the keyboard display event.
- The value **'keyboardHide'** indicates the keyboard hiding event. | +| type | string | Yes | Listening type.
- The value **'keyboardShow'** indicates the keyboard display event.
- The value **'keyboardHide'** indicates the keyboard hiding event.| | callback | () => void | Yes | Callback used to return the result. | **Example** @@ -416,7 +410,7 @@ inputMethodEngine.getInputMethodAbility().on('keyboardHide', () => { off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void -Disables listening for an input method event. This API uses an asynchronous callback to return the result. +Disables listening for a keyboard event. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.InputMethodFramework @@ -602,14 +596,14 @@ Enables listening for the text selection change event. This API uses an asynchro **System capability**: SystemCapability.MiscServices.InputMethodFramework - **Parameters** +**Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | string | Yes | Listening type.
The value **'selectionChange'** indicates the text selection change event.| | callback | (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void | Yes | Callback used to return the text selection information.
- **oldBegin**: start of the selected text before the change.
- **oldEnd**: end of the selected text before the change.
- **newBegin**: start of the selected text after the change.
- **newEnd**: end of the selected text after the change.| - **Example** +**Example** ```js inputMethodEngine.getKeyboardDelegate().on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => { @@ -652,14 +646,14 @@ Enables listening for the text change event. This API uses an asynchronous callb **System capability**: SystemCapability.MiscServices.InputMethodFramework - **Parameters** +**Parameters** | Name | Type | Mandatory| Description | | -------- | ------ | ---- | ------------------------------------------------------------ | | type | string | Yes | Listening type.
The value **'textChange'** indicates the text change event.| | callback | (text: string) => void | Yes | Callback used to return the text content. | - **Example** +**Example** ```js inputMethodEngine.getKeyboardDelegate().on('textChange', (text) => { @@ -719,12 +713,12 @@ For details about the error codes, see [Input Method Framework Error Codes](../e **Example** ```js -KeyboardController.hide((err) => { - if (err === undefined) { - console.error('hide err: ' + JSON.stringify(err)); +keyboardController.hide((err) => { + if (err !== undefined) { + console.error('Failed to hide keyboard: ' + JSON.stringify(err)); return; } - console.log('hide success.'); + console.log('Succeeded in hiding keyboard.'); }); ``` @@ -753,10 +747,10 @@ For details about the error codes, see [Input Method Framework Error Codes](../e **Example** ```js -KeyboardController.hide().then(() => { - console.info('hide success.'); +keyboardController.hide().then(() => { + console.info('Succeeded in hiding keyboard.'); }).catch((err) => { - console.info('hide err: ' + JSON.stringify(err)); + console.info('Failed to hide keyboard: ' + JSON.stringify(err)); }); ``` @@ -781,12 +775,12 @@ Hides the keyboard. This API uses an asynchronous callback to return the result. **Example** ```js -KeyboardController.hideKeyboard((err) => { - if (err === undefined) { - console.error('hideKeyboard err: ' + JSON.stringify(err)); +keyboardController.hideKeyboard((err) => { + if (err !== undefined) { + console.error('Failed to hide Keyboard: ' + JSON.stringify(err)); return; } - console.log('hideKeyboard success.'); + console.log('Succeeded in hiding keyboard.'); }); ``` @@ -811,10 +805,10 @@ Hides the keyboard. This API uses a promise to return the result. **Example** ```js -KeyboardController.hideKeyboard().then(() => { - console.info('hideKeyboard success.'); +keyboardController.hideKeyboard().then(() => { + console.info('Succeeded in hiding keyboard.'); }).catch((err) => { - console.info('hideKeyboard err: ' + JSON.stringify(err)); + console.info('Failed to hide Keyboard: ' + JSON.stringify(err)); }); ``` @@ -850,13 +844,13 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let action = 1; try { - InputClient.sendKeyFunction(action, (err, result) => { - if (err) { - console.error('sendKeyFunction err: ' + JSON.stringify(err)); + inputClient.sendKeyFunction(action, (err, result) => { + if (err !== undefined) { + console.error('Failed to sendKeyFunction: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to sendKeyFunction. '); + console.info('Succeeded in sending key function. '); } else { console.error('Failed to sendKeyFunction. '); } @@ -899,17 +893,17 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let action = 1; try { - InputClient.sendKeyFunction(action).then((result) => { + inputClient.sendKeyFunction(action).then((result) => { if (result) { - console.info('Success to sendKeyFunction. '); + console.info('Succeeded in sending key function. '); } else { console.error('Failed to sendKeyFunction. '); } }).catch((err) => { - console.error('sendKeyFunction err:' + JSON.stringify(err)); + console.error('Failed to sendKeyFunction:' + JSON.stringify(err)); }); } catch (err) { - console.error('sendKeyFunction err: ' + JSON.stringify(err)); + console.error('Failed to sendKeyFunction: ' + JSON.stringify(err)); } ``` @@ -942,15 +936,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let length = 1; try { - InputClient.getForward(length, (err, text) => { - if (err) { - console.error('getForward err: ' + JSON.stringify(err)); + inputClient.getForward(length, (err, text) => { + if (err !== undefined) { + console.error('Failed to getForward: ' + JSON.stringify(err)); return; } - console.log('getForward result: ' + text); + console.log('Succeeded in getting forward, text: ' + text); }); } catch (err) { - console.error('getForward err: ' + JSON.stringify(err)); + console.error('Failed to getForward: ' + JSON.stringify(err)); } ``` @@ -988,13 +982,13 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let length = 1; try { - InputClient.getForward(length).then((text) => { - console.info('getForward resul: ' + text); + inputClient.getForward(length).then((text) => { + console.info('Succeeded in getting forward, text: ' + text); }).catch((err) => { - console.error('getForward err: ' + JSON.stringify(err)); + console.error('Failed to getForward: ' + JSON.stringify(err)); }); } catch (err) { - console.error('getForward err: ' + JSON.stringify(err)); + console.error('Failed to getForward: ' + JSON.stringify(err)); } ``` @@ -1027,15 +1021,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let length = 1; try { - InputClient.getBackward(length, (err, text) => { - if (err) { - console.error('getBackward result: ' + JSON.stringify(err)); + inputClient.getBackward(length, (err, text) => { + if (err !== undefined) { + console.error('Failed to getForward: ' + JSON.stringify(err)); return; } - console.log('getBackward result---text: ' + text); + console.log('Succeeded in getting backward, text: ' + text); }); } catch (err) { - console.error('getBackward result: ' + JSON.stringify(err)); + console.error('Failed to getForward: ' + JSON.stringify(err)); } ``` @@ -1073,13 +1067,13 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let length = 1; try { - InputClient.getBackward(length).then((text) => { - console.info('getBackward result: ' + text); + inputClient.getBackward(length).then((text) => { + console.info('Succeeded in getting backward, text: ' + text); }).catch((err) => { - console.error('getBackward err: ' + JSON.stringify(err)); + console.error('Failed to getForward: ' + JSON.stringify(err)); }); } catch (err) { - console.error('getBackward err: ' + JSON.stringify(err)); + console.error('Failed to getForward: ' + JSON.stringify(err)); } ``` @@ -1112,19 +1106,19 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let length = 1; try { - InputClient.deleteForward(length, (err, result) => { - if (err) { - console.error('deleteForward result: ' + JSON.stringify(err)); + inputClient.deleteForward(length, (err, result) => { + if (err !== undefined) { + console.error('Failed to delete forward: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to deleteForward. '); + console.info('Succeeded in deleting forward. '); } else { - console.error('Failed to deleteForward. '); + console.error('Failed to delete forward: ' + JSON.stringify(err)); } }); } catch (err) { - console.error('deleteForward result: ' + JSON.stringify(err)); + console.error('Failed to delete forward: ' + JSON.stringify(err)); } ``` @@ -1162,17 +1156,17 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let length = 1; try { - InputClient.deleteForward(length).then((result) => { + inputClient.deleteForward(length).then((result) => { if (result) { - console.info('Success to deleteForward. '); + console.info('Succeeded in deleting forward. '); } else { - console.error('Failed to deleteForward. '); + console.error('Failed to delete Forward. '); } }).catch((err) => { - console.error('deleteForward err: ' + JSON.stringify(err)); + console.error('Failed to delete Forward: ' + JSON.stringify(err)); }); } catch (err) { - console.error('deleteForward err: ' + JSON.stringify(err)); + console.error('Failed to delete Forward: ' + JSON.stringify(err)); } ``` @@ -1205,15 +1199,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let length = 1; try { - InputClient.deleteBackward(length, (err, result) => { - if (err) { - console.error('deleteBackward err: ' + JSON.stringify(err)); + inputClient.deleteBackward(length, (err, result) => { + if (err !== undefined) { + console.error('Failed to delete Backward: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to deleteBackward. '); + console.info('Succeeded in deleting backward. '); } else { - console.error('Failed to deleteBackward. '); + console.error('Failed to delete Backward: ' + JSON.stringify(err)); } }); } catch (err) { @@ -1254,14 +1248,14 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js let length = 1; -InputClient.deleteBackward(length).then((result) => { +inputClient.deleteBackward(length).then((result) => { if (result) { - console.info('Success to deleteBackward. '); + console.info('Succeeded in deleting backward. '); } else { console.error('Failed to deleteBackward. '); } }).catch((err) => { - console.error('deleteBackward err: ' + JSON.stringify(err)); + console.error('Failed to deleteBackward: ' + JSON.stringify(err)); }); ``` @@ -1292,13 +1286,13 @@ For details about the error codes, see [Input Method Framework Error Codes](../e **Example** ```js -InputClient.insertText('test', (err, result) => { - if (err) { - console.error('insertText err: ' + JSON.stringify(err)); +inputClient.insertText('test', (err, result) => { + if (err !== undefined) { + console.error('Failed to insertText: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to insertText. '); + console.info('Succeeded in inserting text. '); } else { console.error('Failed to insertText. '); } @@ -1338,17 +1332,17 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js try { - InputClient.insertText('test').then((result) => { + inputClient.insertText('test').then((result) => { if (result) { - console.info('Success to insertText. '); + console.info('Succeeded in inserting text. '); } else { console.error('Failed to insertText. '); } }).catch((err) => { - console.error('insertText err: ' + JSON.stringify(err)); + console.error('Failed to insertText: ' + JSON.stringify(err)); }); } catch (err) { - console.error('insertText err: ' + JSON.stringify(err)); + console.error('Failed to insertText: ' + JSON.stringify(err)); } ``` @@ -1377,9 +1371,9 @@ For details about the error codes, see [Input Method Framework Error Codes](../e **Example** ```js -InputClient.getEditorAttribute((err, editorAttribute) => { - if (err) { - console.error('getEditorAttribute err: ' + JSON.stringify(err)); +inputClient.getEditorAttribute((err, editorAttribute) => { + if (err !== undefined) { + console.error('Failed to getEditorAttribute: ' + JSON.stringify(err)); return; } console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); @@ -1412,11 +1406,11 @@ For details about the error codes, see [Input Method Framework Error Codes](../e **Example** ```js -InputClient.getEditorAttribute().then((editorAttribute) => { +inputClient.getEditorAttribute().then((editorAttribute) => { console.info('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); console.info('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); }).catch((err) => { - console.error('getEditorAttribute err: ' + JSON.stringify(err)); + console.error('Failed to getEditorAttribute: ' + JSON.stringify(err)); }); ``` @@ -1447,15 +1441,15 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js try { - InputClient.moveCursor(inputMethodEngine.CURSOR_xxx, (err) => { - if (err) { - console.error('moveCursor err: ' + JSON.stringify(err)); + inputClient.moveCursor(inputMethodEngine.CURSOR_UP, (err) => { + if (err !== undefined) { + console.error('Failed to moveCursor: ' + JSON.stringify(err)); return; } - console.info('moveCursor success'); + console.info('Succeeded in moving cursor.'); }); } catch (err) { - console.error('moveCursor err: ' + JSON.stringify(err)); + console.error('Failed to moveCursor: ' + JSON.stringify(err)); } ``` @@ -1491,13 +1485,13 @@ For details about the error codes, see [Input Method Framework Error Codes](../e ```js try { - InputClient.moveCursor(inputMethodEngine.CURSOR_UP).then(() => { - console.log('moveCursor success'); + inputClient.moveCursor(inputMethodEngine.CURSOR_UP).then(() => { + console.log('Succeeded in moving cursor.'); }).catch((err) => { - console.error('moveCursor success err: ' + JSON.stringify(err)); + console.error('Failed to moveCursor: ' + JSON.stringify(err)); }); } catch (err) { - console.log('moveCursor err: ' + JSON.stringify(err)); + console.log('Failed to moveCursor: ' + JSON.stringify(err)); } ``` @@ -1554,12 +1548,12 @@ Obtains the specific-length text before the cursor. This API uses an asynchronou ```js let length = 1; -TextInputClient.getForward(length, (err, text) => { - if (err === undefined) { - console.error('getForward err: ' + JSON.stringify(err)); +textInputClient.getForward(length, (err, text) => { + if (err !== undefined) { + console.error('Failed to getForward: ' + JSON.stringify(err)); return; } - console.log('getForward result---text: ' + text); + console.log('Succeeded in getting forward, text: ' + text); }); ``` @@ -1591,10 +1585,10 @@ Obtains the specific-length text before the cursor. This API uses a promise to r ```js let length = 1; -TextInputClient.getForward(length).then((text) => { - console.info('getForward result: ' + JSON.stringify(text)); +textInputClient.getForward(length).then((text) => { + console.info('Succeeded in getting forward, text: ' + text); }).catch((err) => { - console.error('getForward err: ' + JSON.stringify(err)); + console.error('Failed to getForward: ' + JSON.stringify(err)); }); ``` @@ -1621,12 +1615,12 @@ Obtains the specific-length text after the cursor. This API uses an asynchronous ```js let length = 1; -TextInputClient.getBackward(length, (err, text) => { - if (err === undefined) { - console.error('getBackward err: ' + JSON.stringify(err)); +textInputClient.getBackward(length, (err, text) => { + if (err !== undefined) { + console.error('Failed to getBackward: ' + JSON.stringify(err)); return; } - console.log('getBackward result---text: ' + text); + console.log('Succeeded in getting borward, text: ' + text); }); ``` @@ -1658,10 +1652,10 @@ Obtains the specific-length text after the cursor. This API uses a promise to re ```js let length = 1; -TextInputClient.getBackward(length).then((text) => { - console.info('getBackward result: ' + JSON.stringify(text)); +textInputClient.getBackward(length).then((text) => { + console.info('Succeeded in getting backward: ' + JSON.stringify(text)); }).catch((err) => { - console.error('getBackward err: ' + JSON.stringify(err)); + console.error('Failed to getBackward: ' + JSON.stringify(err)); }); ``` @@ -1688,13 +1682,13 @@ Deletes the fixed-length text before the cursor. This API uses an asynchronous c ```js let length = 1; -TextInputClient.deleteForward(length, (err, result) => { - if (err === undefined) { - console.error('deleteForward err: ' + JSON.stringify(err)); +textInputClient.deleteForward(length, (err, result) => { + if (err !== undefined) { + console.error('Failed to deleteForward: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to deleteForward. '); + console.info('Succeeded in deleting forward. '); } else { console.error('Failed to deleteForward. '); } @@ -1729,14 +1723,14 @@ Deletes the fixed-length text before the cursor. This API uses a promise to retu ```js let length = 1; -TextInputClient.deleteForward(length).then((result) => { +textInputClient.deleteForward(length).then((result) => { if (result) { - console.info('Succeed in deleting forward. '); + console.info('Succeeded in deleting forward. '); } else { console.error('Failed to delete forward. '); } }).catch((err) => { - console.error('Failed to delete forward err: ' + JSON.stringify(err)); + console.error('Failed to delete forward: ' + JSON.stringify(err)); }); ``` @@ -1763,13 +1757,13 @@ Deletes the fixed-length text after the cursor. This API uses an asynchronous ca ```js let length = 1; -TextInputClient.deleteBackward(length, (err, result) => { - if (err === undefined) { - console.error('deleteBackward err: ' + JSON.stringify(err)); +textInputClient.deleteBackward(length, (err, result) => { + if (err !== undefined) { + console.error('Failed to delete backward: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to deleteBackward. '); + console.info('Succeeded in deleting backward. '); } else { console.error('Failed to deleteBackward. '); } @@ -1804,14 +1798,14 @@ Deletes the fixed-length text after the cursor. This API uses an asynchronous ca ```js let length = 1; -TextInputClient.deleteBackward(length).then((result) => { +textInputClient.deleteBackward(length).then((result) => { if (result) { - console.info('Success to deleteBackward. '); + console.info('Succeeded in deleting backward. '); } else { console.error('Failed to deleteBackward. '); } }).catch((err) => { - console.error('deleteBackward err: ' + JSON.stringify(err)); + console.error('Failed to deleteBackward: ' + JSON.stringify(err)); }); ``` ### sendKeyFunction(deprecated) @@ -1837,13 +1831,13 @@ Sends the function key. This API uses an asynchronous callback to return the res ```js let action = 1; -TextInputClient.sendKeyFunction(action, (err, result) => { - if (err === undefined) { - console.error('sendKeyFunction err: ' + JSON.stringify(err)); +textInputClient.sendKeyFunction(action, (err, result) => { + if (err !== undefined) { + console.error('Failed to sendKeyFunction: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to sendKeyFunction. '); + console.info('Succeeded in sending key function. '); } else { console.error('Failed to sendKeyFunction. '); } @@ -1878,14 +1872,14 @@ Sends the function key. This API uses a promise to return the result. ```js let action = 1; -TextInputClient.sendKeyFunction(action).then((result) => { +textInputClient.sendKeyFunction(action).then((result) => { if (result) { - console.info('Success to sendKeyFunction. '); + console.info('Succeeded in sending key function. '); } else { console.error('Failed to sendKeyFunction. '); } }).catch((err) => { - console.error('sendKeyFunction err:' + JSON.stringify(err)); + console.error('Failed to sendKeyFunction:' + JSON.stringify(err)); }); ``` @@ -1911,13 +1905,13 @@ Inserts text. This API uses an asynchronous callback to return the result. **Example** ```js -TextInputClient.insertText('test', (err, result) => { - if (err === undefined) { - console.error('insertText err: ' + JSON.stringify(err)); +textInputClient.insertText('test', (err, result) => { + if (err !== undefined) { + console.error('Failed to insertText: ' + JSON.stringify(err)); return; } if (result) { - console.info('Success to insertText. '); + console.info('Succeeded in inserting text. '); } else { console.error('Failed to insertText. '); } @@ -1951,14 +1945,14 @@ Inserts text. This API uses a promise to return the result. **Example** ```js -TextInputClient.insertText('test').then((result) => { +textInputClient.insertText('test').then((result) => { if (result) { - console.info('Success to insertText. '); + console.info('Succeeded in inserting text. '); } else { console.error('Failed to insertText. '); } }).catch((err) => { - console.error('insertText err: ' + JSON.stringify(err)); + console.error('Failed to insertText: ' + JSON.stringify(err)); }); ``` @@ -1983,9 +1977,9 @@ Obtains the attribute of the edit box. This API uses an asynchronous callback to **Example** ```js -TextInputClient.getEditorAttribute((err, editorAttribute) => { - if (err === undefined) { - console.error('getEditorAttribute err: ' + JSON.stringify(err)); +textInputClient.getEditorAttribute((err, editorAttribute) => { + if (err !== undefined) { + console.error('Failed to getEditorAttribute: ' + JSON.stringify(err)); return; } console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); @@ -2014,10 +2008,10 @@ Obtains the attribute of the edit box. This API uses a promise to return the res **Example** ```js -TextInputClient.getEditorAttribute().then((editorAttribute) => { +textInputClient.getEditorAttribute().then((editorAttribute) => { console.info('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); console.info('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); }).catch((err) => { - console.error('getEditorAttribute err: ' + JSON.stringify(err)); + console.error('Failed to getEditorAttribute: ' + JSON.stringify(err)); }); ``` diff --git a/en/application-dev/reference/apis/js-apis-intl.md b/en/application-dev/reference/apis/js-apis-intl.md index 79cdf3ac5627984eba2f03e7eb37b9cc7137de4a..e3cb7bbfd684ae315d6d54363183401442f5167a 100644 --- a/en/application-dev/reference/apis/js-apis-intl.md +++ b/en/application-dev/reference/apis/js-apis-intl.md @@ -1,6 +1,6 @@ # Internationalization – Intl -This module provides basic I18N capabilities, such as time and date formatting, number formatting, and string sorting, through the standard I18N APIs defined in ECMA 402. +The Intl module provides basic I18N capabilities, such as time and date formatting, number formatting, and string sorting, through the standard I18N APIs defined in ECMA 402. The [I18N](js-apis-i18n.md) module provides enhanced I18N capabilities through supplementary APIs that are not defined in ECMA 402. It works with the Intl module to provide a complete suite of I18N capabilities. diff --git a/en/application-dev/reference/apis/js-apis-keycode.md b/en/application-dev/reference/apis/js-apis-keycode.md index 6680ea14f2ea3daa0d9144013469cf094c4904d2..a1261ce5d59d661af602b3ff3657a22ba3538764 100644 --- a/en/application-dev/reference/apis/js-apis-keycode.md +++ b/en/application-dev/reference/apis/js-apis-keycode.md @@ -2,7 +2,8 @@ The Keycode module provides keycodes for a key device. -> **NOTE**
+> **NOTE** +> > The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. ## Modules to Import @@ -337,7 +338,7 @@ import {KeyCode} from '@ohos.multimodalInput.keyCode'; | KEYCODE_WWAN_WIMAX | number | Yes| No| WWAN WiMAX key| | KEYCODE_RFKILL | number | Yes| No| RF Kill key| | KEYCODE_CHANNEL | number | Yes| No| Channel key| -| KEYCODE_BTN_0 | number | Yes| No| Key 0| +| KEYCODE_BTN_0 | number | Yes| No| Button 0| | KEYCODE_BTN_1 | number | Yes| No| Button 1| | KEYCODE_BTN_2 | number | Yes| No| Button 2| | KEYCODE_BTN_3 | number | Yes| No| Button 3| diff --git a/en/application-dev/reference/apis/js-apis-net-connection.md b/en/application-dev/reference/apis/js-apis-net-connection.md index 31414ab325572d7ed25a31b1b3a78a725dce39e6..2fbe0e1c1d90b155fc52702d1dc69982e511c140 100644 --- a/en/application-dev/reference/apis/js-apis-net-connection.md +++ b/en/application-dev/reference/apis/js-apis-net-connection.md @@ -332,7 +332,6 @@ connection.getDefaultNet().then(function (netHandle) { }); ``` - ## connection.reportNetConnected reportNetConnected(netHandle: NetHandle): Promise<void> @@ -490,7 +489,6 @@ connection.getAddressesByName(host).then(function (addresses) { }) ``` - ## connection.enableAirplaneMode enableAirplaneMode(callback: AsyncCallback\): void @@ -539,7 +537,6 @@ connection.enableAirplaneMode().then(function (error) { }) ``` - ## connection.disableAirplaneMode disableAirplaneMode(callback: AsyncCallback\): void @@ -588,7 +585,6 @@ connection.disableAirplaneMode().then(function (error) { }) ``` - ## connection.createNetConnection createNetConnection(netSpecifier?: NetSpecifier, timeout?: number): NetConnection @@ -825,7 +821,7 @@ Before invoking NetHandle APIs, call **getNetHandle** to obtain a **NetHandle** | Name| Type | Description | | ------ | ------ | ------------------------- | -| netId | number | Network ID. The value must be greater than or equal to 100.| +| netId | number | Network ID. The value **0** indicates no default network. Any other value must be greater than or equal to 100.| ### bindSocket @@ -847,33 +843,50 @@ Binds a **TCPSocket** or **UDPSocket** object to the data network. This API uses **Example** ```js -connection.getDefaultNet().then(function (netHandle) { +import socket from "@ohos.net.socket"; +connection.getDefaultNet().then((netHandle)=>{ var tcp = socket.constructTCPSocketInstance(); var udp = socket.constructUDPSocketInstance(); - let socketType = "xxxx"; + let socketType = "TCPSocket"; if (socketType == "TCPSocket") { tcp.bind({ - address: "xxxx", port: xxxx, family: xxxx + address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => { - netHandle.bindSocket(tcp, function (error, data) { - console.log(JSON.stringify(error)) - console.log(JSON.stringify(data)) + if (err) { + console.log('bind fail'); + } + netHandle.bindSocket(tcp, (error, data)=>{ + if (error) { + console.log(JSON.stringify(error)); + } else { + console.log(JSON.stringify(data)); + } + }) }) } else { + let callback = value => { + console.log(TAG + "on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo); + } udp.on('message', callback); udp.bind({ - address: "xxxx", port: xxxx, family: xxxx + address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => { + if (err) { + console.log('bind fail'); + } udp.on('message', (data) => { - console.log(JSON.stringify(data)) - }); - netHandle.bindSocket(udp, function (error, data) { - console.log(JSON.stringify(error)) - console.log(JSON.stringify(data)) + console.log(JSON.stringify(data)) }); + netHandle.bindSocket(udp,(error, data)=>{ + if (error) { + console.log(JSON.stringify(error)); + } else { + console.log(JSON.stringify(data)); + } + }) }) - } -} + } +}) ``` ### bindSocket @@ -901,31 +914,50 @@ Binds a **TCPSocket** or **UDPSocket** object to the data network. This API uses **Example** ```js -connection.getDefaultNet().then(function (netHandle) { +import socket from "@ohos.net.socket"; +connection.getDefaultNet().then((netHandle)=>{ var tcp = socket.constructTCPSocketInstance(); var udp = socket.constructUDPSocketInstance(); - let socketType = "xxxx"; - if(socketType == "TCPSocket") { + let socketType = "TCPSocket"; + if (socketType == "TCPSocket") { tcp.bind({ - address: "xxxx", port: xxxx, family: xxxx + address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => { - netHandle.bindSocket(tcp).then(err, data) { - console.log(JSON.stringify(data)) + if (err) { + console.log('bind fail'); + } + netHandle.bindSocket(tcp).then((err, data) => { + if (err) { + console.log(JSON.stringify(err)); + } else { + console.log(JSON.stringify(data)); + } + }) }) } else { + let callback = value => { + console.log(TAG + "on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo); + } udp.on('message', callback); udp.bind({ - address: "xxxx", port: xxxx, family: xxxx + address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => { + if (err) { + console.log('bind fail'); + } udp.on('message', (data) => { - console.log(JSON.stringify(data)) - }); - netHandle.bindSocket(tcp).then(err, data) { - console.log(JSON.stringify(data)) - }); + console.log(JSON.stringify(data)); + }) + netHandle.bindSocket(udp).then((err, data) => { + if (err) { + console.log(JSON.stringify(err)); + } else { + console.log(JSON.stringify(data)); + } + }) }) - } -} + } +}) ``` diff --git a/en/application-dev/reference/apis/js-apis-net-sharing.md b/en/application-dev/reference/apis/js-apis-net-sharing.md index 23284aeb1715a3f8aed9ec7b2d79ad55d1408319..c63c09c5a84bbec34b5b2274d3089fad4fbb603b 100644 --- a/en/application-dev/reference/apis/js-apis-net-sharing.md +++ b/en/application-dev/reference/apis/js-apis-net-sharing.md @@ -1,6 +1,6 @@ # Network Sharing Management -The Network Sharing Management module allows you to share your device's Internet connection with other connected devices by means of Wi-Fi hotspot, Bluetooth, and USB sharing. It also allows you to query the network sharing state and shared mobile data volume. +The Network Sharing Management module allows you to share your device's Internet connection with other connected devices by means of Wi-Fi hotspot, and Bluetooth sharing. It also allows you to query the network sharing state and shared mobile data volume. > **NOTE** > @@ -405,7 +405,7 @@ Obtains the names of NICs in the specified network sharing state. This API uses **Example** ```js -import SharingIfaceState from '@ohos.net.sharing' +import SharingIfaceType from '@ohos.net.sharing' sharing.getSharingIfaces(SharingIfaceState.SHARING_NIC_CAN_SERVER, (error, data) => { console.log(JSON.stringify(error)); console.log(JSON.stringify(data)); @@ -498,7 +498,7 @@ Obtains the network sharing state of the specified type. This API uses a promise ```js import SharingIfaceType from '@ohos.net.sharing' -sharing.getSharingIfaces(SharingIfaceType.SHARING_WIFI).then(data => { +sharing.getSharingState(SharingIfaceType.SHARING_WIFI).then(data => { console.log(JSON.stringify(data)); }).catch(error => { console.log(JSON.stringify(error)); @@ -525,8 +525,8 @@ Obtains regular expressions of NICs of a specified type. This API uses an asynch **Example** ```js -import SharingIfaceState from '@ohos.net.sharing' -sharing.getSharingState(SharingIfaceType.SHARING_WIFI, (error, data) => { +import SharingIfaceType from '@ohos.net.sharing' +sharing.getSharableRegexes(SharingIfaceType.SHARING_WIFI, (error, data) => { console.log(JSON.stringify(error)); console.log(JSON.stringify(data)); }); @@ -565,7 +565,7 @@ sharing.getSharableRegexes(SharingIfaceType.SHARING_WIFI).then(data => { }); ``` -## on('sharingStateChange') +## sharing.on('sharingStateChange') on(type: 'sharingStateChange', callback: Callback\): void @@ -591,7 +591,7 @@ sharing.on('sharingStateChange', (error, data) => { }); ``` -## off('sharingStateChange') +## sharing.off('sharingStateChange') off(type: 'sharingStateChange', callback?: Callback\): void @@ -617,7 +617,7 @@ sharing.off('sharingStateChange', (error, data) => { }); ``` -## on('interfaceSharingStateChange') +## sharing.on('interfaceSharingStateChange') on(type: 'interfaceSharingStateChange', callback: Callback\<{ type: SharingIfaceType, iface: string, state: SharingIfaceState }>): void @@ -643,7 +643,7 @@ sharing.on('interfaceSharingStateChange', (error, data) => { }); ``` -## off('interfaceSharingStateChange') +## sharing.off('interfaceSharingStateChange') off(type: 'interfaceSharingStateChange', callback?: Callback\<{ type: SharingIfaceType, iface: string, state: SharingIfaceState }>): void @@ -669,7 +669,7 @@ sharing.off('interfaceSharingStateChange', (error, data) => { }); ``` -## on('sharingUpstreamChange') +## sharing.on('sharingUpstreamChange') on(type: 'sharingUpstreamChange', callback: Callback\): void @@ -695,7 +695,7 @@ sharing.on('sharingUpstreamChange', (error, data) => { }); ``` -## off('sharingUpstreamChange') +## sharing.off('sharingUpstreamChange') off(type: 'sharingUpstreamChange', callback?: Callback\): void @@ -735,12 +735,12 @@ Enumerates the network sharing states of an NIC. ## SharingIfaceType -Enumerates the network sharing types of an NIC. +Enumerates the network sharing types of an NIC. **System capability**: SystemCapability.Communication.NetManager.Core | Name | Value | Description | | ------------------------ | ---- | ---------------------- | | SHARING_WIFI | 0 | Wi-Fi hotspot sharing.| -| SHARING_USB | 1 | USB sharing.| +| SHARING_USB | 1 | USB sharing (not supported currently).| | SHARING_BLUETOOTH | 2 | Bluetooth sharing.| diff --git a/en/application-dev/reference/apis/js-apis-notification.md b/en/application-dev/reference/apis/js-apis-notification.md index 99dd6551d098ddf0d6f58a69bde92191e38d083d..9fdf5e1f345b68fcd99e6e027cfb0c44d5da29d8 100644 --- a/en/application-dev/reference/apis/js-apis-notification.md +++ b/en/application-dev/reference/apis/js-apis-notification.md @@ -2,11 +2,11 @@ The **Notification** module provides notification management capabilities, covering notifications, notification slots, notification subscription, notification enabled status, and notification badge status. -Generally, only system applications have the permission to subscribe to and unsubscribe from notifications. - > **NOTE** > > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> +> Notification subscription and unsubscription APIs are available only to system applications. ## Modules to Import @@ -26,8 +26,8 @@ Publishes a notification. This API uses an asynchronous callback to return the r | Name | Type | Mandatory| Description | | -------- | ------------------------------------------- | ---- | ------------------------------------------- | -| request | [NotificationRequest](#notificationrequest) | Yes | **NotificationRequest** object.| -| callback | AsyncCallback\ | Yes | Callback used to return the result. | +| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.| +| callback | AsyncCallback\ | Yes | Callback used to return the result. | **Example** @@ -69,7 +69,7 @@ Publishes a notification. This API uses a promise to return the result. | Name | Type | Mandatory| Description | | -------- | ------------------------------------------- | ---- | ------------------------------------------- | -| request | [NotificationRequest](#notificationrequest) | Yes | **NotificationRequest** object.| +| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.| **Example** @@ -87,7 +87,7 @@ var notificationRequest = { } } Notification.publish(notificationRequest).then(() => { - console.info("publish sucess"); + console.info("publish success"); }); ``` @@ -96,7 +96,7 @@ Notification.publish(notificationRequest).then(() => { publish(request: NotificationRequest, userId: number, callback: AsyncCallback\): void -Publishes a notification. This API uses an asynchronous callback to return the result. +Publishes a notification to a specified user. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -108,8 +108,8 @@ Publishes a notification. This API uses an asynchronous callback to return the r | Name | Type | Mandatory| Description | | -------- | ----------------------------------------- | ---- | ------------------------------------------- | -| request | [NotificationRequest](#notificationrequest) | Yes | **NotificationRequest** object.| -| userId | number | Yes | ID of the user who receives the notification. | +| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.| +| userId | number | Yes | User ID. | | callback | AsyncCallback\ | Yes | Callback used to return the result. | **Example** @@ -123,7 +123,7 @@ function publishCallback(err) { console.info("publish success"); } } -// ID of the user who receives the notification +// User ID var userId = 1 // NotificationRequest object var notificationRequest = { @@ -144,7 +144,7 @@ Notification.publish(notificationRequest, userId, publishCallback); publish(request: NotificationRequest, userId: number): Promise\ -Publishes a notification. This API uses a promise to return the result. +Publishes a notification to a specified user. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -156,8 +156,8 @@ Publishes a notification. This API uses a promise to return the result. | Name | Type | Mandatory| Description | | -------- | ----------------------------------------- | ---- | ------------------------------------------- | -| request | [NotificationRequest](#notificationrequest) | Yes | **NotificationRequest** object.| -| userId | number | Yes | ID of the user who receives the notification. | +| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.| +| userId | number | Yes | User ID. | **Example** @@ -177,7 +177,7 @@ var notificationRequest = { var userId = 1 Notification.publish(notificationRequest, userId).then(() => { - console.info("publish sucess"); + console.info("publish success"); }); ``` @@ -218,7 +218,7 @@ Notification.cancel(0, "label", cancelCallback) cancel(id: number, label?: string): Promise\ -Cancels a notification with the specified ID and label. This API uses a promise to return the result. +Cancels a notification with the specified ID and optional label. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -233,7 +233,7 @@ Cancels a notification with the specified ID and label. This API uses a promise ```js Notification.cancel(0).then(() => { - console.info("cancel sucess"); + console.info("cancel success"); }); ``` @@ -312,7 +312,7 @@ Cancels all notifications. This API uses a promise to return the result. ```js Notification.cancelAll().then(() => { - console.info("cancelAll sucess"); + console.info("cancelAll success"); }); ``` @@ -383,7 +383,7 @@ var notificationSlot = { type: Notification.SlotType.SOCIAL_COMMUNICATION } Notification.addSlot(notificationSlot).then(() => { - console.info("addSlot sucess"); + console.info("addSlot success"); }); ``` @@ -393,7 +393,7 @@ Notification.addSlot(notificationSlot).then(() => { addSlot(type: SlotType, callback: AsyncCallback\): void -Adds a notification slot. This API uses an asynchronous callback to return the result. +Adds a notification slot of a specified type. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -424,7 +424,7 @@ Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION, addSlotCallBack addSlot(type: SlotType): Promise\ -Adds a notification slot. This API uses a promise to return the result. +Adds a notification slot of a specified type. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -438,7 +438,7 @@ Adds a notification slot. This API uses a promise to return the result. ```js Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then(() => { - console.info("addSlot sucess"); + console.info("addSlot success"); }); ``` @@ -448,7 +448,7 @@ Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then(() => { addSlots(slots: Array\, callback: AsyncCallback\): void -Adds multiple notification slots. This API uses an asynchronous callback to return the result. +Adds an array of notification slots. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -491,7 +491,7 @@ Notification.addSlots(notificationSlotArray, addSlotsCallBack) addSlots(slots: Array\): Promise\ -Adds multiple notification slots. This API uses a promise to return the result. +Adds an array of notification slots. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -517,7 +517,7 @@ var notificationSlotArray = new Array(); notificationSlotArray[0] = notificationSlot; Notification.addSlots(notificationSlotArray).then(() => { - console.info("addSlots sucess"); + console.info("addSlots success"); }); ``` @@ -527,7 +527,7 @@ Notification.addSlots(notificationSlotArray).then(() => { getSlot(slotType: SlotType, callback: AsyncCallback\): void -Obtains a notification slot of the specified type. This API uses an asynchronous callback to return the result. +Obtains a notification slot of a specified type. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -542,7 +542,7 @@ Obtains a notification slot of the specified type. This API uses an asynchronous ```js // getSlot callback -function getSlotCallback(err,data) { +function getSlotCallback(err, data) { if (err.code) { console.info("getSlot failed " + JSON.stringify(err)); } else { @@ -559,7 +559,7 @@ Notification.getSlot(slotType, getSlotCallback) getSlot(slotType: SlotType): Promise\ -Obtains a notification slot of the specified type. This API uses a promise to return the result. +Obtains a notification slot of a specified type. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -580,7 +580,7 @@ Obtains a notification slot of the specified type. This API uses a promise to re ```js var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; Notification.getSlot(slotType).then((data) => { - console.info("getSlot sucess, data: " + JSON.stringify(data)); + console.info("getSlot success, data: " + JSON.stringify(data)); }); ``` @@ -604,7 +604,7 @@ Obtains all notification slots. This API uses an asynchronous callback to return ```js // getSlots callback -function getSlotsCallback(err,data) { +function getSlotsCallback(err, data) { if (err.code) { console.info("getSlots failed " + JSON.stringify(err)); } else { @@ -634,7 +634,7 @@ Obtains all notification slots of this application. This API uses a promise to r ```js Notification.getSlots().then((data) => { - console.info("getSlots sucess, data: " + JSON.stringify(data)); + console.info("getSlots success, data: " + JSON.stringify(data)); }); ``` @@ -644,7 +644,7 @@ Notification.getSlots().then((data) => { removeSlot(slotType: SlotType, callback: AsyncCallback\): void -Removes a notification slot of the specified type. This API uses an asynchronous callback to return the result. +Removes a notification slot of a specified type. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -676,7 +676,7 @@ Notification.removeSlot(slotType,removeSlotCallback) removeSlot(slotType: SlotType): Promise\ -Removes a notification slot of the specified type. This API uses a promise to return the result. +Removes a notification slot of a specified type. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -691,7 +691,7 @@ Removes a notification slot of the specified type. This API uses a promise to re ```js var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; Notification.removeSlot(slotType).then(() => { - console.info("removeSlot sucess"); + console.info("removeSlot success"); }); ``` @@ -738,7 +738,7 @@ Removes all notification slots. This API uses a promise to return the result. ```js Notification.removeAllSlots().then(() => { - console.info("removeAllSlots sucess"); + console.info("removeAllSlots success"); }); ``` @@ -761,7 +761,7 @@ Subscribes to a notification with the subscription information specified. This A | Name | Type | Mandatory| Description | | ---------- | ------------------------- | ---- | ---------------- | | subscriber | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber. | -| info | [NotificationSubscribeInfo](#notificationsubscribeinfo) | Yes | Subscription information. | +| info | [NotificationSubscribeInfo](#notificationsubscribeinfo) | Yes | Notification subscription information.| | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** @@ -782,7 +782,7 @@ var subscriber = { onConsume: onConsumeCallback } var info = { - bundleNames: ["bundleName1","bundleName2"] + bundleNames: ["bundleName1", "bundleName2"] } Notification.subscribe(subscriber, info, subscribeCallback); ``` @@ -793,7 +793,7 @@ Notification.subscribe(subscriber, info, subscribeCallback); subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\): void -Subscribes to a notification with the subscription information specified. This API uses an asynchronous callback to return the result. +Subscribes to notifications of all applications under this user. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -846,7 +846,7 @@ Subscribes to a notification with the subscription information specified. This A | Name | Type | Mandatory| Description | | ---------- | ------------------------- | ---- | ------------ | | subscriber | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber.| -| info | [NotificationSubscribeInfo](#notificationsubscribeinfo) | No | Subscription information. | +| info | [NotificationSubscribeInfo](#notificationsubscribeinfo) | No | Notification subscription information. | **Example** @@ -858,7 +858,7 @@ var subscriber = { onConsume: onConsumeCallback }; Notification.subscribe(subscriber).then(() => { - console.info("subscribe sucess"); + console.info("subscribe success"); }); ``` @@ -893,11 +893,11 @@ function unsubscribeCallback(err) { console.info("unsubscribe success"); } } -function onCancelCallback(data) { +function onDisconnectCallback(data) { console.info("Cancel callback: " + JSON.stringify(data)); } var subscriber = { - onCancel: onCancelCallback + onDisconnect: onDisconnectCallback } Notification.unsubscribe(subscriber, unsubscribeCallback); ``` @@ -925,14 +925,14 @@ Unsubscribes from a notification. This API uses a promise to return the result. **Example** ```js -function onCancelCallback(data) { +function onDisconnectCallback(data) { console.info("Cancel callback: " + JSON.stringify(data)); } var subscriber = { - onCancel: onCancelCallback + onDisconnect: onDisconnectCallback }; Notification.unsubscribe(subscriber).then(() => { - console.info("unsubscribe sucess"); + console.info("unsubscribe success"); }); ``` @@ -942,7 +942,7 @@ Notification.unsubscribe(subscriber).then(() => { enableNotification(bundle: BundleOption, enable: boolean, callback: AsyncCallback\): void -Sets whether to enable notification for a specified bundle. This API uses an asynchronous callback to return the result. +Sets whether to enable notification for a specified application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -954,7 +954,7 @@ Sets whether to enable notification for a specified bundle. This API uses an asy | Name | Type | Mandatory| Description | | -------- | --------------------- | ---- | -------------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | enable | boolean | Yes | Whether to enable notification. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| @@ -980,7 +980,7 @@ Notification.enableNotification(bundle, false, enableNotificationCallback); enableNotification(bundle: BundleOption, enable: boolean): Promise\ -Sets whether to enable notification for a specified bundle. This API uses a promise to return the result. +Sets whether to enable notification for a specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -992,7 +992,7 @@ Sets whether to enable notification for a specified bundle. This API uses a prom | Name | Type | Mandatory| Description | | ------ | ------------ | ---- | ---------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.| | enable | boolean | Yes | Whether to enable notification. | **Example** @@ -1002,7 +1002,7 @@ var bundle = { bundle: "bundleName1", } Notification.enableNotification(bundle, false).then(() => { - console.info("enableNotification sucess"); + console.info("enableNotification success"); }); ``` @@ -1012,7 +1012,7 @@ Notification.enableNotification(bundle, false).then(() => { isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\): void -Checks whether notification is enabled for a specified bundle. This API uses an asynchronous callback to return the result. +Checks whether notification is enabled for a specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1024,7 +1024,7 @@ Checks whether notification is enabled for a specified bundle. This API uses an | Name | Type | Mandatory| Description | | -------- | --------------------- | ---- | ------------------------ | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** @@ -1049,7 +1049,7 @@ Notification.isNotificationEnabled(bundle, isNotificationEnabledCallback); isNotificationEnabled(bundle: BundleOption): Promise\ -Checks whether notification is enabled for a specified bundle. This API uses a promise to return the result. +Checks whether notification is enabled for a specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1061,12 +1061,12 @@ Checks whether notification is enabled for a specified bundle. This API uses a p | Name | Type | Mandatory| Description | | ------ | ------------ | ---- | ---------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.| **Return value** -| Type | Description | -| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Type | Description | +| ------------------ | --------------------------------------------------- | | Promise\ | Promise used to return the result.| **Example** @@ -1076,7 +1076,7 @@ var bundle = { bundle: "bundleName1", } Notification.isNotificationEnabled(bundle).then((data) => { - console.info("isNotificationEnabled sucess, data: " + JSON.stringify(data)); + console.info("isNotificationEnabled success, data: " + JSON.stringify(data)); }); ``` @@ -1132,7 +1132,7 @@ Checks whether notification is enabled for this application. This API uses a pro | Name | Type | Mandatory| Description | | ------ | ------------ | ---- | ---------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.| **Return value** @@ -1144,7 +1144,7 @@ Checks whether notification is enabled for this application. This API uses a pro ```js Notification.isNotificationEnabled().then((data) => { - console.info("isNotificationEnabled sucess, data: " + JSON.stringify(data)); + console.info("isNotificationEnabled success, data: " + JSON.stringify(data)); }); ``` @@ -1154,7 +1154,7 @@ Notification.isNotificationEnabled().then((data) => { displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\): void -Sets whether to enable the notification badge for a specified bundle. This API uses an asynchronous callback to return the result. +Sets whether to enable the notification badge for a specified application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1166,7 +1166,7 @@ Sets whether to enable the notification badge for a specified bundle. This API u | Name | Type | Mandatory| Description | | -------- | --------------------- | ---- | -------------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | enable | boolean | Yes | Whether to enable notification. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| @@ -1192,7 +1192,7 @@ Notification.displayBadge(bundle, false, displayBadgeCallback); displayBadge(bundle: BundleOption, enable: boolean): Promise\ -Sets the notification slot for a specified bundle. This API uses a promise to return the result. +Sets whether to enable the notification badge for a specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1204,7 +1204,7 @@ Sets the notification slot for a specified bundle. This API uses a promise to re | Name | Type | Mandatory| Description | | ------ | ------------ | ---- | ---------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.| | enable | boolean | Yes | Whether to enable notification. | **Example** @@ -1214,7 +1214,7 @@ var bundle = { bundle: "bundleName1", } Notification.displayBadge(bundle, false).then(() => { - console.info("displayBadge sucess"); + console.info("displayBadge success"); }); ``` @@ -1224,7 +1224,7 @@ Notification.displayBadge(bundle, false).then(() => { isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\): void -Checks whether the notification badge is enabled for a specified bundle. This API uses an asynchronous callback to return the result. +Checks whether the notification badge is enabled for a specified application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1236,7 +1236,7 @@ Checks whether the notification badge is enabled for a specified bundle. This AP | Name | Type | Mandatory| Description | | -------- | --------------------- | ---- | ------------------------ | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** @@ -1261,7 +1261,7 @@ Notification.isBadgeDisplayed(bundle, isBadgeDisplayedCallback); isBadgeDisplayed(bundle: BundleOption): Promise\ -Checks whether the notification badge is enabled for a specified bundle. This API uses a promise to return the result. +Checks whether the notification badge is enabled for a specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1273,7 +1273,7 @@ Checks whether the notification badge is enabled for a specified bundle. This AP | Name | Type | Mandatory| Description | | ------ | ------------ | ---- | ---------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.| **Return value** @@ -1288,7 +1288,7 @@ var bundle = { bundle: "bundleName1", } Notification.isBadgeDisplayed(bundle).then((data) => { - console.info("isBadgeDisplayed sucess, data: " + JSON.stringify(data)); + console.info("isBadgeDisplayed success, data: " + JSON.stringify(data)); }); ``` @@ -1298,7 +1298,7 @@ Notification.isBadgeDisplayed(bundle).then((data) => { setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback\): void -Sets the notification slot for a specified bundle. This API uses an asynchronous callback to return the result. +Sets the notification slot for a specified application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1310,7 +1310,7 @@ Sets the notification slot for a specified bundle. This API uses an asynchronous | Name | Type | Mandatory| Description | | -------- | --------------------- | ---- | -------------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | slot | [NotificationSlot](#notificationslot) | Yes | Notification slot. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| @@ -1339,7 +1339,7 @@ Notification.setSlotByBundle(bundle, notificationSlot, setSlotByBundleCallback); setSlotByBundle(bundle: BundleOption, slot: NotificationSlot): Promise\ -Sets the notification slot for a specified bundle. This API uses a promise to return the result. +Sets the notification slot for a specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1351,8 +1351,8 @@ Sets the notification slot for a specified bundle. This API uses a promise to re | Name | Type | Mandatory| Description | | ------ | ------------ | ---- | ---------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| -| slot | [NotificationSlot](#notificationslot) | Yes | Whether to enable notification. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.| +| slot | [NotificationSlot](#notificationslot) | Yes | Notification slot.| **Example** @@ -1364,7 +1364,7 @@ var notificationSlot = { type: Notification.SlotType.SOCIAL_COMMUNICATION } Notification.setSlotByBundle(bundle, notificationSlot).then(() => { - console.info("setSlotByBundle sucess"); + console.info("setSlotByBundle success"); }); ``` @@ -1374,7 +1374,7 @@ Notification.setSlotByBundle(bundle, notificationSlot).then(() => { getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback>): void -Obtains the notification slots of a specified bundle. This API uses an asynchronous callback to return the result. +Obtains the notification slots of a specified application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1386,7 +1386,7 @@ Obtains the notification slots of a specified bundle. This API uses an asynchron | Name | Type | Mandatory| Description | | -------- | ---------------------------------------- | ---- | -------------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | callback | AsyncCallback> | Yes | Callback used to return the result.| **Example** @@ -1411,7 +1411,7 @@ Notification.getSlotsByBundle(bundle, getSlotsByBundleCallback); getSlotsByBundle(bundle: BundleOption): Promise> -Obtains the notification slots of a specified bundle. This API uses a promise to return the result. +Obtains the notification slots of a specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1423,7 +1423,7 @@ Obtains the notification slots of a specified bundle. This API uses a promise to | Name | Type | Mandatory| Description | | ------ | ------------ | ---- | ---------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.| **Return value** @@ -1438,7 +1438,7 @@ var bundle = { bundle: "bundleName1", } Notification.getSlotsByBundle(bundle).then((data) => { - console.info("getSlotsByBundle sucess, data: " + JSON.stringify(data)); + console.info("getSlotsByBundle success, data: " + JSON.stringify(data)); }); ``` @@ -1448,7 +1448,7 @@ Notification.getSlotsByBundle(bundle).then((data) => { getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\): void -Obtains the number of notification slots of a specified bundle. This API uses an asynchronous callback to return the result. +Obtains the number of notification slots of a specified application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1460,7 +1460,7 @@ Obtains the number of notification slots of a specified bundle. This API uses an | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** @@ -1485,7 +1485,7 @@ Notification.getSlotNumByBundle(bundle, getSlotNumByBundleCallback); getSlotNumByBundle(bundle: BundleOption): Promise\ -Obtains the number of notification slots of a specified bundle. This API uses a promise to return the result. +Obtains the number of notification slots of a specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1497,7 +1497,7 @@ Obtains the number of notification slots of a specified bundle. This API uses a | Name | Type | Mandatory| Description | | ------ | ------------ | ---- | ---------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.| **Return value** @@ -1512,7 +1512,7 @@ var bundle = { bundle: "bundleName1", } Notification.getSlotNumByBundle(bundle).then((data) => { - console.info("getSlotNumByBundle sucess, data: " + JSON.stringify(data)); + console.info("getSlotNumByBundle success, data: " + JSON.stringify(data)); }); ``` @@ -1534,7 +1534,7 @@ Removes a notification for a specified bundle. This API uses an asynchronous cal | Name | Type | Mandatory| Description | | --------------- | ----------------------------------| ---- | -------------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | notificationKey | [NotificationKey](#notificationkey) | Yes | Notification key. | | reason | [RemoveReason](#removereason9) | Yes | Indicates the reason for deleting a notification. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| @@ -1578,7 +1578,7 @@ Removes a notification for a specified bundle. This API uses a promise to return | Name | Type | Mandatory| Description | | --------------- | --------------- | ---- | ---------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information.| +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.| | notificationKey | [NotificationKey](#notificationkey) | Yes | Notification key. | | reason | [RemoveReason](#removereason9) | Yes | Reason for deleting the notification. | @@ -1594,7 +1594,7 @@ var notificationKey = { } var reason = Notification.RemoveReason.CLICK_REASON_REMOVE; Notification.remove(bundle, notificationKey, reason).then(() => { - console.info("remove sucess"); + console.info("remove success"); }); ``` @@ -1616,7 +1616,7 @@ Removes a notification for a specified bundle. This API uses an asynchronous cal | Name | Type | Mandatory| Description | | -------- | --------------------- | ---- | -------------------- | -| hashCode | string | Yes | Unique notification ID. | +| hashCode | string | Yes | Unique notification ID. It is the **hashCode** in the [NotificationRequest](#notificationrequest) object of [SubscribeCallbackData](#subscribecallbackdata) of the [onConsume](#onconsume) callback.| | reason | [RemoveReason](#removereason9) | Yes | Indicates the reason for deleting a notification. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| @@ -1663,7 +1663,7 @@ Removes a notification for a specified bundle. This API uses a promise to return var hashCode = 'hashCode' var reason = Notification.RemoveReason.CLICK_REASON_REMOVE; Notification.remove(hashCode, reason).then(() => { - console.info("remove sucess"); + console.info("remove success"); }); ``` @@ -1673,7 +1673,7 @@ Notification.remove(hashCode, reason).then(() => { removeAll(bundle: BundleOption, callback: AsyncCallback\): void -Removes all notifications for a specified bundle. This API uses an asynchronous callback to return the result. +Removes all notifications for a specified application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1685,7 +1685,7 @@ Removes all notifications for a specified bundle. This API uses an asynchronous | Name | Type | Mandatory| Description | | -------- | --------------------- | ---- | ---------------------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** @@ -1744,7 +1744,7 @@ Notification.removeAll(removeAllCallback); removeAll(bundle?: BundleOption): Promise\ -Removes all notifications for a specified user. This API uses a promise to return the result. +Removes all notifications for a specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1756,13 +1756,14 @@ Removes all notifications for a specified user. This API uses a promise to retur | Name | Type | Mandatory| Description | | ------ | ------------ | ---- | ---------- | -| bundle | [BundleOption](#bundleoption) | No | Bundle information.| +| bundle | [BundleOption](#bundleoption) | No | Bundle information of the application.| **Example** ```js +// If no application is specified, notifications of all applications are deleted. Notification.removeAll().then(() => { - console.info("removeAll sucess"); + console.info("removeAll success"); }); ``` @@ -1782,7 +1783,7 @@ Removes all notifications for a specified user. This API uses an asynchronous ca | Name | Type | Mandatory| Description | | ------ | ------------ | ---- | ---------- | -| userId | number | Yes | ID of the user who receives the notification.| +| userId | number | Yes | User ID.| | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** @@ -1797,7 +1798,6 @@ function removeAllCallback(err) { } var userId = 1 - Notification.removeAll(userId, removeAllCallback); ``` @@ -1817,22 +1817,15 @@ Removes all notifications for a specified user. This API uses a promise to retur | Name | Type | Mandatory| Description | | ------ | ------------ | ---- | ---------- | -| userId | number | Yes | ID of the user who receives the notification.| +| userId | number | Yes | User ID.| **Example** ```js -function removeAllCallback(err) { - if (err.code) { - console.info("removeAll failed " + JSON.stringify(err)); - } else { - console.info("removeAll success"); - } -} - var userId = 1 - -Notification.removeAll(userId, removeAllCallback); +Notification.removeAll(userId).then(() => { + console.info("removeAll success"); +}); ``` @@ -1892,7 +1885,7 @@ Obtains all active notifications. This API uses a promise to return the result. ```js Notification.getAllActiveNotifications().then((data) => { - console.info("getAllActiveNotifications sucess, data: " + JSON.stringify(data)); + console.info("getAllActiveNotifications success, data: " + JSON.stringify(data)); }); ``` @@ -1902,7 +1895,7 @@ Notification.getAllActiveNotifications().then((data) => { getActiveNotificationCount(callback: AsyncCallback\): void -Obtains the number of active notifications. This API uses an asynchronous callback to return the result. +Obtains the number of active notifications of this application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -1932,21 +1925,21 @@ Notification.getActiveNotificationCount(getActiveNotificationCountCallback); getActiveNotificationCount(): Promise\ -Obtains the number of active notifications. This API uses a promise to return the result. +Obtains the number of active notifications of this application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification **Return value** -| Type | Description | -| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Type | Description | +| ----------------- | ------------------------------------------- | | Promise\ | Promise used to return the result.| **Example** ```js Notification.getActiveNotificationCount().then((data) => { - console.info("getActiveNotificationCount sucess, data: " + JSON.stringify(data)); + console.info("getActiveNotificationCount success, data: " + JSON.stringify(data)); }); ``` @@ -1992,15 +1985,15 @@ Obtains active notifications of this application. This API uses a promise to ret **Return value** -| Type | Description | -| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Type | Description | +| ------------------------------------------------------------ | --------------------------------------- | | Promise\\> | Promise used to return the result.| **Example** ```js Notification.getActiveNotifications().then((data) => { - console.info("removeGroupByBundle sucess, data: " + JSON.stringify(data)); + console.info("removeGroupByBundle success, data: " + JSON.stringify(data)); }); ``` @@ -2010,7 +2003,7 @@ Notification.getActiveNotifications().then((data) => { cancelGroup(groupName: string, callback: AsyncCallback\): void -Cancels a notification group of this application. This API uses an asynchronous callback to return the result. +Cancels notifications under a notification group of this application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -2018,7 +2011,7 @@ Cancels a notification group of this application. This API uses an asynchronous | Name | Type | Mandatory| Description | | --------- | --------------------- | ---- | ---------------------------- | -| groupName | string | Yes | Name of the notification group. | +| groupName | string | Yes | Name of the notification group, which is specified through [NotificationRequest](#notificationrequest) when the notification is published.| | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** @@ -2043,7 +2036,7 @@ Notification.cancelGroup(groupName, cancelGroupCallback); cancelGroup(groupName: string): Promise\ -Cancels a notification group of this application. This API uses a promise to return the result. +Cancels notifications under a notification group of this application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -2058,7 +2051,7 @@ Cancels a notification group of this application. This API uses a promise to ret ```js var groupName = "GroupName"; Notification.cancelGroup(groupName).then(() => { - console.info("cancelGroup sucess"); + console.info("cancelGroup success"); }); ``` @@ -2068,7 +2061,7 @@ Notification.cancelGroup(groupName).then(() => { removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback\): void -Removes a notification group for a specified bundle. This API uses an asynchronous callback to return the result. +Removes notifications under a notification group of a specified application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -2080,7 +2073,7 @@ Removes a notification group for a specified bundle. This API uses an asynchrono | Name | Type | Mandatory| Description | | --------- | --------------------- | ---- | ---------------------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | groupName | string | Yes | Name of the notification group. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| @@ -2107,7 +2100,7 @@ Notification.removeGroupByBundle(bundleOption, groupName, removeGroupByBundleCal removeGroupByBundle(bundle: BundleOption, groupName: string): Promise\ -Removes a notification group for a specified bundle. This API uses a promise to return the result. +Removes notifications under a notification group of a specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -2119,7 +2112,7 @@ Removes a notification group for a specified bundle. This API uses a promise to | Name | Type | Mandatory| Description | | --------- | ------------ | ---- | -------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | groupName | string | Yes | Name of the notification group.| **Example** @@ -2128,7 +2121,7 @@ Removes a notification group for a specified bundle. This API uses a promise to var bundleOption = {bundle: "Bundle"}; var groupName = "GroupName"; Notification.removeGroupByBundle(bundleOption, groupName).then(() => { - console.info("removeGroupByBundle sucess"); + console.info("removeGroupByBundle success"); }); ``` @@ -2202,7 +2195,7 @@ var doNotDisturbDate = { end: new Date(2021, 11, 15, 18, 0) } Notification.setDoNotDisturbDate(doNotDisturbDate).then(() => { - console.info("setDoNotDisturbDate sucess"); + console.info("setDoNotDisturbDate success"); }); ``` @@ -2224,7 +2217,7 @@ Sets the DND time for a specified user. This API uses an asynchronous callback t | Name | Type | Mandatory| Description | | -------- | --------------------- | ---- | ---------------------- | | date | [DoNotDisturbDate](#donotdisturbdate8) | Yes | DND time to set. | -| userId | number | Yes | User ID.| +| userId | number | Yes | ID of the user for whom you want to set the DND time.| | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** @@ -2245,7 +2238,6 @@ var doNotDisturbDate = { } var userId = 1 - Notification.setDoNotDisturbDate(doNotDisturbDate, userId, setDoNotDisturbDateCallback); ``` @@ -2268,7 +2260,7 @@ Sets the DND time for a specified user. This API uses a promise to return the re | Name | Type | Mandatory| Description | | ------ | ---------------- | ---- | -------------- | | date | [DoNotDisturbDate](#donotdisturbdate8) | Yes | DND time to set.| -| userId | number | Yes | User ID.| +| userId | number | Yes | ID of the user for whom you want to set the DND time.| **Example** @@ -2282,7 +2274,7 @@ var doNotDisturbDate = { var userId = 1 Notification.setDoNotDisturbDate(doNotDisturbDate, userId).then(() => { - console.info("setDoNotDisturbDate sucess"); + console.info("setDoNotDisturbDate success"); }); ``` @@ -2308,7 +2300,7 @@ Obtains the DND time. This API uses an asynchronous callback to return the resul **Example** ```js -function getDoNotDisturbDateCallback(err,data) { +function getDoNotDisturbDateCallback(err, data) { if (err.code) { console.info("getDoNotDisturbDate failed " + JSON.stringify(err)); } else { @@ -2335,15 +2327,15 @@ Obtains the DND time. This API uses a promise to return the result. **Return value** -| Type | Description | -| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Type | Description | +| ------------------------------------------------- | ----------------------------------------- | | Promise\<[DoNotDisturbDate](#donotdisturbdate8)\> | Promise used to return the result.| **Example** ```js Notification.getDoNotDisturbDate().then((data) => { - console.info("getDoNotDisturbDate sucess, data: " + JSON.stringify(data)); + console.info("getDoNotDisturbDate success, data: " + JSON.stringify(data)); }); ``` @@ -2405,8 +2397,8 @@ Obtains the DND time of a specified user. This API uses a promise to return the **Return value** -| Type | Description | -| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Type | Description | +| ------------------------------------------------- | ----------------------------------------- | | Promise\<[DoNotDisturbDate](#donotdisturbdate8)\> | Promise used to return the result.| **Example** @@ -2415,7 +2407,7 @@ Obtains the DND time of a specified user. This API uses a promise to return the var userId = 1 Notification.getDoNotDisturbDate(userId).then((data) => { - console.info("getDoNotDisturbDate sucess, data: " + JSON.stringify(data)); + console.info("getDoNotDisturbDate success, data: " + JSON.stringify(data)); }); ``` @@ -2424,7 +2416,7 @@ Notification.getDoNotDisturbDate(userId).then((data) => { supportDoNotDisturbMode(callback: AsyncCallback\): void -Checks whether the DND mode is supported. This API uses an asynchronous callback to return the result. +Checks whether DND mode is supported. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -2458,7 +2450,7 @@ Notification.supportDoNotDisturbMode(supportDoNotDisturbModeCallback); supportDoNotDisturbMode(): Promise\ -Checks whether the DND mode is supported. This API uses a promise to return the result. +Checks whether DND mode is supported. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -2476,7 +2468,7 @@ Checks whether the DND mode is supported. This API uses a promise to return the ```js Notification.supportDoNotDisturbMode().then((data) => { - console.info("supportDoNotDisturbMode sucess, data: " + JSON.stringify(data)); + console.info("supportDoNotDisturbMode success, data: " + JSON.stringify(data)); }); ``` @@ -2567,7 +2559,7 @@ function requestEnableNotificationCallback(err) { if (err.code) { console.info("requestEnableNotification failed " + JSON.stringify(err)); } else { - + console.info("requestEnableNotification success"); } }; @@ -2587,10 +2579,9 @@ Requests notification to be enabled for this application. This API uses a promis **Example** ```javascript -Notification.requestEnableNotification() - .then(() => { - console.info("requestEnableNotification sucess"); - }); +Notification.requestEnableNotification().then(() => { + console.info("requestEnableNotification success"); +}); ``` @@ -2610,7 +2601,7 @@ Sets whether this device supports distributed notifications. This API uses an as | Name | Type | Mandatory| Description | | -------- | ------------------------ | ---- | -------------------------- | -| enable | boolean | Yes | Whether the device supports distributed notifications.
**true**: The device supports distributed notifications.
**false**: The device does not support distributed notifications.| +| enable | boolean | Yes | Whether the device supports distributed notifications.| | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** @@ -2647,17 +2638,15 @@ Sets whether this device supports distributed notifications. This API uses a pro | Name | Type | Mandatory| Description | | -------- | ------------------------ | ---- | -------------------------- | -| enable | boolean | Yes | Whether the device supports distributed notifications.
**true**: The device supports distributed notifications.
**false**: The device does not support distributed notifications.| +| enable | boolean | Yes | Whether the device supports distributed notifications.| **Example** ```javascript var enable = true - -Notification.enableDistributed(enable) - .then(() => { - console.info("enableDistributed sucess"); - }); +Notification.enableDistributed(enable).then(() => { + console.info("enableDistributed success"); +}); ``` @@ -2665,7 +2654,7 @@ Notification.enableDistributed(enable) isDistributedEnabled(callback: AsyncCallback\): void -Obtains whether this device supports distributed notifications. This API uses an asynchronous callback to return the result. +Checks whether this device supports distributed notifications. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -2695,23 +2684,22 @@ Notification.isDistributedEnabled(isDistributedEnabledCallback); isDistributedEnabled(): Promise\ -Obtains whether this device supports distributed notifications. This API uses a promise to return the result. +Checks whether this device supports distributed notifications. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification **Return value** -| Type | Description | -| ------------------ | --------------- | -| Promise\ | Promise used to return the result.
**true**: The device supports distributed notifications.
**false**: The device does not support distributed notifications.| +| Type | Description | +| ------------------ | --------------------------------------------- | +| Promise\ | Promise used to return the result.| **Example** ```javascript -Notification.isDistributedEnabled() - .then((data) => { - console.info("isDistributedEnabled sucess, data: " + JSON.stringify(data)); - }); +Notification.isDistributedEnabled().then((data) => { + console.info("isDistributedEnabled success, data: " + JSON.stringify(data)); +}); ``` @@ -2719,7 +2707,7 @@ Notification.isDistributedEnabled() enableDistributedByBundle(bundle: BundleOption, enable: boolean, callback: AsyncCallback\): void -Sets whether an application supports distributed notifications based on the bundle. This API uses an asynchronous callback to return the result. +Sets whether a specified application supports distributed notifications. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -2731,7 +2719,7 @@ Sets whether an application supports distributed notifications based on the bund | Name | Type | Mandatory| Description | | -------- | ------------------------ | ---- | -------------------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Application bundle. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | enable | boolean | Yes | Whether the device supports distributed notifications. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| @@ -2761,7 +2749,7 @@ Notification.enableDistributedByBundle(bundle, enable, enableDistributedByBundle enableDistributedByBundle(bundle: BundleOption, enable: boolean): Promise\ -Sets whether an application supports distributed notifications based on the bundle. This API uses a promise to return the result. +Sets whether a specified application supports distributed notifications. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -2784,11 +2772,9 @@ var bundle = { } var enable = true - -Notification.enableDistributedByBundle(bundle, enable) - .then(() => { - console.info("enableDistributedByBundle sucess"); - }); +Notification.enableDistributedByBundle(bundle, enable).then(() => { + console.info("enableDistributedByBundle success"); +}); ``` ## Notification.isDistributedEnabledByBundle8+ @@ -2834,7 +2820,7 @@ Notification.isDistributedEnabledByBundle(bundle, isDistributedEnabledByBundleCa isDistributedEnabledByBundle(bundle: BundleOption): Promise\ -Obtains whether an application supports distributed notifications based on the bundle. This API uses a promise to return the result. +Checks whether a specified application supports distributed notifications. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -2850,9 +2836,9 @@ Obtains whether an application supports distributed notifications based on the b **Return value** -| Type | Description | -| ------------------ | --------------- | -| Promise\ | Promise used to return the result.
**true**: The device supports distributed notifications.
**false**: The device does not support distributed notifications.| +| Type | Description | +| ------------------ | ------------------------------------------------- | +| Promise\ | Promise used to return the result.| **Example** @@ -2861,10 +2847,9 @@ var bundle = { bundle: "bundleName1", } -Notification.isDistributedEnabledByBundle(bundle) - .then((data) => { - console.info("isDistributedEnabledByBundle sucess, data: " + JSON.stringify(data)); - }); +Notification.isDistributedEnabledByBundle(bundle).then((data) => { + console.info("isDistributedEnabledByBundle success, data: " + JSON.stringify(data)); +}); ``` @@ -2923,10 +2908,9 @@ Obtains the notification reminder type. This API uses a promise to return the re **Example** ```javascript -Notification.getDeviceRemindType() - .then((data) => { - console.info("getDeviceRemindType sucess, data: " + JSON.stringify(data)); - }); +Notification.getDeviceRemindType().then((data) => { + console.info("getDeviceRemindType success, data: " + JSON.stringify(data)); +}); ``` @@ -2944,18 +2928,18 @@ Publishes an agent-powered notification. This API uses an asynchronous callback **Parameters** -| Name | Type | Mandatory| Description | -| -------------------- | ------------------------------------------- | ---- | --------------------------------------------- | -| request | [NotificationRequest](#notificationrequest) | Yes | **NotificationRequest** object.| -| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | -| userId | number | Yes | ID of the user who receives the notification. | -| callback | AsyncCallback | Yes | Callback used to return the result. | +| Name | Type | Mandatory| Description | +| -------------------- | ------------------------------------------- | ---- | ---------------------------------------- | +| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.| +| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | +| userId | number | Yes | User ID. | +| callback | AsyncCallback | Yes | Callback used to return the result. | **Example** ```js -// Callback for publishAsBundle -function publishAsBundleCallback(err) { +// publishAsBundle callback +function callback(err) { if (err.code) { console.info("publishAsBundle failed " + JSON.stringify(err)); } else { @@ -2964,10 +2948,10 @@ function publishAsBundleCallback(err) { } // Bundle name of the application whose notification function is taken over by the reminder agent let representativeBundle = "com.example.demo" -// ID of the user who receives the notification +// User ID let userId = 100 // NotificationRequest object -let notificationRequest = { +let request = { id: 1, content: { contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, @@ -2979,7 +2963,7 @@ let notificationRequest = { } } -Notification.publishAsBundle(notificationRequest, representativeBundle, userId, publishAsBundleCallback); +Notification.publishAsBundle(request, representativeBundle, userId, callback); ``` ## Notification.publishAsBundle9+ @@ -2999,19 +2983,19 @@ Publishes a notification through the reminder agent. This API uses a promise to | Name | Type | Mandatory| Description | | -------------------- | ------------------------------------------- | ---- | --------------------------------------------- | -| request | [NotificationRequest](#notificationrequest) | Yes | **NotificationRequest** object.| +| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.| | representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | -| userId | number | Yes | ID of the user who receives the notification. | +| userId | number | Yes | User ID. | **Example** ```js // Bundle name of the application whose notification function is taken over by the reminder agent let representativeBundle = "com.example.demo" -// ID of the user who receives the notification +// User ID let userId = 100 // NotificationRequest object -var notificationRequest = { +var request = { id: 1, content: { contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, @@ -3023,8 +3007,8 @@ var notificationRequest = { } } -Notification.publishAsBundle(notificationRequest, representativeBundle, userId).then(() => { - console.info("publishAsBundle sucess"); +Notification.publishAsBundle(request, representativeBundle, userId).then(() => { + console.info("publishAsBundle success"); }); ``` @@ -3048,13 +3032,13 @@ Cancels a notification published by the reminder agent. This API uses an asynchr | -------------------- | ------------- | ---- | ------------------------ | | id | number | Yes | Notification ID. | | representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | -| userId | number | Yes | ID of the user who receives the notification. | +| userId | number | Yes | User ID. | | callback | AsyncCallback | Yes | Callback used to return the result.| **Example** ```js -//cancelAsBundle +// cancelAsBundle function cancelAsBundleCallback(err) { if (err.code) { console.info("cancelAsBundle failed " + JSON.stringify(err)); @@ -3064,7 +3048,7 @@ function cancelAsBundleCallback(err) { } // Bundle name of the application whose notification function is taken over by the reminder agent let representativeBundle = "com.example.demo" -// ID of the user who receives the notification +// User ID let userId = 100 Notification.cancelAsBundle(0, representativeBundle, userId, cancelAsBundleCallback); @@ -3074,7 +3058,7 @@ Notification.cancelAsBundle(0, representativeBundle, userId, cancelAsBundleCallb cancelAsBundle(id: number, representativeBundle: string, userId: number): Promise\ -Publishes a notification through the reminder agent. This API uses a promise to return the result. +Cancels a notification published by the reminder agent. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -3090,14 +3074,14 @@ Publishes a notification through the reminder agent. This API uses a promise to | -------------------- | ------ | ---- | ------------------ | | id | number | Yes | Notification ID. | | representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent.| -| userId | number | Yes | ID of the user who receives the notification.| +| userId | number | Yes | User ID.| **Example** ```js // Bundle name of the application whose notification function is taken over by the reminder agent let representativeBundle = "com.example.demo" -// ID of the user who receives the notification +// User ID let userId = 100 Notification.cancelAsBundle(0, representativeBundle, userId).then(() => { @@ -3109,7 +3093,7 @@ Notification.cancelAsBundle(0, representativeBundle, userId).then(() => { enableNotificationSlot(bundle: BundleOption, type: SlotType, enable: boolean, callback: AsyncCallback\): void -Sets the enabled status for a notification slot of a specified type. This API uses an asynchronous callback to return the result. +Sets the enabled status of a notification slot type for a specified application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -3121,7 +3105,7 @@ Sets the enabled status for a notification slot of a specified type. This API us | Name | Type | Mandatory| Description | | -------- | ----------------------------- | ---- | ---------------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | type | [SlotType](#slottype) | Yes | Notification slot type. | | enable | boolean | Yes | Whether to enable notification. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| @@ -3129,7 +3113,7 @@ Sets the enabled status for a notification slot of a specified type. This API us **Example** ```js -//enableNotificationSlot +// enableNotificationSlot function enableSlotCallback(err) { if (err.code) { console.info("enableNotificationSlot failed " + JSON.stringify(err)); @@ -3149,7 +3133,7 @@ Notification.enableNotificationSlot( enableNotificationSlot(bundle: BundleOption, type: SlotType, enable: boolean): Promise\ -Sets the enabled status for a notification slot of a specified type. This API uses a promise to return the result. +Sets the enabled status of a notification slot type for a specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -3161,27 +3145,25 @@ Sets the enabled status for a notification slot of a specified type. This API us | Name| Type | Mandatory| Description | | ------ | ----------------------------- | ---- | -------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | type | [SlotType](#slottype) | Yes | Notification slot type.| | enable | boolean | Yes | Whether to enable notification. | **Example** ```js -//enableNotificationSlot -Notification.enableNotificationSlot( - { bundle: "ohos.samples.notification", }, - Notification.SlotType.SOCIAL_COMMUNICATION, - true).then(() => { - console.info("enableNotificationSlot sucess"); - }); +// enableNotificationSlot +Notification.enableNotificationSlot({ bundle: "ohos.samples.notification", }, + Notification.SlotType.SOCIAL_COMMUNICATION,true).then(() => { + console.info("enableNotificationSlot success"); +}); ``` ## Notification.isNotificationSlotEnabled 9+ isNotificationSlotEnabled(bundle: BundleOption, type: SlotType, callback: AsyncCallback\): void -Obtains the enabled status of the notification slot of a specified type. This API uses an asynchronous callback to return the result. +Checks whether a specified notification slot type is enabled for a specified application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -3193,14 +3175,14 @@ Obtains the enabled status of the notification slot of a specified type. This AP | Name | Type | Mandatory| Description | | -------- | ----------------------------- | ---- | ---------------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | type | [SlotType](#slottype) | Yes | Notification slot type. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** ```js -//isNotificationSlotEnabled +// isNotificationSlotEnabled function getEnableSlotCallback(err, data) { if (err.code) { console.info("isNotificationSlotEnabled failed " + JSON.stringify(err)); @@ -3219,7 +3201,7 @@ Notification.isNotificationSlotEnabled( isNotificationSlotEnabled(bundle: BundleOption, type: SlotType): Promise\ -Obtains the enabled status of the notification slot of a specified type. This API uses a promise to return the result. +Checks whether a specified notification slot type is enabled for a specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -3231,25 +3213,23 @@ Obtains the enabled status of the notification slot of a specified type. This AP | Name| Type | Mandatory| Description | | ------ | ----------------------------- | ---- | -------------- | -| bundle | [BundleOption](#bundleoption) | Yes | Bundle information. | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | | type | [SlotType](#slottype) | Yes | Notification slot type.| **Return value** -| Type | Description | -| ----------------------------------------------------------- | ------------------------------------------------------------ | -| Promise\ | Promise used to return the enabled status of the notification slot of the specified type.| +| Type | Description | +| ------------------ | ------------------------------- | +| Promise\ | Promise used to return the result.| **Example** ```js -//isNotificationSlotEnabled -Notification.isNotificationSlotEnabled( - { bundle: "ohos.samples.notification", }, - Notification.SlotType.SOCIAL_COMMUNICATION - ).then((data) => { - console.info("isNotificationSlotEnabled success, data: " + JSON.stringify(data)); - }); +// isNotificationSlotEnabled +Notification.isNotificationSlotEnabled({ bundle: "ohos.samples.notification", }, + Notification.SlotType.SOCIAL_COMMUNICATION).then((data) => { + console.info("isNotificationSlotEnabled success, data: " + JSON.stringify(data)); +}); ``` @@ -3257,7 +3237,7 @@ Notification.isNotificationSlotEnabled( setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean, callback: AsyncCallback\): void -Sets whether to sync notifications to devices where the application is not installed. This API uses an asynchronous callback to return the result. +Sets whether to enable the notification sync feature for devices where the application is not installed. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -3270,7 +3250,7 @@ Sets whether to sync notifications to devices where the application is not insta | Name| Type | Mandatory| Description | | ------ | ----------------------------- | ---- | -------------- | | userId | number | Yes | User ID. | -| enable | boolean | Yes | Whether the feature is enabled.
**true**: enabled
**false**: disabled | +| enable | boolean | Yes | Whether the feature is enabled. | | callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** @@ -3279,7 +3259,7 @@ Sets whether to sync notifications to devices where the application is not insta let userId = 100; let enable = true; -function setSyncNotificationEnabledWithoutAppCallback(err) { +function callback(err) { if (err.code) { console.info("setSyncNotificationEnabledWithoutApp failed " + JSON.stringify(err)); } else { @@ -3287,7 +3267,7 @@ function setSyncNotificationEnabledWithoutAppCallback(err) { } } -Notification.setSyncNotificationEnabledWithoutApp(userId, enable, setSyncNotificationEnabledWithoutAppCallback); +Notification.setSyncNotificationEnabledWithoutApp(userId, enable, callback); ``` @@ -3295,7 +3275,7 @@ Notification.setSyncNotificationEnabledWithoutApp(userId, enable, setSyncNotific setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean): Promise\ -Sets whether to sync notifications to devices where the application is not installed. This API uses a promise to return the result. +Sets whether to enable the notification sync feature for devices where the application is not installed. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -3308,7 +3288,7 @@ Sets whether to sync notifications to devices where the application is not insta | Name| Type | Mandatory| Description | | ------ | ----------------------------- | ---- | -------------- | | userId | number | Yes | User ID. | -| enable | boolean | Yes | Whether the feature is enabled.
**true**: enabled
**false**: disabled | +| enable | boolean | Yes | Whether the feature is enabled. | **Return value** @@ -3322,13 +3302,11 @@ Sets whether to sync notifications to devices where the application is not insta let userId = 100; let enable = true; -Notification.setSyncNotificationEnabledWithoutApp(userId, enable) - .then(() => { - console.info('setSyncNotificationEnabledWithoutApp'); - }) - .catch((err) => { - console.info('setSyncNotificationEnabledWithoutApp, err:', err); - }); +Notification.setSyncNotificationEnabledWithoutApp(userId, enable).then(() => { + console.info('setSyncNotificationEnabledWithoutApp success'); +}).catch((err) => { + console.info('setSyncNotificationEnabledWithoutApp, err:' + JSON.stringify(err)); +}); ``` @@ -3336,7 +3314,7 @@ Notification.setSyncNotificationEnabledWithoutApp(userId, enable) getSyncNotificationEnabledWithoutApp(userId: number, callback: AsyncCallback\): void -Obtains whether notifications are synced to devices where the application is not installed. This API uses an asynchronous callback to return the result. +Obtains whether the notification sync feature is enabled for devices where the application is not installed. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -3349,18 +3327,18 @@ Obtains whether notifications are synced to devices where the application is not | Name| Type | Mandatory| Description | | ------ | ----------------------------- | ---- | -------------- | | userId | number | Yes | User ID. | -| callback | AsyncCallback\ | Yes | Callback used to return the result.
**true**: Notifications are synced to devices where the application is not installed.
**false**: Notifications are not synced to devices where the application is not installed.| +| callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** ```js let userId = 100; -function getSyncNotificationEnabledWithoutAppCallback(data, err) { +function getSyncNotificationEnabledWithoutAppCallback(err, data) { if (err) { - console.info('getSyncNotificationEnabledWithoutAppCallback, err' + err); + console.info('getSyncNotificationEnabledWithoutAppCallback, err:' + err); } else { - console.info('getSyncNotificationEnabledWithoutAppCallback, data' + data); + console.info('getSyncNotificationEnabledWithoutAppCallback, data:' + data); } } @@ -3372,7 +3350,7 @@ Notification.getSyncNotificationEnabledWithoutApp(userId, getSyncNotificationEna getSyncNotificationEnabledWithoutApp(userId: number): Promise\ -Obtains whether notifications are synced to devices where the application is not installed. This API uses a promise to return the result. +Obtains whether the notification sync feature is enabled for devices where the application is not installed. This API uses a promise to return the result. **System capability**: SystemCapability.Notification.Notification @@ -3388,29 +3366,26 @@ Obtains whether notifications are synced to devices where the application is not **Return value** -| Type | Description | -| ----------------------------------------------------------- | ------------------------------------------------------------ | -| Promise\ | Promise used to return the result.
**true**: Notifications are synced to devices where the application is not installed.
**false**: Notifications are not synced to devices where the application is not installed.| +| Type | Description | +| ------------------ | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| **Example** ```js let userId = 100; - -Notification.getSyncNotificationEnabledWithoutApp(userId) - .then((data) => { - console.info('getSyncNotificationEnabledWithoutApp, data:', data); - }) - .catch((err) => { - console.info('getSyncNotificationEnabledWithoutApp, err:', err); - }); +Notification.getSyncNotificationEnabledWithoutApp(userId).then((data) => { + console.info('getSyncNotificationEnabledWithoutApp, data:' + data); +}).catch((err) => { + console.info('getSyncNotificationEnabledWithoutApp, err:' + err); +}); ``` ## NotificationSubscriber -Provides callbacks for receiving or removing notifications. +Provides callbacks for receiving or removing notifications and serves as the input parameter of [subscribe](#notificationsubscribe). **System API**: This is a system API and cannot be called by third-party applications. @@ -3428,7 +3403,7 @@ Callback for receiving notifications. | Name| Type| Mandatory| Description| | ------------ | ------------------------ | ---- | -------------------------- | -| data | [SubscribeCallbackData](#subscribecallbackdata) | Yes| Notification information returned.| +| data | [SubscribeCallbackData](#subscribecallbackdata) | Yes| Information about the notification received.| **Example** @@ -3442,7 +3417,6 @@ function subscribeCallback(err) { }; function onConsumeCallback(data) { - console.info('===> onConsume in test'); let req = data.request; console.info('===> onConsume callback req.id:' + req.id); }; @@ -3458,7 +3432,7 @@ Notification.subscribe(subscriber, subscribeCallback); onCancel?:(data: [SubscribeCallbackData](#subscribecallbackdata)) => void -Callback for removing notifications. +Callback for canceling notifications. **System capability**: SystemCapability.Notification.Notification @@ -3468,7 +3442,7 @@ Callback for removing notifications. | Name| Type| Mandatory| Description| | ------------ | ------------------------ | ---- | -------------------------- | -| data | [SubscribeCallbackData](#subscribecallbackdata) | Yes| Notification information returned.| +| data | [SubscribeCallbackData](#subscribecallbackdata) | Yes| Information about the notification to cancel.| **Example** @@ -3482,7 +3456,6 @@ function subscribeCallback(err) { }; function onCancelCallback(data) { - console.info('===> onCancel in test'); let req = data.request; console.info('===> onCancel callback req.id:' + req.id); } @@ -3508,7 +3481,7 @@ Callback for notification sorting updates. | Name| Type| Mandatory| Description| | ------------ | ------------------------ | ---- | -------------------------- | -| data | [NotificationSortingMap](#notificationsortingmap) | Yes| Notification information returned.| +| data | [NotificationSortingMap](#notificationsortingmap) | Yes| Latest notification sorting list.| **Example** @@ -3521,8 +3494,8 @@ function subscribeCallback(err) { } }; -function onUpdateCallback() { - console.info('===> onUpdate in test'); +function onUpdateCallback(map) { + console.info('===> onUpdateCallback map:' + JSON.stringify(map)); } var subscriber = { @@ -3584,16 +3557,30 @@ function subscribeCallback(err) { console.info("subscribeCallback"); } }; +function unsubscribeCallback(err) { + if (err.code) { + console.info("unsubscribe failed " + JSON.stringify(err)); + } else { + console.info("unsubscribeCallback"); + } +}; +function onConnectCallback() { + console.info('===> onConnect in test'); +} function onDisconnectCallback() { console.info('===> onDisconnect in test'); } var subscriber = { + onConnect: onConnectCallback, onDisconnect: onDisconnectCallback }; +// The onConnect callback is invoked when subscription to the notification is complete. Notification.subscribe(subscriber, subscribeCallback); +// The onDisconnect callback is invoked when unsubscription to the notification is complete. +Notification.unsubscribe(subscriber, unsubscribeCallback); ``` ### onDestroy @@ -3654,15 +3641,24 @@ function subscribeCallback(err) { } }; -function onDoNotDisturbDateChangeCallback() { - console.info('===> onDoNotDisturbDateChange in test'); +function onDoNotDisturbDateChangeCallback(mode) { + console.info('===> onDoNotDisturbDateChange:' + mode); } var subscriber = { onDoNotDisturbDateChange: onDoNotDisturbDateChangeCallback }; - Notification.subscribe(subscriber, subscribeCallback); + +var doNotDisturbDate = { + type: Notification.DoNotDisturbType.TYPE_ONCE, + begin: new Date(), + end: new Date(2021, 11, 15, 18, 0) +} +// Set the onDoNotDisturbDateChange callback for DND time setting updates. +Notification.setDoNotDisturbDate(doNotDisturbDate).then(() => { + console.info("setDoNotDisturbDate sucess"); +}); ``` @@ -3670,7 +3666,7 @@ Notification.subscribe(subscriber, subscribeCallback); onEnabledNotificationChanged?:(callbackData: [EnabledNotificationCallbackData](#enablednotificationcallbackdata8)) => void -Listens for the notification enable status changes. This API uses an asynchronous callback to return the result. +Listens for the notification enabled status changes. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Notification.Notification @@ -3694,16 +3690,23 @@ function subscribeCallback(err) { }; function onEnabledNotificationChangedCallback(callbackData) { - console.info("bundle: ", callbackData.bundle); - console.info("uid: ", callbackData.uid); - console.info("enable: ", callbackData.enable); + console.info("bundle: " + callbackData.bundle); + console.info("uid: " + callbackData.uid); + console.info("enable: " + callbackData.enable); }; var subscriber = { onEnabledNotificationChanged: onEnabledNotificationChangedCallback }; - Notification.subscribe(subscriber, subscribeCallback); + +var bundle = { + bundle: "bundleName1", +} +// Set the onEnabledNotificationChanged callback that is triggered when the notification enabled status changes. +Notification.enableNotification(bundle, false).then(() => { + console.info("enableNotification sucess"); +}); ``` ## SubscribeCallbackData @@ -3740,13 +3743,11 @@ Notification.subscribe(subscriber, subscribeCallback); **System API**: This is a system API and cannot be called by third-party applications. -| Name | Type | Readable| Writable| Description | -| ----- ------------------------------------- || ---- | --- | ------------------------ | -| type | [DoNotDisturbType](#donotdisturbtype8) | Yes | No | DND time type.| -| begin | Date | Yes | No | DND start time.| -| end | Date | Yes | No | DND end time.| - - +| Name | Type | Readable| Writable| Description | +| ----- | -------------------------------------- | ---- | ---- | ---------------------- | +| type | [DoNotDisturbType](#donotdisturbtype8) | Yes | Yes | DND time type.| +| begin | Date | Yes | Yes | DND start time.| +| end | Date | Yes | Yes | DND end time.| ## DoNotDisturbType8+ @@ -3793,7 +3794,7 @@ Notification.subscribe(subscriber, subscribeCallback); | Name | Type | Readable| Writable| Description | | ------ | ------ |---- | --- | ------ | -| bundle | string | Yes | Yes | Bundle name. | +| bundle | string | Yes | Yes | Bundle information of the application.| | uid | number | Yes | Yes | User ID.| @@ -3823,14 +3824,14 @@ Notification.subscribe(subscriber, subscribeCallback); ## NotificationActionButton -Enumerates the buttons in the notification. +Describes the button displayed in the notification. **System capability**: SystemCapability.Notification.Notification | Name | Type | Readable| Writable| Description | | --------- | ----------------------------------------------- | --- | ---- | ------------------------- | | title | string | Yes | Yes | Button title. | -| wantAgent | WantAgent | Yes | Yes | **WantAgent** of the button.| +| wantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes | Yes | **WantAgent** of the button.| | extras | { [key: string]: any } | Yes | Yes | Extra information of the button. | | userInput8+ | [NotificationUserInput](#notificationuserinput8) | Yes | Yes | User input object. | @@ -3893,7 +3894,7 @@ Describes the picture-attached notification. | additionalText | string | Yes | Yes | Additional information of the notification.| | briefText | string | Yes | Yes | Brief text of the notification.| | expandedTitle | string | Yes | Yes | Title of the notification in the expanded state. | -| picture | image.PixelMap | Yes | Yes | Picture attached to the notification. | +| picture | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes | Yes | Picture attached to the notification. | ## NotificationContent @@ -3934,8 +3935,8 @@ Enumerates notification flags. | Name | Type | Readable| Writable| Description | | ---------------- | ---------------------- | ---- | ---- | --------------------------------- | -| soundEnabled | NotificationFlagStatus | Yes | No | Whether to enable the sound alert for the notification. | -| vibrationEnabled | NotificationFlagStatus | Yes | No | Whether to enable vibration for the notification. | +| soundEnabled | [NotificationFlagStatus](#notificationflagstatus8) | Yes | No | Whether to enable the sound alert for the notification. | +| vibrationEnabled | [NotificationFlagStatus](#notificationflagstatus8) | Yes | No | Whether to enable vibration for the notification. | ## NotificationRequest @@ -3954,48 +3955,47 @@ Describes the notification request. | deliveryTime | number | Yes | Yes | Time when the notification is sent. | | tapDismissed | boolean | Yes | Yes | Whether the notification is automatically cleared. | | autoDeletedTime | number | Yes | Yes | Time when the notification is automatically cleared. | -| wantAgent | WantAgent | Yes | Yes | **WantAgent** instance to which the notification will be redirected after being clicked. | +| wantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes | Yes | **WantAgent** instance to which the notification will be redirected after being clicked. | | extraInfo | {[key: string]: any} | Yes | Yes | Extended parameters. | -| color | number | Yes | Yes | Background color of the notification. Not supported currently. | -| colorEnabled | boolean | Yes | Yes | Whether the notification background color is enabled. Not supported currently. | +| color | number | Yes | Yes | Background color of the notification. Not supported currently.| +| colorEnabled | boolean | Yes | Yes | Whether the notification background color is enabled. Not supported currently.| | isAlertOnce | boolean | Yes | Yes | Whether the notification triggers an alert only once.| | isStopwatch | boolean | Yes | Yes | Whether to display the stopwatch. | | isCountDown | boolean | Yes | Yes | Whether to display the countdown time. | -| isFloatingIcon | boolean | Yes | Yes | Whether the notification is displayed as a floating icon. | +| isFloatingIcon | boolean | Yes | Yes | Whether the notification is displayed as a floating icon in the status bar. | | label | string | Yes | Yes | Notification label. | | badgeIconStyle | number | Yes | Yes | Notification badge type. | | showDeliveryTime | boolean | Yes | Yes | Whether to display the time when the notification is delivered. | | actionButtons | Array\<[NotificationActionButton](#notificationactionbutton)\> | Yes | Yes | Buttons in the notification. Up to two buttons are allowed. | -| smallIcon | PixelMap | Yes | Yes | Small notification icon. | -| largeIcon | PixelMap | Yes | Yes | Large notification icon. | +| smallIcon | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes | Yes | Small notification icon. This field is optional, and the icon size cannot exceed 30 KB.| +| largeIcon | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes | Yes | Large notification icon. This field is optional, and the icon size cannot exceed 30 KB.| | creatorBundleName | string | Yes | No | Name of the bundle that creates the notification. | | creatorUid | number | Yes | No | UID used for creating the notification. | | creatorPid | number | Yes | No | PID used for creating the notification. | | creatorUserId8+| number | Yes | No | ID of the user who creates the notification. | | hashCode | string | Yes | No | Unique ID of the notification. | | classification | string | Yes | Yes | Notification category.
**System API**: This is a system API and cannot be called by third-party applications. | -| groupName8+| string | Yes | Yes | Group notification name. | +| groupName8+| string | Yes | Yes | Notification group name. | | template8+ | [NotificationTemplate](#notificationtemplate8) | Yes | Yes | Notification template. | | isRemoveAllowed8+ | boolean | Yes | No | Whether the notification can be removed.
**System API**: This is a system API and cannot be called by third-party applications. | | source8+ | number | Yes | No | Notification source.
**System API**: This is a system API and cannot be called by third-party applications. | -| distributedOption8+ | [DistributedOptions](#distributedoptions8) | Yes | Yes | Option of distributed notification. | +| distributedOption8+ | [DistributedOptions](#distributedoptions8) | Yes | Yes | Distributed notification options. | | deviceId8+ | string | Yes | No | Device ID of the notification source.
**System API**: This is a system API and cannot be called by third-party applications. | | notificationFlags8+ | [NotificationFlags](#notificationflags8) | Yes | No | Notification flags. | -| removalWantAgent9+ | WantAgent | Yes | Yes | **WantAgent** instance to which the notification will be redirected when it is removed. | +| removalWantAgent9+ | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes | Yes | **WantAgent** instance to which the notification will be redirected when it is removed. | | badgeNumber9+ | number | Yes | Yes | Number of notifications displayed on the application icon. | - ## DistributedOptions8+ -Describes distributed options. +Describes distributed notifications options. **System capability**: SystemCapability.Notification.Notification | Name | Type | Readable| Writable| Description | | ---------------------- | -------------- | ---- | ---- | ---------------------------------- | | isDistributed | boolean | Yes | Yes | Whether the notification is a distributed notification. | -| supportDisplayDevices | Array\ | Yes | Yes | Types of the devices to which the notification can be synchronized. | -| supportOperateDevices | Array\ | Yes | Yes | Devices on which notification can be enabled. | +| supportDisplayDevices | Array\ | Yes | Yes | List of the devices to which the notification can be synchronized. | +| supportOperateDevices | Array\ | Yes | Yes | List of the devices on which the notification can be opened. | | remindType | number | Yes | No | Notification reminder type.
**System API**: This is a system API and cannot be called by third-party applications. | @@ -4011,14 +4011,14 @@ Describes the notification slot. | level | number | Yes | Yes | Notification level. If this parameter is not set, the default value is used based on the notification slot type.| | desc | string | Yes | Yes | Notification slot description. | | badgeFlag | boolean | Yes | Yes | Whether to display the badge. | -| bypassDnd | boolean | Yes | Yes | Whether to bypass the DND mode in the system. | +| bypassDnd | boolean | Yes | Yes | Whether to bypass DND mode in the system. | | lockscreenVisibility | number | Yes | Yes | Mode for displaying the notification on the lock screen. | -| vibrationEnabled | boolean | Yes | Yes | Whether vibration is supported for the notification. | +| vibrationEnabled | boolean | Yes | Yes | Whether vibration is enabled for the notification. | | sound | string | Yes | Yes | Notification alert tone. | | lightEnabled | boolean | Yes | Yes | Whether the indicator blinks for the notification. | | lightColor | number | Yes | Yes | Indicator color of the notification. | | vibrationValues | Array\ | Yes | Yes | Vibration mode of the notification. | -| enabled9+ | boolean | Yes | No | Enabled status of the notification slot. | +| enabled9+ | boolean | Yes | No | Whether the notification slot is enabled. | ## NotificationSorting @@ -4066,7 +4066,7 @@ Provides the information about the publisher for notification subscription. ## NotificationTemplate8+ -Notification template. +Describes the notification template. **System capability**: SystemCapability.Notification.Notification @@ -4121,5 +4121,5 @@ Provides the notification user input. | Name | Value | Description | | -------------------- | --- | -------------------- | -| CLICK_REASON_REMOVE | 1 | The notification is removed due to a click on it. | +| CLICK_REASON_REMOVE | 1 | The notification is removed after a click on it. | | CANCEL_REASON_REMOVE | 2 | The notification is removed by the user. | diff --git a/en/application-dev/reference/apis/js-apis-notificationManager.md b/en/application-dev/reference/apis/js-apis-notificationManager.md new file mode 100644 index 0000000000000000000000000000000000000000..2d8f497bede97cc9c6d1a8d408b6e80770a2396f --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-notificationManager.md @@ -0,0 +1,3968 @@ +# @ohos.notificationManager + +The **notificationManager** module provides notification management capabilities, covering notifications, notification slots, notification enabled status, and notification badge status. + +> **NOTE** +> +> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. + +## Modules to Import + +```js +import Notification from '@ohos.notificationManager'; +``` + +## Notification.publish + +publish(request: NotificationRequest, callback: AsyncCallback\): void + +Publishes a notification. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------- | ---- | ------------------------------------------- | +| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.| +| callback | AsyncCallback\ | Yes | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600004 | Notification is not enabled. | +| 1600005 | Notification slot is not enabled. | +| 1600009 | Over max number notifications per second. | + +**Example** + +```js +// publish callback +function publishCallback(err) { + if (err) { + console.info("publish failed " + JSON.stringify(err)); + } else { + console.info("publish success"); + } +} +// NotificationRequest object +var notificationRequest = { + id: 1, + content: { + contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + normal: { + title: "test_title", + text: "test_text", + additionalText: "test_additionalText" + } + } +} +Notification.publish(notificationRequest, publishCallback) +``` + + + +## Notification.publish + +publish(request: NotificationRequest): Promise\ + +Publishes a notification. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------- | ---- | ------------------------------------------- | +| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600004 | Notification is not enabled. | +| 1600005 | Notification slot is not enabled. | +| 1600009 | Over max number notifications per second. | + +**Example** + +```js +// NotificationRequest object +var notificationRequest = { + notificationId: 1, + content: { + contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + normal: { + title: "test_title", + text: "test_text", + additionalText: "test_additionalText" + } + } +} +Notification.publish(notificationRequest).then(() => { + console.info("publish success"); +}); + +``` + +## Notification.publish + +publish(request: NotificationRequest, userId: number, callback: AsyncCallback\): void + +Publishes a notification to a specified user. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------- | ---- | ------------------------------------------- | +| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.| +| userId | number | Yes | User ID. | +| callback | AsyncCallback\ | Yes | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600004 | Notification is not enabled. | +| 1600005 | Notification slot is not enabled. | +| 1600008 | The user is not exist. | +| 1600009 | Over max number notifications per second. | + +**Example** + +```js +// publish callback +function publishCallback(err) { + if (err) { + console.info("publish failed " + JSON.stringify(err)); + } else { + console.info("publish success"); + } +} +// User ID +var userId = 1 +// NotificationRequest object +var notificationRequest = { + id: 1, + content: { + contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + normal: { + title: "test_title", + text: "test_text", + additionalText: "test_additionalText" + } + } +} +Notification.publish(notificationRequest, userId, publishCallback); +``` + +## Notification.publish + +publish(request: NotificationRequest, userId: number): Promise\ + +Publishes a notification to a specified user. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------- | ---- | ------------------------------------------- | +| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.| +| userId | number | Yes | User ID. | + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600004 | Notification is not enabled. | +| 1600005 | Notification slot is not enabled. | +| 1600008 | The user is not exist. | +| 1600009 | Over max number notifications per second. | + +**Example** + +```js +var notificationRequest = { + notificationId: 1, + content: { + contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + normal: { + title: "test_title", + text: "test_text", + additionalText: "test_additionalText" + } + } +} + +var userId = 1 + +Notification.publish(notificationRequest, userId).then(() => { + console.info("publish success"); +}); +``` + + +## Notification.cancel + +cancel(id: number, label: string, callback: AsyncCallback\): void + +Cancels a notification with the specified ID and label. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | -------------------- | +| id | number | Yes | Notification ID. | +| label | string | Yes | Notification label. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600007 | The notification is not exist. | + +**Example** + +```js +// cancel callback +function cancelCallback(err) { + if (err) { + console.info("cancel failed " + JSON.stringify(err)); + } else { + console.info("cancel success"); + } +} +Notification.cancel(0, "label", cancelCallback) +``` + + + +## Notification.cancel + +cancel(id: number, label?: string): Promise\ + +Cancels a notification with the specified ID and optional label. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| ----- | ------ | ---- | -------- | +| id | number | Yes | Notification ID. | +| label | string | No | Notification label.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600007 | The notification is not exist. | + +**Example** + +```js +Notification.cancel(0).then(() => { + console.info("cancel success"); +}); +``` + + + +## Notification.cancel + +cancel(id: number, callback: AsyncCallback\): void + +Cancels a notification with the specified ID. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | -------------------- | +| id | number | Yes | Notification ID. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600007 | The notification is not exist. | + +**Example** + +```js +// cancel callback +function cancelCallback(err) { + if (err) { + console.info("cancel failed " + JSON.stringify(err)); + } else { + console.info("cancel success"); + } +} +Notification.cancel(0, cancelCallback) +``` + + + +## Notification.cancelAll + +cancelAll(callback: AsyncCallback\): void + +Cancels all notifications. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | -------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +// cancel callback +function cancelAllCallback(err) { + if (err) { + console.info("cancelAll failed " + JSON.stringify(err)); + } else { + console.info("cancelAll success"); + } +} +Notification.cancelAll(cancelAllCallback) +``` + + + +## Notification.cancelAll + +cancelAll(): Promise\ + +Cancels all notifications. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +Notification.cancelAll().then(() => { + console.info("cancelAll success"); +}); +``` + + + +## Notification.addSlot + +addSlot(slot: NotificationSlot, callback: AsyncCallback\): void + +Adds a notification slot. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | -------------------- | +| slot | [NotificationSlot](#notificationslot) | Yes | Notification slot to add.| +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +// addSlot callback +function addSlotCallBack(err) { + if (err) { + console.info("addSlot failed " + JSON.stringify(err)); + } else { + console.info("addSlot success"); + } +} +// NotificationSlot object +var notificationSlot = { + type: Notification.SlotType.SOCIAL_COMMUNICATION +} +Notification.addSlot(notificationSlot, addSlotCallBack) +``` + + + +## Notification.addSlot + +addSlot(slot: NotificationSlot): Promise\ + +Adds a notification slot. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name| Type | Mandatory| Description | +| ---- | ---------------- | ---- | -------------------- | +| slot | [NotificationSlot](#notificationslot) | Yes | Notification slot to add.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +// NotificationSlot object +var notificationSlot = { + type: Notification.SlotType.SOCIAL_COMMUNICATION +} +Notification.addSlot(notificationSlot).then(() => { + console.info("addSlot success"); +}); +``` + + + +## Notification.addSlot + +addSlot(type: SlotType, callback: AsyncCallback\): void + +Adds a notification slot of a specified type. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | ---------------------- | +| type | [SlotType](#slottype) | Yes | Type of the notification slot to add.| +| callback | AsyncCallback\ | Yes | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +// addSlot callback +function addSlotCallBack(err) { + if (err) { + console.info("addSlot failed " + JSON.stringify(err)); + } else { + console.info("addSlot success"); + } +} +Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION, addSlotCallBack) +``` + + + +## Notification.addSlot + +addSlot(type: SlotType): Promise\ + +Adds a notification slot of a specified type. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name| Type | Mandatory| Description | +| ---- | -------- | ---- | ---------------------- | +| type | [SlotType](#slottype) | Yes | Type of the notification slot to add.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then(() => { + console.info("addSlot success"); +}); +``` + + + +## Notification.addSlots + +addSlots(slots: Array\, callback: AsyncCallback\): void + +Adds an array of notification slots. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ------------------------ | +| slots | Array\<[NotificationSlot](#notificationslot)\> | Yes | Notification slots to add.| +| callback | AsyncCallback\ | Yes | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +// addSlots callback +function addSlotsCallBack(err) { + if (err) { + console.info("addSlots failed " + JSON.stringify(err)); + } else { + console.info("addSlots success"); + } +} +// NotificationSlot object +var notificationSlot = { + type: Notification.SlotType.SOCIAL_COMMUNICATION +} +// NotificationSlotArray object +var notificationSlotArray = new Array(); +notificationSlotArray[0] = notificationSlot; + +Notification.addSlots(notificationSlotArray, addSlotsCallBack) +``` + + + +## Notification.addSlots + +addSlots(slots: Array\): Promise\ + +Adds an array of notification slots. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ----- | ------------------------- | ---- | ------------------------ | +| slots | Array\<[NotificationSlot](#notificationslot)\> | Yes | Notification slots to add.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +// NotificationSlot object +var notificationSlot = { + type: Notification.SlotType.SOCIAL_COMMUNICATION +} +// NotificationSlotArray object +var notificationSlotArray = new Array(); +notificationSlotArray[0] = notificationSlot; + +Notification.addSlots(notificationSlotArray).then(() => { + console.info("addSlots success"); +}); +``` + + + +## Notification.getSlot + +getSlot(slotType: SlotType, callback: AsyncCallback\): void + +Obtains a notification slot of a specified type. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------- | ---- | ----------------------------------------------------------- | +| slotType | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.| +| callback | AsyncCallback\<[NotificationSlot](#notificationslot)\> | Yes | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +// getSlot callback +function getSlotCallback(err,data) { + if (err) { + console.info("getSlot failed " + JSON.stringify(err)); + } else { + console.info("getSlot success"); + } +} +var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; +Notification.getSlot(slotType, getSlotCallback) +``` + + + +## Notification.getSlot + +getSlot(slotType: SlotType): Promise\ + +Obtains a notification slot of a specified type. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------- | ---- | ----------------------------------------------------------- | +| slotType | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.| + +**Return value** + +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; +Notification.getSlot(slotType).then((data) => { + console.info("getSlot success, data: " + JSON.stringify(data)); +}); +``` + + + +## Notification.getSlots + +getSlots(callback: AsyncCallback>): void + +Obtains all notification slots of this application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------- | ---- | -------------------- | +| callback | AsyncCallback\\> | Yes | Callback used to return all notification slots of the current application.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +// getSlots callback +function getSlotsCallback(err,data) { + if (err) { + console.info("getSlots failed " + JSON.stringify(err)); + } else { + console.info("getSlots success"); + } +} +Notification.getSlots(getSlotsCallback) +``` + + + +## Notification.getSlots + +getSlots(): Promise\> + +Obtains all notification slots of this application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Return value** + +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\\> | Promise used to return all notification slots of the current application.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +Notification.getSlots().then((data) => { + console.info("getSlots success, data: " + JSON.stringify(data)); +}); +``` + + + +## Notification.removeSlot + +removeSlot(slotType: SlotType, callback: AsyncCallback\): void + +Removes a notification slot of a specified type. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | ----------------------------------------------------------- | +| slotType | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.| +| callback | AsyncCallback\ | Yes | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +// removeSlot callback +function removeSlotCallback(err) { + if (err) { + console.info("removeSlot failed " + JSON.stringify(err)); + } else { + console.info("removeSlot success"); + } +} +var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; +Notification.removeSlot(slotType,removeSlotCallback) +``` + + + +## Notification.removeSlot + +removeSlot(slotType: SlotType): Promise\ + +Removes a notification slot of a specified type. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------- | ---- | ----------------------------------------------------------- | +| slotType | [SlotType](#slottype) | Yes | Type of the notification slot, which can be used for social communication, service information, content consultation, and other purposes.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; +Notification.removeSlot(slotType).then(() => { + console.info("removeSlot success"); +}); +``` + + + +## Notification.removeAllSlots + +removeAllSlots(callback: AsyncCallback\): void + +Removes all notification slots. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | -------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function removeAllCallBack(err) { + if (err) { + console.info("removeAllSlots failed " + JSON.stringify(err)); + } else { + console.info("removeAllSlots success"); + } +} +Notification.removeAllSlots(removeAllCallBack) +``` + + + +## Notification.removeAllSlots + +removeAllSlots(): Promise\ + +Removes all notification slots. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +Notification.removeAllSlots().then(() => { + console.info("removeAllSlots success"); +}); +``` + + + +## Notification.setNotificationEnable + +setNotificationEnable(bundle: BundleOption, enable: boolean, callback: AsyncCallback\): void + +Sets whether to enable notification for a specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | -------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application. | +| enable | boolean | Yes | Whether to enable notification. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +function setNotificationEnablenCallback(err) { + if (err) { + console.info("setNotificationEnablenCallback failed " + JSON.stringify(err)); + } else { + console.info("setNotificationEnablenCallback success"); + } +} +var bundle = { + bundle: "bundleName1", +} +Notification.setNotificationEnable(bundle, false, setNotificationEnablenCallback); +``` + + + +## Notification.setNotificationEnable + +setNotificationEnable(bundle: BundleOption, enable: boolean): Promise\ + +Sets whether to enable notification for a specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ------------ | ---- | ---------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application.| +| enable | boolean | Yes | Whether to enable notification. | + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +var bundle = { + bundle: "bundleName1", +} +Notification.setNotificationEnable(bundle, false).then(() => { + console.info("setNotificationEnable success"); +}); +``` + + + +## Notification.isNotificationEnabled + +isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\): void + +Checks whether notification is enabled for a specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | ------------------------ | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +function isNotificationEnabledCallback(err, data) { + if (err) { + console.info("isNotificationEnabled failed " + JSON.stringify(err)); + } else { + console.info("isNotificationEnabled success"); + } +} +var bundle = { + bundle: "bundleName1", +} +Notification.isNotificationEnabled(bundle, isNotificationEnabledCallback); +``` + + + +## Notification.isNotificationEnabled + +isNotificationEnabled(bundle: BundleOption): Promise\ + +Checks whether notification is enabled for a specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ------------ | ---- | ---------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application.| + +**Return value** + +| Type | Description | +| ------------------ | --------------------------------------------------- | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +var bundle = { + bundle: "bundleName1", +} +Notification.isNotificationEnabled(bundle).then((data) => { + console.info("isNotificationEnabled success, data: " + JSON.stringify(data)); +}); +``` + + + +## Notification.isNotificationEnabled + +isNotificationEnabled(callback: AsyncCallback\): void + +Checks whether notification is enabled for this application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | ------------------------ | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function isNotificationEnabledCallback(err, data) { + if (err) { + console.info("isNotificationEnabled failed " + JSON.stringify(err)); + } else { + console.info("isNotificationEnabled success"); + } +} + +Notification.isNotificationEnabled(isNotificationEnabledCallback); +``` + + + +## Notification.isNotificationEnabled + +isNotificationEnabled(): Promise\ + +Checks whether notification is enabled for the current application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ------------ | ---- | ---------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application.| + +**Return value** + +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +Notification.isNotificationEnabled().then((data) => { + console.info("isNotificationEnabled success, data: " + JSON.stringify(data)); +}); +``` + + + +## Notification.displayBadge + +displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\): void + +Sets whether to enable the notification badge for a specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | -------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application. | +| enable | boolean | Yes | Whether to enable notification. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +function displayBadgeCallback(err) { + if (err) { + console.info("displayBadge failed " + JSON.stringify(err)); + } else { + console.info("displayBadge success"); + } +} +var bundle = { + bundle: "bundleName1", +} +Notification.displayBadge(bundle, false, displayBadgeCallback); +``` + + + +## Notification.displayBadge + +displayBadge(bundle: BundleOption, enable: boolean): Promise\ + +Sets whether to enable the notification badge for a specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ------------ | ---- | ---------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application.| +| enable | boolean | Yes | Whether to enable notification. | + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +var bundle = { + bundle: "bundleName1", +} +Notification.displayBadge(bundle, false).then(() => { + console.info("displayBadge success"); +}); +``` + + + +## Notification.isBadgeDisplayed + +isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\): void + +Checks whether the notification badge is enabled for a specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | ------------------------ | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +function isBadgeDisplayedCallback(err, data) { + if (err) { + console.info("isBadgeDisplayed failed " + JSON.stringify(err)); + } else { + console.info("isBadgeDisplayed success"); + } +} +var bundle = { + bundle: "bundleName1", +} +Notification.isBadgeDisplayed(bundle, isBadgeDisplayedCallback); +``` + + + +## Notification.isBadgeDisplayed + +isBadgeDisplayed(bundle: BundleOption): Promise\ + +Checks whether the notification badge is enabled for a specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ------------ | ---- | ---------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application.| + +**Return value** + +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +var bundle = { + bundle: "bundleName1", +} +Notification.isBadgeDisplayed(bundle).then((data) => { + console.info("isBadgeDisplayed success, data: " + JSON.stringify(data)); +}); +``` + + + +## Notification.setSlotByBundle + +setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback\): void + +Sets the notification slot for a specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | -------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application. | +| slot | [NotificationSlot](#notificationslot) | Yes | Notification slot. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + + + +**Example** + +```js +function setSlotByBundleCallback(err) { + if (err) { + console.info("setSlotByBundle failed " + JSON.stringify(err)); + } else { + console.info("setSlotByBundle success"); + } +} +var bundle = { + bundle: "bundleName1", +} +var notificationSlot = { + type: Notification.SlotType.SOCIAL_COMMUNICATION +} +Notification.setSlotByBundle(bundle, notificationSlot, setSlotByBundleCallback); +``` + + + +## Notification.setSlotByBundle + +setSlotByBundle(bundle: BundleOption, slot: NotificationSlot): Promise\ + +Sets the notification slot for a specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ------------ | ---- | ---------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application.| +| slot | [NotificationSlot](#notificationslot) | Yes | Notification slot.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +var bundle = { + bundle: "bundleName1", +} +var notificationSlot = { + type: Notification.SlotType.SOCIAL_COMMUNICATION +} +Notification.setSlotByBundle(bundle, notificationSlot).then(() => { + console.info("setSlotByBundle success"); +}); +``` + + + +## Notification.getSlotsByBundle + +getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback>): void + +Obtains the notification slots of a specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ---------------------------------------- | ---- | -------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application. | +| callback | AsyncCallback> | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +function getSlotsByBundleCallback(err, data) { + if (err) { + console.info("getSlotsByBundle failed " + JSON.stringify(err)); + } else { + console.info("getSlotsByBundle success"); + } +} +var bundle = { + bundle: "bundleName1", +} +Notification.getSlotsByBundle(bundle, getSlotsByBundleCallback); +``` + + + +## Notification.getSlotsByBundle + +getSlotsByBundle(bundle: BundleOption): Promise> + +Obtains the notification slots of a specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ------------ | ---- | ---------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application.| + +**Return value** + +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise> | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +var bundle = { + bundle: "bundleName1", +} +Notification.getSlotsByBundle(bundle).then((data) => { + console.info("getSlotsByBundle success, data: " + JSON.stringify(data)); +}); +``` + + + +## Notification.getSlotNumByBundle + +getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\): void + +Obtains the number of notification slots of a specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ---------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +function getSlotNumByBundleCallback(err, data) { + if (err) { + console.info("getSlotNumByBundle failed " + JSON.stringify(err)); + } else { + console.info("getSlotNumByBundle success"); + } +} +var bundle = { + bundle: "bundleName1", +} +Notification.getSlotNumByBundle(bundle, getSlotNumByBundleCallback); +``` + + + +## Notification.getSlotNumByBundle + +getSlotNumByBundle(bundle: BundleOption): Promise\ + +Obtains the number of notification slots of a specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ------------ | ---- | ---------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle of the application.| + +**Return value** + +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +var bundle = { + bundle: "bundleName1", +} +Notification.getSlotNumByBundle(bundle).then((data) => { + console.info("getSlotNumByBundle success, data: " + JSON.stringify(data)); +}); +``` + + + + +## Notification.getAllActiveNotifications + +getAllActiveNotifications(callback: AsyncCallback>): void + +Obtains all active notifications. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | -------------------- | +| callback | AsyncCallback> | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function getAllActiveNotificationsCallback(err, data) { + if (err) { + console.info("getAllActiveNotifications failed " + JSON.stringify(err)); + } else { + console.info("getAllActiveNotifications success"); + } +} + +Notification.getAllActiveNotifications(getAllActiveNotificationsCallback); +``` + + + +## Notification.getAllActiveNotifications + +getAllActiveNotifications(): Promise\\> + +Obtains all active notifications. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Return value** + +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\\> | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +Notification.getAllActiveNotifications().then((data) => { + console.info("getAllActiveNotifications success, data: " + JSON.stringify(data)); +}); +``` + + + +## Notification.getActiveNotificationCount + +getActiveNotificationCount(callback: AsyncCallback\): void + +Obtains the number of active notifications of this application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ---------------------- | ---- | ---------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function getActiveNotificationCountCallback(err, data) { + if (err) { + console.info("getActiveNotificationCount failed " + JSON.stringify(err)); + } else { + console.info("getActiveNotificationCount success"); + } +} + +Notification.getActiveNotificationCount(getActiveNotificationCountCallback); +``` + + + +## Notification.getActiveNotificationCount + +getActiveNotificationCount(): Promise\ + +Obtains the number of active notifications of this application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Return value** + +| Type | Description | +| ----------------- | ------------------------------------------- | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +Notification.getActiveNotificationCount().then((data) => { + console.info("getActiveNotificationCount success, data: " + JSON.stringify(data)); +}); +``` + + + +## Notification.getActiveNotifications + +getActiveNotifications(callback: AsyncCallback>): void + +Obtains active notifications of this application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------ | +| callback | AsyncCallback> | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function getActiveNotificationsCallback(err, data) { + if (err) { + console.info("getActiveNotifications failed " + JSON.stringify(err)); + } else { + console.info("getActiveNotifications success"); + } +} + +Notification.getActiveNotifications(getActiveNotificationsCallback); +``` + + + +## Notification.getActiveNotifications + +getActiveNotifications(): Promise\\> + +Obtains active notifications of this application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Return value** + +| Type | Description | +| ------------------------------------------------------------ | --------------------------------------- | +| Promise\\> | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +Notification.getActiveNotifications().then((data) => { + console.info("removeGroupByBundle success, data: " + JSON.stringify(data)); +}); +``` + + + +## Notification.cancelGroup + +cancelGroup(groupName: string, callback: AsyncCallback\): void + +Cancels notifications under a notification group of this application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| --------- | --------------------- | ---- | ---------------------------- | +| groupName | string | Yes | Name of the notification group, which is specified through [NotificationRequest](#notificationrequest) when the notification is published.| +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function cancelGroupCallback(err) { + if (err) { + console.info("cancelGroup failed " + JSON.stringify(err)); + } else { + console.info("cancelGroup success"); + } +} + +var groupName = "GroupName"; + +Notification.cancelGroup(groupName, cancelGroupCallback); +``` + + + +## Notification.cancelGroup + +cancelGroup(groupName: string): Promise\ + +Cancels notifications under a notification group of this application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| --------- | ------ | ---- | -------------- | +| groupName | string | Yes | Name of the notification group.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +var groupName = "GroupName"; +Notification.cancelGroup(groupName).then(() => { + console.info("cancelGroup success"); +}); +``` + + + +## Notification.removeGroupByBundle + +removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback\): void + +Removes notifications under a notification group of a specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| --------- | --------------------- | ---- | ---------------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | +| groupName | string | Yes | Name of the notification group. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +function removeGroupByBundleCallback(err) { + if (err) { + console.info("removeGroupByBundle failed " + JSON.stringify(err)); + } else { + console.info("removeGroupByBundle success"); + } +} + +var bundleOption = {bundle: "Bundle"}; +var groupName = "GroupName"; + +Notification.removeGroupByBundle(bundleOption, groupName, removeGroupByBundleCallback); +``` + + + +## Notification.removeGroupByBundle + +removeGroupByBundle(bundle: BundleOption, groupName: string): Promise\ + +Removes notifications under a notification group of a specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| --------- | ------------ | ---- | -------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | +| groupName | string | Yes | Name of the notification group.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +var bundleOption = {bundle: "Bundle"}; +var groupName = "GroupName"; +Notification.removeGroupByBundle(bundleOption, groupName).then(() => { + console.info("removeGroupByBundle success"); +}); +``` + + + +## Notification.setDoNotDisturbDate + +setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback\): void + +Sets the DND time. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | ---------------------- | +| date | [DoNotDisturbDate](#donotdisturbdate) | Yes | DND time to set. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function setDoNotDisturbDateCallback(err) { + if (err) { + console.info("setDoNotDisturbDate failed " + JSON.stringify(err)); + } else { + console.info("setDoNotDisturbDate success"); + } +} + +var doNotDisturbDate = { + type: Notification.DoNotDisturbType.TYPE_ONCE, + begin: new Date(), + end: new Date(2021, 11, 15, 18, 0) +} + +Notification.setDoNotDisturbDate(doNotDisturbDate, setDoNotDisturbDateCallback); +``` + + + +## Notification.setDoNotDisturbDate + +setDoNotDisturbDate(date: DoNotDisturbDate): Promise\ + +Sets the DND time. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name| Type | Mandatory| Description | +| ---- | ---------------- | ---- | -------------- | +| date | [DoNotDisturbDate](#donotdisturbdate) | Yes | DND time to set.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +var doNotDisturbDate = { + type: Notification.DoNotDisturbType.TYPE_ONCE, + begin: new Date(), + end: new Date(2021, 11, 15, 18, 0) +} +Notification.setDoNotDisturbDate(doNotDisturbDate).then(() => { + console.info("setDoNotDisturbDate success"); +}); +``` + + +## Notification.setDoNotDisturbDate + +setDoNotDisturbDate(date: DoNotDisturbDate, userId: number, callback: AsyncCallback\): void + +Sets the DND time for a specified user. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | ---------------------- | +| date | [DoNotDisturbDate](#donotdisturbdate) | Yes | DND time to set. | +| userId | number | Yes | ID of the user for whom you want to set the DND time.| +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600008 | The user is not exist. | + +**Example** + +```js +function setDoNotDisturbDateCallback(err) { + if (err) { + console.info("setDoNotDisturbDate failed " + JSON.stringify(err)); + } else { + console.info("setDoNotDisturbDate success"); + } +} + +var doNotDisturbDate = { + type: Notification.DoNotDisturbType.TYPE_ONCE, + begin: new Date(), + end: new Date(2021, 11, 15, 18, 0) +} + +var userId = 1 + +Notification.setDoNotDisturbDate(doNotDisturbDate, userId, setDoNotDisturbDateCallback); +``` + + + +## Notification.setDoNotDisturbDate + +setDoNotDisturbDate(date: DoNotDisturbDate, userId: number): Promise\ + +Sets the DND time for a specified user. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ---------------- | ---- | -------------- | +| date | [DoNotDisturbDate](#donotdisturbdate) | Yes | DND time to set.| +| userId | number | Yes | ID of the user for whom you want to set the DND time.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600008 | The user is not exist. | + +**Example** + +```js +var doNotDisturbDate = { + type: Notification.DoNotDisturbType.TYPE_ONCE, + begin: new Date(), + end: new Date(2021, 11, 15, 18, 0) +} + +var userId = 1 + +Notification.setDoNotDisturbDate(doNotDisturbDate, userId).then(() => { + console.info("setDoNotDisturbDate success"); +}); +``` + + +## Notification.getDoNotDisturbDate + +getDoNotDisturbDate(callback: AsyncCallback\): void + +Obtains the DND time. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------- | ---- | ---------------------- | +| callback | AsyncCallback\<[DoNotDisturbDate](#donotdisturbdate)\> | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function getDoNotDisturbDateCallback(err,data) { + if (err) { + console.info("getDoNotDisturbDate failed " + JSON.stringify(err)); + } else { + console.info("getDoNotDisturbDate success"); + } +} + +Notification.getDoNotDisturbDate(getDoNotDisturbDateCallback); +``` + + + +## Notification.getDoNotDisturbDate + +getDoNotDisturbDate(): Promise\ + +Obtains the DND time. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Return value** + +| Type | Description | +| ------------------------------------------------ | ----------------------------------------- | +| Promise\<[DoNotDisturbDate](#donotdisturbdate)\> | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +Notification.getDoNotDisturbDate().then((data) => { + console.info("getDoNotDisturbDate success, data: " + JSON.stringify(data)); +}); +``` + + +## Notification.getDoNotDisturbDate + +getDoNotDisturbDate(userId: number, callback: AsyncCallback\): void + +Obtains the DND time of a specified user. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------- | ---- | ---------------------- | +| callback | AsyncCallback\<[DoNotDisturbDate](#donotdisturbdate)\> | Yes | Callback used to return the result.| +| userId | number | Yes | User ID.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600008 | The user is not exist. | + +**Example** + +```js +function getDoNotDisturbDateCallback(err,data) { + if (err) { + console.info("getDoNotDisturbDate failed " + JSON.stringify(err)); + } else { + console.info("getDoNotDisturbDate success"); + } +} + +var userId = 1 + +Notification.getDoNotDisturbDate(userId, getDoNotDisturbDateCallback); +``` + + + +## Notification.getDoNotDisturbDate + +getDoNotDisturbDate(userId: number): Promise\ + +Obtains the DND time of a specified user. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------- | ---- | ---------------------- | +| userId | number | Yes | User ID.| + +**Return value** + +| Type | Description | +| ------------------------------------------------ | ----------------------------------------- | +| Promise\<[DoNotDisturbDate](#donotdisturbdate)\> | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600008 | The user is not exist. | + +**Example** + +```js +var userId = 1 + +Notification.getDoNotDisturbDate(userId).then((data) => { + console.info("getDoNotDisturbDate success, data: " + JSON.stringify(data)); +}); +``` + + +## Notification.supportDoNotDisturbMode + +supportDoNotDisturbMode(callback: AsyncCallback\): void + +Checks whether DND mode is supported. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function supportDoNotDisturbModeCallback(err,data) { + if (err) { + console.info("supportDoNotDisturbMode failed " + JSON.stringify(err)); + } else { + console.info("supportDoNotDisturbMode success"); + } +} + +Notification.supportDoNotDisturbMode(supportDoNotDisturbModeCallback); +``` + + + +## Notification.supportDoNotDisturbMode + +supportDoNotDisturbMode(): Promise\ + +Checks whether DND mode is supported. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Return value** + +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +Notification.supportDoNotDisturbMode().then((data) => { + console.info("supportDoNotDisturbMode success, data: " + JSON.stringify(data)); +}); +``` + + + +## Notification.isSupportTemplate + +isSupportTemplate(templateName: string, callback: AsyncCallback\): void + +Checks whether a specified template is supported. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------------ | ------------------------ | ---- | -------------------------- | +| templateName | string | Yes | Template name. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600011 | Read template config failed. | + +**Example** + +```javascript +var templateName = 'process'; +function isSupportTemplateCallback(err, data) { + if (err) { + console.info("isSupportTemplate failed " + JSON.stringify(err)); + } else { + console.info("isSupportTemplate success"); + } +} + +Notification.isSupportTemplate(templateName, isSupportTemplateCallback); +``` + + + +## Notification.isSupportTemplate + +isSupportTemplate(templateName: string): Promise\ + +Checks whether a specified template is supported. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------------ | ------ | ---- | -------- | +| templateName | string | Yes | Template name.| + +**Return value** + +| Type | Description | +| ------------------ | --------------- | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600011 | Read template config failed. | + +**Example** + +```javascript +var templateName = 'process'; + +Notification.isSupportTemplate(templateName).then((data) => { + console.info("isSupportTemplate success, data: " + JSON.stringify(data)); +}); +``` + + + +## Notification.requestEnableNotification + +requestEnableNotification(callback: AsyncCallback\): void + +Requests notification to be enabled for this application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```javascript +function requestEnableNotificationCallback(err) { + if (err) { + console.info("requestEnableNotification failed " + JSON.stringify(err)); + } else { + console.info("requestEnableNotification success"); + } +}; + +Notification.requestEnableNotification(requestEnableNotificationCallback); +``` + + + +## Notification.requestEnableNotification + +requestEnableNotification(): Promise\ + +Requests notification to be enabled for this application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```javascript +Notification.requestEnableNotification().then(() => { + console.info("requestEnableNotification success"); +}); +``` + + + +## Notification.setDistributedEnable + +setDistributedEnable(enable: boolean, callback: AsyncCallback\): void + +Sets whether this device supports distributed notifications. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------- | +| enable | boolean | Yes | Whether the device supports distributed notifications.| +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600010 | Distributed operation failed. | + +**Example** + +```javascript +function setDistributedEnableCallback() { + if (err) { + console.info("setDistributedEnable failed " + JSON.stringify(err)); + } else { + console.info("setDistributedEnable success"); + } +}; + +var enable = true + +Notification.setDistributedEnable(enable, setDistributedEnableCallback); +``` + + + +## Notification.setDistributedEnable + +setDistributedEnable(enable: boolean): Promise\ + +Sets whether this device supports distributed notifications. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------- | +| enable | boolean | Yes | Whether the device supports distributed notifications.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600010 | Distributed operation failed. | + +**Example** + +```javascript +var enable = true + +Notification.setDistributedEnable(enable).then(() => { + console.info("setDistributedEnable success"); + }); +``` + + +## Notification.isDistributedEnabled + +isDistributedEnabled(callback: AsyncCallback\): void + +Checks whether this device supports distributed notifications. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600010 | Distributed operation failed. | + +**Example** + +```javascript +function isDistributedEnabledCallback(err, data) { + if (err) { + console.info("isDistributedEnabled failed " + JSON.stringify(err)); + } else { + console.info("isDistributedEnabled success " + JSON.stringify(data)); + } +}; + +Notification.isDistributedEnabled(isDistributedEnabledCallback); +``` + + + +## Notification.isDistributedEnabled + +isDistributedEnabled(): Promise\ + +Checks whether this device supports distributed notifications. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Return value** + +| Type | Description | +| ------------------ | --------------------------------------------- | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600010 | Distributed operation failed. | + +**Example** + +```javascript +Notification.isDistributedEnabled() + .then((data) => { + console.info("isDistributedEnabled success, data: " + JSON.stringify(data)); + }); +``` + + +## Notification.setDistributedEnableByBundle + +setDistributedEnableByBundle(bundle: BundleOption, enable: boolean, callback: AsyncCallback\): void + +Sets whether a specified application supports distributed notifications. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | +| enable | boolean | Yes | Whether the application supports distributed notifications. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600010 | Distributed operation failed. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```javascript +function setDistributedEnableByBundleCallback(err) { + if (err) { + console.info("enableDistributedByBundle failed " + JSON.stringify(err)); + } else { + console.info("enableDistributedByBundle success"); + } +}; + +var bundle = { + bundle: "bundleName1", +} + +var enable = true + +Notification.setDistributedEnableByBundle(bundle, enable, setDistributedEnableByBundleCallback); +``` + + + +## Notification.setDistributedEnableByBundle + +setDistributedEnableByBundle(bundle: BundleOption, enable: boolean): Promise\ + +Sets whether a specified application supports distributed notifications. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | +| enable | boolean | Yes | Whether the application supports distributed notifications. | + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600010 | Distributed operation failed. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```javascript +var bundle = { + bundle: "bundleName1", +} + +var enable = true + +Notification.setDistributedEnableByBundle(bundle, enable).then(() => { + console.info("setDistributedEnableByBundle success"); + }); +``` + +## Notification.isDistributedEnabledByBundle + +isDistributedEnabledByBundle(bundle: BundleOption, callback: AsyncCallback\): void + +Checks whether a specified application supports distributed notifications. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600010 | Distributed operation failed. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```javascript +function isDistributedEnabledByBundleCallback(data) { + if (err) { + console.info("isDistributedEnabledByBundle failed " + JSON.stringify(err)); + } else { + console.info("isDistributedEnabledByBundle success" + JSON.stringify(data)); + } +}; + +var bundle = { + bundle: "bundleName1", +} + +Notification.isDistributedEnabledByBundle(bundle, isDistributedEnabledByBundleCallback); +``` + + + +## Notification.isDistributedEnabledByBundle + +isDistributedEnabledByBundle(bundle: BundleOption): Promise\ + +Checks whether a specified application supports distributed notifications. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | -------------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | + +**Return value** + +| Type | Description | +| ------------------ | ------------------------------------------------- | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600010 | Distributed operation failed. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```javascript +var bundle = { + bundle: "bundleName1", +} + +Notification.isDistributedEnabledByBundle(bundle).then((data) => { + console.info("isDistributedEnabledByBundle success, data: " + JSON.stringify(data)); +}); +``` + + +## Notification.getDeviceRemindType + +getDeviceRemindType(callback: AsyncCallback\): void + +Obtains the notification reminder type. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------- | ---- | -------------------------- | +| callback | AsyncCallback\<[DeviceRemindType](#deviceremindtype)\> | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```javascript +function getDeviceRemindTypeCallback(err, data) { + if (err) { + console.info("getDeviceRemindType failed " + JSON.stringify(err)); + } else { + console.info("getDeviceRemindType success"); + } +}; + +Notification.getDeviceRemindType(getDeviceRemindTypeCallback); +``` + + + +## Notification.getDeviceRemindType + +getDeviceRemindType(): Promise\ + +Obtains the notification reminder type. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Return value** + +| Type | Description | +| ------------------ | --------------- | +| Promise\<[DeviceRemindType](#deviceremindtype)\> | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```javascript +Notification.getDeviceRemindType().then((data) => { + console.info("getDeviceRemindType success, data: " + JSON.stringify(data)); +}); +``` + + +## Notification.publishAsBundle + +publishAsBundle(request: NotificationRequest, representativeBundle: string, userId: number, callback: AsyncCallback\): void + +Publishes a notification through the reminder agent. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------------------- | ------------------------------------------- | ---- | ---------------------------------------- | +| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.| +| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | +| userId | number | Yes | User ID. | +| callback | AsyncCallback | Yes | Callback used to return the result. | + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600004 | Notification is not enabled. | +| 1600005 | Notification slot is not enabled. | +| 1600008 | The user is not exist. | +| 1600009 | Over max number notifications per second. | + +**Example** + +```js +// publishAsBundle callback +function callback(err) { + if (err) { + console.info("publishAsBundle failed " + JSON.stringify(err)); + } else { + console.info("publishAsBundle success"); + } +} +// Bundle name of the application whose notification function is taken over by the reminder agent +let representativeBundle = "com.example.demo" +// User ID +let userId = 100 +// NotificationRequest object +let request = { + id: 1, + content: { + contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + normal: { + title: "test_title", + text: "test_text", + additionalText: "test_additionalText" + } + } +} + +Notification.publishAsBundle(request, representativeBundle, userId, callback); +``` + +## Notification.publishAsBundle + +publishAsBundle(request: NotificationRequest, representativeBundle: string, userId: number): Promise\ + +Publishes a notification through the reminder agent. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + + +| Name | Type | Mandatory| Description | +| -------------------- | ------------------------------------------- | ---- | --------------------------------------------- | +| request | [NotificationRequest](#notificationrequest) | Yes | Content and related configuration of the notification to publish.| +| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | +| userId | number | Yes | User ID. | + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600004 | Notification is not enabled. | +| 1600005 | Notification slot is not enabled. | +| 1600008 | The user is not exist. | +| 1600009 | Over max number notifications per second. | + +**Example** + +```js +// Bundle name of the application whose notification function is taken over by the reminder agent +let representativeBundle = "com.example.demo" +// User ID +let userId = 100 +// NotificationRequest object +var request = { + id: 1, + content: { + contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + normal: { + title: "test_title", + text: "test_text", + additionalText: "test_additionalText" + } + } +} + +Notification.publishAsBundle(request, representativeBundle, userId).then(() => { + console.info("publishAsBundle success"); +}); +``` + +## Notification.cancelAsBundle + +cancelAsBundle(id: number, representativeBundle: string, userId: number, callback: AsyncCallback\): void + +Cancels a notification published by the reminder agent. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------------------- | ------------- | ---- | ------------------------ | +| id | number | Yes | Notification ID. | +| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent. | +| userId | number | Yes | User ID. | +| callback | AsyncCallback | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600007 | The notification is not exist. | +| 1600008 | The user is not exist. | + +**Example** + +```js +// cancelAsBundle +function cancelAsBundleCallback(err) { + if (err) { + console.info("cancelAsBundle failed " + JSON.stringify(err)); + } else { + console.info("cancelAsBundle success"); + } +} +// Bundle name of the application whose notification function is taken over by the reminder agent +let representativeBundle = "com.example.demo" +// User ID +let userId = 100 + +Notification.cancelAsBundle(0, representativeBundle, userId, cancelAsBundleCallback); +``` + +## Notification.cancelAsBundle + +cancelAsBundle(id: number, representativeBundle: string, userId: number): Promise\ + +Cancels a notification published by the reminder agent. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.NOTIFICATION_AGENT_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------------------- | ------ | ---- | ------------------ | +| id | number | Yes | Notification ID. | +| representativeBundle | string | Yes | Bundle name of the application whose notification function is taken over by the reminder agent.| +| userId | number | Yes | User ID.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600007 | The notification is not exist. | +| 1600008 | The user is not exist. | + +**Example** + +```js +// Bundle name of the application whose notification function is taken over by the reminder agent +let representativeBundle = "com.example.demo" +// User ID +let userId = 100 + +Notification.cancelAsBundle(0, representativeBundle, userId).then(() => { + console.info("cancelAsBundle success"); +}); +``` + +## Notification.setNotificationEnableSlot + +setNotificationEnableSlot(bundle: BundleOption, type: SlotType, enable: boolean, callback: AsyncCallback\): void + +Sets whether to enable a specified notification slot type for a specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------------- | ---- | ---------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | +| type | [SlotType](#slottype) | Yes | Notification slot type. | +| enable | boolean | Yes | Whether to enable the notification slot type. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +// setNotificationEnableSlot +function setNotificationEnableSlotCallback(err) { + if (err) { + console.info("setNotificationEnableSlot failed " + JSON.stringify(err)); + } else { + console.info("setNotificationEnableSlot success"); + } +}; + +Notification.setNotificationEnableSlot( + { bundle: "ohos.samples.notification", }, + Notification.SlotType.SOCIAL_COMMUNICATION, + true, + setNotificationEnableSlotCallback); +``` + +## Notification.setNotificationEnableSlot + +setNotificationEnableSlot(bundle: BundleOption, type: SlotType, enable: boolean): Promise\ + +Sets whether to enable a specified notification slot type for a specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ----------------------------- | ---- | -------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | +| type | [SlotType](#slottype) | Yes | Notification slot type.| +| enable | boolean | Yes | Whether to enable the notification slot type. | + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +// setNotificationEnableSlot +Notification.setNotificationEnableSlot( + { bundle: "ohos.samples.notification", }, + Notification.SlotType.SOCIAL_COMMUNICATION, + true).then(() => { + console.info("setNotificationEnableSlot success"); + }); +``` + +## Notification.isNotificationSlotEnabled + +isNotificationSlotEnabled(bundle: BundleOption, type: SlotType, callback: AsyncCallback\): void + +Checks whether a specified notification slot type is enabled for a specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------------- | ---- | ---------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | +| type | [SlotType](#slottype) | Yes | Notification slot type. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +// isNotificationSlotEnabled +function getEnableSlotCallback(err, data) { + if (err) { + console.info("isNotificationSlotEnabled failed " + JSON.stringify(err)); + } else { + console.info("isNotificationSlotEnabled success"); + } +}; + +Notification.isNotificationSlotEnabled( + { bundle: "ohos.samples.notification", }, + Notification.SlotType.SOCIAL_COMMUNICATION, + getEnableSlotCallback); +``` + +## Notification.isNotificationSlotEnabled + +isNotificationSlotEnabled(bundle: BundleOption, type: SlotType): Promise\ + +Checks whether a specified notification slot type is enabled for a specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ----------------------------- | ---- | -------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | +| type | [SlotType](#slottype) | Yes | Notification slot type.| + +**Return value** + +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +// isNotificationSlotEnabled +Notification.isNotificationSlotEnabled({ bundle: "ohos.samples.notification", }, + Notification.SlotType.SOCIAL_COMMUNICATION).then((data) => { + console.info("isNotificationSlotEnabled success, data: " + JSON.stringify(data)); +}); +``` + + +## Notification.setSyncNotificationEnabledWithoutApp + +setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean, callback: AsyncCallback\): void + +Sets whether to enable the notification sync feature for devices where the application is not installed. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ----------------------------- | ---- | -------------- | +| userId | number | Yes | User ID. | +| enable | boolean | Yes | Whether the feature is enabled. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600008 | The user is not exist. | + +**Example** + +```js +let userId = 100; +let enable = true; + +function callback(err) { + if (err) { + console.info("setSyncNotificationEnabledWithoutApp failed " + JSON.stringify(err)); + } else { + console.info("setSyncNotificationEnabledWithoutApp success"); + } +} + +Notification.setSyncNotificationEnabledWithoutApp(userId, enable, callback); +``` + + +## Notification.setSyncNotificationEnabledWithoutApp + +setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean): Promise\ + +Sets whether to enable the notification sync feature for devices where the application is not installed. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ----------------------------- | ---- | -------------- | +| userId | number | Yes | User ID. | +| enable | boolean | Yes | Whether the feature is enabled. | + +**Return value** + +| Type | Description | +| ----------------------------------------------------------- | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600008 | The user is not exist. | + +**Example** + +```js +let userId = 100; +let enable = true; + +Notification.setSyncNotificationEnabledWithoutApp(userId, enable).then(() => { + console.info('setSyncNotificationEnabledWithoutApp success'); +}).catch((err) => { + console.info('setSyncNotificationEnabledWithoutApp, err:' + JSON.stringify(err)); +}); +``` + + +## Notification.getSyncNotificationEnabledWithoutApp + +getSyncNotificationEnabledWithoutApp(userId: number, callback: AsyncCallback\): void + +Obtains whether the notification sync feature is enabled for devices where the application is not installed. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ----------------------------- | ---- | -------------- | +| userId | number | Yes | User ID. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600008 | The user is not exist. | + +**Example** + +```js +let userId = 100; + +function getSyncNotificationEnabledWithoutAppCallback(err, data) { + if (err) { + console.info('getSyncNotificationEnabledWithoutAppCallback, err:' + err); + } else { + console.info('getSyncNotificationEnabledWithoutAppCallback, data:' + data); + } +} + +Notification.getSyncNotificationEnabledWithoutApp(userId, getSyncNotificationEnabledWithoutAppCallback); +``` + + +## Notification.getSyncNotificationEnabledWithoutApp + +getSyncNotificationEnabledWithoutApp(userId: number): Promise\ + +Obtains whether the notification sync feature is enabled for devices where the application is not installed. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ----------------------------- | ---- | -------------- | +| userId | number | Yes | User ID. | + +**Return value** + +| Type | Description | +| ------------------ | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600008 | The user is not exist. | + +**Example** + +```js +let userId = 100; +Notification.getSyncNotificationEnabledWithoutApp(userId).then((data) => { + console.info('getSyncNotificationEnabledWithoutApp, data:' + data); +}).catch((err) => { + console.info('getSyncNotificationEnabledWithoutApp, err:' + err); +}); + .catch((err) => { + console.info('getSyncNotificationEnabledWithoutApp, err:', err); + }); +``` + + + + +## DoNotDisturbDate + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +| Name | Type | Readable| Writable| Description | +| ----- | ------------------------------------- | ---- | ---- | ---------------------- | +| type | [DoNotDisturbType](#donotdisturbtype) | Yes | Yes | DND time type.| +| begin | Date | Yes | Yes | DND start time.| +| end | Date | Yes | Yes | DND end time.| + + + +## DoNotDisturbType + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +| Name | Value | Description | +| ------------ | ---------------- | ------------------------------------------ | +| TYPE_NONE | 0 | Non-DND. | +| TYPE_ONCE | 1 | One-shot DND at the specified time segment (only considering the hour and minute).| +| TYPE_DAILY | 2 | Daily DND at the specified time segment (only considering the hour and minute).| +| TYPE_CLEARLY | 3 | DND at the specified time segment (considering the year, month, day, hour, and minute). | + + +## ContentType + +**System capability**: SystemCapability.Notification.Notification + +| Name | Value | Description | +| --------------------------------- | ----------- | ------------------ | +| NOTIFICATION_CONTENT_BASIC_TEXT | NOTIFICATION_CONTENT_BASIC_TEXT | Normal text notification. | +| NOTIFICATION_CONTENT_LONG_TEXT | NOTIFICATION_CONTENT_LONG_TEXT | Long text notification. | +| NOTIFICATION_CONTENT_PICTURE | NOTIFICATION_CONTENT_PICTURE | Picture-attached notification. | +| NOTIFICATION_CONTENT_CONVERSATION | NOTIFICATION_CONTENT_CONVERSATION | Conversation notification. | +| NOTIFICATION_CONTENT_MULTILINE | NOTIFICATION_CONTENT_MULTILINE | Multi-line text notification.| + +## SlotLevel + +**System capability**: SystemCapability.Notification.Notification + +| Name | Value | Description | +| --------------------------------- | ----------- | ------------------ | +| LEVEL_NONE | 0 | Notification is disabled. | +| LEVEL_MIN | 1 | Notification is enabled, but the notification icon is not displayed in the status bar, with no banner or alert tone.| +| LEVEL_LOW | 2 | Notification is enabled, and the notification icon is displayed in the status bar, with no banner or alert tone.| +| LEVEL_DEFAULT | 3 | Notification is enabled, and the notification icon is displayed in the status bar, with an alert tone but no banner.| +| LEVEL_HIGH | 4 | Notification is enabled, and the notification icon is displayed in the status bar, with an alert tone and banner.| + + +## BundleOption + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| ------ | ------ |---- | --- | ------ | +| bundle | string | Yes | Yes | Bundle information of the application.| +| uid | number | Yes | Yes | User ID.| + + +## SlotType + +**System capability**: SystemCapability.Notification.Notification + +| Name | Value | Description | +| -------------------- | -------- | ---------- | +| UNKNOWN_TYPE | 0 | Unknown type.| +| SOCIAL_COMMUNICATION | 1 | Notification slot for social communication.| +| SERVICE_INFORMATION | 2 | Notification slot for service information.| +| CONTENT_INFORMATION | 3 | Notification slot for content consultation.| +| OTHER_TYPES | 0xFFFF | Notification slot for other purposes.| + + +## NotificationActionButton + +Describes the button displayed in the notification. + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| --------- | ----------------------------------------------- | --- | ---- | ------------------------- | +| title | string | Yes | Yes | Button title. | +| wantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes | Yes | **WantAgent** of the button.| +| extras | { [key: string]: any } | Yes | Yes | Extra information of the button. | +| userInput | [NotificationUserInput](#notificationuserinput) | Yes | Yes | User input object. | + + +## NotificationBasicContent + +Describes the normal text notification. + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| -------------- | ------ | ---- | ---- | ---------------------------------- | +| title | string | Yes | Yes | Notification title. | +| text | string | Yes | Yes | Notification content. | +| additionalText | string | Yes | Yes | Additional information of the notification.| + + +## NotificationLongTextContent + +Describes the long text notification. + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| -------------- | ------ | ---- | --- | -------------------------------- | +| title | string | Yes | Yes | Notification title. | +| text | string | Yes | Yes | Notification content. | +| additionalText | string | Yes | Yes | Additional information of the notification.| +| longText | string | Yes | Yes | Long text of the notification. | +| briefText | string | Yes | Yes | Brief text of the notification.| +| expandedTitle | string | Yes | Yes | Title of the notification in the expanded state. | + + +## NotificationMultiLineContent + +Describes the multi-line text notification. + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| -------------- | --------------- | --- | --- | -------------------------------- | +| title | string | Yes | Yes | Notification title. | +| text | string | Yes | Yes | Notification content. | +| additionalText | string | Yes | Yes | Additional information of the notification.| +| briefText | string | Yes | Yes | Brief text of the notification.| +| longTitle | string | Yes | Yes | Title of the notification in the expanded state. | +| lines | Array\ | Yes | Yes | Multi-line text of the notification. | + + +## NotificationPictureContent + +Describe the picture-attached notification. + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| -------------- | -------------- | ---- | --- | -------------------------------- | +| title | string | Yes | Yes | Notification title. | +| text | string | Yes | Yes | Notification content. | +| additionalText | string | Yes | Yes | Additional information of the notification.| +| briefText | string | Yes | Yes | Brief text of the notification.| +| expandedTitle | string | Yes | Yes | Title of the notification in the expanded state. | +| picture | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes | Yes | Picture attached to the notification. | + + +## NotificationContent + +Describes the notification content. + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| ----------- | ------------------------------------------------------------ | ---- | --- | ------------------ | +| contentType | [ContentType](#contenttype) | Yes | Yes | Notification content type. | +| normal | [NotificationBasicContent](#notificationbasiccontent) | Yes | Yes | Normal text. | +| longText | [NotificationLongTextContent](#notificationlongtextcontent) | Yes | Yes | Long text.| +| multiLine | [NotificationMultiLineContent](#notificationmultilinecontent) | Yes | Yes | Multi-line text. | +| picture | [NotificationPictureContent](#notificationpicturecontent) | Yes | Yes | Picture-attached. | + + +## NotificationFlagStatus + +Describes the notification flag status. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +| Name | Value | Description | +| -------------- | --- | --------------------------------- | +| TYPE_NONE | 0 | The default flag is used. | +| TYPE_OPEN | 1 | The notification flag is enabled. | +| TYPE_CLOSE | 2 | The notification flag is disabled. | + + +## NotificationFlags + +Enumerates notification flags. + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| ---------------- | ---------------------- | ---- | ---- | --------------------------------- | +| soundEnabled | [NotificationFlagStatus](#notificationflagstatus) | Yes | No | Whether to enable the sound alert for the notification. | +| vibrationEnabled | [NotificationFlagStatus](#notificationflagstatus) | Yes | No | Whether to enable vibration for the notification. | + + +## NotificationRequest + +Describes the notification request. + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| --------------------- | --------------------------------------------- | ---- | --- | -------------------------- | +| content | [NotificationContent](#notificationcontent) | Yes | Yes | Notification content. | +| id | number | Yes | Yes | Notification ID. | +| slotType | [SlotType](#slottype) | Yes | Yes | Notification slot type. | +| isOngoing | boolean | Yes | Yes | Whether the notification is an ongoing notification. | +| isUnremovable | boolean | Yes | Yes | Whether the notification can be removed. | +| deliveryTime | number | Yes | Yes | Time when the notification is sent. | +| tapDismissed | boolean | Yes | Yes | Whether the notification is automatically cleared. | +| autoDeletedTime | number | Yes | Yes | Time when the notification is automatically cleared. | +| wantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes | Yes | **WantAgent** instance to which the notification will be redirected after being clicked.| +| extraInfo | {[key: string]: any} | Yes | Yes | Extended parameters. | +| color | number | Yes | Yes | Background color of the notification. Not supported currently.| +| colorEnabled | boolean | Yes | Yes | Whether the notification background color can be enabled. Not supported currently.| +| isAlertOnce | boolean | Yes | Yes | Whether the notification triggers an alert only once.| +| isStopwatch | boolean | Yes | Yes | Whether to display the stopwatch. | +| isCountDown | boolean | Yes | Yes | Whether to display the countdown time. | +| isFloatingIcon | boolean | Yes | Yes | Whether the notification is displayed as a floating icon in the status bar. | +| label | string | Yes | Yes | Notification label. | +| badgeIconStyle | number | Yes | Yes | Notification badge type. | +| showDeliveryTime | boolean | Yes | Yes | Whether to display the time when the notification is delivered. | +| actionButtons | Array\<[NotificationActionButton](#notificationactionbutton)\> | Yes | Yes | Buttons in the notification. Up to two buttons are allowed. | +| smallIcon | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes | Yes | Small notification icon. This field is optional, and the icon size cannot exceed 30 KB.| +| largeIcon | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes | Yes | Large notification icon. This field is optional, and the icon size cannot exceed 30 KB.| +| creatorBundleName | string | Yes | No | Name of the bundle that creates the notification. | +| creatorUid | number | Yes | No | UID used for creating the notification. | +| creatorPid | number | Yes | No | PID used for creating the notification. | +| creatorUserId| number | Yes | No | ID of the user who creates the notification. | +| hashCode | string | Yes | No | Unique ID of the notification. | +| classification | string | Yes | Yes | Notification category.
**System API**: This is a system API and cannot be called by third-party applications. | +| groupName| string | Yes | Yes | Notification group name. | +| template | [NotificationTemplate](#notificationtemplate) | Yes | Yes | Notification template. | +| isRemoveAllowed | boolean | Yes | No | Whether the notification can be removed.
**System API**: This is a system API and cannot be called by third-party applications. | +| source | number | Yes | No | Notification source.
**System API**: This is a system API and cannot be called by third-party applications. | +| distributedOption | [DistributedOptions](#distributedoptions) | Yes | Yes | Distributed notification options. | +| deviceId | string | Yes | No | Device ID of the notification source.
**System API**: This is a system API and cannot be called by third-party applications. | +| notificationFlags | [NotificationFlags](#notificationflags) | Yes | No | Notification flags. | +| removalWantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes | Yes | **WantAgent** instance to which the notification will be redirected when it is removed. | +| badgeNumber | number | Yes | Yes | Number of notifications displayed on the application icon. | + + +## DistributedOptions + +Describes distributed options. + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| ---------------------- | -------------- | ---- | ---- | ---------------------------------- | +| isDistributed | boolean | Yes | Yes | Whether the notification is a distributed notification. | +| supportDisplayDevices | Array\ | Yes | Yes | List of the devices to which the notification can be synchronized. | +| supportOperateDevices | Array\ | Yes | Yes | List of the devices on which the notification can be opened. | +| remindType | number | Yes | No | Notification reminder type.
**System API**: This is a system API and cannot be called by third-party applications. | + + +## NotificationSlot + +Describes the notification slot. + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| -------------------- | --------------------- | ---- | --- | ------------------------------------------ | +| type | [SlotType](#slottype) | Yes | Yes | Notification slot type. | +| level | number | Yes | Yes | Notification level. If this parameter is not set, the default value is used based on the notification slot type.| +| desc | string | Yes | Yes | Notification slot description. | +| badgeFlag | boolean | Yes | Yes | Whether to display the badge. | +| bypassDnd | boolean | Yes | Yes | Whether to bypass DND mode in the system. | +| lockscreenVisibility | number | Yes | Yes | Mode for displaying the notification on the lock screen. | +| vibrationEnabled | boolean | Yes | Yes | Whether vibration is enabled for the notification. | +| sound | string | Yes | Yes | Notification alert tone. | +| lightEnabled | boolean | Yes | Yes | Whether the indicator blinks for the notification. | +| lightColor | number | Yes | Yes | Indicator color of the notification. | +| vibrationValues | Array\ | Yes | Yes | Vibration mode of the notification. | +| enabled9+ | boolean | Yes | No | Whether the notification slot is enabled. | + + +## NotificationTemplate + +Describes the notification template. + +**System capability**: SystemCapability.Notification.Notification + +| Name| Type | Readable| Writable| Description | +| ---- | ---------------------- | ---- | ---- | ---------- | +| name | string | Yes | Yes | Template name.| +| data | {[key:string]: Object} | Yes | Yes | Template data.| + + +## NotificationUserInput + +Provides the notification user input. + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| -------- | ------ | --- | ---- | ----------------------------- | +| inputKey | string | Yes | Yes | Key to identify the user input.| + + +## DeviceRemindType + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +| Name | Value | Description | +| -------------------- | --- | --------------------------------- | +| IDLE_DONOT_REMIND | 0 | The device is not in use. No notification is required. | +| IDLE_REMIND | 1 | The device is not in use. | +| ACTIVE_DONOT_REMIND | 2 | The device is in use. No notification is required. | +| ACTIVE_REMIND | 3 | The device is in use. | + + +## SourceType + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +| Name | Value | Description | +| -------------------- | --- | -------------------- | +| TYPE_NORMAL | 0 | Normal notification. | +| TYPE_CONTINUOUS | 1 | Continuous notification. | +| TYPE_TIMER | 2 | Timed notification. | diff --git a/en/application-dev/reference/apis/js-apis-notificationSubscribe.md b/en/application-dev/reference/apis/js-apis-notificationSubscribe.md new file mode 100644 index 0000000000000000000000000000000000000000..ed0ad9400ed59c637b5495c7b20f8770b0b4329c --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-notificationSubscribe.md @@ -0,0 +1,1074 @@ +# @ohos.notificationSubscribe + +The **NotificationSubscribe** module provides APIs for notification subscription, notification unsubscription, subscription removal, and more. In general cases, only system applications can call these APIs. + +> **NOTE** +> +> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. + +## Modules to Import + +```js +import NotificationSubscribe from '@ohos.notificationSubscribe'; +``` + + + +## NotificationSubscribe.subscribe + +subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback\): void + +Subscribes to a notification with the subscription information specified. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ---------- | ------------------------- | ---- | ---------------- | +| subscriber | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber. | +| info | [NotificationSubscribeInfo](#notificationsubscribeinfo) | Yes | Notification subscription information.| +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +// subscribe callback +function subscribeCallback(err) { + if (err) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribe success"); + } +} +function onConsumeCallback(data) { + console.info("Consume callback: " + JSON.stringify(data)); +} +var subscriber = { + onConsume: onConsumeCallback +} +var info = { + bundleNames: ["bundleName1","bundleName2"] +} +NotificationSubscribe.subscribe(subscriber, info, subscribeCallback); +``` + + + +## NotificationSubscribe.subscribe + +subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\): void + +Subscribes to notifications of all applications under this user. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ---------- | ---------------------- | ---- | ---------------- | +| subscriber | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function subscribeCallback(err) { + if (err) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribe success"); + } +} +function onConsumeCallback(data) { + console.info("Consume callback: " + JSON.stringify(data)); +} +var subscriber = { + onConsume: onConsumeCallback +} +NotificationSubscribe.subscribe(subscriber, subscribeCallback); +``` + + + +## NotificationSubscribe.subscribe + +subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo): Promise\ + +Subscribes to a notification with the subscription information specified. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ---------- | ------------------------- | ---- | ------------ | +| subscriber | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber.| +| info | [NotificationSubscribeInfo](#notificationsubscribeinfo) | No | Notification subscription information. | + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function onConsumeCallback(data) { + console.info("Consume callback: " + JSON.stringify(data)); +} +var subscriber = { + onConsume: onConsumeCallback +}; +NotificationSubscribe.subscribe(subscriber).then(() => { + console.info("subscribe success"); +}); +``` + + + +## NotificationSubscribe.unsubscribe + +unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\): void + +Unsubscribes from a notification. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ---------- | ---------------------- | ---- | -------------------- | +| subscriber | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function unsubscribeCallback(err) { + if (err) { + console.info("unsubscribe failed " + JSON.stringify(err)); + } else { + console.info("unsubscribe success"); + } +} +function onDisconnectCallback(data) { + console.info("Cancel callback: " + JSON.stringify(data)); +} +var subscriber = { + onDisconnect: onDisconnectCallback +} +NotificationSubscribe.unsubscribe(subscriber, unsubscribeCallback); +``` + + + +## NotificationSubscribe.unsubscribe + +unsubscribe(subscriber: NotificationSubscriber): Promise\ + +Unsubscribes from a notification. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ---------- | ---------------------- | ---- | ------------ | +| subscriber | [NotificationSubscriber](#notificationsubscriber) | Yes | Notification subscriber.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function onDisconnectCallback(data) { + console.info("Cancel callback: " + JSON.stringify(data)); +} +var subscriber = { + onDisconnect: onDisconnectCallback +}; +NotificationSubscribe.unsubscribe(subscriber).then(() => { + console.info("unsubscribe success"); +}); +``` + + + +## NotificationSubscribe.remove + +remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveReason, callback: AsyncCallback\): void + +Removes a notification for a specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| --------------- | ----------------------------------| ---- | -------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | +| notificationKey | [NotificationKey](#notificationkey) | Yes | Notification key. | +| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600007 | The notification is not exist. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +function removeCallback(err) { + if (err) { + console.info("remove failed " + JSON.stringify(err)); + } else { + console.info("remove success"); + } +} +var bundle = { + bundle: "bundleName1", +} +var notificationKey = { + id: 0, + label: "label", +} +var reason = NotificationSubscribe.RemoveReason.CLICK_REASON_REMOVE; +NotificationSubscribe.remove(bundle, notificationKey, reason, removeCallback); +``` + + + +## NotificationSubscribe.remove + +remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveReason): Promise\ + +Removes a notification for a specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| --------------- | --------------- | ---- | ---------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application.| +| notificationKey | [NotificationKey](#notificationkey) | Yes | Notification key. | +| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600007 | The notification is not exist. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +var bundle = { + bundle: "bundleName1", +} +var notificationKey = { + id: 0, + label: "label", +} +var reason = NotificationSubscribe.RemoveReason.CLICK_REASON_REMOVE; +NotificationSubscribe.remove(bundle, notificationKey, reason).then(() => { + console.info("remove success"); +}); +``` + + + +## NotificationSubscribe.remove + +remove(hashCode: string, reason: RemoveReason, callback: AsyncCallback\): void + +Removes a specified notification. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | -------------------- | +| hashCode | string | Yes | Unique notification ID. It is the **hashCode** in the [NotificationRequest](#notificationrequest) object of [SubscribeCallbackData](#subscribecallbackdata) of the [onConsume](#onconsume) callback.| +| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600007 | The notification is not exist. | + +**Example** + +```js +var hashCode = 'hashCode' + +function removeCallback(err) { + if (err) { + console.info("remove failed " + JSON.stringify(err)); + } else { + console.info("remove success"); + } +} +var reason = NotificationSubscribe.RemoveReason.CANCEL_REASON_REMOVE; +NotificationSubscribe.remove(hashCode, reason, removeCallback); +``` + + + +## NotificationSubscribe.remove + +remove(hashCode: string, reason: RemoveReason): Promise\ + +Removes a specified notification. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ---------- | ---- | ---------- | +| hashCode | string | Yes | Unique notification ID.| +| reason | [RemoveReason](#removereason) | Yes | Reason for removing the notification. | + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600007 | The notification is not exist. | + +**Example** + +```js +var hashCode = 'hashCode' +var reason = NotificationSubscribe.RemoveReason.CLICK_REASON_REMOVE; +NotificationSubscribe.remove(hashCode, reason).then(() => { + console.info("remove success"); +}); +``` + + + +## NotificationSubscribe.removeAll + +removeAll(bundle: BundleOption, callback: AsyncCallback\): void + +Removes all notifications for a specified application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | ---------------------------- | +| bundle | [BundleOption](#bundleoption) | Yes | Bundle information of the application. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +function removeAllCallback(err) { + if (err) { + console.info("removeAll failed " + JSON.stringify(err)); + } else { + console.info("removeAll success"); + } +} +var bundle = { + bundle: "bundleName1", +} +NotificationSubscribe.removeAll(bundle, removeAllCallback); +``` + + + +## NotificationSubscribe.removeAll + +removeAll(callback: AsyncCallback\): void + +Removes all notifications. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | -------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | + +**Example** + +```js +function removeAllCallback(err) { + if (err) { + console.info("removeAll failed " + JSON.stringify(err)); + } else { + console.info("removeAll success"); + } +} + +NotificationSubscribe.removeAll(removeAllCallback); +``` + + + +## NotificationSubscribe.removeAll + +removeAll(bundle?: BundleOption): Promise\ + +Removes all notifications for a specified application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ------------ | ---- | ---------- | +| bundle | [BundleOption](#bundleoption) | No | Bundle information of the application.| + +**Error codes** + +| ID| Error Message | +| -------- | ---------------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 17700001 | The specified bundle name was not found. | + +**Example** + +```js +// If no application is specified, notifications of all applications are deleted. +NotificationSubscribe.removeAll().then(() => { + console.info("removeAll success"); +}); +``` + +## NotificationSubscribe.removeAll + +removeAll(userId: number, callback: AsyncCallback\): void + +Removes all notifications for a specified user. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ------------ | ---- | ---------- | +| userId | number | Yes | User ID.| +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600008 | The user is not exist. | + +**Example** + +```js +function removeAllCallback(err) { + if (err) { + console.info("removeAll failed " + JSON.stringify(err)); + } else { + console.info("removeAll success"); + } +} + +var userId = 1 + +NotificationSubscribe.removeAll(userId, removeAllCallback); +``` + +## Notification.removeAll + +removeAll(userId: number): Promise\ + +Removes all notifications for a specified user. This API uses a promise to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**Required permissions**: ohos.permission.NOTIFICATION_CONTROLLER + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ------------ | ---- | ---------- | +| userId | number | Yes | User ID.| + +**Error codes** + +| ID| Error Message | +| -------- | ----------------------------------- | +| 1600001 | Internal error. | +| 1600002 | Marshalling or unmarshalling error. | +| 1600003 | Failed to connect service. | +| 1600008 | The user is not exist. | + +**Example** + +```js +function removeAllCallback(err) { + if (err) { + console.info("removeAll failed " + JSON.stringify(err)); + } else { + console.info("removeAll success"); + } +} + +var userId = 1 + +NotificationSubscribe.removeAll(userId, removeAllCallback); +``` + + + +## NotificationSubscriber + +Provides callbacks for receiving or removing notifications and serves as the input parameter of [subscribe](#notificationsubscribe). + +**System API**: This is a system API and cannot be called by third-party applications. + +### onConsume + +onConsume?: (data: [SubscribeCallbackData](#subscribecallbackdata)) => void + +Callback for receiving notifications. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name| Type| Mandatory| Description| +| ------------ | ------------------------ | ---- | -------------------------- | +| data | [SubscribeCallbackData](#subscribecallbackdata) | Yes| Information about the notification received.| + +**Example** + +```javascript +function subscribeCallback(err) { + if (err) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; + +function onConsumeCallback(data) { + console.info('===> onConsume in test'); + let req = data.request; + console.info('===> onConsume callback req.id:' + req.id); +}; + +var subscriber = { + onConsume: onConsumeCallback +}; + +NotificationSubscribe.subscribe(subscriber, subscribeCallback); +``` + +### onCancel + +onCancel?:(data: [SubscribeCallbackData](#subscribecallbackdata)) => void + +Callback for canceling notifications. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name| Type| Mandatory| Description| +| ------------ | ------------------------ | ---- | -------------------------- | +| data | [SubscribeCallbackData](#subscribecallbackdata) | Yes| Information about the notification to cancel.| + +**Example** + +```javascript +function subscribeCallback(err) { + if (err) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; + +function onCancelCallback(data) { + console.info('===> onCancel in test'); + let req = data.request; + console.info('===> onCancel callback req.id:' + req.id); +} + +var subscriber = { + onCancel: onCancelCallback +}; + +NotificationSubscribe.subscribe(subscriber, subscribeCallback); +``` + +### onUpdate + +onUpdate?:(data: [NotificationSortingMap](#notificationsortingmap)) => void + +Callback for notification sorting updates. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name| Type| Mandatory| Description| +| ------------ | ------------------------ | ---- | -------------------------- | +| data | [NotificationSortingMap](#notificationsortingmap) | Yes| Latest notification sorting list.| + +**Example** + +```javascript +function subscribeCallback(err) { + if (err) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; + +function onUpdateCallback(map) { + console.info('===> onUpdateCallback map:' + JSON.stringify(map)); +} + +var subscriber = { + onUpdate: onUpdateCallback +}; + +NotificationSubscribe.subscribe(subscriber, subscribeCallback); +``` + +### onConnect + +onConnect?:() => void + +Callback for subscription. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Example** + +```javascript +function subscribeCallback(err) { + if (err) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; + +function onConnectCallback() { + console.info('===> onConnect in test'); +} + +var subscriber = { + onConnect: onConnectCallback +}; + +NotificationSubscribe.subscribe(subscriber, subscribeCallback); +``` + +### onDisconnect + +onDisconnect?:() => void + +Callback for unsubscription. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Example** + +```javascript +function subscribeCallback(err) { + if (err) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; +function unsubscribeCallback(err) { + if (err.code) { + console.info("unsubscribe failed " + JSON.stringify(err)); + } else { + console.info("unsubscribeCallback"); + } +}; + +function onConnectCallback() { + console.info('===> onConnect in test'); +} +function onDisconnectCallback() { + console.info('===> onDisconnect in test'); +} + +var subscriber = { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback +}; + +// The onConnect callback is invoked when subscription to the notification is complete. +NotificationSubscribe.subscribe(subscriber, subscribeCallback); +// The onDisconnect callback is invoked when unsubscription to the notification is complete. +NotificationSubscribe.unsubscribe(subscriber, unsubscribeCallback); +``` + +### onDestroy + +onDestroy?:() => void + +Callback for service disconnection. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Example** + +```javascript +function subscribeCallback(err) { + if (err) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; + +function onDestroyCallback() { + console.info('===> onDestroy in test'); +} + +var subscriber = { + onDestroy: onDestroyCallback +}; + +NotificationSubscribe.subscribe(subscriber, subscribeCallback); +``` + +### onDoNotDisturbDateChange + +onDoNotDisturbDateChange?:(mode: notification.[DoNotDisturbDate](js-apis-notificationManager.md#donotdisturbdate)) => void + +Callback for DND time setting updates. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name| Type| Mandatory| Description| +| ------------ | ------------------------ | ---- | -------------------------- | +| mode | notification.[DoNotDisturbDate](js-apis-notificationManager.md#DoNotDisturbDate) | Yes| DND time setting updates.| + +**Example** + +```javascript +function subscribeCallback(err) { + if (err) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; + +function onDoNotDisturbDateChangeCallback(mode) { + console.info('===> onDoNotDisturbDateChange:' + mode); +} + +var subscriber = { + onDoNotDisturbDateChange: onDoNotDisturbDateChangeCallback +}; + +NotificationSubscribe.subscribe(subscriber, subscribeCallback); +``` + + +### onEnabledNotificationChanged + +onEnabledNotificationChanged?:(callbackData: [EnabledNotificationCallbackData](#enablednotificationcallbackdata)) => void + +Listens for the notification enabled status changes. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +**Parameters** + +| Name| Type| Mandatory| Description| +| ------------ | ------------------------ | ---- | -------------------------- | +| callback | AsyncCallback\<[EnabledNotificationCallbackData](#enablednotificationcallbackdata)\> | Yes| Callback used to return the result.| + +**Example** + +```javascript +function subscribeCallback(err) { + if (err) { + console.info("subscribe failed " + JSON.stringify(err)); + } else { + console.info("subscribeCallback"); + } +}; + +function onEnabledNotificationChangedCallback(callbackData) { + console.info("bundle: ", callbackData.bundle); + console.info("uid: ", callbackData.uid); + console.info("enable: ", callbackData.enable); +}; + +var subscriber = { + onEnabledNotificationChanged: onEnabledNotificationChangedCallback +}; + +NotificationSubscribe.subscribe(subscriber, subscribeCallback); +``` + +## BundleOption + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| ------ | ------ |---- | --- | ------ | +| bundle | string | Yes | Yes | Bundle information of the application.| +| uid | number | Yes | Yes | User ID.| + +## NotificationKey + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| ----- | ------ | ---- | --- | -------- | +| id | number | Yes | Yes | Notification ID. | +| label | string | Yes | Yes | Notification label.| + +## SubscribeCallbackData + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +| Name | Type | Readable | Writable | Description | +| --------------- | ------------------------------------------------- | -------- | -------- | -------- | +| request | [NotificationRequest](js-apis-notificationManager.md#notificationrequest) | Yes| No| Notification content.| +| sortingMap | [NotificationSortingMap](#notificationsortingmap) | Yes| No| Notification sorting information.| +| reason | number | Yes | No | Reason for deletion.| +| sound | string | Yes | No | Sound used for notification.| +| vibrationValues | Array\ | Yes | No | Vibration used for notification.| + + +## EnabledNotificationCallbackData + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +| Name | Type | Readable | Writable | Description | +| ------ | ------- | ---------------- | ---------------- | ---------------- | +| bundle | string | Yes| No| Bundle name of the application. | +| uid | number | Yes| No| UID of the application. | +| enable | boolean | Yes| No| Notification enabled status of the application.| + + +## NotificationSorting + +Provides sorting information of activity notifications. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +| Name | Type | Readable| Writable| Description | +| -------- | ------------------------------------- | ---- | --- | ------------ | +| slot | [NotificationSlot](js-apis-notificationManager.md#notificationslot) | Yes | No | Notification slot.| +| hashCode | string | Yes | No | Unique ID of the notification.| +| ranking | number | Yes | No | Notification sequence number.| + + +## NotificationSortingMap + +Provides sorting information of active notifications in all subscribed notifications. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +| Name | Type | Readable| Writable| Description | +| -------------- | ------------------------------------------------------------ | ---- | --- | ---------------- | +| sortings | {[key: string]: [NotificationSorting](#notificationsorting)} | Yes | No | Array of notification sorting information.| +| sortedHashCode | Array\ | Yes | No | Array of unique notification IDs.| + + +## NotificationSubscribeInfo + +Provides the information about the publisher for notification subscription. + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +| Name | Type | Readable| Writable| Description | +| ----------- | --------------- | --- | ---- | ------------------------------- | +| bundleNames | Array\ | Yes | Yes | Bundle names of the applications whose notifications are to be subscribed to.| +| userId | number | Yes | Yes | User whose notifications are to be subscribed to. | + + +## NotificationUserInput + +Provides the notification user input. + +**System capability**: SystemCapability.Notification.Notification + +| Name | Type | Readable| Writable| Description | +| -------- | ------ | --- | ---- | ----------------------------- | +| inputKey | string | Yes | Yes | Key to identify the user input.| + +## RemoveReason + +**System capability**: SystemCapability.Notification.Notification + +**System API**: This is a system API and cannot be called by third-party applications. + +| Name | Value | Description | +| -------------------- | --- | -------------------- | +| CLICK_REASON_REMOVE | 1 | The notification is removed after a click on it. | +| CANCEL_REASON_REMOVE | 2 | The notification is removed by the user. | diff --git a/en/application-dev/reference/apis/js-apis-observer.md b/en/application-dev/reference/apis/js-apis-observer.md index a6fcacc4333ab0aa48dae7cd8b629e1e77bb399f..ad7d19b4ab7a3cfa6593c81f2c70b52f403aa4d1 100644 --- a/en/application-dev/reference/apis/js-apis-observer.md +++ b/en/application-dev/reference/apis/js-apis-observer.md @@ -531,8 +531,8 @@ Enumerates SIM card types and states. **System capability**: SystemCapability.Telephony.StateRegistry -| Name | Type | Description | -| ----------------- | --------------------- | ------------------------------------------------------------ | -| type | [CardType](js-apis-sim.md#cardtype) | SIM card type. For details, see [CardType](js-apis-sim.md#cardtype).| -| state | [SimState](js-apis-sim.md#simstate) | SIM card status. For details, see [SimState](js-apis-sim.md#simstate).| -| reason8+ | [LockReason](#lockreason8) | SIM card lock type.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| type | [CardType](js-apis-sim.md#cardtype) | Yes| SIM card type. For details, see [CardType](js-apis-sim.md#cardtype).| +| state | [SimState](js-apis-sim.md#simstate) | Yes| SIM card status. For details, see [SimState](js-apis-sim.md#simstate).| +| reason8+ | [LockReason](#lockreason8) | Yes| SIM card lock type.| diff --git a/en/application-dev/reference/apis/js-apis-pointer.md b/en/application-dev/reference/apis/js-apis-pointer.md index 06bb32eecce0d9b40133160a8689c6b80c27ad61..ed71da2336509844e7baa5eea49f8a026e969eba 100644 --- a/en/application-dev/reference/apis/js-apis-pointer.md +++ b/en/application-dev/reference/apis/js-apis-pointer.md @@ -142,7 +142,7 @@ Sets the mouse movement speed. This API uses an asynchronous callback to return | Name | Type | Mandatory | Description | | -------- | ------------------------- | ---- | ------------------------------------- | | speed | number | Yes | Mouse movement speed. The value ranges from **1** to **11**. The default value is **5**. | -| callback | AysncCallback<void> | Yes | Callback used to return the result.| +| callback | AsyncCallback<void> | Yes | Callback used to return the result.| **Example** @@ -349,7 +349,7 @@ Sets the mouse pointer style. This API uses an asynchronous callback to return t | ------------ | ------------------------------ | ---- | ----------------------------------- | | windowId | number | Yes | Window ID. | | pointerStyle | [PointerStyle](#pointerstyle9) | Yes | Mouse pointer style ID. | -| callback | AysncCallback<void> | Yes | Callback used to return the result.| +| callback | AsyncCallback<void> | Yes | Callback used to return the result.| **Example** diff --git a/en/application-dev/reference/apis/js-apis-radio.md b/en/application-dev/reference/apis/js-apis-radio.md index 01d439fd2e3e9d1202aa6969cb15fda67fa9059d..91c6be9cd7d076dbb72a502e64363d729668972f 100644 --- a/en/application-dev/reference/apis/js-apis-radio.md +++ b/en/application-dev/reference/apis/js-apis-radio.md @@ -1734,8 +1734,8 @@ Enables listening for **imsRegStateChange** events for the SIM card in the speci **Example** ```js -radio.on('imsRegStateChange', 0, radio.ImsServiceType.TYPE_VIDEO, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +radio.on('imsRegStateChange', 0, radio.ImsServiceType.TYPE_VIDEO, data => { + console.log(`callback: data->${JSON.stringify(data)}`); }); ``` @@ -1763,8 +1763,8 @@ Disables listening for **imsRegStateChange** events for the SIM card in the spec **Example** ```js -radio.off('imsRegStateChange', 0, radio.ImsServiceType.TYPE_VIDEO, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +radio.off('imsRegStateChange', 0, radio.ImsServiceType.TYPE_VIDEO, data => { + console.log(`callback: data->${JSON.stringify(data)}`); }); ``` @@ -1797,10 +1797,10 @@ Defines the signal strength. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ----------- | --------------------------- | ------------------ | -| signalType | [NetworkType](#networktype) | Signal strength type.| -| signalLevel | number | Signal strength level.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| signalType | [NetworkType](#networktype) | Yes| Signal strength type.| +| signalLevel | number | Yes| Signal strength level.| ## NetworkType @@ -1825,17 +1825,17 @@ Defines the network status. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ----------------- | --------------------- | ------------------------------------------------------------ | -| longOperatorName | string | Long carrier name of the registered network.| -| shortOperatorName | string | Short carrier name of the registered network.| -| plmnNumeric | string | PLMN code of the registered network.| -| isRoaming | boolean | Whether the user is roaming.| -| regState | [RegState](#regstate) | Network registration status of the device.| -| cfgTech8+ | [RadioTechnology](#radiotechnology) | RAT of the device.| -| nsaState | [NsaState](#nsastate) | NSA network registration status of the device.| -| isCaActive | boolean | CA status.| -| isEmergency | boolean | Whether only emergency calls are allowed.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| longOperatorName | string | Yes | Long carrier name of the registered network.| +| shortOperatorName | string | Yes | Short carrier name of the registered network.| +| plmnNumeric | string | Yes | PLMN code of the registered network.| +| isRoaming | boolean | Yes | Whether the user is roaming.| +| regState | [RegState](#regstate) | Yes | Network registration status of the device.| +| cfgTech8+ | [RadioTechnology](#radiotechnology) | Yes | RAT of the device.| +| nsaState | [NsaState](#nsastate) | Yes | NSA network registration status of the device.| +| isCaActive | boolean | Yes | CA status.| +| isEmergency | boolean | Yes | Whether only emergency calls are allowed.| ## RegState @@ -1933,13 +1933,13 @@ Defines the cell information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ----------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | -| networkType | [NetworkType](#networktype) | Network type of the cell. | -| isCamped | boolean | Status of the cell. | -| timeStamp | number | Timestamp when cell information is obtained. | -| signalInformation | [SignalInformation](#signalinformation) | Signal information. | -| data | [CdmaCellInformation](#cdmacellinformation8) \| [GsmCellInformation](#gsmcellinformation8) \| [LteCellInformation](#ltecellinformation8) \| [NrCellInformation](#nrcellinformation8) \| [TdscdmaCellInformation](#tdscdmacellinformation8) | CDMA cell information \|GSM cell information \|LTE cell information \|NR cell information \|TD-SCDMA cell information| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| networkType | [NetworkType](#networktype) | Yes | Network type of the cell. | +| isCamped | boolean | Yes | Status of the cell. | +| timeStamp | number | Yes | Timestamp when cell information is obtained. | +| signalInformation | [SignalInformation](#signalinformation) | Yes | Signal information. | +| data | [CdmaCellInformation](#cdmacellinformation8) \| [GsmCellInformation](#gsmcellinformation8) \| [LteCellInformation](#ltecellinformation8) \| [NrCellInformation](#nrcellinformation8) \| [TdscdmaCellInformation](#tdscdmacellinformation8) | Yes | CDMA cell information \|GSM cell information \|LTE cell information \|NR cell information \|TD-SCDMA cell information| ## CdmaCellInformation8+ @@ -1949,13 +1949,13 @@ Defines the CDMA cell information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| --------- | ------ | ------------ | -| baseId | number | Base station ID. | -| latitude | number | Longitude. | -| longitude | number | Latitude. | -| nid | number | Network ID.| -| sid | number | System ID.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| baseId | number | Yes | Base station ID. | +| latitude | number | Yes | Longitude. | +| longitude | number | Yes | Latitude. | +| nid | number | Yes | Network ID.| +| sid | number | Yes | System ID.| ## GsmCellInformation8+ @@ -1965,14 +1965,14 @@ Defines the GSM cell information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ------ | ------ | -------------------- | -| lac | number | Location area code. | -| cellId | number | Cell ID. | -| arfcn | number | Absolute radio frequency channel number.| -| bsic | number | Base station ID. | -| mcc | string | Mobile country code. | -| mnc | string | Mobile network code. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| lac | number | Yes | Location area code. | +| cellId | number | Yes | Cell ID. | +| arfcn | number | Yes | Absolute radio frequency channel number.| +| bsic | number | Yes | Base station ID. | +| mcc | string | Yes | Mobile country code. | +| mnc | string | Yes | Mobile network code. | ## LteCellInformation8+ @@ -1982,16 +1982,16 @@ Defines the LTE cell information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ------------- | ------- | ----------------------- | -| cgi | number | Cell global identification. | -| pci | number | Physical cell ID. | -| tac | number | Tracking area code. | -| earfcn | number | Absolute radio frequency channel number. | -| bandwidth | number | Bandwidth. | -| mcc | string | Mobile country code. | -| mnc | string | Mobile network code. | -| isSupportEndc | boolean | Support New Radio_Dual Connectivity| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| cgi | number | Yes | Cell global identification. | +| pci | number | Yes | Physical cell ID. | +| tac | number | Yes | Tracking area code. | +| earfcn | number | Yes | Absolute radio frequency channel number. | +| bandwidth | number | Yes | Bandwidth. | +| mcc | string | Yes | Mobile country code. | +| mnc | string | Yes | Mobile network code. | +| isSupportEndc | boolean | Yes | Support for New Radio_Dual Connectivity. | ## NrCellInformation8+ @@ -2001,14 +2001,14 @@ Defines the NR cell information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ------- | ------ | ---------------- | -| nrArfcn | number | 5G frequency number. | -| pci | number | Physical cell ID. | -| tac | number | Tracking area code. | -| nci | number | 5G network cell ID.| -| mcc | string | Mobile country code. | -| mnc | string | Mobile network code. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| nrArfcn | number | Yes | 5G frequency number. | +| pci | number | Yes | Physical cell ID. | +| tac | number | Yes | Tracking area code. | +| nci | number | Yes | 5G network cell ID.| +| mcc | string | Yes | Mobile country code. | +| mnc | string | Yes | Mobile network code. | ## TdscdmaCellInformation8+ @@ -2018,14 +2018,14 @@ Defines the TD-SCDMA cell information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ------ | ------ | ------------ | -| lac | number | Location area code.| -| cellId | number | Cell ID. | -| cpid | number | Cell parameter ID.| -| uarfcn | number | Absolute radio frequency number.| -| mcc | string | Mobile country code.| -| mnc | string | Mobile network code. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| lac | number | Yes | Location area code.| +| cellId | number | Yes | Cell ID. | +| cpid | number | Yes | Cell parameter ID.| +| uarfcn | number | Yes | Absolute radio frequency number.| +| mcc | string | Yes | Mobile country code.| +| mnc | string | Yes | Mobile network code. | ## WcdmaCellInformation8+ @@ -2035,14 +2035,14 @@ Defines the WCDMA cell information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ------ | ------ | ------------ | -| lac | number | Location area code.| -| cellId | number | Cell ID. | -| psc | number | Primary scrambling code. | -| uarfcn | number | Absolute radio frequency number.| -| mcc | string | Mobile country code.| -| mnc | string | Mobile network code. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| lac | number | Yes | Location area code.| +| cellId | number | Yes | Cell ID. | +| psc | number | Yes | Primary scrambling code. | +| uarfcn | number | Yes | Absolute radio frequency number.| +| mcc | string | Yes | Mobile country code.| +| mnc | string | Yes | Mobile network code. | ## NrOptionMode8+ @@ -2067,10 +2067,10 @@ Defines the network search result. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ---------------------- | ------------------------------------------------- | -------------- | -| isNetworkSearchSuccess | boolean | Successful network search.| -| networkSearchResult | Array<[NetworkInformation](#networkinformation)\> | Network search result.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| isNetworkSearchSuccess | boolean | Yes | Successful network search.| +| networkSearchResult | Array<[NetworkInformation](#networkinformation)\> | Yes | Network search result.| ## NetworkInformation @@ -2080,12 +2080,12 @@ Defines the network information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| --------------- | ----------------------------------------- | -------------- | -| operatorName | string | Carrier name.| -| operatorNumeric | string | Carrier number. | -| state | [NetworkInformation](#networkinformationstate) | Network information status.| -| radioTech | string | Radio technology. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| operatorName | string | Yes | Carrier name.| +| operatorNumeric | string | Yes | Carrier number. | +| state | [NetworkInformation](#networkinformationstate) | Yes | Network information status.| +| radioTech | string | Yes | Radio technology. | ## NetworkInformationState @@ -2110,12 +2110,12 @@ Defines the network selection mode. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ------------------ | --------------------------------------------- | -------------------------------------- | -| slotId | number | Card slot ID.
- **0**: card slot 1
- **1**: card slot 2| -| selectMode | [NetworkSelectionMode](#networkselectionmode) | Network selection mode. | -| networkInformation | [NetworkInformation](#networkinformation) | Network information. | -| resumeSelection | boolean | Whether to resume selection. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| slotId | number | Yes | Card slot ID.
- **0**: card slot 1
- **1**: card slot 2| +| selectMode | [NetworkSelectionMode](#networkselectionmode) | Yes | Network selection mode. | +| networkInformation | [NetworkInformation](#networkinformation) | Yes | Network information. | +| resumeSelection | boolean | Yes | Whether to resume selection. | ## ImsRegState9+ @@ -2153,10 +2153,10 @@ Defines the IMS registration information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ----------- | ---------------------------- | ------------- | -| imsRegState | [ImsRegState](#imsregstate9) | IMS registration state.| -| imsRegTech | [ImsRegTech](#imsregtech9) | IMS registration technology.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| imsRegState | [ImsRegState](#imsregstate9) | Yes | IMS registration state.| +| imsRegTech | [ImsRegTech](#imsregtech9) | Yes | IMS registration technology.| ## ImsServiceType9+ diff --git a/en/application-dev/reference/apis/js-apis-request.md b/en/application-dev/reference/apis/js-apis-request.md index 2220b4bbc02bd9a68fa900138869b6d3f6620675..5cf97609d706bcf49319962f204635c04ca23663 100644 --- a/en/application-dev/reference/apis/js-apis-request.md +++ b/en/application-dev/reference/apis/js-apis-request.md @@ -44,30 +44,53 @@ Only HTTP requests are supported. HTTPS requests are not supported. **System capability**: SystemCapability.MiscServices.Download -| Name| Type| Readable| Writable| Description| -| -------- | -------- | -------- | -------- | -------- | -| NETWORK_MOBILE | number | Yes| No| Whether download is allowed on a mobile network.| -| NETWORK_WIFI | number | Yes| No| Whether download is allowed on a WLAN.| -| ERROR_CANNOT_RESUME7+ | number | Yes| No| Failure to resume the download due to an error.| -| ERROR_DEVICE_NOT_FOUND7+ | number | Yes| No| Failure to find a storage device such as a memory card.| -| ERROR_FILE_ALREADY_EXISTS7+ | number | Yes| No| Failure to download the file because it already exists.| -| ERROR_FILE_ERROR7+ | number | Yes| No| File operation failure.| -| ERROR_HTTP_DATA_ERROR7+ | number | Yes| No| HTTP transmission failure.| -| ERROR_INSUFFICIENT_SPACE7+ | number | Yes| No| Insufficient storage space.| -| ERROR_TOO_MANY_REDIRECTS7+ | number | Yes| No| Error caused by too many network redirections.| -| ERROR_UNHANDLED_HTTP_CODE7+ | number | Yes| No| Unidentified HTTP code.| -| ERROR_OFFLINE9+ | number | Yes| No| No network connection.| -| ERROR_UNSUPPORTED_NETWORK_TYPE9+ | number | Yes| No| Network type mismatch.| -| ERROR_UNKNOWN7+ | number | Yes| No| Unknown error.| -| PAUSED_QUEUED_FOR_WIFI7+ | number | Yes| No| Download paused and queuing for a WLAN connection, because the file size exceeds the maximum value allowed by a mobile network session.| -| PAUSED_UNKNOWN7+ | number | Yes| No| Download paused due to unknown reasons.| -| PAUSED_WAITING_FOR_NETWORK7+ | number | Yes| No| Download paused due to a network connection problem, for example, network disconnection.| -| PAUSED_WAITING_TO_RETRY7+ | number | Yes| No| Download paused and then retried.| -| SESSION_FAILED7+ | number | Yes| No| Download failure without retry.| -| SESSION_PAUSED7+ | number | Yes| No| Download paused.| -| SESSION_PENDING7+ | number | Yes| No| Download pending.| -| SESSION_RUNNING7+ | number | Yes| No| Download in progress.| -| SESSION_SUCCESSFUL7+ | number | Yes| No| Successful download.| +### Network Types +You can set **networkType** in [DownloadConfig](#downloadconfig) to specify the network type for the download service. + +| Name| Type| Value| Description| +| -------- | -------- | -------- | -------- | +| NETWORK_MOBILE | number | 0x00000001 | Whether download is allowed on a mobile network.| +| NETWORK_WIFI | number | 0x00010000 | Whether download is allowed on a WLAN.| + +### Download Error Codes +The table below lists the error codes that may be returned by [on('fail')7+](#onfail7)/[off('fail')7+](#offfail7)/[getTaskInfo9+](#gettaskinfo9). + +| Name| Type| Value| Description| +| -------- | -------- | -------- | -------- | +| ERROR_CANNOT_RESUME7+ | number | 0 | Failure to resume the download due to network errors.| +| ERROR_DEVICE_NOT_FOUND7+ | number | 1 | Failure to find a storage device such as a memory card.| +| ERROR_FILE_ALREADY_EXISTS7+ | number | 2 | Failure to download the file because it already exists.| +| ERROR_FILE_ERROR7+ | number | 3 | File operation failure.| +| ERROR_HTTP_DATA_ERROR7+ | number | 4 | HTTP transmission failure.| +| ERROR_INSUFFICIENT_SPACE7+ | number | 5 | Insufficient storage space.| +| ERROR_TOO_MANY_REDIRECTS7+ | number | 6 | Error caused by too many network redirections.| +| ERROR_UNHANDLED_HTTP_CODE7+ | number | 7 | Unidentified HTTP code.| +| ERROR_UNKNOWN7+ | number | 8 | Unknown error.| +| ERROR_OFFLINE9+ | number | 9 | No network connection.| +| ERROR_UNSUPPORTED_NETWORK_TYPE9+ | number | 10 | Network type mismatch.| + + +### Causes of Download Pause +The table below lists the causes of download pause that may be returned by [getTaskInfo9+](#gettaskinfo9). + +| Name| Type| Value| Description| +| -------- | -------- | -------- | -------- | +| PAUSED_QUEUED_FOR_WIFI7+ | number | 0 | Download paused and queuing for a WLAN connection, because the file size exceeds the maximum value allowed by a mobile network session.| +| PAUSED_WAITING_FOR_NETWORK7+ | number | 1 | Download paused due to a network connection problem, for example, network disconnection.| +| PAUSED_WAITING_TO_RETRY7+ | number | 2 | Download paused and then retried.| +| PAUSED_BY_USER9+ | number | 3 | The user paused the session. | +| PAUSED_UNKNOWN7+ | number | 4 | Download paused due to unknown reasons.| + +### Download Task Status Codes +The table below lists the download task status codes that may be returned by [getTaskInfo9+](#gettaskinfo9). + +| Name| Type| Value| Description| +| -------- | -------- | -------- | -------- | +| SESSION_SUCCESSFUL7+ | number | 0 | Successful download.| +| SESSION_RUNNING7+ | number | 1 | Download in progress.| +| SESSION_PENDING7+ | number | 2 | Download pending.| +| SESSION_PAUSED7+ | number | 3 | Download paused.| +| SESSION_FAILED7+ | number | 4 | Download failure without retry.| ## request.uploadFile9+ @@ -112,11 +135,15 @@ For details about the error codes, see [Upload and Download Error Codes](../erro files: [{ filename: "test", name: "test", uri: "internal://cache/test.jpg", type: "jpg" }], data: [{ name: "name123", value: "123" }], }; - request.uploadFile(globalThis.abilityContext, uploadConfig).then((data) => { + try { + request.uploadFile(globalThis.abilityContext, uploadConfig).then((data) => { uploadTask = data; - }).catch((err) => { - console.error('Failed to request the upload. Cause: ' + JSON.stringify(err)); - }); + }).catch((err) => { + console.error('Failed to request the upload. Cause: ' + JSON.stringify(err)); + }); + } catch (err) { + console.error('err.code : ' + err.code + ', err.message : ' + err.message); + } ``` @@ -156,13 +183,17 @@ For details about the error codes, see [Upload and Download Error Codes](../erro files: [{ filename: "test", name: "test", uri: "internal://cache/test.jpg", type: "jpg" }], data: [{ name: "name123", value: "123" }], }; - request.uploadFile(globalThis.abilityContext, uploadConfig, (err, data) => { + try { + request.uploadFile(globalThis.abilityContext, uploadConfig, (err, data) => { if (err) { console.error('Failed to request the upload. Cause: ' + JSON.stringify(err)); return; } uploadTask = data; - }); + }); + } catch (err) { + console.error('err.code : ' + err.code + ', err.message : ' + err.message); + } ``` ## request.upload(deprecated) @@ -348,8 +379,6 @@ Uploads files. This API uses an asynchronous callback to return the result. Implements file uploads. Before using any APIs of this class, you must obtain an **UploadTask** object through [request.uploadFile9+](#requestuploadfile9) in promise mode or [request.uploadFile9+](#requestuploadfile9-1) in callback mode. - - ### on('progress') on(type: 'progress', callback:(uploadedSize: number, totalSize: number) => void): void @@ -367,12 +396,12 @@ Subscribes to an upload event. This API uses an asynchronous callback to return | type | string | Yes| Type of the event to subscribe to. The value is **'progress'** (upload progress).| | callback | function | Yes| Callback for the upload progress event.| - Parameters of the callback function +Parameters of the callback function | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| uploadedSize | number | Yes| Size of the uploaded files, in KB.| -| totalSize | number | Yes| Total size of the files to upload, in KB.| +| uploadedSize | number | Yes| Size of the uploaded files, in bytes. | +| totalSize | number | Yes| Total size of the files to upload, in bytes. | **Example** @@ -401,7 +430,7 @@ Subscribes to an upload event. This API uses an asynchronous callback to return | type | string | Yes| Type of the event to subscribe to. The value is **'headerReceive'** (response header).| | callback | function | Yes| Callback for the HTTP Response Header event.| - Parameters of the callback function +Parameters of the callback function | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -434,7 +463,7 @@ Subscribes to an upload event. This API uses an asynchronous callback to return | type | string | Yes| Type of the event to subscribe to. The value **'complete'** means the upload completion event, and **'fail'** means the upload failure event.| | callback | Callback<Array<TaskState>> | Yes| Callback used to return the result.| - Parameters of the callback function +Parameters of the callback function | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -476,12 +505,12 @@ Unsubscribes from an upload event. This API uses an asynchronous callback to ret | type | string | Yes| Type of the event to unsubscribe from. The value is **'progress'** (upload progress).| | callback | function | No| Callback for the upload progress event.| - Parameters of the callback function + Parameters of the callback function | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| uploadedSize | number | Yes| Size of the uploaded files, in KB.| -| totalSize | number | Yes| Total size of the files to upload, in KB.| +| uploadedSize | number | Yes| Size of the uploaded files, in bytes. | +| totalSize | number | Yes| Total size of the files to upload, in bytes. | **Example** @@ -510,7 +539,7 @@ Unsubscribes from an upload event. This API uses an asynchronous callback to ret | type | string | Yes| Type of the event to unsubscribe from. The value is **'headerReceive'** (response header).| | callback | function | No| Callback for the HTTP Response Header event.| - Parameters of the callback function +Parameters of the callback function | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -542,7 +571,7 @@ Unsubscribes from an upload event. This API uses an asynchronous callback to ret | type | string | Yes| Type of the event to subscribe to. The value **'complete'** means the upload completion event, and **'fail'** means the upload failure event.| | callback | Callback<Array<TaskState>> | No| Callback used to return the result.| - Parameters of the callback function +Parameters of the callback function | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -600,7 +629,7 @@ Deletes this upload task. This API uses a promise to return the result. delete(callback: AsyncCallback<boolean>): void -Removes this upload task. This API uses an asynchronous callback to return the result. +Deletes this upload task. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.INTERNET @@ -787,11 +816,15 @@ For details about the error codes, see [Upload and Download Error Codes](../erro ```js let downloadTask; - request.downloadFile(globalThis.abilityContext, { url: 'https://xxxx/xxxx.hap' }).then((data) => { - downloadTask = data; - }).catch((err) => { - console.error('Failed to request the download. Cause: ' + JSON.stringify(err)); - }) + try { + request.downloadFile(globalThis.abilityContext, { url: 'https://xxxx/xxxx.hap' }).then((data) => { + downloadTask = data; + }).catch((err) => { + console.error('Failed to request the download. Cause: ' + JSON.stringify(err)); + }) + } catch (err) { + console.error('err.code : ' + err.code + ', err.message : ' + err.message); + } ``` @@ -826,14 +859,18 @@ For details about the error codes, see [Upload and Download Error Codes](../erro ```js let downloadTask; - request.downloadFile(globalThis.abilityContext, { url: 'https://xxxx/xxxxx.hap', - filePath: 'xxx/xxxxx.hap'}, (err, data) => { - if (err) { - console.error('Failed to request the download. Cause: ' + JSON.stringify(err)); - return; - } - downloadTask = data; - }); + try { + request.downloadFile(globalThis.abilityContext, { url: 'https://xxxx/xxxxx.hap', + filePath: 'xxx/xxxxx.hap'}, (err, data) => { + if (err) { + console.error('Failed to request the download. Cause: ' + JSON.stringify(err)); + return; + } + downloadTask = data; + }); + } catch (err) { + console.error('err.code : ' + err.code + ', err.message : ' + err.message); + } ``` ## request.download(deprecated) @@ -1015,8 +1052,8 @@ Subscribes to a download event. This API uses an asynchronous callback to return | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| receivedSize | number | Yes| Size of the downloaded files, in KB.| -| totalSize | number | Yes| Total size of the files to download, in KB.| +| receivedSize | number | Yes| Size of the downloaded files, in bytes. | +| totalSize | number | Yes| Total size of the files to download, in bytes. | **Example** @@ -1045,12 +1082,12 @@ Unsubscribes from a download event. This API uses an asynchronous callback to re | type | string | Yes| Type of the event to unsubscribe from. The value is **'progress'** (download progress).| | callback | function | No| Callback for the download progress event.| - Parameters of the callback function +Parameters of the callback function | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| receivedSize | number | Yes| Size of the downloaded files.| -| totalSize | number | Yes| Total size of the files to download.| +| receivedSize | number | Yes| Size of the downloaded files, in bytes. | +| totalSize | number | Yes| Total size of the files to download, in bytes. | **Example** @@ -1133,11 +1170,11 @@ Subscribes to the download task failure event. This API uses an asynchronous cal | type | string | Yes| Type of the event to subscribe to. The value is **'fail'** (download failure).| | callback | function | Yes| Callback for the download task failure event.| - Parameters of the callback function +Parameters of the callback function | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| err | number | Yes| Error code of the download failure. For details about the error codes, see [ERROR_*](#constants).| +| err | number | Yes| Error code of the download failure. For details about the error codes, see [Download Error Codes](#download-error-codes).| **Example** @@ -1166,11 +1203,11 @@ Unsubscribes from the download task failure event. This API uses an asynchronous | type | string | Yes| Type of the event to unsubscribe from. The value is **'fail'** (download failure).| | callback | function | No| Callback for the download task failure event.| - Parameters of the callback function +Parameters of the callback function | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| err | number | Yes| Error code of the download failure. For details about the error codes, see [ERROR_*](#constants).| +| err | number | Yes| Error code of the download failure. For details about the error codes, see [Download Error Codes](#download-error-codes).| **Example** @@ -1181,7 +1218,7 @@ Unsubscribes from the download task failure event. This API uses an asynchronous ); ``` - ### delete9+ +### delete9+ delete(): Promise<boolean> @@ -1249,7 +1286,7 @@ Removes this download task. This API uses an asynchronous callback to return the getTaskInfo(): Promise<DownloadInfo> -Queries this download task. This API uses a promise to return the result. +Obtains the information about this download task. This API uses a promise to return the result. **Required permissions**: ohos.permission.INTERNET @@ -1276,7 +1313,7 @@ Queries this download task. This API uses a promise to return the result. getTaskInfo(callback: AsyncCallback<DownloadInfo>): void -Queries this download task. This API uses an asynchronous callback to return the result. +Obtains the information about this download task. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.INTERNET @@ -1842,12 +1879,12 @@ Resumes this download task. This API uses an asynchronous callback to return the | -------- | -------- | -------- | -------- | | url | string | Yes| Resource URL.| | header | Object | No| HTTPS flag header to be included in the download request.
The **X-TLS-Version** parameter in **header** specifies the TLS version to be used. If this parameter is not set, the CURL_SSLVERSION_TLSv1_2 version is used. Available options are as follows:
CURL_SSLVERSION_TLSv1_0
CURL_SSLVERSION_TLSv1_1
CURL_SSLVERSION_TLSv1_2
CURL_SSLVERSION_TLSv1_3
The **X-Cipher-List** parameter in **header** specifies the cipher suite list to be used. If this parameter is not specified, the secure cipher suite list is used. Available options are as follows:
- The TLS 1.2 cipher suite list includes the following ciphers:
TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,TLS_DHE_RSA_WITH_AES_256_GCM_SHA384,
TLS_DHE_DSS_WITH_AES_128_GCM_SHA256,TLS_DSS_RSA_WITH_AES_256_GCM_SHA384,
TLS_PSK_WITH_AES_256_GCM_SHA384,TLS_DHE_PSK_WITH_AES_128_GCM_SHA256,
TLS_DHE_PSK_WITH_AES_256_GCM_SHA384,TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256,
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256,
TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256,TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384,
TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256,TLS_DHE_RSA_WITH_AES_128_CCM,
TLS_DHE_RSA_WITH_AES_256_CCM,TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
TLS_PSK_WITH_AES_256_CCM,TLS_DHE_PSK_WITH_AES_128_CCM,
TLS_DHE_PSK_WITH_AES_256_CCM,TLS_ECDHE_ECDSA_WITH_AES_128_CCM,
TLS_ECDHE_ECDSA_WITH_AES_256_CCM,TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256
- The TLS 1.3 cipher suite list includes the following ciphers:
TLS_AES_128_GCM_SHA256,TLS_AES_256_GCM_SHA384,TLS_CHACHA20_POLY1305_SHA256,TLS_AES_128_CCM_SHA256
- The TLS 1.3 cipher suite list adds the Chinese national cryptographic algorithm:
TLS_SM4_GCM_SM3,TLS_SM4_CCM_SM3 | -| enableMetered | boolean | No| Whether download is allowed on a metered connection.
- **true**: yes
- **false**: no| -| enableRoaming | boolean | No| Whether download is allowed on a roaming network.
- **true**: yes
- **false**: no| +| enableMetered | boolean | No| Whether download is allowed on a metered connection.
- **true**: allowed
- **false**: not allowed | +| enableRoaming | boolean | No| Whether download is allowed on a roaming network.
- **true**: allowed
- **false**: not allowed | | description | string | No| Description of the download session.| -| filePath7+ | string | No| Download path. (The default path is **'internal://cache/'**.)
- filePath:'workspace/test.txt': The **workspace** directory is created in the default path to store files.
- filePath:'test.txt': Files are stored in the default path.
- filePath:'workspace/': The **workspace** directory is created in the default path to store files.| +| filePath7+ | string | No| Path where the downloaded file is stored.
- filePath:'/data/storage/el2/base/haps/entry/files/test.txt': Save the file to an absolute path.
- In the FA model, use [context](js-apis-inner-app-context.md#contextgetcachedir) to obtain the cache directory of the application, for example, **'${featureAbility.getContext().getFilesDir()}/test.txt'**, and store the file in this directory.
- In the stage model, use [AbilityContext](js-apis-inner-application-context.md) to obtain the fie path, for example, **'${globalThis.abilityContext.tempDir}/test.txt'**, and store the file in this path.| | networkType | number | No| Network type allowed for download.
- NETWORK_MOBILE: 0x00000001
- NETWORK_WIFI: 0x00010000| -| title | string | No| Title of the download session.| +| title | string | No| Download task name.| | background9+ | boolean | No| Whether to enable the background task notification. When this parameter is enabled, the download status is displayed in the notification panel.| @@ -1860,13 +1897,13 @@ Resumes this download task. This API uses an asynchronous callback to return the | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | downloadId | number | Yes| ID of the downloaded file.| -| failedReason | number | No| Download failure cause, which can be any constant of [ERROR_*](#constants).| +| failedReason | number | No| Cause of the download failure. The value can be any constant in [Download Error Codes](#download-error-codes).| | fileName | string | Yes| Name of the downloaded file.| | filePath | string | Yes| URI of the saved file.| -| pausedReason | number | No| Reason for session pause, which can be any constant of [PAUSED_*](#constants).| -| status | number | Yes| Download status code, which can be any constant of [SESSION_*](#constants).| +| pausedReason | number | No| Cause of download pause. The value can be any constant in [Causes of Download Pause](#causes-of-download-pause).| +| status | number | Yes| Download task status code. The value can be any constant in [Download Task Status Codes](#download-task-status-codes).| | targetURI | string | Yes| URI of the downloaded file.| -| downloadTitle | string | Yes| Title of the downloaded file.| -| downloadTotalBytes | number | Yes| Total size of the files to download (int bytes).| +| downloadTitle | string | Yes| Download task name.| +| downloadTotalBytes | number | Yes| Total size of the files to download, in bytes.| | description | string | Yes| Description of the file to download.| -| downloadedBytes | number | Yes| Size of the files downloaded (int bytes).| +| downloadedBytes | number | Yes| Size of the files downloaded, in bytes.| 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 8117cdd44862dc934a4022b6b701b9551cd6d25e..865f1104386664ce5b4cafede20ec54ffab711a6 100644 --- a/en/application-dev/reference/apis/js-apis-resource-manager.md +++ b/en/application-dev/reference/apis/js-apis-resource-manager.md @@ -15,8 +15,10 @@ import resourceManager from '@ohos.resourceManager'; ## Instruction -Since API version 9, the stage model allows an application to obtain a **ResourceManager** object based on **context** and call its resource management APIs without first importing the required bundle. This approach, however, is not applicable to the FA model. -For details about how to reference **context** in the stage model, see [Context in the Stage Model]. +Since API version 9, the stage model allows an application to obtain a **ResourceManager** object based on **context** and call its resource management APIs without first importing the required bundle. This approach, however, is not applicable to the FA model. For the FA model, you need to import the required bundle and then call the [getResourceManager](#resourcemanagergetresourcemanager) API to obtain a **ResourceManager** object. + +For details about how to reference **context** in the stage model, see Context in the Stage Model. + ```ts import Ability from '@ohos.application.Ability'; @@ -97,6 +99,7 @@ Obtains the **ResourceManager** object of this application. This API uses a prom **System capability**: SystemCapability.Global.ResourceManager **Return value** + | Type | Description | | ---------------------------------------- | ----------------- | | Promise<[ResourceManager](#resourcemanager)> | Promise used to return the result.| @@ -134,6 +137,7 @@ Obtains the **ResourceManager** object of an application based on the specified | bundleName | string | Yes | Bundle name of the application.| **Return value** + | Type | Description | | ---------------------------------------- | ------------------ | | Promise<[ResourceManager](#resourcemanager)> | Promise used to return the result.| @@ -305,7 +309,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco **Example (stage)** ```ts try { - this.context.getStringValue($r('app.string.test').id, (error, value) => { + this.context.resourceManager.getStringValue($r('app.string.test').id, (error, value) => { if (error != null) { console.log("error is " + error); } else { @@ -333,6 +337,7 @@ Obtains the string corresponding to the specified resource ID. This API uses a p | resId | number | Yes | Resource ID.| **Return value** + | Type | Description | | --------------------- | ----------- | | Promise<string> | Promise used to return the result.| @@ -423,6 +428,7 @@ Obtains the string corresponding to the specified resource object. This API uses | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** + | Type | Description | | --------------------- | ---------------- | | Promise<string> | Promise used to return the result.| @@ -512,6 +518,7 @@ Obtains the string array corresponding to the specified resource ID. This API us | resId | number | Yes | Resource ID.| **Return value** + | Type | Description | | ---------------------------------- | ------------- | | Promise<Array<string>> | Promise used to return the result.| @@ -599,6 +606,7 @@ Obtains the string array corresponding to the specified resource object. This AP | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** + | Type | Description | | ---------------------------------- | ------------------ | | Promise<Array<string>> | Promise used to return the result.| @@ -687,6 +695,7 @@ Obtains the content of the media file corresponding to the specified resource ID | resId | number | Yes | Resource ID.| **Return value** + | Type | Description | | ------------------------- | -------------- | | Promise<Uint8Array> | Promise used to return the result.| @@ -772,6 +781,7 @@ Obtains the content of the media file corresponding to the specified resource ob | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** + | Type | Description | | ------------------------- | ------------------- | | Promise<Uint8Array> | Promise used to return the result.| @@ -859,6 +869,7 @@ Obtains the Base64 code of the image corresponding to the specified resource ID. | resId | number | Yes | Resource ID.| **Return value** + | Type | Description | | --------------------- | -------------------- | | Promise<string> | Promise used to return the result.| @@ -944,6 +955,7 @@ Obtains the Base64 code of the image corresponding to the specified resource obj | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** + | Type | Description | | --------------------- | ------------------------- | | Promise<string> | Promise used to return the result.| @@ -1014,6 +1026,7 @@ Obtains the device configuration. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager **Return value** + | Type | Description | | ---------------------------------------- | ---------------- | | Promise<[Configuration](#configuration)> | Promise used to return the result.| @@ -1069,6 +1082,7 @@ Obtains the device capability. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager **Return value** + | Type | Description | | ---------------------------------------- | ------------------- | | Promise<[DeviceCapability](#devicecapability)> | Promise used to return the result.| @@ -1144,6 +1158,7 @@ Obtains the singular-plural string corresponding to the specified resource ID ba | num | number | Yes | Number. | **Return value** + | Type | Description | | --------------------- | ------------------------- | | Promise<string> | Promise used to return the result.| @@ -1234,6 +1249,7 @@ Obtains the singular-plural string corresponding to the specified resource objec | num | number | Yes | Number. | **Return value** + | Type | Description | | --------------------- | ------------------------------ | | Promise<string> | Promise used to return the result.| @@ -1321,6 +1337,7 @@ Obtains the content of the raw file in the **resources/rawfile** directory. This | path | string | Yes | Path of the raw file.| **Return value** + | Type | Description | | ------------------------- | ----------- | | Promise<Uint8Array> | Promise used to return the result.| @@ -1402,6 +1419,7 @@ Obtains the descriptor of the raw file in the **resources/rawfile** directory. T | path | string | Yes | Path of the raw file.| **Return value** + | Type | Description | | ---------------------------------------- | ------------------- | | Promise<[RawFileDescriptor](#rawfiledescriptor8)> | Promise used to return the result.| @@ -1470,6 +1488,7 @@ Closes the descriptor of the raw file in the **resources/rawfile** directory. Th | path | string | Yes | Path of the raw file.| **Return value** + | Type | Description | | ------------------- | ---- | | Promise<void> | Promise that returns no value.| @@ -1538,6 +1557,7 @@ Closes the descriptor of the raw file in the **resources/rawfile** directory. Th | path | string | Yes | Path of the raw file.| **Return value** + | Type | Description | | ------------------- | ---- | | Promise<void> | Promise that returns no value.| @@ -1634,6 +1654,7 @@ Obtains the string corresponding to the specified resource name. This API uses a | resName | string | Yes | Resource name.| **Return value** + | Type | Description | | --------------------- | ---------- | | Promise<string> | String corresponding to the resource name.| @@ -1716,6 +1737,7 @@ Obtains the string array corresponding to the specified resource name. This API | resName | string | Yes | Resource name.| **Return value** + | Type | Description | | ---------------------------------- | ------------ | | Promise<Array<string>> | Promise used to return the result.| @@ -1798,6 +1820,7 @@ Obtains the content of the media file corresponding to the specified resource na | resName | string | Yes | Resource name.| **Return value** + | Type | Description | | ------------------------- | ------------- | | Promise<Uint8Array> | Promise used to return the result.| @@ -1880,6 +1903,7 @@ Obtains the Base64 code of the image corresponding to the specified resource nam | resName | string | Yes | Resource name.| **Return value** + | Type | Description | | --------------------- | ------------------- | | Promise<string> | Promise used to return the result.| @@ -1965,6 +1989,7 @@ Obtains the plural string corresponding to the specified resource name based on | num | number | Yes | Number. | **Return value** + | Type | Description | | --------------------- | ---------------------- | | Promise<string> | Promise used to return the result.| @@ -2007,6 +2032,7 @@ Obtains the string corresponding to the specified resource ID. This API returns | resId | number | Yes | Resource ID.| **Return value** + | Type | Description | | ------ | ----------- | | string | Promise used to return the result.| @@ -2045,6 +2071,7 @@ Obtains the string corresponding to the specified resource object. This API retu | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** + | Type | Description | | ------ | ---------------- | | string | Promise used to return the result.| @@ -2088,6 +2115,7 @@ Obtains the string corresponding to the specified resource name. This API return | resName | string | Yes | Resource name.| **Return value** + | Type | Description | | ------ | ---------- | | string | String corresponding to the specified resource name.| @@ -2126,6 +2154,7 @@ Obtains the Boolean result corresponding to the specified resource ID. This API | resId | number | Yes | Resource ID.| **Return value** + | Type | Description | | ------- | ------------ | | boolean | Boolean result corresponding to the specified resource ID.| @@ -2163,6 +2192,7 @@ Obtains the Boolean result corresponding to the specified resource object. This | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** + | Type | Description | | ------- | ----------------- | | boolean | Boolean result corresponding to the specified resource object.| @@ -2206,6 +2236,7 @@ Obtains the Boolean result corresponding to the specified resource name. This AP | resName | string | Yes | Resource name.| **Return value** + | Type | Description | | ------- | ----------- | | boolean | Boolean result corresponding to the specified resource name.| @@ -2244,6 +2275,7 @@ Obtains the integer or float value corresponding to the specified resource ID. T | resId | number | Yes | Resource ID.| **Return value** + | Type | Description | | ------ | ---------- | | number | Integer or float value corresponding to the specified resource ID.| @@ -2288,6 +2320,7 @@ Obtains the integer or float value corresponding to the specified resource objec | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** + | Type | Description | | ------ | --------------- | | number | Integer or float value corresponding to the specified resource object.| @@ -2331,6 +2364,7 @@ Obtains the integer or float value corresponding to the specified resource name. | resName | string | Yes | Resource name.| **Return value** + | Type | Description | | ------ | --------- | | number | Integer or float value corresponding to the specified resource name.| @@ -2409,6 +2443,7 @@ This API is deprecated since API version 9. You are advised to use [getStringVal | resId | number | Yes | Resource ID.| **Return value** + | Type | Description | | --------------------- | ----------- | | Promise<string> | Promise used to return the result.| @@ -2473,6 +2508,7 @@ This API is deprecated since API version 9. You are advised to use [getStringArr | resId | number | Yes | Resource ID.| **Return value** + | Type | Description | | ---------------------------------- | ------------- | | Promise<Array<string>> | Promise used to return the result.| @@ -2495,7 +2531,7 @@ getMedia(resId: number, callback: AsyncCallback<Uint8Array>): void Obtains the content of the media file corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. -This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent) instead. +This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent9) instead. **System capability**: SystemCapability.Global.ResourceManager @@ -2526,7 +2562,7 @@ getMedia(resId: number): Promise<Uint8Array> Obtains the content of the media file corresponding to the specified resource ID. This API uses a promise to return the result. -This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent-1) instead. +This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent9-1) instead. **System capability**: SystemCapability.Global.ResourceManager @@ -2537,6 +2573,7 @@ This API is deprecated since API version 9. You are advised to use [getMediaCont | resId | number | Yes | Resource ID.| **Return value** + | Type | Description | | ------------------------- | -------------- | | Promise<Uint8Array> | Promise used to return the result.| @@ -2559,7 +2596,7 @@ getMediaBase64(resId: number, callback: AsyncCallback<string>): void Obtains the Base64 code of the image corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. -This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase64) instead. +This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase649) instead. **System capability**: SystemCapability.Global.ResourceManager @@ -2590,7 +2627,7 @@ getMediaBase64(resId: number): Promise<string> Obtains the Base64 code of the image corresponding to the specified resource ID. This API uses a promise to return the result. -This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase64-1) instead. +This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase649-1) instead. **System capability**: SystemCapability.Global.ResourceManager @@ -2601,6 +2638,7 @@ This API is deprecated since API version 9. You are advised to use [getMediaCont | resId | number | Yes | Resource ID.| **Return value** + | Type | Description | | --------------------- | -------------------- | | Promise<string> | Promise used to return the result.| @@ -2623,7 +2661,7 @@ getPluralString(resId: number, num: number): Promise<string> Obtains the singular-plural string corresponding to the specified resource ID based on the specified number. This API uses a promise to return the result. -This API is deprecated since API version 9. You are advised to use [getPluralStringValue](#getpluralstringvalue) instead. +This API is deprecated since API version 9. You are advised to use [getPluralStringValue](#getpluralstringvalue9) instead. **System capability**: SystemCapability.Global.ResourceManager @@ -2635,6 +2673,7 @@ This API is deprecated since API version 9. You are advised to use [getPluralStr | num | number | Yes | Number. | **Return value** + | Type | Description | | --------------------- | ------------------------- | | Promise<string> | Promise used to return the result.| @@ -2657,7 +2696,7 @@ getPluralString(resId: number, num: number, callback: AsyncCallback<string> Obtains the singular-plural string corresponding to the specified resource ID based on the specified number. This API uses an asynchronous callback to return the result. -This API is deprecated since API version 9. You are advised to use [getPluralStringValue](#getpluralstringvalue-1) instead. +This API is deprecated since API version 9. You are advised to use [getPluralStringValue](#getpluralstringvalue9-1) instead. **System capability**: SystemCapability.Global.ResourceManager @@ -2731,6 +2770,7 @@ This API is deprecated since API version 9. You are advised to use [getRawFileCo | path | string | Yes | Path of the raw file.| **Return value** + | Type | Description | | ------------------------- | ----------- | | Promise<Uint8Array> | Promise used to return the result.| @@ -2796,6 +2836,7 @@ This API is deprecated since API version 9. You are advised to use [getRawFd](#g | path | string | Yes | Path of the raw file.| **Return value** + | Type | Description | | ---------------------------------------- | ------------------- | | Promise<[RawFileDescriptor](#rawfiledescriptor8)> | Promise used to return the result.| diff --git a/en/application-dev/reference/apis/js-apis-sim.md b/en/application-dev/reference/apis/js-apis-sim.md index b0915951260105661f35dcad54468e2417962e89..7c415cc718aa72b7d1d098483a73399fc431d7af 100644 --- a/en/application-dev/reference/apis/js-apis-sim.md +++ b/en/application-dev/reference/apis/js-apis-sim.md @@ -2847,10 +2847,10 @@ Defines the lock status response. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| --------------- | ------ | ------------------ | -| result | number | Operation result. | -| remain?: number | number | Remaining attempts (can be null).| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| result | number | Yes | Operation result. | +| remain?: number | number | Yes | Remaining attempts (can be null).| ## LockInfo8+ @@ -2860,11 +2860,11 @@ Defines the lock information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| -------- | ------------------------ | ------ | -| lockType | [LockType](#locktype8) | Lock type.| -| password | string | Password. | -| state | [LockState](#lockstate8) | Lock state.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| lockType | [LockType](#locktype8) | Yes | Lock type.| +| password | string | Yes | Password. | +| state | [LockState](#lockstate8) | Yes | Lock state.| ## PersoLockInfo8+ @@ -2874,10 +2874,10 @@ Defines the personalized lock information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| -------- | -------------------------------- | ------------ | -| lockType | [PersoLockType](#persolocktype8) | Personalized lock type.| -| password | string | Password. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| lockType | [PersoLockType](#persolocktype8) | Yes | Personalized lock type.| +| password | string | Yes | Password. | ## IccAccountInfo7+ @@ -2887,15 +2887,15 @@ Defines the ICC account information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ---------- | ------- | ---------------- | -| simId | number | SIM card ID. | -| slotIndex | number | Card slot ID. | -| isEsim | boolean | Whether the SIM card is an eSim card.| -| isActive | boolean | Whether the card is activated. | -| iccId | string | ICCID number. | -| showName | string | SIM card display name. | -| showNumber | string | SIM card display number. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| simId | number | Yes | SIM card ID. | +| slotIndex | number | Yes | Card slot ID. | +| isEsim | boolean | Yes | Whether the SIM card is an eSim card.| +| isActive | boolean | Yes | Whether the card is activated. | +| iccId | string | Yes | ICCID number. | +| showName | string | Yes | SIM card display name. | +| showNumber | string | Yes | SIM card display number. | ## OperatorConfig8+ @@ -2905,10 +2905,10 @@ Defines the carrier configuration. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description| -| ----- | ------ | ---- | -| field | string | Field| -| value | string | Value | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| field | string | Yes | Field. | +| value | string | Yes | Value. | ## DiallingNumbersInfo8+ @@ -2918,12 +2918,12 @@ Defines the contact number information. **System capability**: SystemCapability.Telephony.CoreService -| Name | Type | Description | -| ------------ | ------ | -------- | -| alphaTag | string | Alpha tag. | -| number | string | Contact number. | -| recordNumber | number | Record number.| -| pin2 | string | PIN 2.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| alphaTag | string | Yes | Alpha tag. | +| number | string | Yes | Contact number. | +| recordNumber | number | Yes | Record number.| +| pin2 | string | Yes | PIN 2.| ## ContactType8+ diff --git a/en/application-dev/reference/apis/js-apis-sms.md b/en/application-dev/reference/apis/js-apis-sms.md index 7d372978202503f6ed0a0517fa69f85ae5dfcf44..e9e32416426bf852590ed7d7a7f9c5e086a89480 100644 --- a/en/application-dev/reference/apis/js-apis-sms.md +++ b/en/application-dev/reference/apis/js-apis-sms.md @@ -1116,19 +1116,19 @@ Defines an SMS message instance. **System capability**: SystemCapability.Telephony.SmsMms -| Name | Type | Description | -| ------------------------ | --------------------------------------- | ------------------------------------------------------------ | -| hasReplyPath | boolean | Whether the received SMS contains **TP-Reply-Path**. The default value is **false**.
**TP-Reply-Path**: The device returns a response based on the SMSC that sends the SMS message.| -| isReplaceMessage | boolean | Whether the received SMS message is a **replace short message**. The default value is **false**.
For details, see section 9.2.3.9 in **3GPP TS 23.040**.| -| isSmsStatusReportMessage | boolean | Whether the received SMS message is an SMS delivery status report. The default value is **false**.
**SMS-Status-Report**: a message sent from the SMSC to the mobile station to show the SMS message delivery status.| -| messageClass | [ShortMessageClass](#shortmessageclass) | Enumerates SMS message types. | -| pdu | Array<number> | PDU in the SMS message. | -| protocolId | number | Protocol identifier used for delivering the SMS message. | -| scAddress | string | SMSC address. | -| scTimestamp | number | SMSC timestamp. | -| status | number | SMS message status sent by the SMSC in the **SMS-STATUS-REPORT** message.| -| visibleMessageBody | string | SMS message body. | -| visibleRawAddress | string | Sender address. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| hasReplyPath | boolean | Yes |Whether the received SMS contains **TP-Reply-Path**. The default value is **false**.
**TP-Reply-Path**: The device returns a response based on the SMSC that sends the SMS message.| +| isReplaceMessage | boolean | Yes |Whether the received SMS message is a **replace short message**. The default value is **false**.
For details, see section 9.2.3.9 in **3GPP TS 23.040**.| +| isSmsStatusReportMessage | boolean | Yes |Whether the received SMS message is an SMS delivery status report. The default value is **false**.
**SMS-Status-Report**: a message sent from the SMSC to the mobile station to show the SMS message delivery status.| +| messageClass | [ShortMessageClass](#shortmessageclass) | Yes | SMS message type. | +| pdu | Array<number> | Yes | PDU in the SMS message. | +| protocolId | number | Yes | Protocol identifier used for delivering the SMS message. | +| scAddress | string | Yes | SMSC address. | +| scTimestamp | number | Yes | SMSC timestamp. | +| status | number | Yes | SMS message status sent by the SMSC in the **SMS-STATUS-REPORT** message.| +| visibleMessageBody | string | Yes | SMS message body. | +| visibleRawAddress | string | Yes | Sender address. | ## ShortMessageClass diff --git a/en/application-dev/reference/apis/js-apis-system-notification.md b/en/application-dev/reference/apis/js-apis-system-notification.md index 0a46cec929810e8f485a66b26445f1e3042b7672..608bb4d3d3ee2ec6d4c48e7d9b7a4abd01e52c2e 100644 --- a/en/application-dev/reference/apis/js-apis-system-notification.md +++ b/en/application-dev/reference/apis/js-apis-system-notification.md @@ -1,7 +1,6 @@ -# Notification +# @system.notification > **NOTE** -> > - The APIs of this module are no longer maintained since API version 7. You are advised to use [`@ohos.notification`](js-apis-notification.md). > > - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version. @@ -18,22 +17,22 @@ import notification from '@system.notification'; **System capability**: SystemCapability.Notification.Notification -| Name | Readable| Writable| Type | Mandatory| Description | -| ----------- | --- | ---- | ---------------------------------------------- | ---- | ------------------------- | -| bundleName | Yes | Yes | string | Yes | Name of the application bundle to which the notification will be redirected after being clicked. | -| abilityName | Yes | Yes | string | Yes | Name of the application ability to which the notification will be redirected after being clicked.| -| uri | Yes | Yes | string | No | URI of the page to be redirected to. | +| Name | Type | Readable | Writable | Mandatory| Description | +| ----------- | ---------------------------------------------- | ---- | ------------------------- | ------------------------- | ------------------------- | +| bundleName | string | Yes | Yes | Yes | Name of the application bundle to which the notification will be redirected after being clicked. | +| abilityName | string | Yes | Yes | Yes | Name of the application ability to which the notification will be redirected after being clicked.| +| uri | string | Yes | Yes | No | URI of the page to be redirected to. | ## ShowNotificationOptions **System capability**: SystemCapability.Notification.Notification -| Name | Readable| Writable| Type | Mandatory| Description | -| ------------- | --- | ---- | ---------------------------------------------- | ---- | ------------------------- | -| contentTitle | Yes | Yes | string | No | Notification title. | -| contentText | Yes | Yes | string | No | Notification content. | -| clickAction | Yes | Yes | ActionResult | No | Action triggered when the notification is clicked. | +| Name | Type | Readable | Writable | Mandatory| Description | +| ------------- | ---------------------------------------------- | ---- | ------------------------- | ------------------------- | ------------------------- | +| contentTitle | string | Yes | Yes | No | Notification title. | +| contentText | string | Yes | Yes | No | Notification content. | +| clickAction | ActionResult | Yes | Yes | No | Action triggered when the notification is clicked. | ## notification.show diff --git a/en/application-dev/reference/apis/js-apis-system-request.md b/en/application-dev/reference/apis/js-apis-system-request.md index 18b94b676942abb856fa9bd709c1898a6f98588d..a2b939bf7d0983a25202fe11b7c5dd4ddd9d3665 100644 --- a/en/application-dev/reference/apis/js-apis-system-request.md +++ b/en/application-dev/reference/apis/js-apis-system-request.md @@ -1,9 +1,11 @@ -# Uploading and Downloading +# @system.request -> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:** -> - The APIs of this module are no longer maintained since API version 6. It is recommended that you use [`@ohos.request`](js-apis-request.md) instead. +The **system.request** module provides applications with basic upload and download capabilities. + +> **NOTE** +> - The APIs of this module are deprecated since API version 9. You are advised to use [`@ohos.request`](js-apis-request.md) instead. > -> - The initial APIs of this module are supported since API version 4. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version. ## Modules to Import @@ -13,179 +15,245 @@ import request from '@system.request'; ``` -## Required Permissions +## request.upload -ohos.permission.INTERNET. +upload(options: UploadRequestOptions): void +Uploads a file. This API returns no value. -## request.upload +**System capability**: SystemCapability.MiscServices.Upload -upload(Object): void +**Parameters** -Uploads files. + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | options | [UploadRequestOptions](#uploadrequestoptions) | Yes| Upload configurations.| -**Parameters** +**Example** -| Name | Type | Mandatory | Description | -| -------- | -------- | -------- | -------- | -| url | string | Yes | URL of the upload server. | -| header | Object | No | Request header. | -| method | string | No | Request methods available: **POST** and **PUT**. The default value is **POST**. | -| files | Array<File> | Yes | List of files to upload, which is submitted through **multipart/form-data**. | -| data | Array<RequestData> | No | Form data in the request body. | -| success | Function | No | Called when the download task is complete. | -| fail | Function | No | Called when downloading fails or the task does not exist. | -| complete | Function | No | Called when the execution is complete. | + ```js + let uploadRequestOptions = { + url: 'http://www.path.com', + method: 'POST', + files: [{ filename: "test", name: "test", uri: "internal://cache/test.jpg", type: "jpg" }], + data: [{ name: "name123", value: "123" }], + success: function(data) { + console.info(' upload success, code:' + JSON.stringify(data)); + }, + fail: function(data, code) { + console.info(' upload fail data: ' + data + 'code: ' + code); + }, + complete: function (){ + console.info(' upload complete'); + } + } + try { + request.upload(uploadRequestOptions); + console.info('upload start '); + } catch(err) { + console.info(' upload err:' + err); + } + ``` -**Table 1** File -| Name | Type | Mandatory | Description | -| -------- | -------- | -------- | -------- | -| filename | string | No | File name in the header when **multipart** is used. | -| name | string | No | Name of a form item when **multipart** is used. The default value is **file**. | -| uri | string | Yes | Local storage path of a file. | -| type | string | No | Type of the file content. By default, the type is obtained based on the suffix of the file name or URI. | +## UploadRequestOptions -**Table 2** RequestData +**System capability**: SystemCapability.MiscServices.Upload -| Name | Type | Mandatory | Description | -| -------- | -------- | -------- | -------- | -| name | string | Yes | Name of the form element | -| value | string | Yes | Value of the form element | -When the files are successfully uploaded, the following values will be returned. + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | url | string | Yes| URL of the upload server.| + | data | Array<[RequestData](#requestdata)> | No| Form data in the request body.| + | files | Array<[RequestFile](#requestfile)> | Yes| List of files to upload, which is submitted through **multipart/form-data**.| + | header | Object | No| Request header.| + | method | string | No| Request method, which can be **'POST'** or **'PUT'**. The default value is **POST**.| + | success | Function | No| Called when API call is successful.| + | fail | Function | No| Called when API call has failed.| + | complete | Function | No| Called when API call is complete.| -| Name | Type | Description | -| -------- | -------- | -------- | -| code | number | HTTP status code returned by the server. | -| data | string | Content returned by the server. The value type is determined by the type in the returned headers. | -| headers | Object | Headers returned by the server. | +**success parameter** + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | data | [UploadResponse](#uploadresponse) | Yes| Information returned when the upload task is successful.| -When the files fail to be uploaded, an HTTP status code is returned in **code** of **data**. +**fail parameters** + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | data | any | Yes| Header information returned when the upload task fails.| + | code | number | Yes| HTTP status code returned when the upload task fails.| -**Example** -``` -export default { - upLoad() { - request.upload({ - url: 'http://www.path.com', - files: [ - { - uri: 'internal://cache/path/to/file.txt', - name: 'file', - filename: 'file.txt', - }, - ], - data:[ - { - name: 'name1', - value: 'value', - }, - ], - success: function(data) { - console.log('upload success, code:' + data.code); - }, - fail: function() { - console.log('upload fail'); - }, - }); - } -} -``` +## UploadResponse -## request.download +**System capability**: SystemCapability.MiscServices.Upload -download(Object): void + | Name| Type| Description| + | -------- | -------- | -------- | + | code | number | HTTP status code returned by the server.| + | data | string | Content returned by the server. The value type is determined by the type in the returned headers.| + | headers | Object | Headers returned by the server.| -Downloads files. -**Parameters** +## RequestFile + +**System capability**: SystemCapability.MiscServices.Upload + + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | filename | string | No| File name in the header when **multipart** is used.| + | name | string | No| Name of a form item when **multipart** is used. The default value is **file**.| + | uri | string | Yes| Local path for storing files.| + | type | string | No| Type of the file content. By default, the type is obtained based on the extension of the file name or URI.| + + +## RequestData + +**System capability**: SystemCapability.MiscServices.Upload -| Name | Type | Mandatory | Description | -| -------- | -------- | -------- | -------- | -| url | string | Yes | Resource URL. | -| header | Object | No | Request header. | -| description | string | No | Download description. The default value is the file name. | -| filename | string | No | Name of the file to download. The value is obtained from the current request or resource URL by default. | -| success | Function | No | Called when the download task is complete. | -| fail | Function | No | Called when downloading fails or the task does not exist. | -| complete | Function | No | Called when the execution is complete. | + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | name | string | Yes| Name of the form element.| + | value | string | Yes| Value of the form element.| -Return values of the **success** callback -| Name | Type | Description | -| -------- | -------- | -------- | -| token | string | Download token, which is used to obtain the download status. | -One of the following error codes will be returned if the operation fails. +## request.download + +download(options: DownloadRequestOptions): void + +Downloads a file. This API returns no value. + +**System capability**: SystemCapability.MiscServices.Download + +**Parameters** -| Error Code | Description | -| -------- | -------- | -| 400 | Download task failed | + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | options | [DownloadRequestOptions](#downloadrequestoptions) | Yes| Download configurations.| **Example** -``` -export default { - downLoad() { - request.download({ - url: 'http://www.path.com', - success: function(data) { - console.log('call success callback success: ' + data.token); - }, - fail: function(data, code) { - console.log('handling fail'); - }, - }); + ```js + let downloadRequestOptions = { + url: 'http://www.path.com', + filename: 'requestSystenTest', + header: '', + description: 'this is requeSystem download response', + success: function(data) { + console.info(' download success, code:' + JSON.stringify(data)); + }, + fail: function(data, code) { + console.info(' download fail data: ' + data + 'code: ' + code); + }, + complete: function (){ + console.info(' download complete'); + } } -} -``` + try { + request.download(downloadRequestOptions); + console.info('download start '); + } catch(err) { + console.info(' download err:' + err); + } + ``` -## request.onDownloadComplete +## DownloadRequestOptions -onDownloadComplete(Object): void +**System capability**: SystemCapability.MiscServices.Download -Listens to download task status. + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | url | string | Yes| Resource URL.| + | filename | string | No| Name of the file to download. The value is obtained from the current request or resource URL by default.| + | header | Object | No| Request header.| + | description | string | No| Download description. The default value is the file name.| + | success | Function | No| Called when API call is successful.| + | fail | Function | No| Called when API call has failed.| + | complete | Function | No| Called when API call is complete.| -**Parameters** +**success parameter** + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | data | [DownloadResponse](#downloadresponse) | Yes| Information returned when the download task is successful.| + +**fail parameters** + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | data | any | Yes| Header information returned when the download task fails.| + | code | number | Yes| HTTP status code returned when the download task fails.| + +## DownloadResponse + +**System capability**: SystemCapability.MiscServices.Download + + | Name| Type| Description| + | -------- | -------- | -------- | + | token | string | Download token, which is used to obtain the download status| + + +## request.onDownloadComplete -| Name | Type | Mandatory | Description | -| -------- | -------- | -------- | -------- | -| token | string | Yes | Token of the result returned by the download method | -| success | Function | No | Called when the download task is complete. | -| fail | Function | No | Called when downloading fails or the task does not exist. | -| complete | Function | No | Called when the execution is complete. | +onDownloadComplete(options: OnDownloadCompleteOptions): void -Return values of the **success** callback +Listens for download task status. This API returns no value. -| Name | Type | Description | -| -------- | -------- | -------- | -| uri | string | URI of the download file | +**System capability**: SystemCapability.MiscServices.Download -One of the following error codes will be returned if the listening fails. +**Parameters** -| Error Code | Description | -| -------- | -------- | -| 400 | Download task failed | -| 401 | Download task not exist | + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | options | [OnDownloadCompleteOptions](#ondownloadcompleteoptions) | Yes| Configurations of the download task.| **Example** -``` -export default { - onDownloadComplete() { - request.onDownloadComplete({ - token: 'token-index', - success: function(data) { - console.log('download success, uri:' + data.uri); - }, - fail: function(data, code) { - console.log('download fail'); - }, - }); + ```js + let onDownloadCompleteOptions = { + token: 'token-index', + success: function(data) { + console.info(' download success, code:' + JSON.stringify(data)); + }, + fail: function(data, code) { + console.info(' download fail data: ' + data + 'code: ' + code); + }, + complete: function (){ + console.info(' download complete'); + } } -} -``` \ No newline at end of file + request.onDownloadComplete(onDownloadCompleteOptions); + ``` + + +## OnDownloadCompleteOptions + +**System capability**: SystemCapability.MiscServices.Download + + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | token | string | Yes| Result token returned by the download API.| + | success | Function | No| Called when API call is successful.| + | fail | Function | No| Called when API call has failed.| + | complete | Function | No| Called when API call is complete.| + +**success parameter** + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | data | [OnDownloadCompleteResponse](#ondownloadcompleteresponse) | Yes| Information returned when the download task is successful.| + +**fail parameters** + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | data | any | Yes| Header information returned when the download task fails.| + | code | number | Yes| HTTP status code returned when the download task fails.| + + +## OnDownloadCompleteResponse + +**System capability**: SystemCapability.MiscServices.Download + + | Name| Type| Description| + | -------- | -------- | -------- | + | uri | string | URI of the download file.| diff --git a/en/application-dev/reference/apis/js-apis-touchevent.md b/en/application-dev/reference/apis/js-apis-touchevent.md index 05a6e52c9d6f1e402dc9a7e3d8d4a19c9a117ec3..404a78973a81b9604fd3e7644bca5d61d8773a49 100644 --- a/en/application-dev/reference/apis/js-apis-touchevent.md +++ b/en/application-dev/reference/apis/js-apis-touchevent.md @@ -70,7 +70,7 @@ import {Action,ToolType,SourceType,Touch,TouchEvent} from '@ohos.multimodalInput | toolHeight | number | Yes| No| Height of the tool area.| | rawX | number | Yes| No| X coordinate of the input device.| | rawY | number | Yes| No| Y coordinate of the input device.| -| toolType | number | Yes| No| Tool type.| +| toolType | ToolType | Yes| No| Tool type.| ## TouchEvent diff --git a/en/application-dev/reference/apis/js-apis-usb-deprecated.md b/en/application-dev/reference/apis/js-apis-usb-deprecated.md index ca250939af9aadf2c544dee30431c889331d332e..b3be9875df2554c6df5b8c358c9243d734d87874 100644 --- a/en/application-dev/reference/apis/js-apis-usb-deprecated.md +++ b/en/application-dev/reference/apis/js-apis-usb-deprecated.md @@ -638,16 +638,16 @@ Represents the USB endpoint from which data is sent or received. You can obtain **System capability**: SystemCapability.USB.USBManager -| Name | Type | Description | -| ------------- | ------------------------------------------- | ------------- | -| address | number | Endpoint address. | -| attributes | number | Endpoint attributes. | -| interval | number | Endpoint interval. | -| maxPacketSize | number | Maximum size of data packets on the endpoint. | -| direction | [USBRequestDirection](#usbrequestdirection) | Endpoint direction. | -| number | number | Endpoint number. | -| type | number | Endpoint type. | -| interfaceId | number | Unique ID of the interface to which the endpoint belongs.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| address | number | Yes | Endpoint address. | +| attributes | number | Yes | Endpoint attributes. | +| interval | number | Yes | Endpoint interval. | +| maxPacketSize | number | Yes | Maximum size of data packets on the endpoint. | +| direction | [USBRequestDirection](#usbrequestdirection) | Yes | Endpoint direction. | +| number | number | Yes | Endpoint number. | +| type | number | Yes | Endpoint type. | +| interfaceId | number | Yes | Unique ID of the interface to which the endpoint belongs.| ## USBInterface @@ -655,15 +655,15 @@ Represents a USB interface. One [USBConfig](#usbconfig) can contain multiple **U **System capability**: SystemCapability.USB.USBManager -| Name | Type | Description | -| ---------------- | ---------------------------------------- | --------------------- | -| id | number | Unique ID of the USB interface. | -| protocol | number | Interface protocol. | -| clazz | number | Device type. | -| subClass | number | Device subclass. | -| alternateSetting | number | Settings for alternating between descriptors of the same USB interface.| -| name | string | Interface name. | -| endpoints | Array<[USBEndpoint](#usbendpoint)> | Endpoints that belong to the USB interface. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| id | number | Yes | Unique ID of the USB interface. | +| protocol | number | Yes | Interface protocol. | +| clazz | number | Yes | Device type. | +| subClass | number | Yes | Device subclass. | +| alternateSetting | number | Yes | Settings for alternating between descriptors of the same USB interface.| +| name | string | Yes | Interface name. | +| endpoints | Array<[USBEndpoint](#usbendpoint)> | Yes | Endpoints that belong to the USB interface. | ## USBConfig @@ -671,15 +671,15 @@ Represents the USB configuration. One [USBDevice](#usbdevice) can contain multip **System capability**: SystemCapability.USB.USBManager -| Name | Type | Description | -| -------------- | ------------------------------------------------ | --------------- | -| id | number | Unique ID of the USB configuration. | -| attributes | number | Configuration attributes. | -| maxPower | number | Maximum power consumption, in mA. | -| name | string | Configuration name, which can be left empty. | -| isRemoteWakeup | boolean | Support for remote wakeup.| -| isSelfPowered | boolean | Support for independent power supplies.| -| interfaces | Array <[USBInterface](#usbinterface)> | Supported interface attributes. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| id | number | Yes | Unique ID of the USB configuration. | +| attributes | number | Yes | Configuration attributes. | +| maxPower | number | Yes | Maximum power consumption, in mA. | +| name | string | Yes | Configuration name, which can be left empty. | +| isRemoteWakeup | boolean | Yes | Support for remote wakeup.| +| isSelfPowered | boolean | Yes | Support for independent power supplies.| +| interfaces | Array <[USBInterface](#usbinterface)> | Yes | Supported interface attributes. | ## USBDevice @@ -687,21 +687,21 @@ Represents the USB device information. **System capability**: SystemCapability.USB.USBManager -| Name | Type | Description | -| ---------------- | ------------------------------------ | ---------- | -| busNum | number | Bus address. | -| devAddress | number | Device address. | -| serial | string | Sequence number. | -| name | string | Device name. | -| manufacturerName | string | Device manufacturer. | -| productName | string | Product name. | -| version | string | Version number. | -| vendorId | number | Vendor ID. | -| productId | number | Product ID. | -| clazz | number | Device class. | -| subClass | number | Device subclass. | -| protocol | number | Device protocol code. | -| configs | Array<[USBConfig](#usbconfig)> | Device configuration descriptor information.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| busNum | number | Yes | Bus address. | +| devAddress | number | Yes | Device address. | +| serial | string | Yes | Sequence number. | +| name | string | Yes | Device name. | +| manufacturerName | string | Yes | Device manufacturer. | +| productName | string | Yes | Product name. | +| version | string | Yes | Version number. | +| vendorId | number | Yes | Vendor ID. | +| productId | number | Yes | Product ID. | +| clazz | number | Yes | Device class. | +| subClass | number | Yes | Device subclass. | +| protocol | number | Yes | Device protocol code. | +| configs | Array<[USBConfig](#usbconfig)> | Yes | Device configuration descriptor information.| ## USBDevicePipe @@ -709,10 +709,10 @@ Represents a USB device pipe, which is used to determine a USB device. **System capability**: SystemCapability.USB.USBManager -| Name | Type | Description | -| ---------- | ------ | ----- | -| busNum | number | Bus address.| -| devAddress | number | Device address.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| busNum | number | Yes | Bus address.| +| devAddress | number | Yes | Device address.| ## USBControlParams @@ -720,14 +720,14 @@ Represents control transfer parameters. **System capability**: SystemCapability.USB.USBManager -| Name | Type | Description | -| ------- | ----------------------------------------------- | ---------------- | -| request | number | Request type. | -| target | [USBRequestTargetType](#usbrequesttargettype) | Request target type. | -| reqType | [USBControlRequestType](#usbcontrolrequesttype) | Control request type. | -| value | number | Request parameter value. | -| index | number | Index of the request parameter value.| -| data | Uint8Array | Buffer for writing or reading data. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| request | number | Yes | Request type. | +| target | [USBRequestTargetType](#usbrequesttargettype) | Yes | Request target type. | +| reqType | [USBControlRequestType](#usbcontrolrequesttype) | Yes | Control request type. | +| value | number | Yes | Request parameter value. | +| index | number | Yes | Index of the request parameter value.| +| data | Uint8Array | Yes | Buffer for writing or reading data. | ## USBPort9+ @@ -737,11 +737,11 @@ Represents a USB port. **System capability**: SystemCapability.USB.USBManager -| Name | Type | Description | -| -------------- | -------------------------------- | ----------------------------------- | -| id | number | Unique identifier of a USB port. | -| supportedModes | [PortModeType](#portmodetype9) | Numeric mask combination for the supported mode list.| -| status | [USBPortStatus](#usbportstatus9) | USB port role. | +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| id | number | Yes | Unique identifier of a USB port. | +| supportedModes | [PortModeType](#portmodetype9) | Yes | Numeric mask combination for the supported mode list.| +| status | [USBPortStatus](#usbportstatus9) | Yes | USB port role. | ## USBPortStatus9+ @@ -751,11 +751,11 @@ Enumerates USB port roles. **System capability**: SystemCapability.USB.USBManager -| Name | Type| Description | -| ---------------- | -------- | ---------------------- | -| currentMode | number | Current USB mode. | -| currentPowerRole | number | Current power role. | -| currentDataRole | number | Current data role.| +| Name | Type | Mandatory | Description | +| -------- | ------- | --------- | ----------- | +| currentMode | number | Yes | Current USB mode. | +| currentPowerRole | number | Yes | Current power role. | +| currentDataRole | number | Yes | Current data role. | ## USBRequestTargetType diff --git a/en/application-dev/reference/apis/js-apis-usb.md b/en/application-dev/reference/apis/js-apis-usb.md index 18c0ae75e03604340f2d9f61953c869605d01245..3e1c5b919c881ef5c0d0619a5b35e791c48c46cb 100644 --- a/en/application-dev/reference/apis/js-apis-usb.md +++ b/en/application-dev/reference/apis/js-apis-usb.md @@ -720,14 +720,14 @@ Represents the USB endpoint from which data is sent or received. You can obtain | Name | Type | Mandatory |Description | | ------------- | ------------------------------------------- | ------------- |------------- | -| address | number | Yes|Endpoint address. | -| attributes | number | Yes|Endpoint attributes. | -| interval | number | Yes|Endpoint interval. | -| maxPacketSize | number | Yes|Maximum size of data packets on the endpoint. | -| direction | [USBRequestDirection](#usbrequestdirection) | Yes|Endpoint direction. | -| number | number | Yes|Endpoint number. | -| type | number | Yes|Endpoint type. | -| interfaceId | number | Yes|Unique ID of the interface to which the endpoint belongs.| +| address | number | Yes | Endpoint address. | +| attributes | number | Yes | Endpoint attributes. | +| interval | number | Yes | Endpoint interval. | +| maxPacketSize | number | Yes | Maximum size of data packets on the endpoint. | +| direction | [USBRequestDirection](#usbrequestdirection) | Yes | Endpoint direction. | +| number | number | Yes | Endpoint number. | +| type | number | Yes | Endpoint type. | +| interfaceId | number | Yes | Unique ID of the interface to which the endpoint belongs.| ## USBInterface @@ -737,13 +737,13 @@ Represents a USB interface. One [USBConfig](#usbconfig) can contain multiple **U | Name | Type | Mandatory |Description | | ---------------- | ---------------------------------------- | ------------- |--------------------- | -| id | number | Yes|Unique ID of the USB interface. | -| protocol | number | Yes|Interface protocol. | -| clazz | number | Yes|Device type. | -| subClass | number | Yes|Device subclass. | -| alternateSetting | number | Yes|Settings for alternating between descriptors of the same USB interface.| -| name | string | Yes|Interface name. | -| endpoints | Array<[USBEndpoint](#usbendpoint)> | Yes|Endpoints that belong to the USB interface. | +| id | number | Yes | Unique ID of the USB interface. | +| protocol | number | Yes | Interface protocol. | +| clazz | number | Yes | Device type. | +| subClass | number | Yes | Device subclass. | +| alternateSetting | number | Yes | Settings for alternating between descriptors of the same USB interface.| +| name | string | Yes | Interface name. | +| endpoints | Array<[USBEndpoint](#usbendpoint)> | Yes | Endpoints that belong to the USB interface. | ## USBConfig @@ -753,13 +753,13 @@ Represents the USB configuration. One [USBDevice](#usbdevice) can contain multip | Name | Type | Mandatory |Description | | -------------- | ------------------------------------------------ | --------------- |--------------- | -| id | number | Yes|Unique ID of the USB configuration. | -| attributes | number | Yes|Configuration attributes. | -| maxPower | number | Yes|Maximum power consumption, in mA. | -| name | string | Yes|Configuration name, which can be left empty. | -| isRemoteWakeup | boolean | Yes|Support for remote wakeup.| -| isSelfPowered | boolean | Yes| Support for independent power supplies.| -| interfaces | Array <[USBInterface](#usbinterface)> | Yes|Supported interface attributes. | +| id | number | Yes | Unique ID of the USB configuration. | +| attributes | number | Yes | Configuration attributes. | +| maxPower | number | Yes | Maximum power consumption, in mA. | +| name | string | Yes | Configuration name, which can be left empty. | +| isRemoteWakeup | boolean | Yes | Support for remote wakeup.| +| isSelfPowered | boolean | Yes | Support for independent power supplies.| +| interfaces | Array <[USBInterface](#usbinterface)> | Yes | Supported interface attributes. | ## USBDevice @@ -769,19 +769,19 @@ Represents the USB device information. | Name | Type | Mandatory |Description | | ---------------- | ------------------------------------ | ---------- |---------- | -| busNum | number | Yes|Bus address. | -| devAddress | number | Yes|Device address. | -| serial | string | Yes|Sequence number. | -| name | string | Yes|Device name. | -| manufacturerName | string | Yes| Device manufacturer. | -| productName | string | Yes|Product name. | -| version | string | Yes|Version number. | -| vendorId | number | Yes|Vendor ID. | -| productId | number | Yes|Product ID. | -| clazz | number | Yes|Device class. | -| subClass | number | Yes|Device subclass. | -| protocol | number | Yes|Device protocol code. | -| configs | Array<[USBConfig](#usbconfig)> | Yes|Device configuration descriptor information.| +| busNum | number | Yes | Bus address. | +| devAddress | number | Yes | Device address. | +| serial | string | Yes | Sequence number. | +| name | string | Yes | Device name. | +| manufacturerName | string | Yes | Device manufacturer. | +| productName | string | Yes | Product name. | +| version | string | Yes | Version number. | +| vendorId | number | Yes | Vendor ID. | +| productId | number | Yes | Product ID. | +| clazz | number | Yes | Device class. | +| subClass | number | Yes | Device subclass. | +| protocol | number | Yes | Device protocol code. | +| configs | Array<[USBConfig](#usbconfig)> | Yes | Device configuration descriptor information.| ## USBDevicePipe @@ -802,12 +802,12 @@ Represents control transfer parameters. | Name | Type | Mandatory |Description | | ------- | ----------------------------------------------- | ---------------- |---------------- | -| request | number | Yes |Request type. | -| target | [USBRequestTargetType](#usbrequesttargettype) | Yes |Request target type. | -| reqType | [USBControlRequestType](#usbcontrolrequesttype) | Yes |Control request type. | -| value | number | Yes |Request parameter value. | -| index | number | Yes |Index of the request parameter value.| -| data | Uint8Array | Yes |Buffer for writing or reading data. | +| request | number | Yes | Request type. | +| target | [USBRequestTargetType](#usbrequesttargettype) | Yes | Request target type. | +| reqType | [USBControlRequestType](#usbcontrolrequesttype) | Yes | Control request type. | +| value | number | Yes | Request parameter value. | +| index | number | Yes | Index of the request parameter value.| +| data | Uint8Array | Yes | Buffer for writing or reading data. | ## USBPort @@ -819,9 +819,9 @@ Represents a USB port. | Name | Type | Mandatory |Description | | -------------- | ------------------------------- | ------------------- |------------------------ | -| id | number | Yes |Unique identifier of a USB port. | -| supportedModes | [PortModeType](#portmodetype) | Yes |Numeric mask combination for the supported mode list.| -| status | [USBPortStatus](#usbportstatus) | Yes |USB port role. | +| id | number | Yes | Unique identifier of a USB port. | +| supportedModes | [PortModeType](#portmodetype) | Yes | Numeric mask combination for the supported mode list.| +| status | [USBPortStatus](#usbportstatus) | Yes | USB port role. | ## USBPortStatus @@ -833,9 +833,9 @@ Enumerates USB port roles. | Name | Type| Mandatory |Description | | ---------------- | -------- | ---------------- |---------------------- | -| currentMode | number | Yes|Current USB mode. | -| currentPowerRole | number | Yes |Current power role. | -| currentDataRole | number | Yes |Current data role.| +| currentMode | number | Yes | Current USB mode. | +| currentPowerRole | number | Yes | Current power role. | +| currentDataRole | number | Yes | Current data role.| ## USBRequestTargetType @@ -843,12 +843,12 @@ Enumerates request target types. **System capability**: SystemCapability.USB.USBManager -| Name | Value | Description | -| ---------------------------- | ---- | ------ | -| USB_REQUEST_TARGET_DEVICE | 0 | Device| -| USB_REQUEST_TARGET_INTERFACE | 1 | Interface| -| USB_REQUEST_TARGET_ENDPOINT | 2 | Endpoint| -| USB_REQUEST_TARGET_OTHER | 3 | Other| +| Name | Value | Description | +| ---------------------------- | ----- | ----------- | +| USB_REQUEST_TARGET_DEVICE | 0 | Device | +| USB_REQUEST_TARGET_INTERFACE | 1 | Interface | +| USB_REQUEST_TARGET_ENDPOINT | 2 | Endpoint | +| USB_REQUEST_TARGET_OTHER | 3 | Other | ## USBControlRequestType diff --git a/en/application-dev/reference/apis/js-apis-wallpaper.md b/en/application-dev/reference/apis/js-apis-wallpaper.md index 371e69dd03b0e5886456a189f9aceeb4444610c0..c7f4c94d54cc19d3a95ff40784af886d28f1e3ff 100644 --- a/en/application-dev/reference/apis/js-apis-wallpaper.md +++ b/en/application-dev/reference/apis/js-apis-wallpaper.md @@ -1,6 +1,6 @@ # @ohos.wallpaper -The **wallpaper** module is part of the theme framework and provides the system-level wallpaper management service in OpenHarmony. You can use the APIs of this module to show, set, and switch between wallpapers. +The **wallpaper** module is a system service module in OpenHarmony that provides the wallpaper management service. You can use the APIs of this module to show, set, and switch between wallpapers. > **NOTE** > @@ -63,7 +63,12 @@ Obtains the main color information of the wallpaper of the specified type. **Example** ```js -let colors = wallpaper.getColorsSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM); +try { + let colors = wallpaper.getColorsSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM); + console.log(`success to getColorsSync: ${JSON.stringify(colors)}`); +} catch (error) { + console.error(`failed to getColorsSync because: ${JSON.stringify(error)}`); +} ``` ## wallpaper.getIdSync9+ @@ -84,12 +89,17 @@ Obtains the ID of the wallpaper of the specified type. | Type| Description| | -------- | -------- | -| number | ID of the wallpaper. If this type of wallpaper is configured, a number greater than or equal to **0** is returned. Otherwise, **-1** is returned. The value ranges from -1 to 2^31-1.| +| number | ID of the wallpaper. If this type of wallpaper is configured, a number greater than or equal to **0** is returned. Otherwise, **-1** is returned. The value ranges from -1 to (2^31-1).| **Example** ```js -let id = wallpaper.getIdSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM); +try { + let id = wallpaper.getIdSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM); + console.log(`success to getIdSync: ${JSON.stringify(id)}`); +} catch (error) { + console.error(`failed to getIdSync because: ${JSON.stringify(error)}`); +} ``` ## wallpaper.getMinHeightSync9+ @@ -187,7 +197,7 @@ Resets the wallpaper of the specified type to the default wallpaper. This API us | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| -| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is error information.| +| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the wallpaper is reset, **err** is **undefined**. Otherwise, **err** is an error object.| **Example** @@ -247,14 +257,14 @@ Sets a specified source as the wallpaper of a specified type. This API uses an a | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or bitmap of a PNG file.| +| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or pixel map of a PNG file.| | wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| -| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is error information.| +| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the wallpaper is set, **err** is **undefined**. Otherwise, **err** is an error object.| **Example** ```js -//The source type is string. +// The source type is string. let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg"; wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error) => { if (error) { @@ -300,7 +310,7 @@ Sets a specified source as the wallpaper of a specified type. This API uses a pr | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or bitmap of a PNG file.| +| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or pixel map of a PNG file.| | wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| **Return value** @@ -312,7 +322,7 @@ Sets a specified source as the wallpaper of a specified type. This API uses a pr **Example** ```js -//The source type is string. +// The source type is string. let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg"; wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { console.log(`success to setImage.`); @@ -365,7 +375,12 @@ Obtains the wallpaper of the specified type. **Example** ```js -let file = wallpaper.getFileSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM); +try { + let file = wallpaper.getFileSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM); + console.log(`success to getFileSync: ${JSON.stringify(file)}`); +} catch (error) { + console.error(`failed to getFileSync because: ${JSON.stringify(error)}`); +} ``` ## wallpaper.getImage9+ @@ -385,7 +400,7 @@ Obtains the pixel map for the wallpaper of the specified type. This API uses an | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| -| callback | AsyncCallback<[image.PixelMap](js-apis-image.md#pixelmap7)> | Yes| Callback used to return the result. Returns the pixel map size of the wallpaper if the operation is successful; returns an error message otherwise.| +| callback | AsyncCallback<[image.PixelMap](js-apis-image.md#pixelmap7)> | Yes| Callback used to return the result. If the operation is successful, the pixel map of the wallpaper is returned. Otherwise, error information is returned.| **Example** @@ -422,7 +437,7 @@ Obtains the pixel map for the wallpaper of the specified type. This API uses a p | Type| Description| | -------- | -------- | -| Promise<[image.PixelMap](js-apis-image.md#pixelmap7)> | Promise used to return the result. Returns the pixel map size of the wallpaper if the operation is successful; returns an error message otherwise.| +| Promise<[image.PixelMap](js-apis-image.md#pixelmap7)> | Promise used to return the result. If the operation is successful, the pixel map of the wallpaper is returned. Otherwise, error information is returned.| **Example** @@ -452,10 +467,14 @@ Subscribes to the wallpaper color change event. **Example** ```js -let listener = (colors, wallpaperType) => { - console.log(`wallpaper color changed.`); -}; -wallpaper.on('colorChange', listener); +try { + let listener = (colors, wallpaperType) => { + console.log(`wallpaper color changed.`); + }; + wallpaper.on('colorChange', listener); +} catch (error) { + console.error(`failed to on because: ${JSON.stringify(error)}`); +} ``` ## wallpaper.off('colorChange')9+ @@ -479,11 +498,25 @@ Unsubscribes from the wallpaper color change event. let listener = (colors, wallpaperType) => { console.log(`wallpaper color changed.`); }; -wallpaper.on('colorChange', listener); -// Unsubscribe from the listener. -wallpaper.off('colorChange', listener); -// Unsubscribe from all subscriptions of the colorChange type. -wallpaper.off('colorChange'); +try { + wallpaper.on('colorChange', listener); +} catch (error) { + console.error(`failed to on because: ${JSON.stringify(error)}`); +} + +try { + // Unsubscribe from the listener. + wallpaper.off('colorChange', listener); +} catch (error) { + console.error(`failed to off because: ${JSON.stringify(error)}`); +} + +try { + // Unsubscribe from all subscriptions of the colorChange type. + wallpaper.off('colorChange'); +} catch (error) { + console.error(`failed to off because: ${JSON.stringify(error)}`); +} ``` ## wallpaper.getColors(deprecated) @@ -568,7 +601,7 @@ Obtains the ID of the wallpaper of the specified type. This API uses an asynchro | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| -| callback | AsyncCallback<number> | Yes| Callback used to return the wallpaper ID. If the wallpaper of the specified type is configured, a number greater than or equal to **0** is returned. Otherwise, **-1** is returned. The value ranges from -1 to 2^31-1.| +| callback | AsyncCallback<number> | Yes| Callback used to return the wallpaper ID. If the wallpaper of the specified type is configured, a number greater than or equal to **0** is returned. Otherwise, **-1** is returned. The value ranges from -1 to (2^31-1).| **Example** @@ -604,7 +637,7 @@ Obtains the ID of the wallpaper of the specified type. This API uses a promise t | Type| Description| | -------- | -------- | -| Promise<number> | Promise used to return the wallpaper ID. If this type of wallpaper is configured, a number greater than or equal to **0** is returned. Otherwise, **-1** is returned. The value ranges from -1 to 2^31-1.| +| Promise<number> | Promise used to return the wallpaper ID. If this type of wallpaper is configured, a number greater than or equal to **0** is returned. Otherwise, **-1** is returned. The value ranges from -1 to (2^31-1).| **Example** @@ -867,7 +900,7 @@ Resets the wallpaper of the specified type to the default wallpaper. This API us | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| -| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is error information.| +| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the wallpaper is reset, **err** is **undefined**. Otherwise, **err** is an error object.| **Example** @@ -935,14 +968,14 @@ Sets a specified source as the wallpaper of a specified type. This API uses an a | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or bitmap of a PNG file.| +| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or pixel map of a PNG file.| | wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| -| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is error information.| +| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the wallpaper is set, **err** is **undefined**. Otherwise, **err** is an error object.| **Example** ```js -//The source type is string. +// The source type is string. let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg"; wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error) => { if (error) { @@ -992,7 +1025,7 @@ Sets a specified source as the wallpaper of a specified type. This API uses a pr | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or bitmap of a PNG file.| +| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or pixel map of a PNG file.| | wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| **Return value** @@ -1004,7 +1037,7 @@ Sets a specified source as the wallpaper of a specified type. This API uses a pr **Example** ```js -//The source type is string. +// The source type is string. let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg"; wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { console.log(`success to setWallpaper.`); @@ -1123,7 +1156,7 @@ Obtains the pixel map for the wallpaper of the specified type. This API uses an | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| -| callback | AsyncCallback<image.PixelMap> | Yes| Callback used to return the result. Returns the pixel map size of the wallpaper if the operation is successful; returns an error message otherwise.| +| callback | AsyncCallback<image.PixelMap> | Yes| Callback used to return the result. If the operation is successful, the pixel map of the wallpaper is returned. Otherwise, error information is returned.| **Example** @@ -1163,7 +1196,7 @@ Obtains the pixel map for the wallpaper of the specified type. This API uses a p | Type| Description| | -------- | -------- | -| Promise<image.PixelMap> | Promise used to return the result. Returns the pixel map size of the wallpaper if the operation is successful; returns an error message otherwise.| +| Promise<image.PixelMap> | Promise used to return the result. If the operation is successful, the pixel map of the wallpaper is returned. Otherwise, error information is returned.| **Example** diff --git a/en/application-dev/reference/arkui-ts/figures/animation.PNG b/en/application-dev/reference/arkui-ts/figures/animation.PNG new file mode 100644 index 0000000000000000000000000000000000000000..92f92e0001a90840d03ebd00e0b0ef736c2a94c8 Binary files /dev/null and b/en/application-dev/reference/arkui-ts/figures/animation.PNG differ diff --git a/en/application-dev/reference/arkui-ts/figures/animation.gif b/en/application-dev/reference/arkui-ts/figures/animation.gif new file mode 100644 index 0000000000000000000000000000000000000000..6cfbc07fc5122be3ecd69e6b33b6f00c0f676a0f Binary files /dev/null and b/en/application-dev/reference/arkui-ts/figures/animation.gif differ diff --git a/en/application-dev/reference/arkui-ts/figures/animation1.PNG b/en/application-dev/reference/arkui-ts/figures/animation1.PNG new file mode 100644 index 0000000000000000000000000000000000000000..98cc1fa8c0537071549fa8185fa14f7ad103e7f8 Binary files /dev/null and b/en/application-dev/reference/arkui-ts/figures/animation1.PNG differ diff --git a/en/application-dev/reference/arkui-ts/figures/button.gif b/en/application-dev/reference/arkui-ts/figures/button.gif new file mode 100644 index 0000000000000000000000000000000000000000..04ab6ed97635118a7ffd3fb9d6be666f2ac40691 Binary files /dev/null and b/en/application-dev/reference/arkui-ts/figures/button.gif differ diff --git a/en/application-dev/reference/arkui-ts/figures/clipAndMask.PNG b/en/application-dev/reference/arkui-ts/figures/clipAndMask.PNG new file mode 100644 index 0000000000000000000000000000000000000000..6f522bf5a01241f67ad8c493a04f3d9d71aa9be5 Binary files /dev/null and b/en/application-dev/reference/arkui-ts/figures/clipAndMask.PNG differ diff --git a/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001211898492.gif b/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001211898492.gif deleted file mode 100644 index b1724791e4acb31d193a0dce267e42c99288c6bd..0000000000000000000000000000000000000000 Binary files a/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001211898492.gif and /dev/null differ diff --git a/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001211898494.gif b/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001211898494.gif deleted file mode 100644 index 3c81f8cfffb0c4d064335c9ebc0e8c918d10035a..0000000000000000000000000000000000000000 Binary files a/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001211898494.gif and /dev/null differ diff --git a/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001212218452.png b/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001212218452.png deleted file mode 100644 index 2243912034c109d0ffa57837aa28f4fab4ed55d7..0000000000000000000000000000000000000000 Binary files a/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001212218452.png and /dev/null differ diff --git a/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001212378394.png b/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001212378394.png deleted file mode 100644 index 884eb29ed12c00641fec55f358a41f15f581c335..0000000000000000000000000000000000000000 Binary files a/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001212378394.png and /dev/null differ diff --git a/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001212378444.gif b/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001212378444.gif deleted file mode 100644 index 69cc497191325216c394de0ce00328a7c5c5fc8c..0000000000000000000000000000000000000000 Binary files a/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001212378444.gif and /dev/null differ diff --git a/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001256978345.gif b/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001256978345.gif deleted file mode 100644 index 864e3a39a57b7a45f63a07fe50545629db3527c4..0000000000000000000000000000000000000000 Binary files a/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001256978345.gif and /dev/null differ diff --git a/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001257138341.gif b/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001257138341.gif deleted file mode 100644 index bb1dd72311c866d5bf31a706d75fc1e107a5a946..0000000000000000000000000000000000000000 Binary files a/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001257138341.gif and /dev/null differ diff --git a/en/application-dev/reference/arkui-ts/figures/flex.PNG b/en/application-dev/reference/arkui-ts/figures/flex.PNG new file mode 100644 index 0000000000000000000000000000000000000000..9975e8261fd548d2b11607ed3603410dd4a1577e Binary files /dev/null and b/en/application-dev/reference/arkui-ts/figures/flex.PNG differ diff --git a/en/application-dev/reference/arkui-ts/figures/shared.gif b/en/application-dev/reference/arkui-ts/figures/shared.gif new file mode 100644 index 0000000000000000000000000000000000000000..d43a6a38d9516945efc3ed80f4f1592c94645952 Binary files /dev/null and b/en/application-dev/reference/arkui-ts/figures/shared.gif differ diff --git a/en/application-dev/reference/arkui-ts/ts-animatorproperty.md b/en/application-dev/reference/arkui-ts/ts-animatorproperty.md index b390dc8ead870e17ad37c02632295e1f2e414bfc..36d37c6d5fe1e091128d60ee0ff9f337bd13c818 100644 --- a/en/application-dev/reference/arkui-ts/ts-animatorproperty.md +++ b/en/application-dev/reference/arkui-ts/ts-animatorproperty.md @@ -1,23 +1,21 @@ # Property Animator -You can create a property animator to animate certain universal attributes of a component, including **width**, **height**, backgroundColor, **opacity**, **scale**, **rotate**, and **translate**. +You can create a property animator to animate certain universal attributes of a component, including **width**, **height**, **backgroundColor**, **opacity**, **scale**, **rotate**, and **translate**. > **NOTE** > > This event is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. -animation(value: {duration?: number, tempo?: number, curve?: string | Curve | ICurve, delay?:number, iterations: number, playMode?: PlayMode, onFinish?: () => void}) -Applies a property animator to the component to animate its attributes over time. +animation(value: {duration?: number, tempo?: number, curve?: string | Curve | ICurve, delay?:number, iterations: number, playMode?: PlayMode, onFinish?: () => void}) **Parameters** - | Name | Type | Mandatory | Description | | ---------- | ------------------------------------------| ---- | ------------------------------------------------------------ | | duration | number | No | Animation duration, in ms.
Default value: **1000**| | tempo | number | No | Animation playback speed. A greater value indicates a higher animation playback speed.
The value **0** indicates that no animation is applied.
Default value: **1**| -| curve | string \| [Curve](ts-appendix-enums.md#curve) \| ICurve9+ | No | Animation curve.
Default value: **Curve.Linear** | +| curve | string \| [Curve](ts-appendix-enums.md#curve) \| ICurve9+ | No | Animation curve.
Default value: **Curve.Linear** | | delay | number | No | Delay of animation playback, in ms. The value **0** indicates that the playback is not delayed.
Default value: **0** | | iterations | number | No | Number of times that the animation is played. The value **-1** indicates that the animation is played for an unlimited number of times.
Default value: **1**| | playMode | [PlayMode](ts-appendix-enums.md#playmode) | No | Animation playback mode. By default, the animation is played from the beginning after the playback is complete.
Default value: **PlayMode.Normal**| @@ -31,34 +29,49 @@ Applies a property animator to the component to animate its attributes over time @Entry @Component struct AttrAnimationExample { - @State widthSize: number = 200; - @State heightSize: number = 100; - @State flag: boolean = true; + @State widthSize: number = 250 + @State heightSize: number = 100 + @State rotateAngle: number = 0 + @State flag: boolean = true build() { Column() { - Button('click me') - .onClick((event: ClickEvent) => { + Button('change width and height') + .onClick(() => { if (this.flag) { this.widthSize = 100 this.heightSize = 50 } else { - this.widthSize = 200 + this.widthSize = 250 this.heightSize = 100 } this.flag = !this.flag }) - .width(this.widthSize).height(this.heightSize).backgroundColor(0x317aff) + .margin(30) + .width(this.widthSize) + .height(this.heightSize) .animation({ - duration: 2000, // Animation duration - curve: Curve.EaseOut, // Animation curve - delay: 500, // Animation delay - iterations: 1, // Number of playback times - playMode: PlayMode.Normal // Animation playback mode - }) // Animation configuration for the width and height attributes of the