提交 6658f8ba 编写于 作者: W wusongqing

updated docs

Signed-off-by: Nwusongqing <wusongqing@huawei.com>
上级 8d5fb164
...@@ -63,8 +63,8 @@ If this method is called for the first time, a root directory is created. ...@@ -63,8 +63,8 @@ If this method is called for the first time, a root directory is created.
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext(); var context = featureAbility.getContext();
context.getOrCreateLocalDir().then((void) => { context.getOrCreateLocalDir().then((data) => {
console.info("==========================>getOrCreateLocalDirCallback=======================>"); console.info("data=" + data);
}); });
``` ```
...@@ -91,9 +91,9 @@ Verifies whether a specific PID and UID have the given permission. This method u ...@@ -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 featureAbility from '@ohos.ability.featureAbility'
import bundle from '@ohos.bundle' import bundle from '@ohos.bundle'
var context = featureAbility.getContext(); var context = featureAbility.getContext();
var datainfo = await bundle.getBundleInfo('com.context.test',1); bundle.getBundleInfo('com.context.test', 1, (datainfo) =>{
context.verifyPermission("com.example.permission",datainfo.uid) 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 ...@@ -146,8 +146,9 @@ Verifies whether a specific PID and UID have the given permission. This method u
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext(); var context = featureAbility.getContext();
var Permission = context.PermissionOptions(1,1); var Permission = context.PermissionOptions(1,1);
context.getOrCreateLocalDir('com.context.permission',Permission).then((void) => { context.verifyPermission('com.context.permission',Permission).then((data) => {
console.info("==========================>verifyPermissionCallback=======================>"); 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 ...@@ -172,13 +173,16 @@ Requests certain permissions from the system. This method uses a callback to ret
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext(); var context = featureAbility.getContext();
context.getOrCreateLocalDir( context.requestPermissionsFromUser(
["com.example.permission1", ["com.example.permission1",
"com.example.permission2", "com.example.permission2",
"com.example.permission3", "com.example.permission3",
"com.example.permission4", "com.example.permission4",
"com.example.permission5"], "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 ...@@ -223,8 +227,9 @@ Obtains information about the current application. This method uses a promise to
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext(); var context = featureAbility.getContext();
context.getApplicationInfo().then((void) => { context.getApplicationInfo().then((data) => {
console.info("==========================>getApplicationInfoCallback=======================>"); 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 ...@@ -269,8 +274,9 @@ Obtains the bundle name of the current ability. This method uses a promise to re
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext(); var context = featureAbility.getContext();
context.getBundleName().then((void) => { context.getBundleName().then((data) => {
console.info("==========================>getBundleNameCallback=======================>"); 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 ...@@ -315,8 +321,9 @@ Obtains information about the current process, including the PID and process nam
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext(); var context = featureAbility.getContext();
context.getProcessInfo().then((void) => { context.getProcessInfo().then((data) => {
console.info("==========================>getProcessInfoCallback=======================>"); console.info("=======================>getProcessInfoCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
}); });
``` ```
...@@ -365,8 +372,9 @@ This method is available only to Page abilities. ...@@ -365,8 +372,9 @@ This method is available only to Page abilities.
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext(); var context = featureAbility.getContext();
context.getElementName().then((void) => { context.getElementName().then((data) => {
console.info("==========================>getElementNameCallback=======================>"); 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 ...@@ -407,8 +415,9 @@ Obtains the name of the current process. This method uses a promise to return th
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext(); var context = featureAbility.getContext();
context.getProcessName().then((void) => { context.getProcessName().then((data) => {
console.info("==========================>getProcessNameCallback=======================>"); 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 ...@@ -453,8 +462,9 @@ Obtains the bundle name of the calling ability. This method uses a promise to re
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext(); var context = featureAbility.getContext();
context.getCallingBundle().then((void) => { context.getCallingBundle().then((data) => {
console.info("==========================>getCallingBundleCallback=======================>"); console.info("======================>getCallingBundleCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
}); });
``` ```
......
...@@ -27,7 +27,6 @@ Obtains the ID attached to the end of a given URI. ...@@ -27,7 +27,6 @@ Obtains the ID attached to the end of a given URI.
**Example** **Example**
```js ```js
import dataUriUtils from '@ohos.ability.datauriutils'
dataUriUtils.getIdSync("com.example.dataUriUtils/1221") dataUriUtils.getIdSync("com.example.dataUriUtils/1221")
``` ```
...@@ -55,10 +54,9 @@ Attaches an ID to the end of a given URI. ...@@ -55,10 +54,9 @@ Attaches an ID to the end of a given URI.
**Example** **Example**
```js ```js
import dataUriUtils from '@ohos.ability.datauriutils'
var idint = 1122; var idint = 1122;
dataUriUtils.attachId( dataUriUtils.attachId(
"com.example.dataUriUtils" "com.example.dataUriUtils",
idint, idint,
) )
``` ```
...@@ -85,7 +83,6 @@ Deletes the ID from the end of a given URI. ...@@ -85,7 +83,6 @@ Deletes the ID from the end of a given URI.
**Example** **Example**
```js ```js
import dataUriUtils from '@ohos.ability.datauriutils'
dataUriUtils.deleteId("com.example.dataUriUtils/1221") dataUriUtils.deleteId("com.example.dataUriUtils/1221")
``` ```
...@@ -112,10 +109,9 @@ Updates the ID in a given URI. ...@@ -112,10 +109,9 @@ Updates the ID in a given URI.
**Example** **Example**
```js ```js
import dataUriUtils from '@ohos.ability.datauriutils'
var idint = 1122; var idint = 1122;
dataUriUtils.updateId( dataUriUtils.updateId(
"com.example.dataUriUtils" "com.example.dataUriUtils",
idint, idint
) )
``` ```
# DataAbilityHelper Module (JavaScript SDK APIs) # DataAbilityHelper Module (JavaScript SDK APIs)
#### Modules to Import ## Modules to Import
``` ```
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -8,26 +8,23 @@ import ohos_data_ability from '@ohos.data.dataability' ...@@ -8,26 +8,23 @@ import ohos_data_ability from '@ohos.data.dataability'
import ohos_data_rdb from '@ohos.data.rdb' import ohos_data_rdb from '@ohos.data.rdb'
``` ```
#### DataAbilityHelper.openFile(uri: string, mode: string, callback: AsyncCallback\<number>) ## 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\<number>): 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| | Name| Type| Mandatory| Description|
| -------- | -------- | -------------------- | ---- | ------------------------ | | -------- | ---------------------- | ---- | ---------------------------------- |
| uri | Read-only| string | Yes| URI of the file to open.| | uri | string | Yes| URI of the file to open.|
| mode | Read-only| string | Yes| Mode for opening the file. The value can be **rwt**.| | mode | string | Yes| Mode for opening the file. The value can be **rwt**.|
| callback | Read-only| AsyncCallback\<void> | Yes| Callback used to return the result.| | callback | AsyncCallback\<number> | Yes| Callback used to return the file descriptor.|
* Return values **Example**
Returns a file descriptor.
* Example
```javascript ```javascript
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -43,24 +40,25 @@ DAHelper.openFile( ...@@ -43,24 +40,25 @@ DAHelper.openFile(
}); });
``` ```
#### DataAbilityHelper.openFile(uri: string, mode: string) ### openFile
- Functionality
Opens a file with a specified URI. This method uses a promise to return the result. openFile(uri: string, mode: string): Promise\<number>
* Parameters Opens a file with a specified URI. This method uses a promise to return the result.
| Name| Readable/Writable| Type| Mandatory| Description| **Parameters**
| ---- | -------- | ------ | ---- | ------------------------ |
| 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**.|
* 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\<number> | Promise used to return the file descriptor.|
* Example **Example**
```javascript ```javascript
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -70,30 +68,26 @@ var DAHelper = featureAbility.acquireDataAbilityHelper( ...@@ -70,30 +68,26 @@ var DAHelper = featureAbility.acquireDataAbilityHelper(
var mode = "rwt"; var mode = "rwt";
DAHelper.openFile( DAHelper.openFile(
"dataability:///com.example.DataAbility", "dataability:///com.example.DataAbility",
mode).then((void) => { mode).then((data) => {
console.info("==========================>openFileCallback=======================>"); console.info("==========================>openFileCallback=======================>");
}); });
``` ```
#### DataAbilityHelper.on(type: 'dataChange', uri: string, callback: AsyncCallback\<void>) ### on('dataChange')
- Functionality
Registers an observer to observe data specified by a given URI. This method uses a callback to return the result.
- Parameters on(type: 'dataChange', uri: string, callback: AsyncCallback\<void>): void
| Name| Readable/Writable| Type| Mandatory| Description| Registers an observer to observe data specified by a given URI. This method uses a callback to return the result.
| -------- | -------- | -------------------- | ---- | ------------------------ |
| 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\<void> | Yes| Callback invoked when the data is changed.|
- 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\<void> | Yes| Callback invoked when the data is changed.|
- Example **Example**
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -110,25 +104,21 @@ helper.on( ...@@ -110,25 +104,21 @@ helper.on(
) )
``` ```
#### DataAbilityHelper.off(type: 'dataChange', uri: string, callback?: AsyncCallback\<void>) ### off('dataChange')
- Functionality off(type: 'dataChange', uri: string, callback?: AsyncCallback\<void>): 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| | Name| Type| Mandatory| Description|
| -------- | -------- | -------------------- | ---- | ------------------------ | | -------- | -------------------- | ---- | ------------------------ |
| type | Read-only| string | Yes| Type of the event to observe. The value is **dataChange**.| | type | string | Yes| Type of the event to observe. The value is **dataChange**.|
| uri | Read-only| string | Yes| URI of the data.| | uri | string | Yes| URI of the data.|
| callback | Read-only| AsyncCallback\<void> | No| Callback used to return the result.| | callback | AsyncCallback\<void> | No| Callback used to return the result.|
- Return value **Example**
void
- Example
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -149,24 +139,20 @@ helper.off( ...@@ -149,24 +139,20 @@ helper.off(
) )
``` ```
#### DataAbilityHelper.getType(uri: string, callback: AsyncCallback\<string>) ### getType
- Functionality
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\<string>): 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| **Parameters**
| -------- | -------- | ---------------------- | ---- | ------------------------ |
| uri | Read-only| string | Yes| URI of the data.|
| callback | Read-only| AsyncCallback\<string> | Yes| Callback used to return the result.|
- Return value | Name| Type| Mandatory| Description|
| -------- | ---------------------- | ---- | --------------------------------------------- |
| uri | string | Yes| URI of the data.|
| callback | AsyncCallback\<string> | Yes| Callback used to return the MIME type.|
Returns the MIME type that matches the data specified by the URI. **Example**
- Example
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -180,23 +166,24 @@ DAHelper.getType( ...@@ -180,23 +166,24 @@ DAHelper.getType(
}); });
``` ```
#### DataAbilityHelper.getType(uri: string) ### getType
- Functionality
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\<string>
- 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| **Parameters**
| ---- | -------- | ------ | ---- | ------------------------ |
| uri | Read-only| string | Yes| URI of the data.|
- 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\<string> | Promise used to return the MIME type.|
- Example **Example**
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -210,25 +197,21 @@ DAHelper.getType( ...@@ -210,25 +197,21 @@ DAHelper.getType(
}); });
``` ```
#### DataAbilityHelper.getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array\<string>>) ### getFileTypes
- Functionality getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array\<string>>): 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| | Name| Type| Mandatory| Description|
| -------------- | -------- | ------------------------------ | ---- | ---------------------------- | | -------------- | ------------------------------ | ---- | ---------------------------------- |
| uri | Read-only| string | Yes| URI of the file.| | uri | string | Yes| URI of the file.|
| mimeTypeFilter | Read-only| string | Yes| MIME type of the file.| | mimeTypeFilter | string | Yes| MIME type of the file.|
| callback | Read-only| AsyncCallback\<Array\<string>> | Yes| Callback used to return the result.| | callback | AsyncCallback\<Array\<string>> | Yes| Callback used to return the supported MIME types.|
- Return value **Example**
Returns a MIME type array.
- Example
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -243,24 +226,27 @@ DAHelper.getFileTypes( ...@@ -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\<Array\<string>>
- 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| **Parameters**
| -------------- | -------- | ------ | ---- | ---------------------------- |
| uri | Read-only| string | Yes| URI of the file.|
| mimeTypeFilter | Read-only| string | Yes| MIME type of the file.|
- 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\<Array\<string>> | Promise used to return the supported MIME types.|
- Example **Example**
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -275,24 +261,20 @@ DAHelper.getFileTypes( ...@@ -275,24 +261,20 @@ DAHelper.getFileTypes(
}); });
``` ```
#### DataAbilityHelper.normalizeUri(uri: string, callback: AsyncCallback\<string>) ### normalizeUri
- Functionality
Converts the URI that refers to a Data ability into a normalized URI. This method uses a callback to return the result.
- Parameters normalizeUri(uri: string, callback: AsyncCallback\<string>): void
| Name| Readable/Writable| Type| Mandatory| Description| Converts the URI that refers to a Data ability into a normalized URI. This method uses a callback to return the result.
| -------- | -------- | ---------------------- | ---- | ----------------------- |
| uri | Read-only| string | Yes| URI object to normalize.|
| callback | Read-only| AsyncCallback\<string> | Yes| Callback used 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\<string> | 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 ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -306,23 +288,24 @@ DAHelper.normalizeUri( ...@@ -306,23 +288,24 @@ DAHelper.normalizeUri(
}); });
``` ```
#### DataAbilityHelper.normalizeUri(uri: string) ### normalizeUri
- Functionality normalizeUri(uri: string): Promise\<string>
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| | Name| Type| Mandatory| Description|
| ---- | -------- | ------ | ---- | ----------------------- | | ---- | ------ | ---- | ----------------------- |
| uri | Read-only| string | Yes| URI object to normalize.| | uri | string | Yes| URI object to normalize.|
- Return value **Return value**
| Type| Description|
| ---------------- | ------------------------------------------------------ |
| Promise\<string> | 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 ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -336,24 +319,20 @@ DAHelper.normalizeUri( ...@@ -336,24 +319,20 @@ DAHelper.normalizeUri(
}); });
``` ```
#### DataAbilityHelper.denormalizeUri(uri: string, callback: AsyncCallback\<string>) ### denormalizeUri
- Functionality
Converts a normalized URI generated by **DataAbilityHelper.normalizeUri(uri: string, callback: AsyncCallback\<string>)** to a denormalized one. This method uses a callback to return the result.
- Parameters denormalizeUri(uri: string, callback: AsyncCallback\<string>): void
| Name| Readable/Writable| Type| Mandatory| Description| Converts a normalized URI generated by **DataAbilityHelper.normalizeUri(uri: string, callback: AsyncCallback\<string>)** to a denormalized one. This method uses a callback to return the result.
| -------- | -------- | ---------------------- | ---- | ----------------------- |
| uri | Read-only| string | Yes| URI object to denormalize.|
| callback | Read-only| AsyncCallback\<string> | Yes| Callback used 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\<string> | Yes| Callback used to return the denormalized URI object.|
- Example **Example**
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -361,29 +340,32 @@ var DAHelper = featureAbility.acquireDataAbilityHelper( ...@@ -361,29 +340,32 @@ var DAHelper = featureAbility.acquireDataAbilityHelper(
"dataability:///com.example.DataAbility" "dataability:///com.example.DataAbility"
); );
DAHelper.denormalizeUri( DAHelper.denormalizeUri(
"dataability:///com.example.DataAbility",, "dataability:///com.example.DataAbility",
(err, data) => { (err, data) => {
console.info("==========================>Called=======================>"); 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\<string>
- 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| **Parameters**
| ---- | -------- | ------ | ---- | ----------------------- |
| uri | Read-only| string | Yes| URI object to denormalize.|
- Return value | Name| Type| Mandatory| Description|
| ---- | ------ | ---- | ----------------------- |
| uri | string | Yes| URI object to normalize.|
Returns the denormalized URI object. **Return value**
| Type| Description|
| ---------------- | ----------------------------------------- |
| Promise\<string> | Promise used to return the denormalized URI object.|
- Example **Example**
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -397,24 +379,20 @@ DAHelper.denormalizeUri( ...@@ -397,24 +379,20 @@ DAHelper.denormalizeUri(
}); });
``` ```
#### DataAbilityHelper.notifyChange(uri: string, callback: AsyncCallback\<void>) ### notifyChange
- Functionality notifyChange(uri: string, callback: AsyncCallback\<void>): 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| | Name| Type| Mandatory| Description|
| -------- | -------- | -------------------- | ---- | ------------------------ | | -------- | -------------------- | ---- | ------------------------ |
| uri | Read-only| string | Yes| URI of the data.| | uri | string | Yes| URI of the data.|
| callback | Read-only| AsyncCallback\<void> | Yes| Callback used to return the result.| | callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
- Return value **Example**
void
- Example
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -422,29 +400,30 @@ var helper = featureAbility.acquireDataAbilityHelper( ...@@ -422,29 +400,30 @@ var helper = featureAbility.acquireDataAbilityHelper(
"dataability:///com.example.DataAbility" "dataability:///com.example.DataAbility"
); );
helper.notifyChange( helper.notifyChange(
"dataability:///com.example.DataAbility",, "dataability:///com.example.DataAbility",
(err) => { (err) => {
console.info("==========================>Called=======================>"); console.info("==========================>Called=======================>");
}); });
``` ```
#### DataAbilityHelper.notifyChange(uri: string) ### notifyChange
- Functionality notifyChange(uri: string): Promise\<void>
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| | Name| Type| Mandatory| Description|
| ---- | -------- | ------ | ---- | ------------------------ | | ---- | ------ | ---- | ------------------------ |
| uri | Read-only| string | Yes| URI of the data.| | uri | string | Yes| URI of the data.|
- Return value **Return value**
| Type| Description|
| -------------- | --------------------- |
| Promise\<void> | Promise used to return the result.|
void **Example**
- Example
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -453,30 +432,26 @@ var DAHelper = featureAbility.acquireDataAbilityHelper( ...@@ -453,30 +432,26 @@ var DAHelper = featureAbility.acquireDataAbilityHelper(
); );
DAHelper.notifyChange( DAHelper.notifyChange(
"dataability:///com.example.DataAbility", "dataability:///com.example.DataAbility",
).then((void) => { ).then(() => {
console.info("==========================>notifyChangeCallback=======================>"); console.info("==========================>notifyChangeCallback=======================>");
}); });
``` ```
#### DataAbilityHelper.insert(uri: string, valuesBucket: rdb.ValuesBucket, callback: AsyncCallback\<number>) ### insert
- Functionality
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\<number>): 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| **Parameters**
| ------------ | -------- | ---------------------- | ---- | ------------------------------------------------------ |
| 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\<number> | Yes| Callback used to return the result.|
- 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\<number> | Yes| Callback used to return the index of the inserted data record.|
Returns the index of the inserted data record. **Example**
- Example
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -497,24 +472,25 @@ DAHelper.insert( ...@@ -497,24 +472,25 @@ DAHelper.insert(
}); });
``` ```
#### DataAbilityHelper.insert(uri: string, valuesBucket: rdb.ValuesBucket) ### insert
- Functionality
Inserts a single data record into the database. This method uses a promise to return the result. insert(uri: string, valuesBucket: rdb.ValuesBucket): Promise\<number>
- Parameters Inserts a single data record into the database. This method uses a promise to return the result.
| Name| Readable/Writable| Type| Mandatory| Description| **Parameters**
| ------------ | -------- | ---------------- | ---- | ------------------------------------------------------ |
| 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.|
- 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\<number> | Promise used to return the index of the inserted data record.|
- Example **Example**
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -535,25 +511,21 @@ DAHelper.insert( ...@@ -535,25 +511,21 @@ DAHelper.insert(
}); });
``` ```
#### DataAbilityHelper.batchInsert(uri: string, valuesBuckets: Array<rdb.ValuesBucket>, callback: AsyncCallback\<number>) ### batchInsert
- Functionality
Inserts multiple data records into the database. This method uses a callback to return the result. batchInsert(uri: string, valuesBuckets: Array<rdb.ValuesBucket>, callback: AsyncCallback\<number>): void
- Parameters Inserts multiple data records into the database. This method uses a callback to return the result.
| Name| Readable/Writable| Type| Mandatory| Description| **Parameters**
| ------------ | -------- | ----------------------- | ---- | ------------------------ |
| uri | Read-only| string | Yes| URI of the data to insert.|
| valuesBucket | Read-only| Array<rdb.ValuesBucket> | Yes| Data records to insert.|
| callback | Read-only| AsyncCallback\<number> | Yes| Callback used to return the result.|
- Return value | Name| Type| Mandatory| Description|
| ------------ | ----------------------- | ---- | -------------------------------- |
| uri | string | Yes| URI of the data to insert.|
| valuesBucket | Array<rdb.ValuesBucket> | Yes| Data records to insert.|
| callback | AsyncCallback\<number> | Yes| Callback used to return the number of inserted data records.|
Returns the number of inserted data records. **Example**
- Example
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -571,24 +543,25 @@ DAHelper.batchInsert( ...@@ -571,24 +543,25 @@ DAHelper.batchInsert(
}); });
``` ```
#### DataAbilityHelper.batchInsert(uri: string, valuesBuckets: Array<rdb.ValuesBucket>) ### batchInsert
- Functionality
Inserts multiple data records into the database. This method uses a promise to return the result. batchInsert(uri: string, valuesBuckets: Array<rdb.ValuesBucket>): Promise\<number>
- Parameters Inserts multiple data records into the database. This method uses a promise to return the result.
| Name| Readable/Writable| Type| Mandatory| Description| **Parameters**
| ------------ | -------- | ----------------------- | ---- | ------------------------ |
| uri | Read-only| string | Yes| URI of the data to insert.|
| valuesBucket | Read-only| Array<rdb.ValuesBucket> | Yes| Data records to insert.|
- Return value | Name| Type| Mandatory| Description|
| ------------ | ----------------------- | ---- | ------------------------ |
| uri | string | Yes| URI of the data to insert.|
| valuesBucket | Array<rdb.ValuesBucket> | Yes| Data record to insert.|
Returns the number of inserted data records. **Return value**
| Type| Description|
| ---------------- | ---------------------- |
| Promise\<number> | Promise used to return the number of inserted data records.|
- Example **Example**
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -606,25 +579,21 @@ DAHelper.batchInsert( ...@@ -606,25 +579,21 @@ DAHelper.batchInsert(
}); });
``` ```
#### DataAbilityHelper.delete(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<number>) ### delete
- Functionality delete(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<number>): 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| | Name| Type| Mandatory| Description|
| ------------ | -------- | --------------------------------- | ---- | ------------------------------------------------ | | ------------ | --------------------------------- | ---- | ------------------------------------------------ |
| uri | Read-only| string | Yes| URI of the data to delete.| | uri | 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**.| | valuesBucket | dataAbility.DataAbilityPredicates | Yes| Filter criteria. You should define the processing logic when this parameter is **null**.|
| callback | Read-only| AsyncCallback\<number> | Yes| Callback used to return the result.| | callback | AsyncCallback\<number> | Yes| Callback used to return the number of deleted data records.|
- Return value **Example**
Returns the number of deleted data records.
- Example
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -641,24 +610,25 @@ DAHelper.delete( ...@@ -641,24 +610,25 @@ DAHelper.delete(
}); });
``` ```
#### DataAbilityHelper.delete(uri: string, predicates: dataAbility.DataAbilityPredicates) ### delete
- Functionality
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\<number>
- 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| **Parameters**
| ------------ | -------- | --------------------------------- | ---- | ------------------------------------------------ |
| 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**.|
- 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\<number> | Promise used to return the number of deleted data records.|
- Example **Example**
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -674,26 +644,22 @@ DAHelper.delete( ...@@ -674,26 +644,22 @@ DAHelper.delete(
}); });
``` ```
#### DataAbilityHelper.update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<number>) ### update
- Functionality
Updates data records in the database. This method uses a callback to return the result.
- Parameters update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<number>): void
| Name| Readable/Writable| Type| Mandatory| Description| Updates data records in the database. This method uses a callback to return the result.
| ------------ | -------- | --------------------------------- | ---- | ------------------------------------------------ |
| 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\<number> | Yes| Callback used 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\<number> | Yes| Callback used to return the number of updated data records.|
- Example **Example**
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -717,25 +683,26 @@ DAHelper.update( ...@@ -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\<number>
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| | Name| Type| Mandatory| Description|
| ------------ | -------- | --------------------------------- | ---- | ------------------------------------------------ | | ------------ | --------------------------------- | ---- | ------------------------------------------------ |
| uri | Read-only| string | Yes| URI of the data to update.| | uri | string | Yes| URI of the data to update.|
| valuesBucket | Read-only| rdb.ValuesBucket | Yes| New values.| | valuesBucket | rdb.ValuesBucket | Yes| New values.|
| predicates | Read-only| dataAbility.DataAbilityPredicates | Yes| Filter criteria. You should define the processing logic when this parameter is **null**.| | predicates | dataAbility.DataAbilityPredicates | Yes| Filter criteria. You should define the processing logic when this parameter is **null**.|
- Return value **Return value**
| Type| Description|
| ---------------- | -------------------------------------------- |
| Promise\<number> | Promise used to return the number of updated data records.|
Returns the number of updated data records. **Example**
- Example
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -759,26 +726,22 @@ DAHelper.update( ...@@ -759,26 +726,22 @@ DAHelper.update(
}); });
``` ```
#### DataAbilityHelper.query(uri: string, columns: Array\<string>, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<ResultSet>) ### query
- Functionality
Queries data in the database. This method uses a callback to return the result. query(uri: string, columns: Array\<string>, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<ResultSet>): void
- Parameters Queries data in the database. This method uses a callback to return the result.
| Name| Readable/Writable| Type| Mandatory| Description| **Parameters**
| ---------- | -------- | --------------------------------- | ---- | ------------------------------------------------ |
| 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\<ResultSet> | Yes| Callback used to return the result.|
- 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\<ResultSet> | Yes| Callback used to return the data queried.|
Returns the data queried. **Example**
- Example
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -786,7 +749,7 @@ import ohos_data_ability from '@ohos.data.dataability' ...@@ -786,7 +749,7 @@ import ohos_data_ability from '@ohos.data.dataability'
var DAHelper = featureAbility.acquireDataAbilityHelper( var DAHelper = featureAbility.acquireDataAbilityHelper(
"dataability:///com.example.DataAbility" "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() let da = new ohos_data_ability.DataAbilityPredicates()
DAHelper.query( DAHelper.query(
"dataability:///com.example.DataAbility", "dataability:///com.example.DataAbility",
...@@ -799,25 +762,26 @@ DAHelper.query( ...@@ -799,25 +762,26 @@ DAHelper.query(
#### DataAbilityHelper.query(uri: string, columns: Array\<string>, predicates: dataAbility.DataAbilityPredicates) ### query
- Functionality
Queries data in the database. This method uses a promise to return the result. query(uri: string, columns: Array\<string>, predicates: dataAbility.DataAbilityPredicates): Promise\<ResultSet>
- Parameters Queries data in the database. This method uses a promise to return the result.
| Name| Readable/Writable| Type| Mandatory| Description| **Parameters**
| ---------- | -------- | --------------------------------- | ---- | ------------------------------------------------ |
| 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**.|
- 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\<ResultSet> | Promise used to return the data queried.|
- Example **Example**
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
...@@ -825,7 +789,7 @@ import ohos_data_ability from '@ohos.data.dataability' ...@@ -825,7 +789,7 @@ import ohos_data_ability from '@ohos.data.dataability'
var DAHelper = featureAbility.acquireDataAbilityHelper( var DAHelper = featureAbility.acquireDataAbilityHelper(
"dataability:///com.example.DataAbility" "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() let da = new ohos_data_ability.DataAbilityPredicates()
DAHelper.query( DAHelper.query(
"dataability:///com.example.DataAbility", "dataability:///com.example.DataAbility",
......
# ServiceExtensionContext # 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. > 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. ...@@ -29,8 +29,8 @@ Starts an ability. This method uses a callback to return the result.
"abilityName": "com.example.myapp.MyAbility" "abilityName": "com.example.myapp.MyAbility"
}; };
this.context.startAbility(want, (err) => { 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. ...@@ -58,7 +58,7 @@ Starts an ability. This method uses a promise to return the result.
}; };
this.context.startAbility(want).then((data) => { this.context.startAbility(want).then((data) => {
console.log('success:' + JSON.stringfy(data)); console.log('success:' + JSON.stringfy(data));
)).catch((error) => { }).catch((error) => {
console.log('failed:' + JSON.stringfy(error)); console.log('failed:' + JSON.stringfy(error));
}); });
``` ```
...@@ -78,8 +78,8 @@ Terminates this ability. This method uses a callback to return the result. ...@@ -78,8 +78,8 @@ Terminates this ability. This method uses a callback to return the result.
- Example - Example
``` ```
this.context.terminateSelf((err) => { 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. ...@@ -98,7 +98,7 @@ Terminates this ability. This method uses a promise to return the result.
``` ```
this.context.terminateSelf(want).then((data) => { this.context.terminateSelf(want).then((data) => {
console.log('success:' + JSON.stringfy(data)); console.log('success:' + JSON.stringfy(data));
)).catch((error) => { }).catch((error) => {
console.log('failed:' + JSON.stringfy(error)); console.log('failed:' + JSON.stringfy(error));
}); });
``` ```
...@@ -128,8 +128,8 @@ Connects this ability to a Service ability. ...@@ -128,8 +128,8 @@ Connects this ability to a Service ability.
"abilityName": "com.example.myapp.MyAbility" "abilityName": "com.example.myapp.MyAbility"
}; };
let options = { let options = {
onConnect: function(elementName, proxy) {} onConnect: function(elementName, proxy) {},
onDisConnect: function(elementName) {} onDisConnect: function(elementName) {},
onFailed: function(code) {} onFailed: function(code) {}
} }
let connection = this.context.connectAbility(want,options); let connection = this.context.connectAbility(want,options);
...@@ -151,8 +151,8 @@ Disconnects this ability from the Service ability. This method uses a callback t ...@@ -151,8 +151,8 @@ Disconnects this ability from the Service ability. This method uses a callback t
- Example - Example
``` ```
this.context.disconnectAbility(connection, (err) => { // connection is the return value of connectAbility. 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 ...@@ -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. this.context.disconnectAbility(connection).then((data) => { // connection is the return value of connectAbility.
console.log('success:' + JSON.stringfy(data)); console.log('success:' + JSON.stringfy(data));
)).catch((error) => { }).catch((error) => {
console.log('failed:' + JSON.stringfy(error)); console.log('failed:' + JSON.stringfy(error));
}); });
``` ```
......
# ServiceExtension # 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. > 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,9 +39,11 @@ Called when an extension is created to initialize the service logic. ...@@ -39,9 +39,11 @@ Called when an extension is created to initialize the service logic.
- Example - Example
``` ```
class ServiceExt extends ServiceExtension {
onCreate(want) { onCreate(want) {
console.log('onCreate, want:' + want.abilityName); console.log('onCreate, want:' + want.abilityName);
} }
}
``` ```
...@@ -53,9 +55,10 @@ Called when this extension is destroyed to clear resources. ...@@ -53,9 +55,10 @@ Called when this extension is destroyed to clear resources.
- Example - Example
``` ```
class ServiceExt extends ServiceExtension {
onDestroy() { onDestroy() {
console.log('onDestroy'); console.log('onDestroy');
destory(); }
} }
``` ```
...@@ -74,9 +77,11 @@ Called after **onCreate** is invoked when an ability is started by calling **sta ...@@ -74,9 +77,11 @@ Called after **onCreate** is invoked when an ability is started by calling **sta
- Example - Example
``` ```
onRequest(want: Want, startId: number) { class ServiceExt extends ServiceExtension {
onRequest(want, startId) {
console.log('onRequest, want:' + want.abilityName); console.log('onRequest, want:' + want.abilityName);
} }
}
``` ```
...@@ -106,11 +111,12 @@ Called after **onCreate** is invoked when an ability is started by calling **con ...@@ -106,11 +111,12 @@ Called after **onCreate** is invoked when an ability is started by calling **con
onRemoteRequest(code, data, reply, option) { onRemoteRequest(code, data, reply, option) {
} }
} }
... class ServiceExt extends ServiceExtension {
onConnect(want) { onConnect(want) {
console.log('onConnect , want:' + want.abilityName); console.log('onConnect , want:' + want.abilityName);
return new StubTest("test"); return new StubTest("test");
} }
}
``` ```
...@@ -127,7 +133,9 @@ Called when the ability is disconnected. ...@@ -127,7 +133,9 @@ Called when the ability is disconnected.
- Example - Example
``` ```
class ServiceExt extends ServiceExtension {
onDisconnect(want) { onDisconnect(want) {
console.log('onDisconnect, want:' + want.abilityName); console.log('onDisconnect, want:' + want.abilityName);
} }
}
``` ```
...@@ -44,6 +44,8 @@ DAHelper.openFile( ...@@ -44,6 +44,8 @@ DAHelper.openFile(
openFile(uri: string, mode: string): Promise\<number> openFile(uri: string, mode: string): Promise\<number>
在指定的远程路径中打开文件(promise形式)。
**参数:** **参数:**
| 名称 | 类型 | 必填 | 描述 | | 名称 | 类型 | 必填 | 描述 |
...@@ -270,7 +272,7 @@ normalizeUri(uri: string, callback: AsyncCallback\<string>): void ...@@ -270,7 +272,7 @@ normalizeUri(uri: string, callback: AsyncCallback\<string>): void
| 名称 | 类型 | 必填 | 描述 | | 名称 | 类型 | 必填 | 描述 |
| -------- | ---------------------- | ---- | ------------------------------------------------------------ | | -------- | ---------------------- | ---- | ------------------------------------------------------------ |
| uri | string | 是 | 指示要规范化的uri对象。 | | uri | string | 是 | 指示要规范化的uri对象。 |
| callback | AsyncCallback\<string> | 是 | 回调方法。如果数据功能支持uri规范化或null,则返回规范化uri对象。 | | callback | AsyncCallback\<string> | 是 | 回调方法。如果数据功能支持uri规范化,则返回规范化uri对象;否则返回null。 |
**示例:** **示例:**
...@@ -301,7 +303,7 @@ normalizeUri(uri: string): Promise\<string> ...@@ -301,7 +303,7 @@ normalizeUri(uri: string): Promise\<string>
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------- | ------------------------------------------------------ | | ---------------- | ------------------------------------------------------ |
| Promise\<string> | 如果数据功能支持uri规范化或null,则返回规范化uri对象。 | | Promise\<string> | 如果数据功能支持uri规范化,则返回规范化uri对象;否则返回null。 |
**示例:** **示例:**
...@@ -698,7 +700,7 @@ update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.Data ...@@ -698,7 +700,7 @@ update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.Data
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------- | -------------------------------------------- | | ---------------- | -------------------------------------------- |
| Promise\<number> | 返回值为Promise对象,Promise中包含应用信息。 | | Promise\<number> | 返回更新的数据记录数。 |
**示例:** **示例:**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册