From 6658f8baac9a46e49d86a96b85af09d7871bd58e Mon Sep 17 00:00:00 2001 From: wusongqing Date: Thu, 3 Mar 2022 16:35:10 +0800 Subject: [PATCH] updated docs Signed-off-by: wusongqing --- .../reference/apis/js-apis-Context.md | 52 +- .../reference/apis/js-apis-DataUriUtils.md | 10 +- .../apis/js-apis-dataAbilityHelper.md | 594 ++++++++---------- .../apis/js-apis-service-extension-context.md | 24 +- .../apis/js-apis-service-extension.md | 24 +- .../apis/js-apis-dataAbilityHelper.md | 8 +- 6 files changed, 346 insertions(+), 366 deletions(-) diff --git a/en/application-dev/reference/apis/js-apis-Context.md b/en/application-dev/reference/apis/js-apis-Context.md index 3687d1cea2..57a9f803f3 100644 --- a/en/application-dev/reference/apis/js-apis-Context.md +++ b/en/application-dev/reference/apis/js-apis-Context.md @@ -63,8 +63,8 @@ If this method is called for the first time, a root directory is created. ```js import featureAbility from '@ohos.ability.featureAbility' var context = featureAbility.getContext(); -context.getOrCreateLocalDir().then((void) => { - console.info("==========================>getOrCreateLocalDirCallback=======================>"); +context.getOrCreateLocalDir().then((data) => { + console.info("data=" + data); }); ``` @@ -91,9 +91,9 @@ Verifies whether a specific PID and UID have the given permission. This method u import featureAbility from '@ohos.ability.featureAbility' import bundle from '@ohos.bundle' var context = featureAbility.getContext(); -var datainfo = await bundle.getBundleInfo('com.context.test',1); -context.verifyPermission("com.example.permission",datainfo.uid) - +bundle.getBundleInfo('com.context.test', 1, (datainfo) =>{ + context.verifyPermission("com.example.permission", datainfo.uid); +}); ``` @@ -146,8 +146,9 @@ Verifies whether a specific PID and UID have the given permission. This method u import featureAbility from '@ohos.ability.featureAbility' var context = featureAbility.getContext(); var Permission = context.PermissionOptions(1,1); -context.getOrCreateLocalDir('com.context.permission',Permission).then((void) => { - console.info("==========================>verifyPermissionCallback=======================>"); +context.verifyPermission('com.context.permission',Permission).then((data) => { + console.info("======================>verifyPermissionCallback====================>"); + console.info("====>data====>" + JSON.stringify(data)); }); ``` @@ -172,13 +173,16 @@ Requests certain permissions from the system. This method uses a callback to ret ```js import featureAbility from '@ohos.ability.featureAbility' var context = featureAbility.getContext(); -context.getOrCreateLocalDir( +context.requestPermissionsFromUser( ["com.example.permission1", "com.example.permission2", "com.example.permission3", "com.example.permission4", "com.example.permission5"], - 1, + 1,(err, data)=>{ + console.info("====>requestdata====>" + JSON.stringify(data)); + console.info("====>requesterrcode====>" + JSON.stringify(err.code)); + } ) ``` @@ -223,8 +227,9 @@ Obtains information about the current application. This method uses a promise to ```js import featureAbility from '@ohos.ability.featureAbility' var context = featureAbility.getContext(); -context.getApplicationInfo().then((void) => { - console.info("==========================>getApplicationInfoCallback=======================>"); +context.getApplicationInfo().then((data) => { + console.info("=====================>getApplicationInfoCallback===================>"); + console.info("====>data====>" + JSON.stringify(data)); }); ``` @@ -269,8 +274,9 @@ Obtains the bundle name of the current ability. This method uses a promise to re ```js import featureAbility from '@ohos.ability.featureAbility' var context = featureAbility.getContext(); -context.getBundleName().then((void) => { - console.info("==========================>getBundleNameCallback=======================>"); +context.getBundleName().then((data) => { + console.info("=======================>getBundleNameCallback====================>"); + console.info("====>data====>" + JSON.stringify(data)); }); ``` @@ -315,8 +321,9 @@ Obtains information about the current process, including the PID and process nam ```js import featureAbility from '@ohos.ability.featureAbility' var context = featureAbility.getContext(); -context.getProcessInfo().then((void) => { - console.info("==========================>getProcessInfoCallback=======================>"); +context.getProcessInfo().then((data) => { + console.info("=======================>getProcessInfoCallback====================>"); + console.info("====>data====>" + JSON.stringify(data)); }); ``` @@ -365,8 +372,9 @@ This method is available only to Page abilities. ```js import featureAbility from '@ohos.ability.featureAbility' var context = featureAbility.getContext(); -context.getElementName().then((void) => { - console.info("==========================>getElementNameCallback=======================>"); +context.getElementName().then((data) => { + console.info("=======================>getElementNameCallback====================>"); + console.info("====>data====>" + JSON.stringify(data)); }); ``` @@ -407,8 +415,9 @@ Obtains the name of the current process. This method uses a promise to return th ```js import featureAbility from '@ohos.ability.featureAbility' var context = featureAbility.getContext(); -context.getProcessName().then((void) => { - console.info("==========================>getProcessNameCallback=======================>"); +context.getProcessName().then((data) => { + console.info("=======================>getProcessNameCallback====================>"); + console.info("====>data====>" + JSON.stringify(data)); }); ``` @@ -453,8 +462,9 @@ Obtains the bundle name of the calling ability. This method uses a promise to re ```js import featureAbility from '@ohos.ability.featureAbility' var context = featureAbility.getContext(); -context.getCallingBundle().then((void) => { - console.info("==========================>getCallingBundleCallback=======================>"); +context.getCallingBundle().then((data) => { + console.info("======================>getCallingBundleCallback====================>"); + console.info("====>data====>" + JSON.stringify(data)); }); ``` diff --git a/en/application-dev/reference/apis/js-apis-DataUriUtils.md b/en/application-dev/reference/apis/js-apis-DataUriUtils.md index 4aa00cd0b3..b45c839bc4 100644 --- a/en/application-dev/reference/apis/js-apis-DataUriUtils.md +++ b/en/application-dev/reference/apis/js-apis-DataUriUtils.md @@ -27,7 +27,6 @@ Obtains the ID attached to the end of a given URI. **Example** ```js -import dataUriUtils from '@ohos.ability.datauriutils' dataUriUtils.getIdSync("com.example.dataUriUtils/1221") ``` @@ -55,10 +54,9 @@ Attaches an ID to the end of a given URI. **Example** ```js -import dataUriUtils from '@ohos.ability.datauriutils' var idint = 1122; dataUriUtils.attachId( - "com.example.dataUriUtils" + "com.example.dataUriUtils", idint, ) ``` @@ -85,7 +83,6 @@ Deletes the ID from the end of a given URI. **Example** ```js -import dataUriUtils from '@ohos.ability.datauriutils' dataUriUtils.deleteId("com.example.dataUriUtils/1221") ``` @@ -112,10 +109,9 @@ Updates the ID in a given URI. **Example** ```js -import dataUriUtils from '@ohos.ability.datauriutils' var idint = 1122; dataUriUtils.updateId( - "com.example.dataUriUtils" - idint, + "com.example.dataUriUtils", + idint ) ``` diff --git a/en/application-dev/reference/apis/js-apis-dataAbilityHelper.md b/en/application-dev/reference/apis/js-apis-dataAbilityHelper.md index dc09e18685..75adfb3f60 100644 --- a/en/application-dev/reference/apis/js-apis-dataAbilityHelper.md +++ b/en/application-dev/reference/apis/js-apis-dataAbilityHelper.md @@ -1,6 +1,6 @@ # DataAbilityHelper Module (JavaScript SDK APIs) -#### Modules to Import +## Modules to Import ``` import featureAbility from '@ohos.ability.featureAbility' @@ -8,26 +8,23 @@ import ohos_data_ability from '@ohos.data.dataability' import ohos_data_rdb from '@ohos.data.rdb' ``` -#### DataAbilityHelper.openFile(uri: string, mode: string, callback: AsyncCallback\) +## DataAbilityHelper -- Functionality +### openFile - Opens a file with a specified URI. This method uses a callback to return the result. +openFile(uri: string, mode: string, callback: AsyncCallback\): void +Opens a file with a specified URI. This method uses a callback to return the result. -* Parameters +**Parameters** - | Name| Readable/Writable| Type| Mandatory| Description| - | -------- | -------- | -------------------- | ---- | ------------------------ | - | uri | Read-only| string | Yes| URI of the file to open.| - | mode | Read-only| string | Yes| Mode for opening the file. The value can be **rwt**.| - | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +| Name| Type| Mandatory| Description| +| -------- | ---------------------- | ---- | ---------------------------------- | +| uri | string | Yes| URI of the file to open.| +| mode | string | Yes| Mode for opening the file. The value can be **rwt**.| +| callback | AsyncCallback\ | Yes| Callback used to return the file descriptor.| -* Return values - - Returns a file descriptor. - -* Example +**Example** ```javascript import featureAbility from '@ohos.ability.featureAbility' @@ -43,24 +40,25 @@ DAHelper.openFile( }); ``` -#### DataAbilityHelper.openFile(uri: string, mode: string) - -- Functionality +### openFile - Opens a file with a specified URI. This method uses a promise to return the result. +openFile(uri: string, mode: string): Promise\ -* Parameters +Opens a file with a specified URI. This method uses a promise to return the result. - | Name| Readable/Writable| Type| Mandatory| Description| - | ---- | -------- | ------ | ---- | ------------------------ | - | uri | Read-only| string | Yes| URI of the file to open.| - | mode | Read-only| string | Yes| Mode for opening the file. The value can be **rwt**.| +**Parameters** -* Return values +| Name| Type| Mandatory| Description| +| ---- | ------ | ---- | ------------------------ | +| uri | string | Yes| URI of the file to open.| +| mode | string | Yes| Mode for opening the file. The value can be **rwt**.| - Returns a file descriptor. +**Return value** +| Type| Description| +| ---------------- | ---------------- | +| Promise\ | Promise used to return the file descriptor.| -* Example +**Example** ```javascript import featureAbility from '@ohos.ability.featureAbility' @@ -70,30 +68,26 @@ var DAHelper = featureAbility.acquireDataAbilityHelper( var mode = "rwt"; DAHelper.openFile( "dataability:///com.example.DataAbility", - mode).then((void) => { + mode).then((data) => { console.info("==========================>openFileCallback=======================>"); }); ``` -#### DataAbilityHelper.on(type: 'dataChange', uri: string, callback: AsyncCallback\) - -- Functionality - - Registers an observer to observe data specified by a given URI. This method uses a callback to return the result. +### on('dataChange') -- Parameters +on(type: 'dataChange', uri: string, callback: AsyncCallback\): void - | Name| Readable/Writable| Type| Mandatory| Description| - | -------- | -------- | -------------------- | ---- | ------------------------ | - | type | Read-only| string | Yes| Type of the event to observe. The value is **dataChange**.| - | uri | Read-only| string | Yes| URI of the data.| - | callback | Read-only| AsyncCallback\ | Yes| Callback invoked when the data is changed.| +Registers an observer to observe data specified by a given URI. This method uses a callback to return the result. -- Return value +**Parameters** - void +| Name| Type| Mandatory| Description| +| -------- | -------------------- | ---- | ------------------------ | +| type | string | Yes| Type of the event to observe. The value is **dataChange**.| +| uri | string | Yes| URI of the data.| +| callback | AsyncCallback\ | Yes| Callback invoked when the data is changed.| -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -110,25 +104,21 @@ helper.on( ) ``` -#### DataAbilityHelper.off(type: 'dataChange', uri: string, callback?: AsyncCallback\) +### off('dataChange') -- Functionality +off(type: 'dataChange', uri: string, callback?: AsyncCallback\): void - Unregisters the observer used to observe data specified by a given URI. This method uses a callback to return the result. +Unregisters the observer used to observe data specified by a given URI. This method uses a callback to return the result. -- Parameters +**Parameters** - | Name| Readable/Writable| Type| Mandatory| Description| - | -------- | -------- | -------------------- | ---- | ------------------------ | - | type | Read-only| string | Yes| Type of the event to observe. The value is **dataChange**.| - | uri | Read-only| string | Yes| URI of the data.| - | callback | Read-only| AsyncCallback\ | No| Callback used to return the result.| +| Name| Type| Mandatory| Description| +| -------- | -------------------- | ---- | ------------------------ | +| type | string | Yes| Type of the event to observe. The value is **dataChange**.| +| uri | string | Yes| URI of the data.| +| callback | AsyncCallback\ | No| Callback used to return the result.| -- Return value - - void - -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -149,24 +139,20 @@ helper.off( ) ``` -#### DataAbilityHelper.getType(uri: string, callback: AsyncCallback\) - -- Functionality +### getType - Obtains the MIME type of the data specified by a given URI. This method uses a callback to return the result. +getType(uri: string, callback: AsyncCallback\): void -- Parameters +Obtains the MIME type of the data specified by a given URI. This method uses a callback to return the result. - | Name| Readable/Writable| Type| Mandatory| Description| - | -------- | -------- | ---------------------- | ---- | ------------------------ | - | uri | Read-only| string | Yes| URI of the data.| - | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**Parameters** -- Return value +| Name| Type| Mandatory| Description| +| -------- | ---------------------- | ---- | --------------------------------------------- | +| uri | string | Yes| URI of the data.| +| callback | AsyncCallback\ | Yes| Callback used to return the MIME type.| - Returns the MIME type that matches the data specified by the URI. - -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -180,23 +166,24 @@ DAHelper.getType( }); ``` -#### DataAbilityHelper.getType(uri: string) - -- Functionality +### getType - Obtains the MIME type of the data specified by a given URI. This method uses a promise to return the result. +getType(uri: string): Promise\ -- Parameters +Obtains the MIME type of the data specified by a given URI. This method uses a promise to return the result. - | Name| Readable/Writable| Type| Mandatory| Description| - | ---- | -------- | ------ | ---- | ------------------------ | - | uri | Read-only| string | Yes| URI of the data.| +**Parameters** -- Return value +| Name| Type| Mandatory| Description| +| ---- | ------ | ---- | ------------------------ | +| uri | string | Yes| URI of the data.| - Returns the MIME type that matches the data specified by the URI. +**Return value** +| Type| Description| +| ---------------- | ----------------------------------- | +| Promise\ | Promise used to return the MIME type.| -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -210,25 +197,21 @@ DAHelper.getType( }); ``` -#### DataAbilityHelper.getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback>) +### getFileTypes -- Functionality +getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback>): void - Obtains the supported MIME types of a specified file. This method uses a callback to return the result. +Obtains the supported MIME types of a specified file. This method uses a callback to return the result. -- Parameters +**Parameters** - | Name| Readable/Writable| Type| Mandatory| Description| - | -------------- | -------- | ------------------------------ | ---- | ---------------------------- | - | uri | Read-only| string | Yes| URI of the file.| - | mimeTypeFilter | Read-only| string | Yes| MIME type of the file.| - | callback | Read-only| AsyncCallback\> | Yes| Callback used to return the result.| +| Name| Type| Mandatory| Description| +| -------------- | ------------------------------ | ---- | ---------------------------------- | +| uri | string | Yes| URI of the file.| +| mimeTypeFilter | string | Yes| MIME type of the file.| +| callback | AsyncCallback\> | Yes| Callback used to return the supported MIME types.| -- Return value - - Returns a MIME type array. - -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -243,24 +226,27 @@ DAHelper.getFileTypes( }); ``` -#### DataAbilityHelper.getFileTypes(uri: string, mimeTypeFilter: string) -- Functionality - Obtains the supported MIME types of a specified file. This method uses a promise to return the result. +### getFileTypes + +getFileTypes(uri: string, mimeTypeFilter: string): Promise\> -- Parameters +Obtains the supported MIME types of a specified file. This method uses a promise to return the result. - | Name| Readable/Writable| Type| Mandatory| Description| - | -------------- | -------- | ------ | ---- | ---------------------------- | - | uri | Read-only| string | Yes| URI of the file.| - | mimeTypeFilter | Read-only| string | Yes| MIME type of the file.| +**Parameters** -- Return value +| Name| Type| Mandatory| Description| +| -------------- | ------ | ---- | ---------------------------- | +| uri | string | Yes| URI of the file.| +| mimeTypeFilter | string | Yes| MIME type of the file.| - Returns a MIME type array. +**Return value** +| Type| Description| +| ------------------------ | ------------------------ | +| Promise\> | Promise used to return the supported MIME types.| -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -275,24 +261,20 @@ DAHelper.getFileTypes( }); ``` -#### DataAbilityHelper.normalizeUri(uri: string, callback: AsyncCallback\) - -- Functionality - - Converts the URI that refers to a Data ability into a normalized URI. This method uses a callback to return the result. +### normalizeUri -- Parameters +normalizeUri(uri: string, callback: AsyncCallback\): void - | Name| Readable/Writable| Type| Mandatory| Description| - | -------- | -------- | ---------------------- | ---- | ----------------------- | - | uri | Read-only| string | Yes| URI object to normalize.| - | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +Converts the URI that refers to a Data ability into a normalized URI. This method uses a callback to return the result. -- Return value +**Parameters** - Returns the normalized URI object if the Data ability supports URI normalization; returns **null** otherwise. +| Name| Type| Mandatory| Description| +| -------- | ---------------------- | ---- | ------------------------------------------------------------ | +| uri | string | Yes| URI object to normalize.| +| callback | AsyncCallback\ | Yes| Callback used to return the normalized URI object if the Data ability supports URI normalization. If the Data ability does not support URI normalization, **null** is returned.| -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -306,23 +288,24 @@ DAHelper.normalizeUri( }); ``` -#### DataAbilityHelper.normalizeUri(uri: string) +### normalizeUri -- Functionality +normalizeUri(uri: string): Promise\ - Converts the URI that refers to a Data ability into a normalized URI. This method uses a promise to return the result. +Converts the URI that refers to a Data ability into a normalized URI. This method uses a promise to return the result. -- Parameters +**Parameters** - | Name| Readable/Writable| Type| Mandatory| Description| - | ---- | -------- | ------ | ---- | ----------------------- | - | uri | Read-only| string | Yes| URI object to normalize.| +| Name| Type| Mandatory| Description| +| ---- | ------ | ---- | ----------------------- | +| uri | string | Yes| URI object to normalize.| -- Return value +**Return value** +| Type| Description| +| ---------------- | ------------------------------------------------------ | +| Promise\ | Promise used to return the normalized URI object if the Data ability supports URI normalization. If the Data ability does not support URI normalization, **null** is returned.| - Returns the normalized URI object if the Data ability supports URI normalization; returns **null** otherwise. - -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -336,24 +319,20 @@ DAHelper.normalizeUri( }); ``` -#### DataAbilityHelper.denormalizeUri(uri: string, callback: AsyncCallback\) - -- Functionality - - Converts a normalized URI generated by **DataAbilityHelper.normalizeUri(uri: string, callback: AsyncCallback\)** to a denormalized one. This method uses a callback to return the result. +### denormalizeUri -- Parameters +denormalizeUri(uri: string, callback: AsyncCallback\): void - | Name| Readable/Writable| Type| Mandatory| Description| - | -------- | -------- | ---------------------- | ---- | ----------------------- | - | uri | Read-only| string | Yes| URI object to denormalize.| - | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +Converts a normalized URI generated by **DataAbilityHelper.normalizeUri(uri: string, callback: AsyncCallback\)** to a denormalized one. This method uses a callback to return the result. -- Return value +**Parameters** - Returns the denormalized URI object. +| Name| Type| Mandatory| Description| +| -------- | ---------------------- | ---- | --------------------------------------------------- | +| uri | string | Yes| URI object to normalize.| +| callback | AsyncCallback\ | Yes| Callback used to return the denormalized URI object.| -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -361,29 +340,32 @@ var DAHelper = featureAbility.acquireDataAbilityHelper( "dataability:///com.example.DataAbility" ); DAHelper.denormalizeUri( - "dataability:///com.example.DataAbility",, + "dataability:///com.example.DataAbility", (err, data) => { console.info("==========================>Called=======================>"); }); ``` -#### DataAbilityHelper.denormalizeUri(uri: string) -- Functionality - Converts a normalized URI generated by **DataAbilityHelper.normalizeUri(uri: string)** to a denormalized one. This method uses a promise to return the result. +### denormalizeUri + +denormalizeUri(uri: string): Promise\ -- Parameters +Converts a normalized URI generated by **DataAbilityHelper.normalizeUri(uri: string)** to a denormalized one. This method uses a promise to return the result. - | Name| Readable/Writable| Type| Mandatory| Description| - | ---- | -------- | ------ | ---- | ----------------------- | - | uri | Read-only| string | Yes| URI object to denormalize.| +**Parameters** -- Return value +| Name| Type| Mandatory| Description| +| ---- | ------ | ---- | ----------------------- | +| uri | string | Yes| URI object to normalize.| - Returns the denormalized URI object. +**Return value** +| Type| Description| +| ---------------- | ----------------------------------------- | +| Promise\ | Promise used to return the denormalized URI object.| -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -397,24 +379,20 @@ DAHelper.denormalizeUri( }); ``` -#### DataAbilityHelper.notifyChange(uri: string, callback: AsyncCallback\) +### notifyChange -- Functionality +notifyChange(uri: string, callback: AsyncCallback\): void - Notifies the registered observer of a change to the data specified by the URI. This method uses a callback to return the result. +Notifies the registered observer of a change to the data specified by the URI. This method uses a callback to return the result. -- Parameters +**Parameters** - | Name| Readable/Writable| Type| Mandatory| Description| - | -------- | -------- | -------------------- | ---- | ------------------------ | - | uri | Read-only| string | Yes| URI of the data.| - | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +| Name| Type| Mandatory| Description| +| -------- | -------------------- | ---- | ------------------------ | +| uri | string | Yes| URI of the data.| +| callback | AsyncCallback\ | Yes| Callback used to return the result.| -- Return value - - void - -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -422,29 +400,30 @@ var helper = featureAbility.acquireDataAbilityHelper( "dataability:///com.example.DataAbility" ); helper.notifyChange( - "dataability:///com.example.DataAbility",, + "dataability:///com.example.DataAbility", (err) => { console.info("==========================>Called=======================>"); }); ``` -#### DataAbilityHelper.notifyChange(uri: string) +### notifyChange -- Functionality +notifyChange(uri: string): Promise\ - Notifies the registered observer of a change to the data specified by the URI. This method uses a promise to return the result. +Notifies the registered observer of a change to the data specified by the URI. This method uses a promise to return the result. -- Parameters +**Parameters** - | Name| Readable/Writable| Type| Mandatory| Description| - | ---- | -------- | ------ | ---- | ------------------------ | - | uri | Read-only| string | Yes| URI of the data.| +| Name| Type| Mandatory| Description| +| ---- | ------ | ---- | ------------------------ | +| uri | string | Yes| URI of the data.| -- Return value +**Return value** +| Type| Description| +| -------------- | --------------------- | +| Promise\ | Promise used to return the result.| - void - -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -453,30 +432,26 @@ var DAHelper = featureAbility.acquireDataAbilityHelper( ); DAHelper.notifyChange( "dataability:///com.example.DataAbility", - ).then((void) => { + ).then(() => { console.info("==========================>notifyChangeCallback=======================>"); }); ``` -#### DataAbilityHelper.insert(uri: string, valuesBucket: rdb.ValuesBucket, callback: AsyncCallback\) - -- Functionality +### insert - Inserts a single data record into the database. This method uses a callback to return the result. +insert(uri: string, valuesBucket: rdb.ValuesBucket, callback: AsyncCallback\): void -- Parameters +Inserts a single data record into the database. This method uses a callback to return the result. - | Name| Readable/Writable| Type| Mandatory| Description| - | ------------ | -------- | ---------------------- | ---- | ------------------------------------------------------ | - | uri | Read-only| string | Yes| URI of the data to insert.| - | valuesBucket | Read-only| rdb.ValuesBucket | Yes| Data record to insert. If this parameter is **null**, a blank row will be inserted.| - | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**Parameters** -- Return value +| Name| Type| Mandatory| Description| +| ------------ | ---------------------- | ---- | ------------------------------------------------------ | +| uri | string | Yes| URI of the data to insert.| +| valuesBucket | rdb.ValuesBucket | Yes| Data record to insert. If this parameter is **null**, a blank row will be inserted.| +| callback | AsyncCallback\ | Yes| Callback used to return the index of the inserted data record.| - Returns the index of the inserted data record. - -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -497,24 +472,25 @@ DAHelper.insert( }); ``` -#### DataAbilityHelper.insert(uri: string, valuesBucket: rdb.ValuesBucket) - -- Functionality +### insert - Inserts a single data record into the database. This method uses a promise to return the result. +insert(uri: string, valuesBucket: rdb.ValuesBucket): Promise\ -- Parameters +Inserts a single data record into the database. This method uses a promise to return the result. - | Name| Readable/Writable| Type| Mandatory| Description| - | ------------ | -------- | ---------------- | ---- | ------------------------------------------------------ | - | uri | Read-only| string | Yes| URI of the data to insert.| - | valuesBucket | Read-only| rdb.ValuesBucket | Yes| Data record to insert. If this parameter is **null**, a blank row will be inserted.| +**Parameters** -- Return value +| Name| Type| Mandatory| Description| +| ------------ | ---------------- | ---- | ------------------------------------------------------ | +| uri | string | Yes| URI of the data to insert.| +| valuesBucket | rdb.ValuesBucket | Yes| Data record to insert. If this parameter is **null**, a blank row will be inserted.| - Returns the index of the inserted data record. +**Return value** +| Type| Description| +| ---------------- | ------------------------ | +| Promise\ | Promise used to return the index of the inserted data record.| -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -535,25 +511,21 @@ DAHelper.insert( }); ``` -#### DataAbilityHelper.batchInsert(uri: string, valuesBuckets: Array, callback: AsyncCallback\) - -- Functionality +### batchInsert - Inserts multiple data records into the database. This method uses a callback to return the result. +batchInsert(uri: string, valuesBuckets: Array, callback: AsyncCallback\): void -- Parameters +Inserts multiple data records into the database. This method uses a callback to return the result. - | Name| Readable/Writable| Type| Mandatory| Description| - | ------------ | -------- | ----------------------- | ---- | ------------------------ | - | uri | Read-only| string | Yes| URI of the data to insert.| - | valuesBucket | Read-only| Array | Yes| Data records to insert.| - | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**Parameters** -- Return value +| Name| Type| Mandatory| Description| +| ------------ | ----------------------- | ---- | -------------------------------- | +| uri | string | Yes| URI of the data to insert.| +| valuesBucket | Array | Yes| Data records to insert.| +| callback | AsyncCallback\ | Yes| Callback used to return the number of inserted data records.| - Returns the number of inserted data records. - -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -571,24 +543,25 @@ DAHelper.batchInsert( }); ``` -#### DataAbilityHelper.batchInsert(uri: string, valuesBuckets: Array) - -- Functionality +### batchInsert - Inserts multiple data records into the database. This method uses a promise to return the result. +batchInsert(uri: string, valuesBuckets: Array): Promise\ -- Parameters +Inserts multiple data records into the database. This method uses a promise to return the result. - | Name| Readable/Writable| Type| Mandatory| Description| - | ------------ | -------- | ----------------------- | ---- | ------------------------ | - | uri | Read-only| string | Yes| URI of the data to insert.| - | valuesBucket | Read-only| Array | Yes| Data records to insert.| +**Parameters** -- Return value +| Name| Type| Mandatory| Description| +| ------------ | ----------------------- | ---- | ------------------------ | +| uri | string | Yes| URI of the data to insert.| +| valuesBucket | Array | Yes| Data record to insert.| - Returns the number of inserted data records. +**Return value** +| Type| Description| +| ---------------- | ---------------------- | +| Promise\ | Promise used to return the number of inserted data records.| -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -606,25 +579,21 @@ DAHelper.batchInsert( }); ``` -#### DataAbilityHelper.delete(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\) +### delete -- Functionality +delete(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\): void - Deletes one or more data records from the database. This method uses a callback to return the result. +Deletes one or more data records from the database. This method uses a callback to return the result. -- Parameters +**Parameters** - | Name| Readable/Writable| Type| Mandatory| Description| - | ------------ | -------- | --------------------------------- | ---- | ------------------------------------------------ | - | uri | Read-only| string | Yes| URI of the data to delete.| - | valuesBucket | Read-only| dataAbility.DataAbilityPredicates | Yes| Filter criteria. You should define the processing logic when this parameter is **null**.| - | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +| Name| Type| Mandatory| Description| +| ------------ | --------------------------------- | ---- | ------------------------------------------------ | +| uri | string | Yes| URI of the data to delete.| +| valuesBucket | dataAbility.DataAbilityPredicates | Yes| Filter criteria. You should define the processing logic when this parameter is **null**.| +| callback | AsyncCallback\ | Yes| Callback used to return the number of deleted data records.| -- Return value - - Returns the number of deleted data records. - -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -641,24 +610,25 @@ DAHelper.delete( }); ``` -#### DataAbilityHelper.delete(uri: string, predicates: dataAbility.DataAbilityPredicates) - -- Functionality +### delete - Deletes one or more data records from the database. This method uses a promise to return the result. +delete(uri: string, predicates: dataAbility.DataAbilityPredicates): Promise\ -- Parameters +Deletes one or more data records from the database. This method uses a promise to return the result. - | Name| Readable/Writable| Type| Mandatory| Description| - | ------------ | -------- | --------------------------------- | ---- | ------------------------------------------------ | - | uri | Read-only| string | Yes| URI of the data to delete.| - | valuesBucket | Read-only| dataAbility.DataAbilityPredicates | Yes| Filter criteria. You should define the processing logic when this parameter is **null**.| +**Parameters** -- Return value +| Name| Type| Mandatory| Description| +| ------------ | --------------------------------- | ---- | ------------------------------------------------ | +| uri | string | Yes| URI of the data to delete.| +| valuesBucket | dataAbility.DataAbilityPredicates | Yes| Filter criteria. You should define the processing logic when this parameter is **null**.| - Returns the number of deleted data records. +**Return value** +| Type| Description| +| ---------------- | ------------------------ | +| Promise\ | Promise used to return the number of deleted data records.| -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -674,26 +644,22 @@ DAHelper.delete( }); ``` -#### DataAbilityHelper.update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\) - -- Functionality - - Updates data records in the database. This method uses a callback to return the result. +### update -- Parameters +update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\): void - | Name| Readable/Writable| Type| Mandatory| Description| - | ------------ | -------- | --------------------------------- | ---- | ------------------------------------------------ | - | uri | Read-only| string | Yes| URI of the data to update.| - | valuesBucket | Read-only| rdb.ValuesBucket | Yes| New values.| - | predicates | Read-only| dataAbility.DataAbilityPredicates | Yes| Filter criteria. You should define the processing logic when this parameter is **null**.| - | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +Updates data records in the database. This method uses a callback to return the result. -- Return value +**Parameters** - Returns the number of updated data records. +| Name| Type| Mandatory| Description| +| ------------ | --------------------------------- | ---- | ------------------------------------------------ | +| uri | string | Yes| URI of the data to update.| +| valuesBucket | rdb.ValuesBucket | Yes| New values.| +| predicates | dataAbility.DataAbilityPredicates | Yes| Filter criteria. You should define the processing logic when this parameter is **null**.| +| callback | AsyncCallback\ | Yes| Callback used to return the number of updated data records.| -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -717,25 +683,26 @@ DAHelper.update( }); ``` -#### DataAbilityHelper.update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates) +### update -- Functionality +update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates): Promise\ - Updates data records in the database. This method uses a promise to return the result. +Updates data records in the database. This method uses a promise to return the result. -- Parameters +**Parameters** - | Name| Readable/Writable| Type| Mandatory| Description| - | ------------ | -------- | --------------------------------- | ---- | ------------------------------------------------ | - | uri | Read-only| string | Yes| URI of the data to update.| - | valuesBucket | Read-only| rdb.ValuesBucket | Yes| New values.| - | predicates | Read-only| dataAbility.DataAbilityPredicates | Yes| Filter criteria. You should define the processing logic when this parameter is **null**.| +| Name| Type| Mandatory| Description| +| ------------ | --------------------------------- | ---- | ------------------------------------------------ | +| uri | string | Yes| URI of the data to update.| +| valuesBucket | rdb.ValuesBucket | Yes| New values.| +| predicates | dataAbility.DataAbilityPredicates | Yes| Filter criteria. You should define the processing logic when this parameter is **null**.| -- Return value +**Return value** +| Type| Description| +| ---------------- | -------------------------------------------- | +| Promise\ | Promise used to return the number of updated data records.| - Returns the number of updated data records. - -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -759,26 +726,22 @@ DAHelper.update( }); ``` -#### DataAbilityHelper.query(uri: string, columns: Array\, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\) - -- Functionality +### query - Queries data in the database. This method uses a callback to return the result. +query(uri: string, columns: Array\, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\): void -- Parameters +Queries data in the database. This method uses a callback to return the result. - | Name| Readable/Writable| Type| Mandatory| Description| - | ---------- | -------- | --------------------------------- | ---- | ------------------------------------------------ | - | uri | Read-only| string | Yes| URI of the data to query.| - | columns | Read-only| rdb.ValuesBucket | Yes| Columns to query. If this parameter is **null**, all columns will be queried.| - | predicates | Read-only| dataAbility.DataAbilityPredicates | Yes| Filter criteria. You should define the processing logic when this parameter is **null**.| - | callback | Read-only| AsyncCallback\ | Yes| Callback used to return the result.| +**Parameters** -- Return value +| Name| Type| Mandatory| Description| +| ---------- | --------------------------------- | ---- | ------------------------------------------------ | +| uri | string | Yes| URI of the data to query.| +| columns | rdb.ValuesBucket | Yes| Columns to query. If this parameter is **null**, all columns will be queried.| +| predicates | dataAbility.DataAbilityPredicates | Yes| Filter criteria. You should define the processing logic when this parameter is **null**.| +| callback | AsyncCallback\ | Yes| Callback used to return the data queried.| - Returns the data queried. - -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -786,7 +749,7 @@ import ohos_data_ability from '@ohos.data.dataability' var DAHelper = featureAbility.acquireDataAbilityHelper( "dataability:///com.example.DataAbility" ); -var cars=new Array({"value1"}, {"value2"}, {"value3"}, {"value4"}); +var cars=new Array("value1", "value2", "value3", "value4"); let da = new ohos_data_ability.DataAbilityPredicates() DAHelper.query( "dataability:///com.example.DataAbility", @@ -799,25 +762,26 @@ DAHelper.query( -#### DataAbilityHelper.query(uri: string, columns: Array\, predicates: dataAbility.DataAbilityPredicates) - -- Functionality +### query - Queries data in the database. This method uses a promise to return the result. +query(uri: string, columns: Array\, predicates: dataAbility.DataAbilityPredicates): Promise\ -- Parameters +Queries data in the database. This method uses a promise to return the result. - | Name| Readable/Writable| Type| Mandatory| Description| - | ---------- | -------- | --------------------------------- | ---- | ------------------------------------------------ | - | uri | Readable and writable| string | Yes| URI of the data to query.| - | columns | Readable and writable| rdb.ValuesBucket | Yes| Columns to query. If this parameter is **null**, all columns will be queried.| - | predicates | Readable and writable| dataAbility.DataAbilityPredicates | Yes| Filter criteria. You should define the processing logic when this parameter is **null**.| +**Parameters** -- Return value +| Name| Type| Mandatory| Description| +| ---------- | --------------------------------- | ---- | ------------------------------------------------ | +| uri | string | Yes| URI of the data to query.| +| columns | rdb.ValuesBucket | Yes| Columns to query. If this parameter is **null**, all columns will be queried.| +| predicates | dataAbility.DataAbilityPredicates | Yes| Filter criteria. You should define the processing logic when this parameter is **null**.| - Returns the data queried. +**Return value** +| Type| Description| +| ------------------- | -------------- | +| Promise\ | Promise used to return the data queried.| -- Example +**Example** ```js import featureAbility from '@ohos.ability.featureAbility' @@ -825,7 +789,7 @@ import ohos_data_ability from '@ohos.data.dataability' var DAHelper = featureAbility.acquireDataAbilityHelper( "dataability:///com.example.DataAbility" ); -var cars=new Array({"value1"}, {"value2"}, {"value3"}, {"value4"}); +var cars=new Array("value1", "value2", "value3", "value4"); let da = new ohos_data_ability.DataAbilityPredicates() DAHelper.query( "dataability:///com.example.DataAbility", diff --git a/en/application-dev/reference/apis/js-apis-service-extension-context.md b/en/application-dev/reference/apis/js-apis-service-extension-context.md index fa46ef6df1..de067acf57 100644 --- a/en/application-dev/reference/apis/js-apis-service-extension-context.md +++ b/en/application-dev/reference/apis/js-apis-service-extension-context.md @@ -1,6 +1,6 @@ # ServiceExtensionContext -> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:** +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > The initial APIs of this module are supported since API 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. @@ -29,8 +29,8 @@ Starts an ability. This method uses a callback to return the result. "abilityName": "com.example.myapp.MyAbility" }; this.context.startAbility(want, (err) => { - console.log('startAbility result:' + JSON.stringfy(err); - } + console.log('startAbility result:' + JSON.stringfy(err)); + }); ``` @@ -58,7 +58,7 @@ Starts an ability. This method uses a promise to return the result. }; this.context.startAbility(want).then((data) => { console.log('success:' + JSON.stringfy(data)); - )).catch((error) => { + }).catch((error) => { console.log('failed:' + JSON.stringfy(error)); }); ``` @@ -78,8 +78,8 @@ Terminates this ability. This method uses a callback to return the result. - Example ``` this.context.terminateSelf((err) => { - console.log('terminateSelf result:' + JSON.stringfy(err); - } + console.log('terminateSelf result:' + JSON.stringfy(err)); + }); ``` @@ -98,7 +98,7 @@ Terminates this ability. This method uses a promise to return the result. ``` this.context.terminateSelf(want).then((data) => { console.log('success:' + JSON.stringfy(data)); - )).catch((error) => { + }).catch((error) => { console.log('failed:' + JSON.stringfy(error)); }); ``` @@ -128,8 +128,8 @@ Connects this ability to a Service ability. "abilityName": "com.example.myapp.MyAbility" }; let options = { - onConnect: function(elementName, proxy) {} - onDisConnect: function(elementName) {} + onConnect: function(elementName, proxy) {}, + onDisConnect: function(elementName) {}, onFailed: function(code) {} } let connection = this.context.connectAbility(want,options); @@ -151,8 +151,8 @@ Disconnects this ability from the Service ability. This method uses a callback t - Example ``` this.context.disconnectAbility(connection, (err) => { // connection is the return value of connectAbility. - console.log('terminateSelf result:' + JSON.stringfy(err); - } + console.log('terminateSelf result:' + JSON.stringfy(err)); + }); ``` @@ -176,7 +176,7 @@ Disconnects this ability from the Service ability. This method uses a promise to ``` this.context.disconnectAbility(connection).then((data) => { // connection is the return value of connectAbility. console.log('success:' + JSON.stringfy(data)); - )).catch((error) => { + }).catch((error) => { console.log('failed:' + JSON.stringfy(error)); }); ``` diff --git a/en/application-dev/reference/apis/js-apis-service-extension.md b/en/application-dev/reference/apis/js-apis-service-extension.md index 22f46948c0..3696ec05ec 100644 --- a/en/application-dev/reference/apis/js-apis-service-extension.md +++ b/en/application-dev/reference/apis/js-apis-service-extension.md @@ -1,6 +1,6 @@ # ServiceExtension -> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:** +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > The initial APIs of this module are supported since API 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. @@ -39,8 +39,10 @@ Called when an extension is created to initialize the service logic. - Example ``` - onCreate(want) { + class ServiceExt extends ServiceExtension { + onCreate(want) { console.log('onCreate, want:' + want.abilityName); + } } ``` @@ -53,9 +55,10 @@ Called when this extension is destroyed to clear resources. - Example ``` - onDestroy() { + class ServiceExt extends ServiceExtension { + onDestroy() { console.log('onDestroy'); - destory(); + } } ``` @@ -74,8 +77,10 @@ Called after **onCreate** is invoked when an ability is started by calling **sta - Example ``` - onRequest(want: Want, startId: number) { + class ServiceExt extends ServiceExtension { + onRequest(want, startId) { console.log('onRequest, want:' + want.abilityName); + } } ``` @@ -106,10 +111,11 @@ Called after **onCreate** is invoked when an ability is started by calling **con onRemoteRequest(code, data, reply, option) { } } - ... - onConnect(want) { + class ServiceExt extends ServiceExtension { + onConnect(want) { console.log('onConnect , want:' + want.abilityName); return new StubTest("test"); + } } ``` @@ -127,7 +133,9 @@ Called when the ability is disconnected. - Example ``` - onDisconnect(want) { + class ServiceExt extends ServiceExtension { + onDisconnect(want) { console.log('onDisconnect, want:' + want.abilityName); + } } ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-dataAbilityHelper.md b/zh-cn/application-dev/reference/apis/js-apis-dataAbilityHelper.md index 3c0e4627e4..7985887426 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-dataAbilityHelper.md +++ b/zh-cn/application-dev/reference/apis/js-apis-dataAbilityHelper.md @@ -44,6 +44,8 @@ DAHelper.openFile( openFile(uri: string, mode: string): Promise\ +在指定的远程路径中打开文件(promise形式)。 + **参数:** | 名称 | 类型 | 必填 | 描述 | @@ -270,7 +272,7 @@ normalizeUri(uri: string, callback: AsyncCallback\): void | 名称 | 类型 | 必填 | 描述 | | -------- | ---------------------- | ---- | ------------------------------------------------------------ | | uri | string | 是 | 指示要规范化的uri对象。 | -| callback | AsyncCallback\ | 是 | 回调方法。如果数据功能支持uri规范化或null,则返回规范化uri对象。 | +| callback | AsyncCallback\ | 是 | 回调方法。如果数据功能支持uri规范化,则返回规范化uri对象;否则返回null。 | **示例:** @@ -301,7 +303,7 @@ normalizeUri(uri: string): Promise\ **返回值:** | 类型 | 说明 | | ---------------- | ------------------------------------------------------ | -| Promise\ | 如果数据功能支持uri规范化或null,则返回规范化uri对象。 | +| Promise\ | 如果数据功能支持uri规范化,则返回规范化uri对象;否则返回null。 | **示例:** @@ -698,7 +700,7 @@ update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.Data **返回值:** | 类型 | 说明 | | ---------------- | -------------------------------------------- | -| Promise\ | 返回值为Promise对象,Promise中包含应用信息。 | +| Promise\ | 返回更新的数据记录数。 | **示例:** -- GitLab