未验证 提交 951d2859 编写于 作者: O openharmony_ci 提交者: Gitee

!1779 Done! 1620:修改老的文档示例代码

Merge pull request !1779 from wusongqing/TR1620
......@@ -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));
});
```
......
......@@ -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
)
```
# 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\<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|
| -------- | -------- | -------------------- | ---- | ------------------------ |
| 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\<void> | 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\<number> | 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\<number>
* 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\<number> | 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\<void>)
- 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>): 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\<void> | 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\<void> | 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\<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|
| -------- | -------- | -------------------- | ---- | ------------------------ |
| 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> | 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\<void> | 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\<string>)
- 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\<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|
| -------- | -------- | ---------------------- | ---- | ------------------------ |
| uri | Read-only| string | Yes| URI of the data.|
| callback | Read-only| AsyncCallback\<string> | Yes| Callback used to return the result.|
**Parameters**
- 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
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\<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|
| ---- | -------- | ------ | ---- | ------------------------ |
| 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\<string> | 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<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|
| -------------- | -------- | ------------------------------ | ---- | ---------------------------- |
| uri | Read-only| string | Yes| URI of the file.|
| mimeTypeFilter | Read-only| string | Yes| MIME type of the file.|
| callback | Read-only| AsyncCallback\<Array\<string>> | 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\<Array\<string>> | 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\<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|
| -------------- | -------- | ------ | ---- | ---------------------------- |
| 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\<Array\<string>> | 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\<string>)
- 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\<string>): void
| Name| Readable/Writable| Type| Mandatory| Description|
| -------- | -------- | ---------------------- | ---- | ----------------------- |
| uri | Read-only| string | Yes| URI object to normalize.|
| callback | Read-only| AsyncCallback\<string> | 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\<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
import featureAbility from '@ohos.ability.featureAbility'
......@@ -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|
| ---- | -------- | ------ | ---- | ----------------------- |
| 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\<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
import featureAbility from '@ohos.ability.featureAbility'
......@@ -336,24 +319,20 @@ DAHelper.normalizeUri(
});
```
#### DataAbilityHelper.denormalizeUri(uri: string, callback: AsyncCallback\<string>)
- 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.
### denormalizeUri
- Parameters
denormalizeUri(uri: string, callback: AsyncCallback\<string>): void
| Name| Readable/Writable| Type| Mandatory| Description|
| -------- | -------- | ---------------------- | ---- | ----------------------- |
| uri | Read-only| string | Yes| URI object to denormalize.|
| callback | Read-only| AsyncCallback\<string> | Yes| Callback used to return the result.|
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.
- 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
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\<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|
| ---- | -------- | ------ | ---- | ----------------------- |
| 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\<string> | 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\<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|
| -------- | -------- | -------------------- | ---- | ------------------------ |
| uri | Read-only| string | Yes| URI of the data.|
| callback | Read-only| AsyncCallback\<void> | Yes| Callback used to return the result.|
| Name| Type| Mandatory| Description|
| -------- | -------------------- | ---- | ------------------------ |
| uri | string | Yes| URI of the data.|
| callback | AsyncCallback\<void> | 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\<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|
| ---- | -------- | ------ | ---- | ------------------------ |
| 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\<void> | 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\<number>)
- 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\<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|
| ------------ | -------- | ---------------------- | ---- | ------------------------------------------------------ |
| 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.|
**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\<number> | 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\<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|
| ------------ | -------- | ---------------- | ---- | ------------------------------------------------------ |
| 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\<number> | 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<rdb.ValuesBucket>, callback: AsyncCallback\<number>)
- Functionality
### batchInsert
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|
| ------------ | -------- | ----------------------- | ---- | ------------------------ |
| 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.|
**Parameters**
- 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
import featureAbility from '@ohos.ability.featureAbility'
......@@ -571,24 +543,25 @@ DAHelper.batchInsert(
});
```
#### DataAbilityHelper.batchInsert(uri: string, valuesBuckets: Array<rdb.ValuesBucket>)
- Functionality
### batchInsert
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|
| ------------ | -------- | ----------------------- | ---- | ------------------------ |
| uri | Read-only| string | Yes| URI of the data to insert.|
| valuesBucket | Read-only| Array<rdb.ValuesBucket> | Yes| Data records to insert.|
**Parameters**
- 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
import featureAbility from '@ohos.ability.featureAbility'
......@@ -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|
| ------------ | -------- | --------------------------------- | ---- | ------------------------------------------------ |
| 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\<number> | 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\<number> | 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\<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|
| ------------ | -------- | --------------------------------- | ---- | ------------------------------------------------ |
| 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\<number> | 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\<number>)
- 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\<number>): 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\<number> | 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\<number> | 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\<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|
| ------------ | -------- | --------------------------------- | ---- | ------------------------------------------------ |
| 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\<number> | 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\<string>, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\<ResultSet>)
- Functionality
### query
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|
| ---------- | -------- | --------------------------------- | ---- | ------------------------------------------------ |
| 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.|
**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\<ResultSet> | 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\<string>, predicates: dataAbility.DataAbilityPredicates)
- Functionality
### query
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|
| ---------- | -------- | --------------------------------- | ---- | ------------------------------------------------ |
| 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\<ResultSet> | 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",
......
# 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));
});
```
......
# 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);
}
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册