提交 98b1384c 编写于 作者: L lijialang

Merge branch 'master' of gitee.com:lijialang/docs

...@@ -123,7 +123,7 @@ Unsubscribes from the device status. ...@@ -123,7 +123,7 @@ Unsubscribes from the device status.
| -------------------- | -------------------------------------------------- | ---- | ---------------------------- | | -------------------- | -------------------------------------------------- | ---- | ---------------------------- |
| activity | [ActivityType](#activitytype) | Yes | Device status type. | | activity | [ActivityType](#activitytype) | Yes | Device status type. |
| event | [ActivityEvent](#activityevent) | Yes | Event type. | | event | [ActivityEvent](#activityevent) | Yes | Event type. |
| callback | Callback<[ActivityResponse](#activityresponse)\> | No | Callback used to receive reported data. | | callback | Callback<[ActivityResponse](#activityresponse)\> | No | Callback used to receive reported data, if the callback parameter is not passed, all callbacks subscribed to this type under this process will be removed. |
**Example** **Example**
......
...@@ -209,8 +209,8 @@ Removes the permission for the application to access a USB device. ...@@ -209,8 +209,8 @@ Removes the permission for the application to access a USB device.
**Example** **Example**
```js ```js
let devicesName="1-1"; let devicesName= "1-1";
if usb.removeRight(devicesName) { if (usb.removeRight(devicesName)) {
console.log(`Succeed in removing right`); console.log(`Succeed in removing right`);
} }
``` ```
...@@ -245,7 +245,7 @@ Adds the permission for the application to access a USB device. ...@@ -245,7 +245,7 @@ Adds the permission for the application to access a USB device.
```js ```js
let devicesName = "1-1"; let devicesName = "1-1";
let bundleName = "com.example.hello"; let bundleName = "com.example.hello";
if usb.addRight(bundleName, devicesName) { if (usb.addRight(bundleName, devicesName)) {
console.log(`Succeed in adding right`); console.log(`Succeed in adding right`);
} }
``` ```
...@@ -454,7 +454,14 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi ...@@ -454,7 +454,14 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**Example** **Example**
```js ```js
let param = new usb.USBControlParams(); let param = {
request: 0,
reqType: 0,
target:0,
value: 0,
index: 0,
data: null
};
usb.controlTransfer(devicepipe, param).then((ret) => { usb.controlTransfer(devicepipe, param).then((ret) => {
console.log(`controlTransfer = ${ret}`); console.log(`controlTransfer = ${ret}`);
}) })
...@@ -579,7 +586,7 @@ Converts the USB function list in the numeric mask format to a string in Device ...@@ -579,7 +586,7 @@ Converts the USB function list in the numeric mask format to a string in Device
**Example** **Example**
```js ```js
let funcs = usb.ACM | usb.ECM; let funcs = usb.FunctionType.ACM | usb.FunctionType.ECM;
let ret = usb.usbFunctionsToString(funcs); let ret = usb.usbFunctionsToString(funcs);
``` ```
...@@ -608,7 +615,7 @@ Sets the current USB function list in Device mode. ...@@ -608,7 +615,7 @@ Sets the current USB function list in Device mode.
**Example** **Example**
```js ```js
let funcs = usb.HDC; let funcs = usb.FunctionType.HDC;
usb.setCurrentFunctions(funcs).then(() => { usb.setCurrentFunctions(funcs).then(() => {
console.info('usb setCurrentFunctions successfully.'); console.info('usb setCurrentFunctions successfully.');
}).catch(err => { }).catch(err => {
......
# app.js # app.js
## Application Lifecycle<sup>4+</sup>
You can implement lifecycle logic specific to your application in the **app.js** file. Available application lifecycle functions are as follows: You can implement lifecycle logic specific to your application in the **app.js** file. Available application lifecycle functions are as follows:
...@@ -11,7 +12,9 @@ You can implement lifecycle logic specific to your application in the **app.js** ...@@ -11,7 +12,9 @@ You can implement lifecycle logic specific to your application in the **app.js**
In the following example, logs are printed only in the lifecycle functions. In the following example, logs are printed only in the lifecycle functions.
```
```js
// app.js // app.js
export default { export default {
onCreate() { onCreate() {
...@@ -22,3 +25,63 @@ export default { ...@@ -22,3 +25,63 @@ export default {
}, },
} }
``` ```
## Application Object<sup>10+</sup>
| Attribute | Type | Description |
| ------ | -------- | ---------------------------------------- |
| getApp | Function | Obtains the data object exposed in **app.js** from the page JS file. This API works globally.|
> **NOTE**
>
> The application object is global data and occupies JS memory before the application exits. Although it facilitates data sharing between different pages, exercise caution when using it on small-system devices, whose memory is small. If they are overused, exceptions may occur due to insufficient memory when the application displays complex pages.
The following is an example:
Declare the application object in **app.js**.
```javascript
// app.js
export default {
data: {
test: "by getAPP"
},
onCreate() {
console.info('Application onCreate');
},
onDestroy() {
console.info('Application onDestroy');
},
};
```
Access the application object on a specific page.
```javascript
// index.js
export default {
data: {
title: ""
},
onInit() {
if (typeof getApp !== 'undefined') {
var appData = getApp().data;
if (typeof appData !== 'undefined') {
this.title = appData.name; // read from app data
}
}
},
clickHandler() {
if (typeof getApp !== 'undefined') {
var appData = getApp().data;
if (typeof appData !== 'undefined') {
appData.name = this.title; // write to app data
}
}
}
}
```
> **NOTE**
>
> To ensure that the application can run properly on an earlier version that does not support **getApp**, compatibility processing must be performed in the code. That is, before using **getApp**, check whether it is available.
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
**Lottie** allows you to implement animation-specific operations. **Lottie** allows you to implement animation-specific operations.
> **NOTE** > **NOTE**
> >
> The APIs of this module are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version. > The APIs of this module are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
...@@ -16,9 +16,7 @@ import lottie from '@ohos/lottieETS' ...@@ -16,9 +16,7 @@ import lottie from '@ohos/lottieETS'
> **NOTE** > **NOTE**
> >
> In the **Terminal** window, run the `npm install @ohos/lottieETS` command to download Lottie. The download requires the related permission. > To use **Lottie**, download it first by running the **ohpm install @ohos/lottieETS** command in the Terminal window.
>
> To install an OpenHarmony npm third-party package, run the `npm config set @ohos:registry=https://repo.harmonyos.com/npm/` command to set the repository address.
## lottie.loadAnimation ## lottie.loadAnimation
...@@ -31,15 +29,15 @@ Loads an animation. Before calling this API, declare the **Animator('__lottie_et ...@@ -31,15 +29,15 @@ Loads an animation. Before calling this API, declare the **Animator('__lottie_et
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| -------------- | --------------------------- | ---- | ------------------------------------------------------------ | | -------------- | --------------------------- | ---- | ---------------------------------------- |
| path | string | Yes | Path of the animation resource file in the HAP file. The resource file must be in JSON format. Example: **path: "common/lottie/data.json"**| | path | string | Yes | Path of the animation resource file in the HAP file. The resource file must be in JSON format. Example: **path: "common/lottie/data.json"**|
| container | object | Yes | Canvas drawing context. A **CanvasRenderingContext2D** object must be declared in advance.| | container | object | Yes | Canvas drawing context. A **CanvasRenderingContext2D** object must be declared in advance.|
| render | string | Yes | Rendering type. The value can only be **"canvas"**. | | render | string | Yes | Rendering type. The value can only be **"canvas"**. |
| loop | boolean \| number | No | If the value is of the Boolean type, this parameter indicates whether to repeat the animation cyclically after the animation ends; the default value is **true**. If the value is of the number type and is greater than or equal to 1, this parameter indicates the number of times the animation plays.| | loop | boolean \| number | No | If the value is of the Boolean type, this parameter indicates whether to repeat the animation cyclically after the animation ends. If the value is of the number type and is greater than or equal to 1, this parameter indicates the number of times the animation plays.<br>Default value: **true**|
| autoplay | boolean | No | Whether to automatically play the animation.<br>Default value: **true** | | autoplay | boolean | No | Whether to automatically play the animation<br>Default value: **true** |
| name | string | No | Custom animation name. In later versions, the name can be used to reference and control the animation.<br/>Default value: null | | name | string | No | Custom animation name. In later versions, the name can be used to reference and control the animation. <br>Default value: **""** |
| initialSegment | [number, number] | No | Start frame and end frame of the animation, respectively. | | initialSegment | [number, number] | No | Start frame and end frame of the animation, respectively. |
## lottie.destroy ## lottie.destroy
...@@ -52,10 +50,9 @@ Destroys the animation. This API must be called when a page exits. This API can ...@@ -52,10 +50,9 @@ Destroys the animation. This API must be called when a page exits. This API can
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| name | string | Yes | Name of the animation to destroy, which is the same as the **name** in the **loadAnimation** API. By default, all animations are destroyed. | | name | string | Yes | Name of the animation to destroy, which is the same as the **name** in the **loadAnimation** API. By default, all animations are destroyed.|
**Example** **Example**
```ts ```ts
// xxx.ets // xxx.ets
import lottie from '@ohos/lottieETS' import lottie from '@ohos/lottieETS'
...@@ -134,7 +131,7 @@ Plays a specified animation. ...@@ -134,7 +131,7 @@ Plays a specified animation.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| name | string | Yes | Name of the animation to play, which is the same as the **name** in the **loadAnimation** API. By default, all animations are played. | | name | string | Yes | Name of the animation to play, which is the same as the **name** in the **loadAnimation** API. By default, all animations are played.|
**Example** **Example**
...@@ -153,7 +150,7 @@ Pauses a specified animation. The next time **lottie.play()** is called, the ani ...@@ -153,7 +150,7 @@ Pauses a specified animation. The next time **lottie.play()** is called, the ani
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| name | string | Yes | Name of the animation to pause, which is the same as the **name** in the **loadAnimation** API. By default, all animations are paused. | | name | string | Yes | Name of the animation to pause, which is the same as the **name** in the **loadAnimation** API. By default, all animations are paused.|
**Example** **Example**
...@@ -172,7 +169,7 @@ Pauses or plays a specified animation. This API is equivalent to the switching b ...@@ -172,7 +169,7 @@ Pauses or plays a specified animation. This API is equivalent to the switching b
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation** API. By default, all animations are paused or played. | | name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation** API. By default, all animations are paused or played.|
**Example** **Example**
...@@ -191,7 +188,7 @@ Stops the specified animation. The next time **lottie.play()** is called, the an ...@@ -191,7 +188,7 @@ Stops the specified animation. The next time **lottie.play()** is called, the an
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation** API. By default, all animations are stopped. | | name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation** API. By default, all animations are stopped.|
**Example** **Example**
...@@ -210,8 +207,8 @@ Sets the playback speed of the specified animation. ...@@ -210,8 +207,8 @@ Sets the playback speed of the specified animation.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----- | ------ | ---- | ---------------------------------------- | | ----- | ------ | ---- | ---------------------------------------- |
| speed | number | Yes | Playback speed. The value is a floating-point number. If the value is greater than 0, the animation plays in forward direction. If the value is less than 0, the animation plays in reversed direction. If the value is **0**, the animation is paused. If the value is **1.0** or **-1.0**, the animation plays at the normal speed. | | speed | number | Yes | Playback speed. The value is a floating-point number. If the value is greater than 0, the animation plays in forward direction. If the value is less than 0, the animation plays in reversed direction. If the value is **0**, the animation is paused. If the value is **1.0** or **-1.0**, the animation plays at the normal speed.|
| name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation** API. By default, all animations are set. | | name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation** API. By default, all animations are set.|
**Example** **Example**
...@@ -231,7 +228,7 @@ Sets the direction in which the specified animation plays. ...@@ -231,7 +228,7 @@ Sets the direction in which the specified animation plays.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ------------------ | ---- | ---------------------------------------- | | --------- | ------------------ | ---- | ---------------------------------------- |
| direction | AnimationDirection | Yes | Direction in which the animation plays. **1**: forwards; **-1**: backwards. When set to play backwards, the animation plays from the current playback progress to the first frame. When this setting is combined with **loop** being set to **true**, the animation plays backwards continuously. When the value of **speed** is less than 0, the animation also plays backwards.<br>AnimationDirection: 1 \| -1 | | direction | AnimationDirection | Yes | Direction in which the animation plays. **1**: forwards; **-1**: backwards. When set to play backwards, the animation plays from the current playback progress to the first frame. When this setting is combined with **loop** being set to **true**, the animation plays backwards continuously. When the value of **speed** is less than 0, the animation also plays backwards.<br>AnimationDirection: 1 \| -1 |
| name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation** API. By default, all animations are set. | | name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation** API. By default, all animations are set.|
**Example** **Example**
...@@ -254,18 +251,18 @@ Defines an **AnimationItem** object, which is returned by the **loadAnimation** ...@@ -254,18 +251,18 @@ Defines an **AnimationItem** object, which is returned by the **loadAnimation**
| totalFrames | number | Total number of frames in the animation segment that is being played. | | totalFrames | number | Total number of frames in the animation segment that is being played. |
| frameRate | number | Frame rate (frame/s). | | frameRate | number | Frame rate (frame/s). |
| frameMult | number | Frame rate (frame/ms). | | frameMult | number | Frame rate (frame/ms). |
| playSpeed | number | Playback speed. The value is a floating-point number. If the value is greater than 0, the animation plays forward. If the value is less than 0, the animation plays backward. If the value is **0**, the animation is paused. If the value is **1.0** or **-1.0**, the animation plays at the normal speed. | | playSpeed | number | Playback speed. The value is a floating-point number. If the value is greater than 0, the animation plays forward. If the value is less than 0, the animation plays backward. If the value is **0**, the animation is paused. If the value is **1.0** or **-1.0**, the animation plays at the normal speed.|
| playDirection | number | Playback direction.<br>**1**: forward.<br/>**-1**: backward. | | playDirection | number | Playback direction.<br>**1**: forward.<br/>**-1**: backward. |
| playCount | number | Number of times the animation plays. | | playCount | number | Number of times the animation plays. |
| isPaused | boolean | Whether the current animation is paused. The value **true** means that the animation is paused. | | isPaused | boolean | Whether the current animation is paused. The value **true** means that the animation is paused. |
| autoplay | boolean | Whether to automatically play the animation upon completion of the loading. The value **false** means that the **play()** API needs to be called to start playing. | | autoplay | boolean | Whether to automatically play the animation upon completion of the loading. The value **false** means that the **play()** API needs to be called to start playing.|
| loop | boolean \| number | If the value is of the Boolean type, this parameter indicates whether to repeat the animation cyclically after the animation ends. If the value is of the number type and is greater than or equal to 1, this parameter indicates the number of times the animation plays. | | loop | boolean \| number | If the value is of the Boolean type, this parameter indicates whether to repeat the animation cyclically after the animation ends. If the value is of the number type and is greater than or equal to 1, this parameter indicates the number of times the animation plays. |
| renderer | any | Animation rendering object, which depends on the rendering type. | | renderer | any | Animation rendering object, which depends on the rendering type. |
| animationID | string | Animation ID. | | animationID | string | Animation ID. |
| timeCompleted | number | Number of frames that are played for an animation sequence. The value is affected by the setting of **AnimationSegment** and is the same as the value of **totalFrames**.| | timeCompleted | number | Number of frames that are played for an animation sequence. The value is affected by the setting of **AnimationSegment** and is the same as the value of **totalFrames**.|
| segmentPos | number | ID of the current animation segment. The value is a positive integer greater than or equal to 0. | | segmentPos | number | ID of the current animation segment. The value is a positive integer greater than or equal to 0. |
| isSubframeEnabled | boolean | Whether the precision of **currentFrame** is a floating point number. | | isSubframeEnabled | boolean | Whether the precision of **currentFrame** is a floating point number. |
| segments | AnimationSegment \| AnimationSegment[] | Current segment of the animation. | | segments | AnimationSegment \| AnimationSegment[] | Current segment of the animation. |
## AnimationItem.play ## AnimationItem.play
...@@ -278,7 +275,7 @@ Plays an animation. ...@@ -278,7 +275,7 @@ Plays an animation.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | --------------- | | ---- | ------ | ---- | --------------- |
| name | string | No | Name of the target animation. By default, the value is null.| | name | string | No | Name of the target animation.<br>Default value: **""** |
**Example** **Example**
...@@ -373,7 +370,7 @@ Sets the playback speed of an animation. ...@@ -373,7 +370,7 @@ Sets the playback speed of an animation.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----- | ------ | ---- | ---------------------------------------- | | ----- | ------ | ---- | ---------------------------------------- |
| speed | number | Yes | Playback speed. The value is a floating-point number. If the value is greater than 0, the animation plays forward. If the value is less than 0, the animation plays backward. If the value is **0**, the animation is paused. If the value is **1.0** or **-1.0**, the animation plays at the normal speed. | | speed | number | Yes | Playback speed. The value is a floating-point number. If the value is greater than 0, the animation plays forward. If the value is less than 0, the animation plays backward. If the value is 0, the animation is paused. If the value is **1.0** or **-1.0**, the animation plays at the normal speed.|
**Example** **Example**
...@@ -412,8 +409,8 @@ Sets the animation to stop at the specified frame or time. ...@@ -412,8 +409,8 @@ Sets the animation to stop at the specified frame or time.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------- | ---- | ---------------------------------------- | | ------- | ------- | ---- | ---------------------------------------- |
| value | number | Yes | Frame ID (greater than or equal to 0) or time progress (ms) at which the animation will stop. | | value | number | Yes | Frame ID (greater than or equal to 0) or time progress (ms) at which the animation will stop. |
| isFrame | boolean | No | Whether to set the animation to stop at the specified frame. The value **true** means to set the animation to stop at the specified frame, and **false** means to set the animation to stop at the specified time progress.<br/>Default value: **false** | | isFrame | boolean | No | Whether to set the animation to stop at the specified frame. The value **true** means to set the animation to stop at the specified frame, and **false** means to set the animation to stop at the specified time progress.<br>Default value: **false**|
| name | string | No | Name of the target animation. By default, the value is null. | | name | string | No | Name of the target animation. By default, the value is null. |
**Example** **Example**
...@@ -436,8 +433,8 @@ Sets the animation to start from the specified frame or time progress. ...@@ -436,8 +433,8 @@ Sets the animation to start from the specified frame or time progress.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------- | ---- | ---------------------------------------- | | ------- | ------- | ---- | ---------------------------------------- |
| value | number | Yes | Frame ID (greater than or equal to 0) or time progress (ms) at which the animation will start. | | value | number | Yes | Frame ID (greater than or equal to 0) or time progress (ms) at which the animation will start. |
| isFrame | boolean | Yes | Whether to set the animation to start from the specified frame. The value **true** means to set the animation to start from the specified frame, and **false** means to set the animation to start from the specified time progress.<br/>Default value: **false** | | isFrame | boolean | Yes | Whether to set the animation to start from the specified frame. The value **true** means to set the animation to start from the specified frame, and **false** means to set the animation to start from the specified time progress.<br>Default value: **false**|
| name | string | No | Name of the target animation.<br/>Default value: null | | name | string | No | Name of the target animation.<br>Default value: **""** |
**Example** **Example**
...@@ -460,7 +457,7 @@ Sets the animation to play only the specified segment. ...@@ -460,7 +457,7 @@ Sets the animation to play only the specified segment.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | ---------------------------------------- | | --------- | ---------------------------------------- | ---- | ---------------------------------------- |
| segments | AnimationSegment = [number, number] \| AnimationSegment[] | Yes | Segment or segment list.<br>If all segments in the segment list are played, only the last segment is played in the next cycle.| | segments | AnimationSegment = [number, number] \| AnimationSegment[] | Yes | Segment or segment list.<br>If all segments in the segment list are played, only the last segment is played in the next cycle.|
| forceFlag | boolean | Yes | Whether the settings take effect immediately. The value **true** means the settings take effect immediately, and **false** means the settings take effect until the current cycle of playback is completed. | | forceFlag | boolean | Yes | Whether the settings take effect immediately. The value **true** means the settings take effect immediately, and **false** means the settings take effect until the current cycle of playback is completed. |
**Example** **Example**
...@@ -533,7 +530,7 @@ Obtains the duration (irrelevant to the playback speed) or number of frames for ...@@ -533,7 +530,7 @@ Obtains the duration (irrelevant to the playback speed) or number of frames for
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------- | ---- | ---------------------------------------- | | -------- | ------- | ---- | ---------------------------------------- |
| inFrames | boolean | No | Whether to obtain the duration or number of frames.<br>**true**: number of frames.<br>**false**: duration, in ms.<br/>Default value: **false** | | inFrames | boolean | No | Whether to obtain the duration or number of frames.<br>**true**: number of frames.<br>**false**: duration, in ms.<br>Default value: **false**|
**Example** **Example**
...@@ -579,7 +576,7 @@ Removes an event listener. ...@@ -579,7 +576,7 @@ Removes an event listener.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ---------------------------------------- | | -------- | ------------------------------- | ---- | ---------------------------------------- |
| name | AnimationEventName | Yes | Animation event type. The available options are as follows:<br>'enterFrame', 'loopComplete', 'complete', 'segmentStart', 'destroy', 'config_ready', 'data_ready', 'DOMLoaded', 'error', 'data_failed', 'loaded_images'| | name | AnimationEventName | Yes | Animation event type. The available options are as follows:<br>'enterFrame', 'loopComplete', 'complete', 'segmentStart', 'destroy', 'config_ready', 'data_ready', 'DOMLoaded', 'error', 'data_failed', 'loaded_images'|
| callback | AnimationEventCallback&lt;T&gt; | No | Custom callback. By default, the value is null, meaning that all callbacks of the event will be removed. | | callback | AnimationEventCallback&lt;T&gt; | No | Custom callback. By default, the value is null, meaning that all callbacks of the event will be removed. |
**Example** **Example**
......
...@@ -63,8 +63,8 @@ ...@@ -63,8 +63,8 @@
- [跨端迁移(仅对系统应用开放)](hop-cross-device-migration.md) - [跨端迁移(仅对系统应用开放)](hop-cross-device-migration.md)
- [多端协同(仅对系统应用开放)](hop-multi-device-collaboration.md) - [多端协同(仅对系统应用开放)](hop-multi-device-collaboration.md)
- [订阅系统环境变量的变化](subscribe-system-environment-variable-changes.md) - [订阅系统环境变量的变化](subscribe-system-environment-variable-changes.md)
- 进程间通信 - 了解进程模型
- [进程模型](process-model-stage.md) - [进程模型概述](process-model-stage.md)
- 公共事件 - 公共事件
- [公共事件简介](common-event-overview.md) - [公共事件简介](common-event-overview.md)
- 公共事件订阅 - 公共事件订阅
...@@ -75,8 +75,8 @@ ...@@ -75,8 +75,8 @@
- [公共事件发布](common-event-publish.md) - [公共事件发布](common-event-publish.md)
- [移除粘性公共事件](common-event-remove-sticky.md) - [移除粘性公共事件](common-event-remove-sticky.md)
- [后台服务](background-services.md) - [后台服务](background-services.md)
- 线程间通信 - 了解线程模型
- [线程模型](thread-model-stage.md) - [线程模型概述](thread-model-stage.md)
- [使用Emitter进行线程间通信](itc-with-emitter.md) - [使用Emitter进行线程间通信](itc-with-emitter.md)
- [使用Worker进行线程间通信](itc-with-worker.md) - [使用Worker进行线程间通信](itc-with-worker.md)
- 任务管理 - 任务管理
...@@ -121,12 +121,12 @@ ...@@ -121,12 +121,12 @@
- [FA模型的Context](application-context-fa.md) - [FA模型的Context](application-context-fa.md)
- [信息传递载体Want](want-fa.md) - [信息传递载体Want](want-fa.md)
- [组件启动规则(FA模型)](component-startup-rules-fa.md) - [组件启动规则(FA模型)](component-startup-rules-fa.md)
- 进程间通信 - 了解进程模型
- [进程模型](process-model-fa.md) - [进程模型概述](process-model-fa.md)
- [公共事件](common-event-fa.md) - [公共事件](common-event-fa.md)
- [后台服务](rpc.md) - [后台服务](rpc.md)
- 线程间通信 - 了解线程模型
- [线程模型](thread-model-fa.md) - [线程模型概述](thread-model-fa.md)
- [线程间通信](itc-fa-overview.md) - [线程间通信](itc-fa-overview.md)
- [任务管理](mission-management-fa.md) - [任务管理](mission-management-fa.md)
- [FA模型应用配置文件](config-file-fa.md) - [FA模型应用配置文件](config-file-fa.md)
......
...@@ -35,7 +35,7 @@ AccessibilityExtensionAbility为无障碍扩展服务框架,允许三方开发 ...@@ -35,7 +35,7 @@ AccessibilityExtensionAbility为无障碍扩展服务框架,允许三方开发
## 如何创建一个无障碍扩展服务 ## 如何创建一个无障碍扩展服务
开发者在创建一个无障碍扩展服务时,如工程满足环境要求,开发者可自主选择是否跳过创建工程步骤,在已有工程中新增无障碍扩展服务。 开发者在创建一个无障碍扩展服务时,如工程满足环境要求,开发者可自主选择是否跳过创建工程步骤,在已有工程中新增无障碍扩展服务。一个工程仅支持创建一个无障碍扩展服务。
### 创建工程 ### 创建工程
......
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
在开发应用时,需要配置应用的一些标签,例如应用的包名、图标等标识特征的属性。本文描述了在开发应用需要配置的一些关键标签。 在开发应用时,需要配置应用的一些标签,例如应用的包名、图标等标识特征的属性。本文描述了在开发应用需要配置的一些关键标签。
图标和标签通常一起配置,可以分为应用图标、应用标签和入口图标、入口标签,分别对应[app.json5配置文件](../quick-start/app-configuration-file.md)[module.json5配置文件](../quick-start/module-configuration-file.md)文件中的icon和label标签。 图标和标签通常一起配置,可以分为应用图标、应用标签和入口图标、入口标签,分别对应[app.json5配置文件](../quick-start/app-configuration-file.md)[module.json5配置文件](../quick-start/module-configuration-file.md)中的icon和label标签。
应用图标和标签是在设置应用中使用,例如设置应用中的应用列表。入口图标是应用安装完成后在设备桌面上显示出来的,如图一所示。入口图标是以[UIAbility](uiability-overview.md)为粒度,支持同一个应用存在多个入口图标和标签,点击后进入对应的UIAbility界面。 应用图标和标签是在设置应用中使用,例如设置应用中的应用列表。入口图标是应用安装完成后在设备桌面上显示出来的,如下图所示。入口图标是以[UIAbility](uiability-overview.md)为粒度,支持同一个应用存在多个入口图标和入口标签,点击后进入对应的UIAbility界面。
**图1** 应用图标和标签   **图1** 应用图标和标签  
![application-component-configuration-stage](figures/application-component-configuration-stage.png) ![application-component-configuration-stage](figures/application-component-configuration-stage.png)
- **应用包名配置** - **应用包名配置**
...@@ -62,6 +62,33 @@ ...@@ -62,6 +62,33 @@
} }
} }
``` ```
OpenHarmony系统对无图标应用严格管控,防止一些恶意应用故意配置无入口图标,导致用户找不到软件所在的位置,无法操作卸载应用,在一定程度上保证用户的手机安全。
如果应用确需隐藏入口图标,需要配置AllowAppDesktopIconHide应用特权,具体配置方式参考[应用特权配置指南](../../device-dev/subsystems/subsys-app-privilege-config-guide.md)。详细的入口图标及入口标签的显示规则如下。
* HAP中包含UIAbility
* 在module.json5配置文件的abilities标签中设置了入口图标
* 该应用没有隐藏图标的特权
* 系统将使用该UIAbility配置的icon作为入口图标,并显示在桌面上。用户点击该图标,页面跳转到该UIAbility首页。
* 系统将使用该UIAbility配置的label作为入口标签,并显示在桌面上,如果没有配置label,系统将使用app.json5中的label作为入口标签,并显示在桌面上。
* 该应用具有隐藏图标的特权
* 桌面应用查询时不返回应用信息,不会在桌面上显示对应的入口图标和标签。
* 在module.json5配置文件的abilities标签中未设置入口图标
* 该应用没有隐藏图标的特权
* 系统将使用app.json5中的icon作为入口图标,并显示在桌面上。用户点击该图标,页面跳转到应用管理中对应的应用详情页面,如下图所示。
* 系统将使用app.json5中的label作为入口标签,并显示在桌面上。
* 该应用具有隐藏图标的特权
* 桌面应用查询时不返回应用信息,不会在桌面上显示对应的入口图标和标签。
* HAP中不包含UIAbility
* 该应用没有隐藏图标的特权
* 系统将使用app.json5中的icon作为入口图标,并显示在桌面上。用户点击该图标,页面跳转到应用管理中对应的应用详情页面,如下图所示。
* 系统将使用app.json5中的label作为入口标签,并显示在桌面上。
* 该应用具有隐藏图标的特权
* 桌面应用查询时不返回应用信息,不会在桌面上显示对应的入口图标和标签。
**图2** 应用的详情页示意图
![应用的详情页例图](figures/application_details.jpg)
- **应用版本声明配置** - **应用版本声明配置**
应用版本声明需要在工程的AppScope目录下的[app.json5配置文件](../quick-start/app-configuration-file.md)中配置versionCode标签和versionName标签。versionCode用于标识应用的版本号,该标签值为32位非负整数。此数字仅用于确定某个版本是否比另一个版本更新,数值越大表示版本越高。versionName标签标识版本号的文字描述。 应用版本声明需要在工程的AppScope目录下的[app.json5配置文件](../quick-start/app-configuration-file.md)中配置versionCode标签和versionName标签。versionCode用于标识应用的版本号,该标签值为32位非负整数。此数字仅用于确定某个版本是否比另一个版本更新,数值越大表示版本越高。versionName标签标识版本号的文字描述。
......
# OpenHarmony应用模型的构成要素 # 应用模型的构成要素
应用模型是OpenHarmony为开发者提供的应用程序所需能力的抽象提炼,它提供了应用程序必备的组件和运行机制。有了应用模型,开发者可以基于一套统一的模型进行应用开发,使应用开发更简单、高效。 应用模型是OpenHarmony为开发者提供的应用程序所需能力的抽象提炼,它提供了应用程序必备的组件和运行机制。有了应用模型,开发者可以基于一套统一的模型进行应用开发,使应用开发更简单、高效。
......
# OpenHarmony应用模型解读 # 应用模型解读
## OpenHarmony应用模型概况 ## OpenHarmony应用模型概况
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
当前卡片框架提供了如下几种按时间刷新卡片的方式: 当前卡片框架提供了如下几种按时间刷新卡片的方式:
- 定时刷新:表示在一定时间间隔内自动刷新卡片内容。可以在form_config.json配置文件的[`updateDuration`](arkts-ui-widget-configuration.md)字段中进行设置。例如,可以将刷新时间设置为每小时一次。 - 定时刷新:表示在一定时间间隔内调用[onUpdateForm](../reference/apis/js-apis-app-form-formExtensionAbility.md#onupdateform)的生命周期回调函数自动刷新卡片内容。可以在form_config.json配置文件的[`updateDuration`](arkts-ui-widget-configuration.md)字段中进行设置。例如,可以将刷新时间设置为每小时一次。
> **说明:** > **说明:**
> >
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
| 任务 | 简介 | 相关指导 | | 任务 | 简介 | 相关指导 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| 应用组件开发 | 本章节介绍了如何使用FA模型的PageAbility、ServiceAbility、DataAbility以及服务卡片进行应用开发。 | [应用/组件级配置](application-component-configuration-fa.md)<br/>[PageAbility开发指导](pageability-overview.md)<br/>[ServiceAbility开发指导](serviceability-overview.md)<br/>[DataAbility开发指导](dataability-overview.md)<br/>[服务卡片开发指导](widget-development-fa.md)<br/>[FA模型的Context](application-context-fa.md)<br/>[信息传递载体Want](want-fa.md) | | 应用组件开发 | 本章节介绍了如何使用FA模型的PageAbility、ServiceAbility、DataAbility以及服务卡片进行应用开发。 | [应用/组件级配置](application-component-configuration-fa.md)<br/>[PageAbility开发指导](pageability-overview.md)<br/>[ServiceAbility开发指导](serviceability-overview.md)<br/>[DataAbility开发指导](dataability-overview.md)<br/>[服务卡片开发指导](widget-development-fa.md)<br/>[FA模型的Context](application-context-fa.md)<br/>[信息传递载体Want](want-fa.md) |
| 进程间通信 | 本章节介绍了FA模型的进程模型以及几种常用的进程间通信方式。 | [公共事件](common-event-fa.md)<br/>[后台服务](rpc.md) | | 了解进程模型 | 本章节介绍了FA模型的进程模型以及几种常用的进程间通信方式。 | [公共事件](common-event-fa.md)<br/>[后台服务](rpc.md) |
| 线程间通信 | 本章节介绍了FA模型的线程模型以及几种常用的线程间通信方式。 | [线程间通信](itc-fa-overview.md) | | 了解线程模型 | 本章节介绍了FA模型的线程模型以及几种常用的线程间通信方式。 | [线程间通信](itc-fa-overview.md) |
| 任务管理 | 本章节介绍了FA模型中任务管理的基本概念和典型场景。 | [任务管理](mission-management-fa.md) | | 任务管理 | 本章节介绍了FA模型中任务管理的基本概念和典型场景。 | [任务管理](mission-management-fa.md) |
| 应用配置文件 | 本章节介绍FA模型中应用配置文件的开发要求。 | [FA模型应用配置文件](config-file-fa.md) | | 应用配置文件 | 本章节介绍FA模型中应用配置文件的开发要求。 | [FA模型应用配置文件](config-file-fa.md) |
...@@ -81,7 +81,7 @@ Stage卡片开发,即基于[Stage模型](stage-model-development-overview.md) ...@@ -81,7 +81,7 @@ Stage卡片开发,即基于[Stage模型](stage-model-development-overview.md)
- [配置卡片配置文件](#配置卡片配置文件):配置应用配置文件module.json5和profile配置文件。 - [配置卡片配置文件](#配置卡片配置文件):配置应用配置文件module.json5和profile配置文件。
- [卡片数据交互](#卡片数据交互):对卡片信息进行持久化管理。 - [卡片信息的持久化](#卡片数据交互):对卡片信息进行持久化管理。
- [卡片数据交互](#卡片数据交互):通过updateForm更新卡片显示的信息。 - [卡片数据交互](#卡片数据交互):通过updateForm更新卡片显示的信息。
......
# 进程模型 # 进程模型概述
OpenHarmony的进程模型如下图所示: OpenHarmony的进程模型如下图所示:
......
# 进程模型 # 进程模型概述
OpenHarmony的进程模型如下图所示: OpenHarmony的进程模型如下图所示:
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
| 任务 | 简介 | 相关指导 | | 任务 | 简介 | 相关指导 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| 应用组件开发 | 本章节介绍了如何使用Stage模型的UIAbility组件和ExtensionAbility组件开发应用。 | -&nbsp;[应用/组件级配置](application-component-configuration-stage.md)<br/>-&nbsp;[UIAbility组件](uiability-overview.md)<br/>-&nbsp;[ExtensionAbility组件](extensionability-overview.md)<br/>-&nbsp;[AbilityStage组件容器](abilitystage.md)<br/>-&nbsp;[应用上下文Context](application-context-stage.md)<br/>-&nbsp;[组件启动规则](component-startup-rules.md) | | 应用组件开发 | 本章节介绍了如何使用Stage模型的UIAbility组件和ExtensionAbility组件开发应用。 | -&nbsp;[应用/组件级配置](application-component-configuration-stage.md)<br/>-&nbsp;[UIAbility组件](uiability-overview.md)<br/>-&nbsp;[ExtensionAbility组件](extensionability-overview.md)<br/>-&nbsp;[AbilityStage组件容器](abilitystage.md)<br/>-&nbsp;[应用上下文Context](application-context-stage.md)<br/>-&nbsp;[组件启动规则](component-startup-rules.md) |
| 进程间通信 | 本章节介绍了Stage模型的进程模型以及几种常用的进程间通信方式。 | -&nbsp;[公共事件](common-event-overview.md)<br/>-&nbsp;[后台服务](background-services.md) | | 了解进程模型 | 本章节介绍了Stage模型的进程模型以及几种常用的进程间通信方式。 | -&nbsp;[公共事件](common-event-overview.md)<br/>-&nbsp;[后台服务](background-services.md) |
| 线程间通信 | 本章节介绍了Stage模型的线程模型以及几种常用的线程间通信方式。 | -&nbsp;[Emitter](itc-with-emitter.md)<br/>-&nbsp;[Worker](itc-with-worker.md) | | 了解线程模型 | 本章节介绍了Stage模型的线程模型以及几种常用的线程间通信方式。 | -&nbsp;[Emitter](itc-with-emitter.md)<br/>-&nbsp;[Worker](itc-with-worker.md) |
| 任务管理 | 本章节介绍了Stage模型中任务管理的基本概念和典型场景。 | -&nbsp;[任务管理场景介绍](mission-management-overview.md)<br/>-&nbsp;[任务管理与启动模式](mission-management-launch-type.md)<br/>-&nbsp;[页面栈和任务链](page-mission-stack.md) | | 任务管理 | 本章节介绍了Stage模型中任务管理的基本概念和典型场景。 | -&nbsp;[任务管理场景介绍](mission-management-overview.md)<br/>-&nbsp;[任务管理与启动模式](mission-management-launch-type.md)<br/>-&nbsp;[页面栈和任务链](page-mission-stack.md) |
| 应用配置文件 | 本章节介绍Stage模型中应用配置文件的开发要求。 | [Stage模型应用配置文件](config-file-stage.md) | | 应用配置文件 | 本章节介绍Stage模型中应用配置文件的开发要求。 | [Stage模型应用配置文件](config-file-stage.md) |
# 线程模型 # 线程模型概述
在OpenHarmony应用中,每个进程都会有一个主线程,主线程具有以下职责: 在OpenHarmony应用中,每个进程都会有一个主线程,主线程具有以下职责:
......
...@@ -29,7 +29,7 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信, ...@@ -29,7 +29,7 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信,
external_deps = [ external_deps = [
"ipc:ipc_single", "ipc:ipc_single",
] ]
#rpc场景 #rpc场景
external_deps = [ external_deps = [
"ipc:ipc_core", "ipc:ipc_core",
...@@ -50,12 +50,12 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信, ...@@ -50,12 +50,12 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信,
```c++ ```c++
#include "iremote_broker.h" #include "iremote_broker.h"
//定义消息码 //定义消息码
const int TRANS_ID_PING_ABILITY = 5 const int TRANS_ID_PING_ABILITY = 5;
const std::string DESCRIPTOR = "test.ITestAbility"; const std::string DESCRIPTOR = "test.ITestAbility";
class ITestAbility : public IRemoteBroker { class ITestAbility : public IRemoteBroker {
public: public:
// DECLARE_INTERFACE_DESCRIPTOR是必需的,入参需使用std::u16string; // DECLARE_INTERFACE_DESCRIPTOR是必需的,入参需使用std::u16string;
...@@ -71,13 +71,13 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信, ...@@ -71,13 +71,13 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信,
```c++ ```c++
#include "iability_test.h" #include "iability_test.h"
#include "iremote_stub.h" #include "iremote_stub.h"
class TestAbilityStub : public IRemoteStub<ITestAbility> { class TestAbilityStub : public IRemoteStub<ITestAbility> {
public: public:
virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
int TestPingAbility(const std::u16string &dummy) override; int TestPingAbility(const std::u16string &dummy) override;
}; };
int TestAbilityStub::OnRemoteRequest(uint32_t code, int TestAbilityStub::OnRemoteRequest(uint32_t code,
MessageParcel &data, MessageParcel &reply, MessageOption &option) MessageParcel &data, MessageParcel &reply, MessageOption &option)
{ {
...@@ -98,12 +98,12 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信, ...@@ -98,12 +98,12 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信,
```c++ ```c++
#include "iability_server_test.h" #include "iability_server_test.h"
class TestAbility : public TestAbilityStub { class TestAbility : public TestAbilityStub {
public: public:
int TestPingAbility(const std::u16string &dummy); int TestPingAbility(const std::u16string &dummy);
} }
int TestAbility::TestPingAbility(const std::u16string &dummy) { int TestAbility::TestPingAbility(const std::u16string &dummy) {
return 0; return 0;
} }
...@@ -117,7 +117,7 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信, ...@@ -117,7 +117,7 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信,
#include "iability_test.h" #include "iability_test.h"
#include "iremote_proxy.h" #include "iremote_proxy.h"
#include "iremote_object.h" #include "iremote_object.h"
class TestAbilityProxy : public IRemoteProxy<ITestAbility> { class TestAbilityProxy : public IRemoteProxy<ITestAbility> {
public: public:
explicit TestAbilityProxy(const sptr<IRemoteObject> &impl); explicit TestAbilityProxy(const sptr<IRemoteObject> &impl);
...@@ -125,12 +125,12 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信, ...@@ -125,12 +125,12 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信,
private: private:
static inline BrokerDelegator<TestAbilityProxy> delegator_; // 方便后续使用iface_cast宏 static inline BrokerDelegator<TestAbilityProxy> delegator_; // 方便后续使用iface_cast宏
} }
TestAbilityProxy::TestAbilityProxy(const sptr<IRemoteObject> &impl) TestAbilityProxy::TestAbilityProxy(const sptr<IRemoteObject> &impl)
: IRemoteProxy<ITestAbility>(impl) : IRemoteProxy<ITestAbility>(impl)
{ {
} }
int TestAbilityProxy::TestPingAbility(const std::u16string &dummy){ int TestAbilityProxy::TestPingAbility(const std::u16string &dummy){
MessageOption option; MessageOption option;
MessageParcel dataParcel, replyParcel; MessageParcel dataParcel, replyParcel;
...@@ -149,7 +149,7 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信, ...@@ -149,7 +149,7 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信,
// 注册到本设备内 // 注册到本设备内
auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
samgr->AddSystemAbility(saId, new TestAbility()); samgr->AddSystemAbility(saId, new TestAbility());
// 在组网场景下,会被同步到其他设备上 // 在组网场景下,会被同步到其他设备上
auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
ISystemAbilityManager::SAExtraProp saExtra; ISystemAbilityManager::SAExtraProp saExtra;
...@@ -166,10 +166,10 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信, ...@@ -166,10 +166,10 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信,
sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
sptr<IRemoteObject> remoteObject = samgr->GetSystemAbility(saId); sptr<IRemoteObject> remoteObject = samgr->GetSystemAbility(saId);
sptr<ITestAbility> testAbility = iface_cast<ITestAbility>(remoteObject); // 使用iface_cast宏转换成具体类型 sptr<ITestAbility> testAbility = iface_cast<ITestAbility>(remoteObject); // 使用iface_cast宏转换成具体类型
// 获取其他设备注册的SA的proxy // 获取其他设备注册的SA的proxy
sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
// networkId是组网场景下对应设备的标识符,可以通过GetLocalNodeDeviceInfo获取 // networkId是组网场景下对应设备的标识符,可以通过GetLocalNodeDeviceInfo获取
sptr<IRemoteObject> remoteObject = samgr->GetSystemAbility(saId, networkId); sptr<IRemoteObject> remoteObject = samgr->GetSystemAbility(saId, networkId);
sptr<TestAbilityProxy> proxy(new TestAbilityProxy(remoteObject)); // 直接构造具体Proxy sptr<TestAbilityProxy> proxy(new TestAbilityProxy(remoteObject)); // 直接构造具体Proxy
...@@ -180,59 +180,97 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信, ...@@ -180,59 +180,97 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信,
1. 添加依赖 1. 添加依赖
```ts ```ts
import rpc from "@ohos.rpc" import rpc from "@ohos.rpc";
import featureAbility from "@ohos.ability.featureAbility" // 仅FA模型需要导入@ohos.ability.featureAbility
// import featureAbility from "@ohos.ability.featureAbility";
``` ```
Stage模型需要获取context
```ts
import Ability from "@ohos.app.ability.UIAbility";
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
console.log("[Demo] MainAbility onCreate");
globalThis.context = this.context;
}
onDestroy() {
console.log("[Demo] MainAbility onDestroy");
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("[Demo] MainAbility onWindowStageCreate");
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log("[Demo] MainAbility onWindowStageDestroy");
}
onForeground() {
// Ability has brought to foreground
console.log("[Demo] MainAbility onForeground");
}
onBackground() {
// Ability has back to background
console.log("[Demo] MainAbility onBackground");
}
}
```
2. 绑定Ability 2. 绑定Ability
首先,构造变量want,指定要绑定的Ability所在应用的包名、组件名,如果是跨设备的场景,还需要绑定目标设备NetworkId(组网场景下对应设备的标识符,可以使用deviceManager获取目标设备的NetworkId);然后,构造变量connect,指定绑定成功、绑定失败、断开连接时的回调函数;最后,使用featureAbility提供的接口绑定Ability。 首先,构造变量want,指定要绑定的Ability所在应用的包名、组件名,如果是跨设备的场景,还需要绑定目标设备NetworkId(组网场景下对应设备的标识符,可以使用deviceManager获取目标设备的NetworkId);然后,构造变量connect,指定绑定成功、绑定失败、断开连接时的回调函数;最后,FA模型使用featureAbility提供的接口绑定Ability,Stage模型通过context获取服务后用提供的接口绑定Ability。
```ts ```ts
import rpc from "@ohos.rpc" import rpc from "@ohos.rpc";
import featureAbility from "@ohos.ability.featureAbility" // 仅FA模型需要导入@ohos.ability.featureAbility
// import featureAbility from "@ohos.ability.featureAbility";
let proxy = null
let connectId = null let proxy = null;
let connectId = null;
// 单个设备绑定Ability // 单个设备绑定Ability
let want = { let want = {
// 包名和组件名写实际的值 // 包名和组件名写实际的值
"bundleName": "ohos.rpc.test.server", "bundleName": "ohos.rpc.test.server",
"abilityName": "ohos.rpc.test.server.ServiceAbility", "abilityName": "ohos.rpc.test.server.ServiceAbility",
} };
let connect = { let connect = {
onConnect:function(elementName, remote) { onConnect:function(elementName, remote) {
proxy = remote proxy = remote;
}, },
onDisconnect:function(elementName) { onDisconnect:function(elementName) {
}, },
onFailed:function() { onFailed:function() {
proxy = null proxy = null;
} }
} };
connectId = featureAbility.connectAbility(want, connect) // FA模型使用此方法连接服务
// connectId = featureAbility.connectAbility(want, connect);
connectId = globalThis.context.connectServiceExtensionAbility(want,connect);
// 如果是跨设备绑定,可以使用deviceManager获取目标设备NetworkId // 如果是跨设备绑定,可以使用deviceManager获取目标设备NetworkId
import deviceManager from '@ohos.distributedHardware.deviceManager' import deviceManager from '@ohos.distributedHardware.deviceManager';
function deviceManagerCallback(deviceManager) { function deviceManagerCallback(deviceManager) {
let deviceList = deviceManager.getTrustedDeviceListSync() let deviceList = deviceManager.getTrustedDeviceListSync();
let networkId = deviceList[0].networkId let networkId = deviceList[0].networkId;
let want = { let want = {
"bundleName": "ohos.rpc.test.server", "bundleName": "ohos.rpc.test.server",
"abilityName": "ohos.rpc.test.service.ServiceAbility", "abilityName": "ohos.rpc.test.service.ServiceAbility",
"networkId": networkId, "networkId": networkId,
"flags": 256 "flags": 256
} };
connectId = featureAbility.connectAbility(want, connect) // 建立连接后返回的Id需要保存下来,在断开连接时需要作为参数传入
// FA模型使用此方法连接服务
// connectId = featureAbility.connectAbility(want, connect);
connectId = globalThis.context.connectServiceExtensionAbility(want,connect);
} }
// 第一个参数是本应用的包名,第二个参数是接收deviceManager的回调函数 // 第一个参数是本应用的包名,第二个参数是接收deviceManager的回调函数
deviceManager.createDeviceManager("ohos.rpc.test", deviceManagerCallback) deviceManager.createDeviceManager("ohos.rpc.test", deviceManagerCallback);
``` ```
3. 服务端处理客户端请求 3. 服务端处理客户端请求
...@@ -240,78 +278,80 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信, ...@@ -240,78 +278,80 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信,
```ts ```ts
onConnect(want: Want) { onConnect(want: Want) {
var robj:rpc.RemoteObject = new Stub("rpcTestAbility") var robj:rpc.RemoteObject = new Stub("rpcTestAbility");
return robj return robj;
} }
class Stub extends rpc.RemoteObject { class Stub extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor) super(descriptor);
} }
onRemoteMessageRequest(code, data, reply, option) { onRemoteMessageRequest(code, data, reply, option) {
// 根据code处理客户端的请求 // 根据code处理客户端的请求
return true return true;
} }
} }
``` ```
4. 客户端处理服务端响应 4. 客户端处理服务端响应
客户端在onConnect回调里接收到代理对象,调用sendRequestAsync方法发起请求,在期约(JavaScript期约:用于表示一个异步操作的最终完成或失败及其结果值)或者回调函数里接收结果。 客户端在onConnect回调里接收到代理对象,调用sendRequest方法发起请求,在期约(JavaScript期约:用于表示一个异步操作的最终完成或失败及其结果值)或者回调函数里接收结果。
```ts ```ts
// 使用期约 // 使用期约
let option = new rpc.MessageOption() let option = new rpc.MessageOption();
let data = rpc.MessageParcel.create() let data = rpc.MessageParcel.create();
let reply = rpc.MessageParcel.create() let reply = rpc.MessageParcel.create();
// 往data里写入参数 // 往data里写入参数
proxy.sendRequestAsync(1, data, reply, option) proxy.sendRequest(1, data, reply, option)
.then(function(result) { .then(function(result) {
if (result.errCode != 0) { if (result.errCode != 0) {
console.error("send request failed, errCode: " + result.errCode) console.error("send request failed, errCode: " + result.errCode);
return return;
} }
// 从result.reply里读取结果 // 从result.reply里读取结果
}) })
.catch(function(e) { .catch(function(e) {
console.error("send request got exception: " + e) console.error("send request got exception: " + e);
} })
.finally(() => { .finally(() => {
data.reclaim() data.reclaim();
reply.reclaim() reply.reclaim();
}) })
// 使用回调函数 // 使用回调函数
function sendRequestCallback(result) { function sendRequestCallback(result) {
try { try {
if (result.errCode != 0) { if (result.errCode != 0) {
console.error("send request failed, errCode: " + result.errCode) console.error("send request failed, errCode: " + result.errCode);
return return;
} }
// 从result.reply里读取结果 // 从result.reply里读取结果
} finally { } finally {
result.data.reclaim() result.data.reclaim();
result.reply.reclaim() result.reply.reclaim();
} }
} }
let option = new rpc.MessageOption() let option = new rpc.MessageOption();
let data = rpc.MessageParcel.create() let data = rpc.MessageParcel.create();
let reply = rpc.MessageParcel.create() let reply = rpc.MessageParcel.create();
// 往data里写入参数 // 往data里写入参数
proxy.sendRequest(1, data, reply, option, sendRequestCallback) proxy.sendRequest(1, data, reply, option, sendRequestCallback);
``` ```
5. 断开连接 5. 断开连接
IPC通信结束后,使用featureAbility的接口断开连接。 IPC通信结束后,FA模型使用featureAbility的接口断开连接,Stage模型在获取context后用提供的接口断开连接。
```ts ```ts
import rpc from "@ohos.rpc" import rpc from "@ohos.rpc";
import featureAbility from "@ohos.ability.featureAbility" // 仅FA模型需要导入@ohos.ability.featureAbility
// import featureAbility from "@ohos.ability.featureAbility";
function disconnectCallback() { function disconnectCallback() {
console.info("disconnect ability done") console.info("disconnect ability done");
} }
featureAbility.disconnectAbility(connectId, disconnectCallback) // FA模型使用此方法断开连接
// featureAbility.disconnectAbility(connectId, disconnectCallback);
globalThis.context.disconnectServiceExtensionAbility(connectId);
``` ```
...@@ -3,35 +3,25 @@ ...@@ -3,35 +3,25 @@
## 基本概念 ## 基本概念
IPC(Inter-Process Communication)与RPC(Remote Procedure Call)用于实现跨进程通信,不同的是前者使用Binder驱动,用于设备内的跨进程通信,后者使用软总线驱动,用于跨设备跨进程通信。需要跨进程通信的原因是因为每个进程都有自己独立的资源和内存空间,其他进程不能随意访问不同进程的内存和资源,IPC/RPC便是为了突破这一点。IPC和RPC通常采用客户端-服务器(Client-Server)模型,在使用时,请求服务的(Client)一端进程可获取提供服务(Server)一端所在进程的代理(Proxy),并通过此代理读写数据来实现进程间的数据通信,更具体的讲,首先请求服务的(Client)一端会建立一个服务提供端(Server)的代理对象,这个代理对象具备和服务提供端(Server)一样的功能,若想访问服务提供端(Server)中的某一个方法,只需访问代理对象中对应的方法即可,代理对象会将请求发送给服务提供端(Server);然后服务提供端(Server)处理接受到的请求,处理完之后通过驱动返回处理结果给代理对象;最后代理对象将请求结果进一步返回给请求服务端(Client)。通常,Server会先注册系统能力(System Ability)到系统能力管理者(System Ability Manager,缩写SAMgr)中,SAMgr负责管理这些SA并向Client提供相关的接口。Client要和某个具体的SA通信,必须先从SAMgr中获取该SA的代理,然后使用代理和SA通信。下文直接使用Proxy表示服务请求方,Stub表示服务提供方。 IPC(Inter-Process Communication)与RPC(Remote Procedure Call)用于实现跨进程通信,不同的是前者使用Binder驱动,用于设备内的跨进程通信,后者使用软总线驱动,用于跨设备跨进程通信。需要跨进程通信的原因是因为每个进程都有自己独立的资源和内存空间,其他进程不能随意访问不同进程的内存和资源,IPC/RPC便是为了突破这一点。
![IPC&RPC通信机制](figures/075sd302-aeb9-481a-bb8f-e552sdb61ead.PNG) > **说明:**
> Stage模型不能直接使用本文介绍的IPC和RPC,需要通过以下能力实现相关业务场景:
>- IPC典型使用场景为[后台服务](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/application-models/background-services.md),后台服务通过IPC机制提供跨进程的服务调用能力。
## 约束与限制 >- RPC典型使用场景为[多端协同](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/application-models/hop-multi-device-collaboration.md),多端协同通过RPC机制提供远端接口调用与数据传递。
- 单个设备上跨进程通信时,传输的数据量最大约为1MB,过大的数据量请使用[匿名共享内存](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-rpc.md#ashmem8)
- 不支持在RPC中订阅匿名Stub对象(没有向SAMgr注册Stub对象)的死亡通知。
- 不支持把跨设备的Proxy对象传递回该Proxy对象所指向的Stub对象所在的设备,即指向远端设备Stub的Proxy对象不能在本设备内进行二次跨进程传递。
## 使用建议
首先,需要编写接口类,接口类中必须定义消息码,供通信双方标识操作,可以有未实现的的方法,因为通信双方均需继承该接口类且双方不能是抽象类,所以此时定义的未实现的方法必须在双方继承时给出实现,这保证了继承双方不是抽象类。然后,需要编写Stub端相关类及其接口,并且实现AsObject方法及OnRemoteRequest方法。同时,也需要编写Proxy端,实现接口类中的方法和AsObject方法,也可以封装一些额外的方法用于调用SendRequest向对端发送数据。以上三者都具备后,便可以向SAMgr注册SA了,此时的注册应该在Stub所在进程完成。最后,在需要的地方从SAMgr中获取Proxy,便可通过Proxy实现与Stub的跨进程通信了。
相关步骤:
- 实现接口类:需继承IRemoteBroker,需定义消息码,可声明不在此类实现的方法。 ## 实现原理
- 实现服务提供端(Stub):需继承IRemoteStub或者RemoteObject,需重写AsObject方法及OnRemoteRequest方法 IPC和RPC通常采用客户端-服务器(Client-Server)模型,在使用时,请求服务的(Client)一端进程可获取提供服务(Server)一端所在进程的代理(Proxy),并通过此代理读写数据来实现进程间的数据通信,更具体的讲,首先请求服务的(Client)一端会建立一个服务提供端(Server)的代理对象,这个代理对象具备和服务提供端(Server)一样的功能,若想访问服务提供端(Server)中的某一个方法,只需访问代理对象中对应的方法即可,代理对象会将请求发送给服务提供端(Server);然后服务提供端(Server)处理接受到的请求,处理完之后通过驱动返回处理结果给代理对象;最后代理对象将请求结果进一步返回给请求服务端(Client)。通常,Server会先注册系统能力(System Ability)到系统能力管理者(System Ability Manager,缩写SAMgr)中,SAMgr负责管理这些SA并向Client提供相关的接口。Client要和某个具体的SA通信,必须先从SAMgr中获取该SA的代理,然后使用代理和SA通信。下文直接使用Proxy表示服务请求方,Stub表示服务提供方
- 实现服务请求端(Proxy):需继承IRemoteProxy或RemoteProxy,需重写AsObject方法,封装所需方法调用SendRequest。 ![IPC&RPC通信机制](figures/075sd302-aeb9-481a-bb8f-e552sdb61ead.PNG)
- 注册SA:申请SA的唯一ID,向SAMgr注册SA。
- 获取SA:通过SA的ID和设备ID获取Proxy,使用Proxy与远端通信 ## 约束与限制
- 单个设备上跨进程通信时,传输的数据量最大约为1MB,过大的数据量请使用[匿名共享内存](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-rpc.md#ashmem8)
## 相关模块 - 不支持在RPC中订阅匿名Stub对象(没有向SAMgr注册Stub对象)的死亡通知。
[分布式任务调度子系统](https://gitee.com/openharmony/ability_dmsfwk) - 不支持把跨设备的Proxy对象传递回该Proxy对象所指向的Stub对象所在的设备,即指向远端设备Stub的Proxy对象不能在本设备内进行二次跨进程传递。
\ No newline at end of file
# 远端状态订阅开发实例 # 远端状态订阅开发实例
IPC/RPC提供对远端Stub对象状态的订阅机制, 在远端Stub对象消亡时,可触发消亡通知告诉本地Proxy对象。这种状态通知订阅需要调用特定接口完成,当不再需要订阅时也需要调用特定接口取消。使用这种订阅机制的用户,需要实现消亡通知接口DeathRecipient并实现onRemoteDied方法清理资源。该方法会在远端Stub对象所在进程消亡或所在设备离开组网时被回调。值得注意的是,调用这些接口有一定的顺序。首先,需要Proxy订阅Stub消亡通知,若在订阅期间Stub状态正常,则在不再需要时取消订阅;若在订阅期间Stub所在进程退出或者所在设备退出组网,则会自动触发Proxy自定义的后续操作。 IPC/RPC提供对远端Stub对象状态的订阅机制,在远端Stub对象消亡时,可触发消亡通知告诉本地Proxy对象。这种状态通知订阅需要调用特定接口完成,当不再需要订阅时也需要调用特定接口取消。使用这种订阅机制的用户,需要实现消亡通知接口DeathRecipient并实现onRemoteDied方法清理资源。该方法会在远端Stub对象所在进程消亡或所在设备离开组网时被回调。值得注意的是,调用这些接口有一定的顺序。首先,需要Proxy订阅Stub消亡通知,若在订阅期间Stub状态正常,则在不再需要时取消订阅;若在订阅期间Stub所在进程退出或者所在设备退出组网,则会自动触发Proxy自定义的后续操作。
## 使用场景 ## 使用场景
...@@ -21,7 +21,6 @@ IPC/RPC提供对远端Stub对象状态的订阅机制, 在远端Stub对象消 ...@@ -21,7 +21,6 @@ IPC/RPC提供对远端Stub对象状态的订阅机制, 在远端Stub对象消
#include "iremote_broker.h" #include "iremote_broker.h"
#include "iremote_stub.h" #include "iremote_stub.h"
//定义消息码 //定义消息码
enum { enum {
TRANS_ID_PING_ABILITY = 5, TRANS_ID_PING_ABILITY = 5,
...@@ -61,9 +60,6 @@ int TestServiceProxy::TestPingAbility(const std::u16string &dummy){ ...@@ -61,9 +60,6 @@ int TestServiceProxy::TestPingAbility(const std::u16string &dummy){
} }
``` ```
```c++ ```c++
#include "iremote_object.h" #include "iremote_object.h"
...@@ -86,16 +82,52 @@ result = object->RemoveDeathRecipient(deathRecipient); // 移除消亡通知 ...@@ -86,16 +82,52 @@ result = object->RemoveDeathRecipient(deathRecipient); // 移除消亡通知
## JS侧接口 ## JS侧接口
| 接口名 | 返回值类型 | 功能描述 | | 接口名 | 返回值类型 | 功能描述 |
| -------------------- | ---------- | ------------------------------------------------------------ | | ------------------------ | ---------- | ----------------------------------------------------------------- |
| addDeathRecippient | boolean | 注册用于接收远程对象消亡通知的回调,增加proxy对象上的消亡通知。 | | registerDeathRecipient | void | 注册用于接收远程对象消亡通知的回调,增加 proxy 对象上的消亡通知。 |
| removeDeathRecipient | boolean | 注销用于接收远程对象消亡通知的回调。 | | unregisterDeathRecipient | void | 注销用于接收远程对象消亡通知的回调。 |
| onRemoteDied | void | 在成功添加死亡通知订阅后,当远端对象死亡时,将自动调用本方法。 | | onRemoteDied | void | 在成功添加死亡通知订阅后,当远端对象死亡时,将自动调用本方法。 |
### 获取context
Stage模型在连接服务前需要先获取context
```ts
import Ability from "@ohos.app.ability.UIAbility";
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
console.log("[Demo] MainAbility onCreate");
globalThis.context = this.context;
}
onDestroy() {
console.log("[Demo] MainAbility onDestroy");
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("[Demo] MainAbility onWindowStageCreate");
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log("[Demo] MainAbility onWindowStageDestroy");
}
onForeground() {
// Ability has brought to foreground
console.log("[Demo] MainAbility onForeground");
}
onBackground() {
// Ability has back to background
console.log("[Demo] MainAbility onBackground");
}
}
```
### 参考代码 ### 参考代码
```ts ```ts
import FA from "@ohos.ability.featureAbility"; // 仅FA模型需要导入@ohos.ability.featureAbility
// import FA from "@ohos.ability.featureAbility";
let proxy; let proxy;
let connect = { let connect = {
onConnect: function(elementName, remoteProxy) { onConnect: function(elementName, remoteProxy) {
...@@ -113,15 +145,19 @@ let want = { ...@@ -113,15 +145,19 @@ let want = {
"bundleName": "com.ohos.server", "bundleName": "com.ohos.server",
"abilityName": "com.ohos.server.EntryAbility", "abilityName": "com.ohos.server.EntryAbility",
}; };
FA.connectAbility(want, connect); // FA模型通过此方法连接服务
// FA.connectAbility(want, connect);
globalThis.context.connectServiceExtensionAbility(want, connect);
class MyDeathRecipient { class MyDeathRecipient {
onRemoteDied() { onRemoteDied() {
console.log("server died"); console.log("server died");
} }
} }
let deathRecipient = new MyDeathRecipient(); let deathRecipient = new MyDeathRecipient();
proxy.addDeathRecippient(deathRecipient, 0); proxy.registerDeathRecippient(deathRecipient, 0);
proxy.removeDeathRecipient(deathRecipient, 0); proxy.unregisterDeathRecipient(deathRecipient, 0);
``` ```
## Stub感知Proxy消亡(匿名Stub的使用) ## Stub感知Proxy消亡(匿名Stub的使用)
......
...@@ -167,4 +167,4 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例 ...@@ -167,4 +167,4 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
针对USB管理开发,有以下相关实例可供参考: 针对USB管理开发,有以下相关实例可供参考:
- [`USBManager`:USB管理(ArkTS)(API9)](https://gitee.com/openharmony/applications_app_samples/tree/master/code/BasicFeature/DeviceManagement/USBManager) - [`DeviceManagementCollection`:设备管理合集(ArkTS)(API9)](https://gitee.com/openharmony/applications_app_samples/tree/master/code/BasicFeature/DeviceManagement/DeviceManagementCollection)
\ No newline at end of file \ No newline at end of file
# Stage模型应用程序包结构 # Stage模型应用程序包结构
基于[Stage模型](application-configuration-file-overview-stage.md)开发的应用,经编译打包后,其应用程序包结构如下图**应用程序包结构(Stage模型)**所示。开发者需要熟悉应用程序包结构相关的基本概念。 基于[Stage模型](application-configuration-file-overview-stage.md)开发的应用,经编译打包后,其应用程序包结构如下图“应用程序包结构(Stage模型)”所示。开发者需要熟悉应用程序包结构相关的基本概念。
- 在开发态,一个应用包含一个或者多个Module,可以在[DevEco Studio](https://developer.harmonyos.com/cn/develop/deveco-studio/)工程中[创建一个或者多个Module](https://developer.harmonyos.com/cn/docs/documentation/doc-guides-V3/ohos-adding-deleting-module-0000001218760594-V3)。Module是OpenHarmony应用/服务的基本功能单元,包含了源代码、资源文件、第三方库及应用/服务配置文件,每一个Module都可以独立进行编译和运行。Module分为“Ability”和“Library”两种类型,“Ability”类型的Module对应于编译后的HAP(Harmony Ability Package);“Library”类型的Module对应于[HAR](har-package.md)(Harmony Archive),或者[HSP](shared-guide.md)(Harmony Shared Package)。 - 在开发态,一个应用包含一个或者多个Module,可以在[DevEco Studio](https://developer.harmonyos.com/cn/develop/deveco-studio/)工程中[创建一个或者多个Module](https://developer.harmonyos.com/cn/docs/documentation/doc-guides-V3/add_new_module-0000001053223741-V3)。Module是OpenHarmony应用/服务的基本功能单元,包含了源代码、资源文件、第三方库及应用/服务配置文件,每一个Module都可以独立进行编译和运行。Module分为“Ability”和“Library”两种类型,“Ability”类型的Module对应于编译后的HAP(Harmony Ability Package);“Library”类型的Module对应于[HAR](har-package.md)(Harmony Archive),或者[HSP](shared-guide.md)(Harmony Shared Package)。
一个Module可以包含一个或多个[UIAbility](../application-models/uiability-overview.md)组件,如**Module与UIAbility组件关系示意图**所示。 一个Module可以包含一个或多个[UIAbility](../application-models/uiability-overview.md)组件,如**Module与UIAbility组件关系示意图**所示。
**图1** Module与UIAbility组件关系示意图 **图1** Module与UIAbility组件关系示意图
......
...@@ -228,66 +228,6 @@ deviceTypes示例: ...@@ -228,66 +228,6 @@ deviceTypes示例:
abilities标签描述UIAbility组件的配置信息,标签值为数组类型,该标签下的配置只对当前UIAbility生效。 abilities标签描述UIAbility组件的配置信息,标签值为数组类型,该标签下的配置只对当前UIAbility生效。
**OpenHarmony中不允许应用隐藏入口图标**
OpenHarmony系统对无图标应用严格管控。如果HAP中没有配置入口图标,那么系统将应用app.json中的icon作为入口图标,并显示在桌面上。<br>
用户点击该图标,将跳转到设置应用管理中对应的应用详情页面(图1)中。<br>
如果应用想要隐藏入口图标,需要配置AllowAppDesktopIconHide应用特权,具体配置方式参考[应用特权配置指南](../../device-dev/subsystems/subsys-app-privilege-config-guide.md)
**场景说明:** 该功能能防止一些恶意应用,故意配置无入口图标,导致用户找不到软件所在的位置,无法操作卸载应用,在一定程度上保证用户的手机安全
**入口图标的设置:** 需要在配置文件(module.json5)中abilities配置下设置icon,label以及skills,而且skills的配置下的必须同时包含“ohos.want.action.home” 和 “entity.system.home”:
```
{
"module":{
...
"abilities": [{
"icon": "$media:icon",
"label": "Login",
"skills": [{
"actions": ["ohos.want.action.home"],
"entities": ["entity.system.home"],
"uris": []
}]
}],
...
}
}
```
**入口图标及入口标签的显示规则**
* HAP中包含UIAbility
* 配置文件(module.json5)中abilities配置中设置了入口图标
* 该应用没有隐藏图标的特权
* 显示桌面图标为该UIAbility配置的图标
* 显示桌面Label为该UIAbility配置的Label(如果没有配置Label,返回包名)
* 显示组件名为该UIAbility的组件名
* 用户点击该桌面图标,页面跳转到该UIAbility首页
* 该应用具有隐藏图标的特权
* 桌面查询时不返回应用信息,不会在桌面上显示对应的图标。
* 配置文件(module.json5)中abilities配置中未设置入口图标
* 该应用没有隐藏图标的特权
* 显示桌面图标为app配置下的图标(app.json中icon为必填项)
* 显示桌面Label为app配置下的label(app.json中label为必填项)
* 用户点击该桌面图标,页面跳转到该应用的详情页面(图1)
* 该应用具有隐藏图标的特权
* 桌面查询时不返回应用信息,不会在桌面上显示对应的图标。
* HAP中不包含UIAbility
* 该应用没有隐藏图标的特权
* 显示桌面图标为app配置下的图标(app.json中icon为必填项)
* 显示桌面Label为app配置下的label(app.json中label为必填项)
* 用户点击该桌面图标,页面跳转到该应用的详情页面(图1)
* 该应用具有隐藏图标的特权
* 桌面查询时不返回应用信息,不会在桌面上显示对应的图标。<br><br>
应用的详情页例图
![应用的详情页例图](figures/application_details.jpg)
**表6** **abilities标签说明** **表6** **abilities标签说明**
| 属性名称 | 含义 | 数据类型 | 是否可缺省 | | 属性名称 | 含义 | 数据类型 | 是否可缺省 |
......
...@@ -120,6 +120,7 @@ ...@@ -120,6 +120,7 @@
- [@ohos.events.emitter (Emitter)](js-apis-emitter.md) - [@ohos.events.emitter (Emitter)](js-apis-emitter.md)
- [@ohos.notificationManager (NotificationManager模块)(推荐)](js-apis-notificationManager.md) - [@ohos.notificationManager (NotificationManager模块)(推荐)](js-apis-notificationManager.md)
- [@ohos.notificationSubscribe (NotificationSubscribe模块)(推荐)](js-apis-notificationSubscribe.md) - [@ohos.notificationSubscribe (NotificationSubscribe模块)(推荐)](js-apis-notificationSubscribe.md)
- [@ohos.application.StaticSubscriberExtensionContext (NotificationSubscribe模块)(推荐)](js-apis-application-StaticSubscriberExtensionContext.md)
- [系统公共事件定义 (待停用)](commonEvent-definitions.md) - [系统公共事件定义 (待停用)](commonEvent-definitions.md)
- [@ohos.commonEvent (公共事件模块)(待停用)](js-apis-commonEvent.md) - [@ohos.commonEvent (公共事件模块)(待停用)](js-apis-commonEvent.md)
- [@ohos.notification (Notification模块)(待停用)](js-apis-notification.md) - [@ohos.notification (Notification模块)(待停用)](js-apis-notification.md)
......
...@@ -7,6 +7,12 @@ ...@@ -7,6 +7,12 @@
> 本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块接口仅可在Stage模型下使用。 > 本模块接口仅可在Stage模型下使用。
## 导入模块
```ts
import Ability from '@ohos.app.ability.Ability';
```
## Ability.onConfigurationUpdate ## Ability.onConfigurationUpdate
onConfigurationUpdate(newConfig: Configuration): void; onConfigurationUpdate(newConfig: Configuration): void;
......
...@@ -30,7 +30,7 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant'; ...@@ -30,7 +30,7 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant';
Ability初次启动原因,该类型为枚举,可配合[Ability](js-apis-app-ability-uiAbility.md)[onCreate(want, launchParam)](js-apis-app-ability-uiAbility.md#uiabilityoncreate)方法根据launchParam.launchReason的不同类型执行相应操作。 Ability初次启动原因,该类型为枚举,可配合[Ability](js-apis-app-ability-uiAbility.md)[onCreate(want, launchParam)](js-apis-app-ability-uiAbility.md#uiabilityoncreate)方法根据launchParam.launchReason的不同类型执行相应操作。
**系统能力**以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core **系统能力**:SystemCapability.Ability.AbilityRuntime.Core
| 名称 | 值 | 说明 | | 名称 | 值 | 说明 |
| ----------------------------- | ---- | ------------------------------------------------------------ | | ----------------------------- | ---- | ------------------------------------------------------------ |
...@@ -59,7 +59,7 @@ class MyAbility extends UIAbility { ...@@ -59,7 +59,7 @@ class MyAbility extends UIAbility {
Ability上次退出原因,该类型为枚举,可配合[Ability](js-apis-app-ability-uiAbility.md)[onCreate(want, launchParam)](js-apis-app-ability-uiAbility.md#uiabilityoncreate)方法根据launchParam.lastExitReason的不同类型执行相应操作。 Ability上次退出原因,该类型为枚举,可配合[Ability](js-apis-app-ability-uiAbility.md)[onCreate(want, launchParam)](js-apis-app-ability-uiAbility.md#uiabilityoncreate)方法根据launchParam.lastExitReason的不同类型执行相应操作。
**系统能力**以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core **系统能力**:SystemCapability.Ability.AbilityRuntime.Core
| 名称 | 值 | 说明 | | 名称 | 值 | 说明 |
| ----------------------------- | ---- | ------------------------------------------------------------ | | ----------------------------- | ---- | ------------------------------------------------------------ |
...@@ -85,7 +85,7 @@ class MyAbility extends UIAbility { ...@@ -85,7 +85,7 @@ class MyAbility extends UIAbility {
Ability迁移结果,该类型为枚举,可配合[Ability](js-apis-app-ability-uiAbility.md)[onContinue(wantParam)](js-apis-app-ability-uiAbility.md#uiabilityoncontinue)方法进完成相应的返回。 Ability迁移结果,该类型为枚举,可配合[Ability](js-apis-app-ability-uiAbility.md)[onContinue(wantParam)](js-apis-app-ability-uiAbility.md#uiabilityoncontinue)方法进完成相应的返回。
**系统能力**以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core **系统能力**:SystemCapability.Ability.AbilityRuntime.Core
| 名称 | 值 | 说明 | | 名称 | 值 | 说明 |
| ----------------------------- | ---- | ------------------------------------------------------------ | | ----------------------------- | ---- | ------------------------------------------------------------ |
......
...@@ -412,7 +412,7 @@ acquireShareData(missionId: number, callback: AsyncCallback<{[key: string]: Obje ...@@ -412,7 +412,7 @@ acquireShareData(missionId: number, callback: AsyncCallback<{[key: string]: Obje
```ts ```ts
import abilityManager from '@ohos.app.ability.abilityManager'; import abilityManager from '@ohos.app.ability.abilityManager';
abilityManager.acquireShareData(1, (err, wantParam) => { abilityManager.acquireShareData(1, (err, data) => {
if (err) { if (err) {
console.error(`acquireShareData fail, err: ${JSON.stringify(err)}`); console.error(`acquireShareData fail, err: ${JSON.stringify(err)}`);
} else { } else {
...@@ -449,7 +449,7 @@ acquireShareData(missionId: number): Promise<{[key: string]: Object}>; ...@@ -449,7 +449,7 @@ acquireShareData(missionId: number): Promise<{[key: string]: Object}>;
```ts ```ts
import abilityManager from '@ohos.app.ability.abilityManager'; import abilityManager from '@ohos.app.ability.abilityManager';
try { try {
abilityManager.acquireShareData(1).then((wantParam) => { abilityManager.acquireShareData(1).then((data) => {
console.log(`acquireShareData success, data: ${JSON.stringify(data)}`); console.log(`acquireShareData success, data: ${JSON.stringify(data)}`);
}).catch((err) => { }).catch((err) => {
console.error(`acquireShareData fail, err: ${JSON.stringify(err)}`); console.error(`acquireShareData fail, err: ${JSON.stringify(err)}`);
......
...@@ -669,7 +669,11 @@ killProcessWithAccount(bundleName: string, accountId: number): Promise\<void\> ...@@ -669,7 +669,11 @@ killProcessWithAccount(bundleName: string, accountId: number): Promise\<void\>
切断account进程(Promise形式)。 切断account进程(Promise形式)。
**需要权限**:ohos.permission.CLEAN_BACKGROUND_PROCESSES,ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS权限。 > **说明:**
>
> 当accountId为当前用户时,不需要校验ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS权限。
**需要权限**:ohos.permission.CLEAN_BACKGROUND_PROCESSES,ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core **系统能力**:SystemCapability.Ability.AbilityRuntime.Core
...@@ -715,12 +719,16 @@ killProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCal ...@@ -715,12 +719,16 @@ killProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCal
切断account进程(callback形式)。 切断account进程(callback形式)。
> **说明:**
>
> 当accountId为当前用户时,不需要校验ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS权限。
**需要权限**:ohos.permission.CLEAN_BACKGROUND_PROCESSES,ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core **系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**系统API**: 此接口为系统接口,三方应用不支持调用。 **系统API**: 此接口为系统接口,三方应用不支持调用。
**需要权限**:ohos.permission.CLEAN_BACKGROUND_PROCESSES,ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS权限。
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
......
...@@ -173,9 +173,17 @@ saveAppState(context?: UIAbilityContext): boolean; ...@@ -173,9 +173,17 @@ saveAppState(context?: UIAbilityContext): boolean;
```ts ```ts
import appRecovery from '@ohos.app.ability.appRecovery'; import appRecovery from '@ohos.app.ability.appRecovery';
onBackground() { let observer = {
hilog.info(0x0000, '[demo]', '%{public}s', 'EntryAbility onBackground'); onUnhandledException(errorMsg) {
appRecovery.saveAppState(this.context) console.log('onUnhandledException, errorMsg: ', errorMsg);
appRecovery.saveAppState(this.context);
}
};
try {
errorManager.on('error', observer);
} catch (paramError) {
console.error('error: ${paramError.code}, ${paramError.message}');
} }
``` ```
......
...@@ -6,6 +6,12 @@ ...@@ -6,6 +6,12 @@
> >
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
```ts
import Configuration from '@ohos.app.ability.Configuration';
```
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityBase **系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityBase
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
......
...@@ -22,7 +22,7 @@ getId(uri: string): number ...@@ -22,7 +22,7 @@ getId(uri: string): number
**参数:** **参数:**
| 名称 | 类型 | 必填 | 描述 | | 参数名 | 类型 | 必填 | 说明 |
| ---- | ------ | ---- | --------------------------- | | ---- | ------ | ---- | --------------------------- |
| uri | string | 是 | 表示uri对象。 | | uri | string | 是 | 表示uri对象。 |
...@@ -55,7 +55,7 @@ attachId(uri: string, id: number): string ...@@ -55,7 +55,7 @@ attachId(uri: string, id: number): string
**参数:** **参数:**
| 名称 | 类型 | 必填 | 描述 | | 参数名 | 类型 | 必填 | 说明 |
| ---- | ------ | ---- | --------------------------- | | ---- | ------ | ---- | --------------------------- |
| uri | string | 是 | 表示uri对象。 | | uri | string | 是 | 表示uri对象。 |
| id | number | 是 | 表示要附加的ID。 | | id | number | 是 | 表示要附加的ID。 |
...@@ -94,7 +94,7 @@ deleteId(uri: string): string ...@@ -94,7 +94,7 @@ deleteId(uri: string): string
**参数:** **参数:**
| 名称 | 类型 | 必填 | 描述 | | 参数名 | 类型 | 必填 | 说明 |
| ---- | ------ | ---- | --------------------------- | | ---- | ------ | ---- | --------------------------- |
| uri | string | 是 | 表示要从中删除ID的uri对象。 | | uri | string | 是 | 表示要从中删除ID的uri对象。 |
...@@ -128,7 +128,7 @@ updateId(uri: string, id: number): string ...@@ -128,7 +128,7 @@ updateId(uri: string, id: number): string
**参数:** **参数:**
| 名称 | 类型 | 必填 | 描述 | | 参数名 | 类型 | 必填 | 说明 |
| ---- | ------ | ---- | ------------------- | | ---- | ------ | ---- | ------------------- |
| uri | string | 是 | 表示uri对象 | | uri | string | 是 | 表示uri对象 |
| id | number | 是 | 表示要更新的ID | | id | number | 是 | 表示要更新的ID |
......
...@@ -24,7 +24,7 @@ getRequestInfo(want: Want): RequestInfo ...@@ -24,7 +24,7 @@ getRequestInfo(want: Want): RequestInfo
**参数:** **参数:**
| 名称 | 类型 | 必填 | 描述 | | 参数名 | 类型 | 必填 | 说明 |
| ---- | ------ | ---- | --------------------------- | | ---- | ------ | ---- | --------------------------- |
| want | [Want](js-apis-application-want.md) | 是 | 表示发起方请求弹框时传入的want信息。 | | want | [Want](js-apis-application-want.md) | 是 | 表示发起方请求弹框时传入的want信息。 |
...@@ -41,32 +41,71 @@ getRequestInfo(want: Want): RequestInfo ...@@ -41,32 +41,71 @@ getRequestInfo(want: Want): RequestInfo
import rpc from '@ohos.rpc'; import rpc from '@ohos.rpc';
import dialogRequest from '@ohos.app.ability.dialogRequest'; import dialogRequest from '@ohos.app.ability.dialogRequest';
export default class ServiceExtAbility extends ServiceExtensionAbility { const REQUEST_VALUE = 1;
onCreate(want) {
console.info(TAG, `onCreate, want: ${want.abilityName}`);
}
onRequest(want, startId) { class StubTest extends rpc.RemoteObject {
console.info(TAG, `onRequest, want: ${want.abilityName}`); constructor(des) {
try { super(des);
var requestInfo = dialogRequest.getRequestInfo(want); }
} catch(err) {
console.error('getRequestInfo err= ${JSON.stringify(err)}'); onRemoteRequest(code, data, reply, option) {
if (code === REQUEST_VALUE) {
let optFir = data.readInt();
let optSec = data.readInt();
reply.writeInt(optFir + optSec);
} }
} return true;
}
queryLocallInterface(descriptor) {
return null;
}
getInterfaceDescriptor() {
return "";
}
getCallingPid() {
return REQUEST_VALUE;
}
getCallingUid() {
return REQUEST_VALUE;
}
attachLocalInterface(localInterface, descriptor) {
}
}
let TAG = "getRequestInfoTest";
export default class ServiceExtAbility extends ServiceExtensionAbility {
onCreate(want) {
console.info(TAG, `onCreate, want: ${want.abilityName}`);
}
onRequest(want, startId) {
console.info(TAG, `onRequest, want: ${want.abilityName}`);
try {
var requestInfo = dialogRequest.getRequestInfo(want);
} catch (err) {
console.error('getRequestInfo err= ${JSON.stringify(err)}');
}
}
onConnect(want) { onConnect(want) {
console.info(TAG, `onConnect, want: ${want.abilityName}`); console.info(TAG, `onConnect, want: ${want.abilityName}`);
} return new StubTest("test");
}
onDisconnect(want) { onDisconnect(want) {
console.info(TAG, `onDisconnect, want: ${want.abilityName}`); console.info(TAG, `onDisconnect, want: ${want.abilityName}`);
} }
onDestroy() { onDestroy() {
console.info(TAG, `onDestroy`); console.info(TAG, `onDestroy`);
} }
} }
``` ```
## dialogRequest.getRequestCallback ## dialogRequest.getRequestCallback
...@@ -79,7 +118,7 @@ getRequestCallback(want: Want): RequestCallback ...@@ -79,7 +118,7 @@ getRequestCallback(want: Want): RequestCallback
**参数:** **参数:**
| 名称 | 类型 | 必填 | 描述 | | 参数名 | 类型 | 必填 | 说明 |
| ---- | ------ | ---- | --------------------------- | | ---- | ------ | ---- | --------------------------- |
| want | [Want](js-apis-application-want.md) | 是 | 表示发起方请求弹框时传入的want信息。 | | want | [Want](js-apis-application-want.md) | 是 | 表示发起方请求弹框时传入的want信息。 |
...@@ -95,6 +134,44 @@ getRequestCallback(want: Want): RequestCallback ...@@ -95,6 +134,44 @@ getRequestCallback(want: Want): RequestCallback
import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility'; import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility';
import rpc from '@ohos.rpc'; import rpc from '@ohos.rpc';
import dialogRequest from '@ohos.app.ability.dialogRequest'; import dialogRequest from '@ohos.app.ability.dialogRequest';
let TAG = "getRequestCallbackTest";
const REQUEST_VALUE = 1;
class StubTest extends rpc.RemoteObject {
constructor(des) {
super(des);
}
onRemoteRequest(code, data, reply, option) {
if (code === REQUEST_VALUE) {
let optFir = data.readInt();
let optSec = data.readInt();
reply.writeInt(optFir + optSec);
}
return true;
}
queryLocallInterface(descriptor) {
return null;
}
getInterfaceDescriptor() {
return "";
}
getCallingPid() {
return REQUEST_VALUE;
}
getCallingUid() {
return REQUEST_VALUE;
}
attachLocalInterface(localInterface, descriptor) {
}
}
export default class ServiceExtAbility extends ServiceExtensionAbility { export default class ServiceExtAbility extends ServiceExtensionAbility {
onCreate(want) { onCreate(want) {
...@@ -112,6 +189,7 @@ getRequestCallback(want: Want): RequestCallback ...@@ -112,6 +189,7 @@ getRequestCallback(want: Want): RequestCallback
onConnect(want) { onConnect(want) {
console.info(TAG, `onConnect, want: ${want.abilityName}`); console.info(TAG, `onConnect, want: ${want.abilityName}`);
return new StubTest("test");
} }
onDisconnect(want) { onDisconnect(want) {
...@@ -127,7 +205,7 @@ getRequestCallback(want: Want): RequestCallback ...@@ -127,7 +205,7 @@ getRequestCallback(want: Want): RequestCallback
## RequestInfo ## RequestInfo
表示发起方请求信息,作为窗口绑定模态弹框的入参。 表示发起方请求信息,作为窗口绑定模态弹框的入参。
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore **系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**示例:** **示例:**
...@@ -136,6 +214,44 @@ getRequestCallback(want: Want): RequestCallback ...@@ -136,6 +214,44 @@ getRequestCallback(want: Want): RequestCallback
import rpc from '@ohos.rpc'; import rpc from '@ohos.rpc';
import dialogRequest from '@ohos.app.ability.dialogRequest'; import dialogRequest from '@ohos.app.ability.dialogRequest';
import window from '@ohos.window'; import window from '@ohos.window';
let TAG = "RequestInfoTest";
const REQUEST_VALUE = 1;
class StubTest extends rpc.RemoteObject {
constructor(des) {
super(des);
}
onRemoteRequest(code, data, reply, option) {
if (code === REQUEST_VALUE) {
let optFir = data.readInt();
let optSec = data.readInt();
reply.writeInt(optFir + optSec);
}
return true;
}
queryLocallInterface(descriptor) {
return null;
}
getInterfaceDescriptor() {
return "";
}
getCallingPid() {
return REQUEST_VALUE;
}
getCallingUid() {
return REQUEST_VALUE;
}
attachLocalInterface(localInterface, descriptor) {
}
}
export default class ServiceExtAbility extends ServiceExtensionAbility { export default class ServiceExtAbility extends ServiceExtensionAbility {
onCreate(want) { onCreate(want) {
...@@ -162,6 +278,8 @@ getRequestCallback(want: Want): RequestCallback ...@@ -162,6 +278,8 @@ getRequestCallback(want: Want): RequestCallback
onConnect(want) { onConnect(want) {
console.info(TAG, `onConnect, want: ${want.abilityName}`); console.info(TAG, `onConnect, want: ${want.abilityName}`);
return new StubTest("test");
} }
onDisconnect(want) { onDisconnect(want) {
...@@ -178,9 +296,9 @@ getRequestCallback(want: Want): RequestCallback ...@@ -178,9 +296,9 @@ getRequestCallback(want: Want): RequestCallback
模态弹框请求结果码。 模态弹框请求结果码。
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore。 **系统能力**:SystemCapability.Ability.AbilityRuntime.Core
| 名称 | 值 | 说明 | | 参数名 | 值 | 说明 |
| ------------ | ------------------ | ---------------------- | | ------------ | ------------------ | ---------------------- |
| RESULT_OK | 0 | 表示成功。 | | RESULT_OK | 0 | 表示成功。 |
| RESULT_CANCEL | 1 | 表示失败。 | | RESULT_CANCEL | 1 | 表示失败。 |
...@@ -190,7 +308,7 @@ getRequestCallback(want: Want): RequestCallback ...@@ -190,7 +308,7 @@ getRequestCallback(want: Want): RequestCallback
## 属性 ## 属性
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore **系统能力**:SystemCapability.Ability.AbilityRuntime.Core
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
...@@ -206,7 +324,7 @@ setRequestResult(result: RequestResult): void; ...@@ -206,7 +324,7 @@ setRequestResult(result: RequestResult): void;
设置请求结果 设置请求结果
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore **系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:** **参数:**
...@@ -228,6 +346,44 @@ setRequestResult(result: RequestResult): void; ...@@ -228,6 +346,44 @@ setRequestResult(result: RequestResult): void;
import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility'; import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility';
import rpc from '@ohos.rpc'; import rpc from '@ohos.rpc';
import dialogRequest from '@ohos.app.ability.dialogRequest'; import dialogRequest from '@ohos.app.ability.dialogRequest';
let TAG = "setRequestResultTest";
const REQUEST_VALUE = 1;
class StubTest extends rpc.RemoteObject {
constructor(des) {
super(des);
}
onRemoteRequest(code, data, reply, option) {
if (code === REQUEST_VALUE) {
let optFir = data.readInt();
let optSec = data.readInt();
reply.writeInt(optFir + optSec);
}
return true;
}
queryLocallInterface(descriptor) {
return null;
}
getInterfaceDescriptor() {
return "";
}
getCallingPid() {
return REQUEST_VALUE;
}
getCallingUid() {
return REQUEST_VALUE;
}
attachLocalInterface(localInterface, descriptor) {
}
}
export default class ServiceExtAbility extends ServiceExtensionAbility { export default class ServiceExtAbility extends ServiceExtensionAbility {
onCreate(want) { onCreate(want) {
...@@ -249,6 +405,7 @@ setRequestResult(result: RequestResult): void; ...@@ -249,6 +405,7 @@ setRequestResult(result: RequestResult): void;
onConnect(want) { onConnect(want) {
console.info(TAG, `onConnect, want: ${want.abilityName}`); console.info(TAG, `onConnect, want: ${want.abilityName}`);
return new StubTest("test");
} }
onDisconnect(want) { onDisconnect(want) {
......
...@@ -45,8 +45,7 @@ onMemoryLevel(level: AbilityConstant.MemoryLevel): void; ...@@ -45,8 +45,7 @@ onMemoryLevel(level: AbilityConstant.MemoryLevel): void;
**示例:** **示例:**
```ts
```ts
import UIAbility from '@ohos.app.ability.Ability'; import UIAbility from '@ohos.app.ability.Ability';
let callbackId; let callbackId;
...@@ -58,7 +57,7 @@ export default class MyAbility extends UIAbility { ...@@ -58,7 +57,7 @@ export default class MyAbility extends UIAbility {
let environmentCallback = { let environmentCallback = {
onConfigurationUpdated(config){ onConfigurationUpdated(config){
console.log('onConfigurationUpdated config: ${JSON.stringify(config)}'); console.log('onConfigurationUpdated config: ${JSON.stringify(config)}');
} },
onMemoryLevel(level){ onMemoryLevel(level){
console.log('onMemoryLevel level: ${JSON.stringify(level)}'); console.log('onMemoryLevel level: ${JSON.stringify(level)}');
...@@ -81,4 +80,4 @@ export default class MyAbility extends UIAbility { ...@@ -81,4 +80,4 @@ export default class MyAbility extends UIAbility {
}); });
} }
} }
``` ```
\ No newline at end of file \ No newline at end of file
...@@ -311,33 +311,36 @@ getMissionInfo(deviceId: string, missionId: number, callback: AsyncCallback&lt;M ...@@ -311,33 +311,36 @@ getMissionInfo(deviceId: string, missionId: number, callback: AsyncCallback&lt;M
**示例:** **示例:**
```ts ```ts
import missionManager from '@ohos.app.ability.missionManager'; import missionManager from '@ohos.app.ability.missionManager';
let testMissionId = 1; let testMissionId = 1;
try {
let allMissions=await missionManager.getMissionInfos('',10).catch(function(err){console.log(err);});
if (allMissions && allMissions.length > 0) {
testMissionId = allMissions[0].missionId;
}
missionManager.getMissionInfo('', testMissionId, (error, mission) => { missionManager.getMissionInfos('',10)
if (error) { .then((allMissions) => {
try {
if (allMissions && allMissions.length > 0) {
testMissionId = allMissions[0].missionId;
}
missionManager.getMissionInfo('', testMissionId, (error, mission) => {
if (error) {
console.error('getMissionInfo failed, error.code: ${error.code}, error.message: ${error.message}'); console.error('getMissionInfo failed, error.code: ${error.code}, error.message: ${error.message}');
} else { } else {
console.log('mission.missionId = ${mission.missionId}'); console.log('mission.missionId = ${mission.missionId}');
console.log('mission.runningState = ${mission.runningState}'); console.log('mission.runningState = ${mission.runningState}');
console.log('mission.lockedState = ${mission.lockedState}'); console.log('mission.lockedState = ${mission.lockedState}');
console.log('mission.timestamp = ${mission.timestamp}'); console.log('mission.timestamp = ${mission.timestamp}');
console.log('mission.label = ${mission.label}'); console.log('mission.label = ${mission.label}');
console.log('mission.iconPath = ${mission.iconPath}'); console.log('mission.iconPath = ${mission.iconPath}');
}
});
} catch (paramError) {
console.error('error.code: ${paramError.code}, error.message: ${paramError.message}');
} }
}); })
} catch (paramError) { .catch(function(err){console.log(err);});
console.error('error.code: ${paramError.code}, error.message: ${paramError.message}');
}
``` ```
## missionManager.getMissionInfo ## missionManager.getMissionInfo
getMissionInfo(deviceId: string, missionId: number): Promise&lt;MissionInfo&gt;; getMissionInfo(deviceId: string, missionId: number): Promise&lt;MissionInfo&gt;;
...@@ -943,8 +946,8 @@ clearAllMissions(): Promise&lt;void&gt;; ...@@ -943,8 +946,8 @@ clearAllMissions(): Promise&lt;void&gt;;
import missionManager from '@ohos.app.ability.missionManager'; import missionManager from '@ohos.app.ability.missionManager';
try { try {
missionManager.clearAllMissions(bundleName).then(() => { missionManager.clearAllMissions(bundleName).then((data) => {
console.info('clearAllMissions successfully.'); console.info('clearAllMissions successfully. Data: ${JSON.stringify(data)}');
}).catch(err => { }).catch(err => {
console.error('clearAllMissions failed: ${err.message}'); console.error('clearAllMissions failed: ${err.message}');
}); });
......
...@@ -66,7 +66,7 @@ applyQuickFix(hapModuleQuickFixFiles: Array\<string>, callback: AsyncCallback\<v ...@@ -66,7 +66,7 @@ applyQuickFix(hapModuleQuickFixFiles: Array\<string>, callback: AsyncCallback\<v
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------- | | ------- | -------- |
| 18500002 | Copy file failed, maybe not exist or inaccessible. | | 18500002 | The specified quick fix is invalid. It may not exist or inaccessible. |
| 18500008 | Internal error. | | 18500008 | Internal error. |
在打补丁过程中发生的错误,其错误码及错误信息通过公共事件[COMMON_EVENT_QUICK_FIX_APPLY_RESULT](commonEvent-definitions.md#common_event_quick_fix_apply_result9)的参数返回给应用开发者。这部分错误码及错误信息如下: 在打补丁过程中发生的错误,其错误码及错误信息通过公共事件[COMMON_EVENT_QUICK_FIX_APPLY_RESULT](commonEvent-definitions.md#common_event_quick_fix_apply_result9)的参数返回给应用开发者。这部分错误码及错误信息如下:
...@@ -128,7 +128,7 @@ applyQuickFix(hapModuleQuickFixFiles: Array\<string>): Promise\<void>; ...@@ -128,7 +128,7 @@ applyQuickFix(hapModuleQuickFixFiles: Array\<string>): Promise\<void>;
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------- | | ------- | -------- |
| 18500002 | Copy file failed, maybe not exist or inaccessible. | | 18500002 | The specified quick fix is invalid. It may not exist or inaccessible. |
| 18500008 | Internal error. | | 18500008 | Internal error. |
在打补丁过程中发生的错误,其错误码及错误信息通过公共事件[COMMON_EVENT_QUICK_FIX_APPLY_RESULT](commonEvent-definitions.md#common_event_quick_fix_apply_result9)的参数返回给应用开发者。这部分错误码及错误信息如下: 在打补丁过程中发生的错误,其错误码及错误信息通过公共事件[COMMON_EVENT_QUICK_FIX_APPLY_RESULT](commonEvent-definitions.md#common_event_quick_fix_apply_result9)的参数返回给应用开发者。这部分错误码及错误信息如下:
...@@ -181,7 +181,7 @@ getApplicationQuickFixInfo(bundleName: string, callback: AsyncCallback\<Applicat ...@@ -181,7 +181,7 @@ getApplicationQuickFixInfo(bundleName: string, callback: AsyncCallback\<Applicat
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------- | | ------- | -------- |
| 18500001 | The bundle is not exist. | | 18500001 | The specified bundleName is invalid. |
| 18500008 | Internal error. | | 18500008 | Internal error. |
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md) 以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
...@@ -231,7 +231,7 @@ getApplicationQuickFixInfo(bundleName: string): Promise\<ApplicationQuickFixInfo ...@@ -231,7 +231,7 @@ getApplicationQuickFixInfo(bundleName: string): Promise\<ApplicationQuickFixInfo
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------- | | ------- | -------- |
| 18500001 | The bundle is not exist. | | 18500001 | The specified bundleName is invalid. |
| 18500008 | Internal error. | | 18500008 | Internal error. |
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md) 以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
......
...@@ -15,11 +15,8 @@ import StartOptions from '@ohos.app.ability.StartOptions'; ...@@ -15,11 +15,8 @@ import StartOptions from '@ohos.app.ability.StartOptions';
## 属性 ## 属性
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core **系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
**系统API**: 此接口为系统接口,三方应用不支持调用。
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| [windowMode](js-apis-app-ability-abilityConstant.md#abilityconstantwindowmode) | number | 否 | 窗口模式。 | | [windowMode](js-apis-app-ability-abilityConstant.md#abilityconstantwindowmode) | number | 否 | 窗口模式。 |
......
...@@ -371,7 +371,7 @@ call(method: string, data: rpc.Parcelable): Promise&lt;void&gt;; ...@@ -371,7 +371,7 @@ call(method: string, data: rpc.Parcelable): Promise&lt;void&gt;;
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 16200001 | Caller released. The caller has been released. | | 16200001 | Caller released. The caller has been released. |
| 16200002 | Callee invalid. The callee does not exist. | | 16200002 | Callee invalid. The callee does not exist. |
| 16000050 | Internal Error. | | 16000050 | Internal error. |
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md) 以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
...@@ -452,7 +452,7 @@ callWithResult(method: string, data: rpc.Parcelable): Promise&lt;rpc.MessageSequ ...@@ -452,7 +452,7 @@ callWithResult(method: string, data: rpc.Parcelable): Promise&lt;rpc.MessageSequ
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 16200001 | Caller released. The caller has been released. | | 16200001 | Caller released. The caller has been released. |
| 16200002 | Callee invalid. The callee does not exist. | | 16200002 | Callee invalid. The callee does not exist. |
| 16000050 | Internal Error. | | 16000050 | Internal error. |
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md) 以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
...@@ -597,9 +597,9 @@ release(): void; ...@@ -597,9 +597,9 @@ release(): void;
} }
``` ```
## Caller.onRemoteStateChange ## Caller.onRemoteStateChange<sup>10+</sup>
onRemoteStateChange(callback: OnRemoteStateChangeCallback): void; onRemoteStateChange(callback: OnRemoteStateChangeCallback): void;
注册协同场景下跨设备组件状态变化监听通知。 注册协同场景下跨设备组件状态变化监听通知。
...@@ -650,7 +650,7 @@ release(): void; ...@@ -650,7 +650,7 @@ release(): void;
## Caller.on ## Caller.on
on(type: 'release', callback: OnReleaseCallback): void; on(type: 'release', callback: OnReleaseCallback): void;
注册通用组件服务端Stub(桩)断开监听通知。 注册通用组件服务端Stub(桩)断开监听通知。
...@@ -667,6 +667,7 @@ release(): void; ...@@ -667,6 +667,7 @@ release(): void;
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| ------- | -------------------------------- | | ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
| 16200001 | Caller released. The caller has been released. | | 16200001 | Caller released. The caller has been released. |
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md) 以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
...@@ -712,6 +713,12 @@ off(type: 'release', callback: OnReleaseCallback): void; ...@@ -712,6 +713,12 @@ off(type: 'release', callback: OnReleaseCallback): void;
| type | string | 是 | 监听releaseCall事件,固定为'release'。 | | type | string | 是 | 监听releaseCall事件,固定为'release'。 |
| callback | [OnReleaseCallback](#onreleasecallback) | 是 | 返回off回调结果。 | | callback | [OnReleaseCallback](#onreleasecallback) | 是 | 返回off回调结果。 |
**错误码:**
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
**示例:** **示例:**
```ts ```ts
...@@ -903,7 +910,7 @@ off(method: string): void; ...@@ -903,7 +910,7 @@ off(method: string): void;
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| (msg: string) | 是 | 否 | function | 调用者注册的侦听器函数接口的原型。 | | (msg: string) | 是 | 否 | function | 调用者注册的侦听器函数接口的原型。 |
## OnRemoteStateChangeCallback ## OnRemoteStateChangeCallback<sup>10+</sup>
(msg: string): void; (msg: string): void;
......
...@@ -26,7 +26,7 @@ import Want from '@ohos.app.ability.Want'; ...@@ -26,7 +26,7 @@ import Want from '@ohos.app.ability.Want';
| entities | Array\<string> | 否 | 表示目标Ability额外的类别信息(如:浏览器、视频播放器)。在隐式Want中是对action字段的补充。在隐式Want中,您可以定义该字段,来过滤匹配Ability类型。 | | entities | Array\<string> | 否 | 表示目标Ability额外的类别信息(如:浏览器、视频播放器)。在隐式Want中是对action字段的补充。在隐式Want中,您可以定义该字段,来过滤匹配Ability类型。 |
| uri | string | 否 | 表示携带的数据,一般配合type使用,指明待处理的数据类型。如果在Want中指定了uri,则Want将匹配指定的Uri信息,包括`scheme``schemeSpecificPart``authority``path`信息。 | | uri | string | 否 | 表示携带的数据,一般配合type使用,指明待处理的数据类型。如果在Want中指定了uri,则Want将匹配指定的Uri信息,包括`scheme``schemeSpecificPart``authority``path`信息。 |
| type | string | 否 | 表示MIME type类型描述,打开文件的类型,主要用于文管打开文件。比如:'text/xml' 、 'image/*'等,MIME定义请参见https://www.iana.org/assignments/media-types/media-types.xhtml?utm_source=ld246.com。 | | type | string | 否 | 表示MIME type类型描述,打开文件的类型,主要用于文管打开文件。比如:'text/xml' 、 'image/*'等,MIME定义请参见https://www.iana.org/assignments/media-types/media-types.xhtml?utm_source=ld246.com。 |
| parameters | {[key: string]: any} | 否 | 表示WantParams描述,由开发者自行决定传入的键值对。默认会携带以下key值:<br />- ohos.aafwk.callerPid:表示拉起方的pid。<br />- ohos.aafwk.param.callerBundleName:表示拉起方的Bundle Name。<br />- ohos.aafwk.param.callerToken:表示拉起方的token。<br />- ohos.aafwk.param.callerUid:表示[BundleInfo](js-apis-bundleManager-bundleInfo.md#bundleinfo-1)中的uid,应用包里应用程序的uid。<br />- component.startup.newRules:表示是否启用新的管控规则。<br />- moduleName:表示拉起方的模块名,该字段的值即使定义成其他字符串,在传递到另一端时会被修改为正确的值。<br />- ohos.dlp.params.sandbox:表示dlp文件才会有。 | | parameters | {[key: string]: any} | 否 | 表示WantParams描述,由开发者自行决定传入的键值对。默认会携带以下key值:<br />- ohos.aafwk.callerPid:表示拉起方的pid。<br />- ohos.aafwk.param.callerBundleName:表示拉起方的Bundle Name。<br />- ohos.aafwk.param.callerToken:表示拉起方的token。<br />- ohos.aafwk.param.callerUid:表示[BundleInfo](js-apis-bundleManager-bundleInfo.md#bundleinfo-1)中的uid,应用包里应用程序的uid。<br />- component.startup.newRules:表示是否启用新的管控规则。<br />- moduleName:表示拉起方的模块名,该字段的值即使定义成其他字符串,在传递到另一端时会被修改为正确的值。<br />- ohos.dlp.params.sandbox:表示dlp文件才会有。<br />- ability.params.backToOtherMissionStack:表示是否支持跨任务链返回。 |
| [flags](js-apis-ability-wantConstant.md#wantconstantflags) | number | 否 | 表示处理Want的方式。默认传数字。<br />例如通过wantConstant.Flags.FLAG_ABILITY_CONTINUATION表示是否以设备间迁移方式启动Ability。 | | [flags](js-apis-ability-wantConstant.md#wantconstantflags) | number | 否 | 表示处理Want的方式。默认传数字。<br />例如通过wantConstant.Flags.FLAG_ABILITY_CONTINUATION表示是否以设备间迁移方式启动Ability。 |
**示例:** **示例:**
...@@ -34,7 +34,8 @@ import Want from '@ohos.app.ability.Want'; ...@@ -34,7 +34,8 @@ import Want from '@ohos.app.ability.Want';
- 基础用法:在UIAbility对象中调用,示例中的context的获取方式请参见[获取UIAbility的上下文信息](../../application-models/uiability-usage.md#获取uiability的上下文信息) - 基础用法:在UIAbility对象中调用,示例中的context的获取方式请参见[获取UIAbility的上下文信息](../../application-models/uiability-usage.md#获取uiability的上下文信息)
```ts ```ts
let context = ...; // UIAbilityContext import common from '@ohos.app.ability.common';
let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
let want = { let want = {
'deviceId': '', // deviceId为空表示本设备 'deviceId': '', // deviceId为空表示本设备
'bundleName': 'com.example.myapplication', 'bundleName': 'com.example.myapplication',
...@@ -52,7 +53,8 @@ import Want from '@ohos.app.ability.Want'; ...@@ -52,7 +53,8 @@ import Want from '@ohos.app.ability.Want';
* 字符串(String) * 字符串(String)
```ts ```ts
let context = ...; // UIAbilityContext import common from '@ohos.app.ability.common';
let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
let want = { let want = {
bundleName: 'com.example.myapplication', bundleName: 'com.example.myapplication',
abilityName: 'FuncAbility', abilityName: 'FuncAbility',
...@@ -67,7 +69,8 @@ import Want from '@ohos.app.ability.Want'; ...@@ -67,7 +69,8 @@ import Want from '@ohos.app.ability.Want';
``` ```
* 数字(Number) * 数字(Number)
```ts ```ts
let context = ...; // UIAbilityContext import common from '@ohos.app.ability.common';
let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
let want = { let want = {
bundleName: 'com.example.myapplication', bundleName: 'com.example.myapplication',
abilityName: 'FuncAbility', abilityName: 'FuncAbility',
...@@ -83,7 +86,8 @@ import Want from '@ohos.app.ability.Want'; ...@@ -83,7 +86,8 @@ import Want from '@ohos.app.ability.Want';
``` ```
* 布尔(Boolean) * 布尔(Boolean)
```ts ```ts
let context = ...; // UIAbilityContext import common from '@ohos.app.ability.common';
let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
let want = { let want = {
bundleName: 'com.example.myapplication', bundleName: 'com.example.myapplication',
abilityName: 'FuncAbility', abilityName: 'FuncAbility',
...@@ -98,7 +102,8 @@ import Want from '@ohos.app.ability.Want'; ...@@ -98,7 +102,8 @@ import Want from '@ohos.app.ability.Want';
``` ```
* 对象(Object) * 对象(Object)
```ts ```ts
let context = ...; // UIAbilityContext import common from '@ohos.app.ability.common';
let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
let want = { let want = {
bundleName: 'com.example.myapplication', bundleName: 'com.example.myapplication',
abilityName: 'FuncAbility', abilityName: 'FuncAbility',
...@@ -118,7 +123,8 @@ import Want from '@ohos.app.ability.Want'; ...@@ -118,7 +123,8 @@ import Want from '@ohos.app.ability.Want';
``` ```
* 数组(Array) * 数组(Array)
```ts ```ts
let context = ...; // UIAbilityContext import common from '@ohos.app.ability.common';
let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
let want = { let want = {
bundleName: 'com.example.myapplication', bundleName: 'com.example.myapplication',
abilityName: 'FuncAbility', abilityName: 'FuncAbility',
...@@ -138,7 +144,8 @@ import Want from '@ohos.app.ability.Want'; ...@@ -138,7 +144,8 @@ import Want from '@ohos.app.ability.Want';
```ts ```ts
import fs from '@ohos.file.fs'; import fs from '@ohos.file.fs';
let context = ...; // UIAbilityContext import common from '@ohos.app.ability.common';
let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
let fd; let fd;
try { try {
...@@ -160,3 +167,33 @@ import Want from '@ohos.app.ability.Want'; ...@@ -160,3 +167,33 @@ import Want from '@ohos.app.ability.Want';
console.error(`Failed to startAbility. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to startAbility. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
- parameter参数用法:以ability.params.backToOtherMissionStack为例,ServiceExtension在拉起UIAbility的时候,可以支持跨任务链返回。
```ts
// (1) UIAbility1启动一个ServiceExtension
let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
let want = {
bundleName: 'com.example.myapplication1',
abilityName: 'ServiceExtensionAbility',
};
context.startAbility(want, (err) => {
console.error(`Failed to startAbility. Code: ${err.code}, message: ${err.message}`);
});
// (2) 该ServiceExtension去启动另一个UIAbility2,并在启动的时候携带参数ability.params.backToOtherMissionStack为true
let context = ...; // ServiceExtensionContext
let want = {
bundleName: 'com.example.myapplication2',
abilityName: 'MainAbility',
parameters: {
"ability.params.backToOtherMissionStack": true,
},
};
context.startAbility(want, (err) => {
console.error(`Failed to startAbility. Code: ${err.code}, message: ${err.message}`);
});
```
说明:上例中,如果ServiceExtension启动UIAbility2时不携带ability.params.backToOtherMissionStack参数,或者携带的ability.params.backToOtherMissionStack参数为false,则UIAbility1和UIAbility2不在同一个任务栈里面,在UIAbility2的界面点back键,不会回到UIAbility1的界面。如果携带的ability.params.backToOtherMissionStack参数为true,则表示支持跨任务链返回,此时在UIAbility2的界面点back键,会回到UIAbility1的界面。
...@@ -118,6 +118,7 @@ getWantAgent(info: WantAgentInfo): Promise\<WantAgent\> ...@@ -118,6 +118,7 @@ getWantAgent(info: WantAgentInfo): Promise\<WantAgent\>
**示例:** **示例:**
```ts ```ts
let wantAgent;
//WantAgentInfo对象 //WantAgentInfo对象
let wantAgentInfo = { let wantAgentInfo = {
wants: [ wants: [
...@@ -1181,7 +1182,7 @@ function getWantAgentCallback(err, data) { ...@@ -1181,7 +1182,7 @@ function getWantAgentCallback(err, data) {
} }
} }
try { try {
WantAgent.getOperationTypeCallback(wantAgent, getOperationTypeCallback); WantAgent.getOperationType(wantAgent, getOperationTypeCallback);
} catch(err) { } catch(err) {
console.error('getOperationTypeCallback failed! ${err.code} ${err.message}'); console.error('getOperationTypeCallback failed! ${err.code} ${err.message}');
} }
......
...@@ -16,6 +16,8 @@ import wantConstant from '@ohos.app.ability.wantConstant'; ...@@ -16,6 +16,8 @@ import wantConstant from '@ohos.app.ability.wantConstant';
want的Params操作的常量。 want的Params操作的常量。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityBase
| 名称 | 值 | 说明 | | 名称 | 值 | 说明 |
| ----------------------- | ---------------------------------- | ------------------------------------------------------------------------------ | | ----------------------- | ---------------------------------- | ------------------------------------------------------------------------------ |
| DLP_PARAMS_SANDBOX | ohos.dlp.params.sandbox | 指示沙盒标志的参数的操作。<br>**系统API**:该接口为系统接口,三方应用不支持调用。 | | DLP_PARAMS_SANDBOX | ohos.dlp.params.sandbox | 指示沙盒标志的参数的操作。<br>**系统API**:该接口为系统接口,三方应用不支持调用。 |
...@@ -23,10 +25,11 @@ want的Params操作的常量。 ...@@ -23,10 +25,11 @@ want的Params操作的常量。
| DLP_PARAMS_MODULE_NAME | ohos.dlp.params.moduleName | 指示DLP模块名称的参数的操作。 <br>**系统API**:该接口为系统接口,三方应用不支持调用。 | | DLP_PARAMS_MODULE_NAME | ohos.dlp.params.moduleName | 指示DLP模块名称的参数的操作。 <br>**系统API**:该接口为系统接口,三方应用不支持调用。 |
| DLP_PARAMS_ABILITY_NAME | ohos.dlp.params.abilityName | 指示DLP能力名称的参数的操作。 <br>**系统API**:该接口为系统接口,三方应用不支持调用。 | | DLP_PARAMS_ABILITY_NAME | ohos.dlp.params.abilityName | 指示DLP能力名称的参数的操作。 <br>**系统API**:该接口为系统接口,三方应用不支持调用。 |
| DLP_PARAMS_INDEX | ohos.dlp.params.index | 指示DLP索引参数的操作。 <br>**系统API**:该接口为系统接口,三方应用不支持调用。 | | DLP_PARAMS_INDEX | ohos.dlp.params.index | 指示DLP索引参数的操作。 <br>**系统API**:该接口为系统接口,三方应用不支持调用。 |
| ABILITY_RECOVERY_RESTART | ohos.ability.params.abilityRecoveryRestart | 指示当前Ability是否发生了故障恢复重启。 | | ABILITY_BACK_TO_OTHER_MISSION_STACK | ability.params.backToOtherMissionStack | 表示是否支持跨任务链返回。 <br>**系统API**:该接口为系统接口,三方应用不支持调用。 |
| CONTENT_TITLE_KEY | ohos.extra.param.key.contentTitle | 指示原子化服务支持分享标题的参数的操作。 <br>**系统API**:该接口为系统接口,三方应用不支持调用。 | | ABILITY_RECOVERY_RESTART<sup>10+</sup> | ohos.ability.params.abilityRecoveryRestart | 指示当前Ability是否发生了故障恢复重启。 |
| SHARE_ABSTRACT_KEY | ohos.extra.param.key.shareAbstract | 指示原子化服务支持分享内容的参数的操作。 <br>**系统API**:该接口为系统接口,三方应用不支持调用。 | | CONTENT_TITLE_KEY<sup>10+</sup> | ohos.extra.param.key.contentTitle | 指示原子化服务支持分享标题的参数的操作。 |
| SHARE_URL_KEY | ohos.extra.param.key.shareUrl | 指示原子化服务支持分享链接的参数的操作。 <br>**系统API**:该接口为系统接口,三方应用不支持调用。 | | SHARE_ABSTRACT_KEY<sup>10+</sup> | ohos.extra.param.key.shareAbstract | 指示原子化服务支持分享内容的参数的操作。 |
| SHARE_URL_KEY<sup>10+</sup> | ohos.extra.param.key.shareUrl | 指示原子化服务支持分享链接的参数的操作。 |
## wantConstant.Flags ## wantConstant.Flags
......
...@@ -18,6 +18,8 @@ import formInfo from '@ohos.app.form.formInfo'; ...@@ -18,6 +18,8 @@ import formInfo from '@ohos.app.form.formInfo';
**系统能力**:SystemCapability.Ability.Form **系统能力**:SystemCapability.Ability.Form
**系统API**: 此接口为系统接口,三方应用不支持调用。
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| ----------- | -------- | -------- | -------------------- | ------------------------------------------------------------ | | ----------- | -------- | -------- | -------------------- | ------------------------------------------------------------ |
| bundleName | string | 是 | 否 | 卡片所属包的Bundle名称。 | | bundleName | string | 是 | 否 | 卡片所属包的Bundle名称。 |
...@@ -100,7 +102,7 @@ import formInfo from '@ohos.app.form.formInfo'; ...@@ -100,7 +102,7 @@ import formInfo from '@ohos.app.form.formInfo';
| HEIGHT_KEY | 'ohos.extra.param.key.form_height' | 卡片高度。 | | HEIGHT_KEY | 'ohos.extra.param.key.form_height' | 卡片高度。 |
| TEMPORARY_KEY | 'ohos.extra.param.key.form_temporary' | 临时卡片。 | | TEMPORARY_KEY | 'ohos.extra.param.key.form_temporary' | 临时卡片。 |
| ABILITY_NAME_KEY | 'ohos.extra.param.key.ability_name' | ability名称。 | | ABILITY_NAME_KEY | 'ohos.extra.param.key.ability_name' | ability名称。 |
| DEVICE_ID_KEY | 'ohos.extra.param.key.device_id' | 设备标识。 | | DEVICE_ID_KEY | 'ohos.extra.param.key.device_id' <br>**系统API**: 此接口为系统接口,三方应用不支持调用。 | 设备标识。 |
| BUNDLE_NAME_KEY | 'ohos.extra.param.key.bundle_name' | 指示指定要获取的捆绑Bundle名称的键。 | | BUNDLE_NAME_KEY | 'ohos.extra.param.key.bundle_name' | 指示指定要获取的捆绑Bundle名称的键。 |
| LAUNCH_REASON_KEY<sup>10+</sup> | 'ohos.extra.param.key.form_launch_reason' | 卡片创建原因。 | | LAUNCH_REASON_KEY<sup>10+</sup> | 'ohos.extra.param.key.form_launch_reason' | 卡片创建原因。 |
| PARAM_FORM_CUSTOMIZE_KEY<sup>10+</sup> | 'ohos.extra.param.key.form_customize' | 自定义数据。 | | PARAM_FORM_CUSTOMIZE_KEY<sup>10+</sup> | 'ohos.extra.param.key.form_customize' | 自定义数据。 |
...@@ -138,6 +140,7 @@ import formInfo from '@ohos.app.form.formInfo'; ...@@ -138,6 +140,7 @@ import formInfo from '@ohos.app.form.formInfo';
| 名称 | 值 | 说明 | | 名称 | 值 | 说明 |
| ----------- | ---- | ------------ | | ----------- | ---- | ------------ |
| UNKNOWN | 0 | 表示卡片为未知。 |
| FORM_VISIBLE | 1 | 表示卡片为可见。 | | FORM_VISIBLE | 1 | 表示卡片为可见。 |
| FORM_INVISIBLE | 2 | 表示卡片为不可见。 | | FORM_INVISIBLE | 2 | 表示卡片为不可见。 |
......
...@@ -39,13 +39,12 @@ setFormNextRefreshTime(formId: string, minute: number, callback: AsyncCallback&l ...@@ -39,13 +39,12 @@ setFormNextRefreshTime(formId: string, minute: number, callback: AsyncCallback&l
| 16501001 | The ID of the form to be operated does not exist. | | 16501001 | The ID of the form to be operated does not exist. |
| 16501002 | The number of forms exceeds upper bound. | | 16501002 | The number of forms exceeds upper bound. |
| 16501003 | The form can not be operated by the current application. | | 16501003 | The form can not be operated by the current application. |
|以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。||
以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)
**示例:** **示例:**
```ts ```ts
import formProvider from '@ohos.app.form.formProvider';
let formId = '12400633174999288'; let formId = '12400633174999288';
try { try {
formProvider.setFormNextRefreshTime(formId, 5, (error) => { formProvider.setFormNextRefreshTime(formId, 5, (error) => {
...@@ -93,13 +92,12 @@ setFormNextRefreshTime(formId: string, minute: number): Promise&lt;void&gt; ...@@ -93,13 +92,12 @@ setFormNextRefreshTime(formId: string, minute: number): Promise&lt;void&gt;
| 16501001 | The ID of the form to be operated does not exist. | | 16501001 | The ID of the form to be operated does not exist. |
| 16501002 | The number of forms exceeds upper bound. | | 16501002 | The number of forms exceeds upper bound. |
| 16501003 | The form can not be operated by the current application. | | 16501003 | The form can not be operated by the current application. |
|以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。||
以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)
**示例:** **示例:**
```ts ```ts
import formProvider from '@ohos.app.form.formProvider';
let formId = '12400633174999288'; let formId = '12400633174999288';
try { try {
formProvider.setFormNextRefreshTime(formId, 5).then(() => { formProvider.setFormNextRefreshTime(formId, 5).then(() => {
...@@ -139,13 +137,13 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData,call ...@@ -139,13 +137,13 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData,call
| 16501000 | An internal functional error occurred. | | 16501000 | An internal functional error occurred. |
| 16501001 | The ID of the form to be operated does not exist. | | 16501001 | The ID of the form to be operated does not exist. |
| 16501003 | The form can not be operated by the current application. | | 16501003 | The form can not be operated by the current application. |
|以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。||
以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)
**示例:** **示例:**
```ts ```ts
import formBindingData from '@ohos.app.form.formBindingData'; import formBindingData from '@ohos.app.form.formBindingData';
import formProvider from '@ohos.app.form.formProvider';
let formId = '12400633174999288'; let formId = '12400633174999288';
try { try {
...@@ -194,13 +192,13 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Pr ...@@ -194,13 +192,13 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Pr
| 16501000 | An internal functional error occurred. | | 16501000 | An internal functional error occurred. |
| 16501001 | The ID of the form to be operated does not exist. | | 16501001 | The ID of the form to be operated does not exist. |
| 16501003 | The form can not be operated by the current application. | | 16501003 | The form can not be operated by the current application. |
|以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。||
以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)
**示例:** **示例:**
```ts ```ts
import formBindingData from '@ohos.app.form.formBindingData'; import formBindingData from '@ohos.app.form.formBindingData';
import formProvider from '@ohos.app.form.formProvider';
let formId = '12400633174999288'; let formId = '12400633174999288';
let obj = formBindingData.createFormBindingData({ temperature: '22c', time: '22:00' }); let obj = formBindingData.createFormBindingData({ temperature: '22c', time: '22:00' });
...@@ -236,14 +234,13 @@ getFormsInfo(callback: AsyncCallback&lt;Array&lt;formInfo.FormInfo&gt;&gt;): voi ...@@ -236,14 +234,13 @@ getFormsInfo(callback: AsyncCallback&lt;Array&lt;formInfo.FormInfo&gt;&gt;): voi
| 16500050 | An IPC connection error happened. | | 16500050 | An IPC connection error happened. |
| 16500100 | Failed to obtain the configuration information. | | 16500100 | Failed to obtain the configuration information. |
| 16501000 | An internal functional error occurred. | | 16501000 | An internal functional error occurred. |
|以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。||
以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)
**示例:** **示例:**
```ts ```ts
import formProvider from '@ohos.app.form.formProvider';
try { try {
formProvider.getFormsInfo((error, data) => { formProvider.getFormsInfo((error, data) => {
if (error) { if (error) {
...@@ -279,13 +276,13 @@ getFormsInfo(filter: formInfo.FormInfoFilter, callback: AsyncCallback&lt;Array&l ...@@ -279,13 +276,13 @@ getFormsInfo(filter: formInfo.FormInfoFilter, callback: AsyncCallback&lt;Array&l
| 16500050 | An IPC connection error happened. | | 16500050 | An IPC connection error happened. |
| 16500100 | Failed to obtain the configuration information. | | 16500100 | Failed to obtain the configuration information. |
| 16501000 | An internal functional error occurred. | | 16501000 | An internal functional error occurred. |
|以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。||
以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)
**示例:** **示例:**
```ts ```ts
import formInfo from '@ohos.app.form.formInfo'; import formInfo from '@ohos.app.form.formInfo';
import formProvider from '@ohos.app.form.formProvider';
const filter: formInfo.FormInfoFilter = { const filter: formInfo.FormInfoFilter = {
// get info of forms belong to module entry. // get info of forms belong to module entry.
...@@ -332,13 +329,13 @@ getFormsInfo(filter?: formInfo.FormInfoFilter): Promise&lt;Array&lt;formInfo.For ...@@ -332,13 +329,13 @@ getFormsInfo(filter?: formInfo.FormInfoFilter): Promise&lt;Array&lt;formInfo.For
| 16500050 | An IPC connection error happened. | | 16500050 | An IPC connection error happened. |
| 16500100 | Failed to obtain the configuration information. | | 16500100 | Failed to obtain the configuration information. |
| 16501000 | An internal functional error occurred. | | 16501000 | An internal functional error occurred. |
|以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。||
以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)
**示例:** **示例:**
```ts ```ts
import formInfo from '@ohos.app.form.formInfo'; import formInfo from '@ohos.app.form.formInfo';
import formProvider from '@ohos.app.form.formProvider';
const filter: formInfo.FormInfoFilter = { const filter: formInfo.FormInfoFilter = {
// get info of forms belong to module entry. // get info of forms belong to module entry.
...@@ -382,13 +379,13 @@ requestPublishForm(want: Want, formBindingData: formBindingData.FormBindingData, ...@@ -382,13 +379,13 @@ requestPublishForm(want: Want, formBindingData: formBindingData.FormBindingData,
| 16500050 | An IPC connection error happened. | | 16500050 | An IPC connection error happened. |
| 16500100 | Failed to obtain the configuration information. | | 16500100 | Failed to obtain the configuration information. |
| 16501000 | An internal functional error occurred. | | 16501000 | An internal functional error occurred. |
|以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。||
以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)
**示例:** **示例:**
```ts ```ts
import formBindingData from '@ohos.app.form.formBindingData'; import formBindingData from '@ohos.app.form.formBindingData';
import formProvider from '@ohos.app.form.formProvider';
let want = { let want = {
abilityName: 'FormAbility', abilityName: 'FormAbility',
...@@ -438,13 +435,12 @@ requestPublishForm(want: Want, callback: AsyncCallback&lt;string&gt;): void ...@@ -438,13 +435,12 @@ requestPublishForm(want: Want, callback: AsyncCallback&lt;string&gt;): void
| 16500050 | An IPC connection error happened. | | 16500050 | An IPC connection error happened. |
| 16500100 | Failed to obtain the configuration information. | | 16500100 | Failed to obtain the configuration information. |
| 16501000 | An internal functional error occurred. | | 16501000 | An internal functional error occurred. |
|以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。||
以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)
**示例:** **示例:**
```ts ```ts
import formProvider from '@ohos.app.form.formProvider';
let want = { let want = {
abilityName: 'FormAbility', abilityName: 'FormAbility',
parameters: { parameters: {
...@@ -498,13 +494,12 @@ requestPublishForm(want: Want, formBindingData?: formBindingData.FormBindingData ...@@ -498,13 +494,12 @@ requestPublishForm(want: Want, formBindingData?: formBindingData.FormBindingData
| 16500050 | An IPC connection error happened. | | 16500050 | An IPC connection error happened. |
| 16500100 | Failed to obtain the configuration information. | | 16500100 | Failed to obtain the configuration information. |
| 16501000 | An internal functional error occurred. | | 16501000 | An internal functional error occurred. |
|以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。||
以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)
**示例:** **示例:**
```ts ```ts
import formProvider from '@ohos.app.form.formProvider';
let want = { let want = {
abilityName: 'FormAbility', abilityName: 'FormAbility',
parameters: { parameters: {
...@@ -548,13 +543,12 @@ isRequestPublishFormSupported(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -548,13 +543,12 @@ isRequestPublishFormSupported(callback: AsyncCallback&lt;boolean&gt;): void
| 401 | If the input parameter is not valid parameter. | | 401 | If the input parameter is not valid parameter. |
| 16500050 | An IPC connection error happened. | | 16500050 | An IPC connection error happened. |
| 16501000 | An internal functional error occurred. | | 16501000 | An internal functional error occurred. |
|以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。||
以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)
**示例:** **示例:**
```ts ```ts
import formProvider from '@ohos.app.form.formProvider';
try { try {
formProvider.isRequestPublishFormSupported((error, isSupported) => { formProvider.isRequestPublishFormSupported((error, isSupported) => {
if (error) { if (error) {
...@@ -611,13 +605,12 @@ isRequestPublishFormSupported(): Promise&lt;boolean&gt; ...@@ -611,13 +605,12 @@ isRequestPublishFormSupported(): Promise&lt;boolean&gt;
| 202 | The application is not a system application. | | 202 | The application is not a system application. |
| 16500050 | An IPC connection error happened. | | 16500050 | An IPC connection error happened. |
| 16501000 | An internal functional error occurred. | | 16501000 | An internal functional error occurred. |
|以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。||
以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)
**示例:** **示例:**
```ts ```ts
import formProvider from '@ohos.app.form.formProvider';
try { try {
formProvider.isRequestPublishFormSupported().then((isSupported) => { formProvider.isRequestPublishFormSupported().then((isSupported) => {
if (isSupported) { if (isSupported) {
......
# @ohos.application.StaticSubscriberExtensionContext (StaticSubscriberExtensionContext)
StaticSubscriberExtensionContext模块是StaticSubscriberExtensionAbility的上下文环境,继承自ExtensionContext。
StaticSubscriberExtensionContext模块提供StaticSubscriberExtensionAbility具有的接口和能力。
> **说明:**
>
> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块接口仅可在Stage模型下使用。
## 使用说明
在使用StaticSubscriberExtensionContext的功能前,需要通过StaticSubscriberExtensionAbility获取。
```ts
import StaticSubscriberExtensionAbility from '@ohos.application.StaticSubscriberExtensionAbility'
export default class MyStaticSubscriberExtensionAbility extends StaticSubscriberExtensionAbility {
context = this.context;
};
```
## StaticSubscriberExtensionContext.startAbility
startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void;
拉起一个静态订阅所属的同应用的Ability。使用callback异步回调。
使用规则:
- 调用方应用位于后台时,使用该接口启动Ability需申请`ohos.permission.START_ABILITIES_FROM_BACKGROUND`权限
- 跨应用场景下,目标Ability的visible属性若配置为false,调用方应用需申请`ohos.permission.START_INVISIBLE_ABILITY`权限
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**系统API**:该接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------- | ---- | -------------------------- |
| want | [Want](js-apis-application-want.md) | 是 | 启动Ability的want信息。 |
| callback | AsyncCallback&lt;void&gt; | 是 | callback形式返回启动结果。 |
**错误码:**
以下错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 |
| -------- | ------------------------------------------------------------ |
| 16000001 | The specified ability does not exist. |
| 16000002 | Incorrect ability type. |
| 16000004 | Can not start invisible component. |
| 16000005 | The specified process does not have the permission. |
| 16000006 | Cross-user operations are not allowed. |
| 16000008 | The crowdtesting application expires. |
| 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000011 | The context does not exist. |
| 16000050 | Internal error. |
| 16000053 | The ability is not on the top of the UI. |
| 16000055 | Installation-free timed out. |
| 16200001 | The caller has been released. |
| 16300003 | The target application is not self application. |
**示例:**
```ts
let want = {
bundleName: "com.example.myapp",
abilityName: "MyAbility"
};
try {
this.context.startAbility(want, (error) => {
if (error) {
// 处理业务逻辑错误
console.log('startAbility failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(error.message));
return;
}
// 执行正常业务
console.log('startAbility succeed');
});
} catch (paramError) {
// 处理入参错误异常
console.log('startAbility failed, error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
}
```
## StaticSubscriberExtensionContext.startAbility
startAbility(want: Want): Promise&lt;void&gt;;
拉起一个静态订阅所属的同应用的Ability。使用Promise异步回调。
使用规则:
- 调用方应用位于后台时,使用该接口启动Ability需申请`ohos.permission.START_ABILITIES_FROM_BACKGROUND`权限
- 跨应用场景下,目标Ability的visible属性若配置为false,调用方应用需申请`ohos.permission.START_INVISIBLE_ABILITY`权限
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**系统API**:该接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ----------------------------------- | ---- | ----------------------- |
| want | [Want](js-apis-application-want.md) | 是 | 启动Ability的want信息。 |
**返回值:**
| 类型 | 说明 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise形式返回启动结果。 |
**错误码:**
以下错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
| 错误码ID | 错误信息 |
| -------- | ------------------------------------------------------------ |
| 16000001 | The specified ability does not exist. |
| 16000002 | Incorrect ability type. |
| 16000004 | Can not start invisible component. |
| 16000005 | The specified process does not have the permission. |
| 16000006 | Cross-user operations are not allowed. |
| 16000008 | The crowdtesting application expires. |
| 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000011 | The context does not exist. |
| 16000050 | Internal error. |
| 16000053 | The ability is not on the top of the UI. |
| 16000055 | Installation-free timed out. |
| 16200001 | The caller has been released. |
| 16300003 | The target application is not self application. |
**示例:**
```ts
let want = {
bundleName: "com.example.myapp",
abilityName: "MyAbility"
};
try {
this.context.startAbility(want)
.then(() => {
// 执行正常业务
console.log('startAbility succeed');
})
.catch((error) => {
// 处理业务逻辑错误
console.log('startAbility failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(error.message));
});
} catch (paramError) {
// 处理入参错误异常
console.log('startAbility failed, error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
}
```
\ No newline at end of file
...@@ -400,7 +400,11 @@ killProcessWithAccount(bundleName: string, accountId: number): Promise\<void\> ...@@ -400,7 +400,11 @@ killProcessWithAccount(bundleName: string, accountId: number): Promise\<void\>
切断account进程(Promise形式)。 切断account进程(Promise形式)。
**需要权限**:ohos.permission.CLEAN_BACKGROUND_PROCESSES,ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS权限。 > **说明:**
>
> 当accountId为当前用户时,不需要校验ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS权限。
**需要权限**:ohos.permission.CLEAN_BACKGROUND_PROCESSES,ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core **系统能力**:SystemCapability.Ability.AbilityRuntime.Core
...@@ -434,11 +438,15 @@ killProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCal ...@@ -434,11 +438,15 @@ killProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCal
切断account进程(callback形式)。 切断account进程(callback形式)。
> **说明:**
>
> 当accountId为当前用户时,不需要校验ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core **系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**系统API**: 此接口为系统接口,三方应用不支持调用。 **系统API**: 此接口为系统接口,三方应用不支持调用。
**需要权限**:ohos.permission.CLEAN_BACKGROUND_PROCESSES,ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS权限。 **需要权限**:ohos.permission.CLEAN_BACKGROUND_PROCESSES,ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**参数:** **参数:**
......
...@@ -3,9 +3,16 @@ ...@@ -3,9 +3,16 @@
定义环境变化信息。Configuration是接口定义,仅做字段声明。 定义环境变化信息。Configuration是接口定义,仅做字段声明。
> **说明:** > **说明:**
>
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块从API version 9废弃,替换模块为[@ohos.app.ability.Configuration (Configuration)](js-apis-app-ability-configuration.md) > 本模块从API version 9废弃,替换模块为[@ohos.app.ability.Configuration (Configuration)](js-apis-app-ability-configuration.md)
## 导入模块
```ts
import Configuration from '@ohos.app.application.Configuration';
```
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityBase **系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityBase
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
......
# @ohos.application.EnvironmentCallback (EnvironmentCallback)
EnvironmentCallback模块提供应用上下文ApplicationContext对系统环境变化监听回调的能力,包括onConfigurationUpdated、onMemoryLevel方法。
> **说明:**
>
> 本模块首批接口从API version 9 开始支持,从API version 9后续版本废弃,替换模块为[@ohos.app.ability.EnvironmentCallback](js-apis-app-ability-environmentCallback.md)。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块接口仅可在Stage模型下使用。
## 导入模块
```ts
import EnvironmentCallback from '@ohos.application.EnvironmentCallback';
```
## EnvironmentCallback.onConfigurationUpdated
onConfigurationUpdated(config: Configuration): void;
注册系统环境变化的监听后,在系统环境变化时触发回调。
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| config | [Configuration](js-apis-application-configuration.md) | 是 | 变化后的Configuration对象。 |
## EnvironmentCallback.onMemoryLevel
onMemoryLevel(level: number): void;
注册系统内存基线水平变化监听后,在系统内存基线水平变化时触发回调。
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| level | [MemoryLevel](js-apis-app-ability-abilityConstant.md#abilityconstantmemorylevel) | 是 | 表示当前内存的基线水平。 |
**示例:**
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
let callbackId;
export default class EntryAbility extends UIAbility {
onCreate() {
console.log('MyAbility onCreate');
globalThis.applicationContext = this.context.getApplicationContext();
let environmentCallback = {
onConfigurationUpdated(config){
console.log('onConfigurationUpdated config: ${JSON.stringify(config)}');
},
onMemoryLevel(level){
console.log('onMemoryLevel level: ${level}');
}
};
// 1.获取applicationContext
let applicationContext = globalThis.applicationContext;
// 2.通过applicationContext注册监听应用内生命周期
callbackId = applicationContext.registerEnvironmentCallback(environmentCallback);
console.log('registerEnvironmentCallback number: ${JSON.stringify(callbackId)}');
}
onDestroy() {
let applicationContext = globalThis.applicationContext;
applicationContext.unregisterEnvironmentCallback(callbackId, (error, data) => {
if (error && error.code !== 0) {
console.error('unregisterEnvironmentCallback fail, error: ${JSON.stringify(error)}');
} else {
console.log('unregisterEnvironmentCallback success, data: ${JSON.stringify(data)}');
}
});
}
}
```
\ No newline at end of file
...@@ -12,6 +12,14 @@ StaticSubscriberExtensionAbility模块提供静态订阅者ExtensionAbility的 ...@@ -12,6 +12,14 @@ StaticSubscriberExtensionAbility模块提供静态订阅者ExtensionAbility的
import StaticSubscriberExtensionAbility from '@ohos.application.StaticSubscriberExtensionAbility'; import StaticSubscriberExtensionAbility from '@ohos.application.StaticSubscriberExtensionAbility';
``` ```
## 属性
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.AbilityCore
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ------- | ------------------------------------------------------------ | ---- | ---- | -------- |
| context | [StaticSubscriberExtensionContext](js-apis-application-StaticSubscriberExtensionContext.md) | 是 | 否 | 上下文。 |
## StaticSubscriberExtensionAbility.onReceiveEvent ## StaticSubscriberExtensionAbility.onReceiveEvent
onReceiveEvent(event: CommonEventData): void; onReceiveEvent(event: CommonEventData): void;
......
...@@ -49,7 +49,7 @@ struct SnapshotExample { ...@@ -49,7 +49,7 @@ struct SnapshotExample {
// ...Components // ...Components
Button("click to generate UI snapshot") Button("click to generate UI snapshot")
.onClick(() => { .onClick(() => {
componentSnapshot.get("root", (error: BusinessError, pixmap: image.PixelMap) => { componentSnapshot.get("root", (error: Error, pixmap: image.PixelMap) => {
this.pixmap = pixmap this.pixmap = pixmap
// save pixmap to file // save pixmap to file
// .... // ....
...@@ -85,6 +85,12 @@ get(id: string): Promise<image.PixelMap> ...@@ -85,6 +85,12 @@ get(id: string): Promise<image.PixelMap>
| ----------------------------- | -------------- | | ----------------------------- | -------------- |
| Promise&lt;image.PixelMap&gt; | 截图返回的结果。 | | Promise&lt;image.PixelMap&gt; | 截图返回的结果。 |
**错误码:**
| 错误码ID | 错误信息 |
| -------- | ------------------- |
| 100001 | if id is not valid. |
**示例:** **示例:**
```js ```js
...@@ -139,9 +145,10 @@ createFromBuilder(builder: CustomBuilder, callback: AsyncCallback<image.PixelMap ...@@ -139,9 +145,10 @@ createFromBuilder(builder: CustomBuilder, callback: AsyncCallback<image.PixelMap
**示例:** **示例:**
```js ```ts
import componentSnapshot from '@ohos.arkui.componentSnapshot' import componentSnapshot from '@ohos.arkui.componentSnapshot'
import image from '@ohos.multimedia.image' import image from '@ohos.multimedia.image'
@Entry @Entry
@Component @Component
struct OffscreenSnapshotExample { struct OffscreenSnapshotExample {
...@@ -149,7 +156,7 @@ struct OffscreenSnapshotExample { ...@@ -149,7 +156,7 @@ struct OffscreenSnapshotExample {
@Builder @Builder
RandomBuilder() { RandomBuilder() {
Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
Text('Test menu item 1') Text('Test menu item 1')
.fontSize(20) .fontSize(20)
.width(100) .width(100)
...@@ -163,16 +170,17 @@ struct OffscreenSnapshotExample { ...@@ -163,16 +170,17 @@ struct OffscreenSnapshotExample {
.textAlign(TextAlign.Center) .textAlign(TextAlign.Center)
}.width(100) }.width(100)
} }
build() { build() {
Column() { Column() {
Button("click to generate offscreen UI snapshot") Button("click to generate offscreen UI snapshot")
.onClick(()=> { .onClick(() => {
componentSnapshot.createFromBuilder(this.RandomBuilder.bind(this), componentSnapshot.createFromBuilder(this.RandomBuilder.bind(this),
(error: BusinessError, pixmap: image.PixelMap) => { (error: Error, pixmap: image.PixelMap) => {
this.pixmap = pixmap this.pixmap = pixmap
// save pixmap to file // save pixmap to file
// .... // ....
}) })
}) })
}.width('80%').margin({ left: 10, top: 5, bottom: 5 }).height(200) }.width('80%').margin({ left: 10, top: 5, bottom: 5 }).height(200)
.border({ color: '#880606', width: 2 }) .border({ color: '#880606', width: 2 })
...@@ -200,11 +208,18 @@ createFromBuilder(builder: CustomBuilder): Promise<image.PixelMap> ...@@ -200,11 +208,18 @@ createFromBuilder(builder: CustomBuilder): Promise<image.PixelMap>
| ----------------------------- | -------------- | | ----------------------------- | -------------- |
| Promise&lt;image.PixelMap&gt; | 截图返回的结果。 | | Promise&lt;image.PixelMap&gt; | 截图返回的结果。 |
**错误码:**
| 错误码ID | 错误信息 |
| -------- | ----------------------------------------- |
| 100001 | if builder is not a valid build function. |
**示例:** **示例:**
```js ```ts
import componentSnapshot from '@ohos.arkui.componentSnapshot' import componentSnapshot from '@ohos.arkui.componentSnapshot'
import image from '@ohos.multimedia.image' import image from '@ohos.multimedia.image'
@Entry @Entry
@Component @Component
struct OffscreenSnapshotExample { struct OffscreenSnapshotExample {
...@@ -212,7 +227,7 @@ struct OffscreenSnapshotExample { ...@@ -212,7 +227,7 @@ struct OffscreenSnapshotExample {
@Builder @Builder
RandomBuilder() { RandomBuilder() {
Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
Text('Test menu item 1') Text('Test menu item 1')
.fontSize(20) .fontSize(20)
.width(100) .width(100)
...@@ -226,16 +241,17 @@ struct OffscreenSnapshotExample { ...@@ -226,16 +241,17 @@ struct OffscreenSnapshotExample {
.textAlign(TextAlign.Center) .textAlign(TextAlign.Center)
}.width(100) }.width(100)
} }
build() { build() {
Column() { Column() {
Button("click to generate offscreen UI snapshot") Button("click to generate offscreen UI snapshot")
.onClick(()=> { .onClick(() => {
componentSnapshot.createFromBuilder(this.RandomBuilder.bind(this)) componentSnapshot.createFromBuilder(this.RandomBuilder.bind(this))
.then((pixmap: image.PixelMap) { .then((pixmap: image.PixelMap) => {
this.pixmap = pixmap this.pixmap = pixmap
// save pixmap to file // save pixmap to file
// .... // ....
}) })
}) })
}.width('80%').margin({ left: 10, top: 5, bottom: 5 }).height(200) }.width('80%').margin({ left: 10, top: 5, bottom: 5 }).height(200)
.border({ color: '#880606', width: 2 }) .border({ color: '#880606', width: 2 })
......
...@@ -32,16 +32,25 @@ constructor() ...@@ -32,16 +32,25 @@ constructor()
当传入资源id或name为包含前景和背景资源的json文件时,生成LayeredDrawableDescriptor对象。 当传入资源id或name为包含前景和背景资源的json文件时,生成LayeredDrawableDescriptor对象。
**示例:** **示例:**
```js ```ts
// xxx.ets
import { DrawableDescriptor, LayeredDrawableDescriptor } from '@ohos.arkui.drawableDescriptor'
@Entry @Entry
@Component @Component
struct Index { struct Index {
private resManager = getContext().resourceManager private resManager = getContext().resourceManager
let drawable1 = resManager.getDrawableDescriptor($r('app.media.icon').id)
let drawable2 = resManager.getDrawableDescriptorByName(icon) build() {
let layeredDrawable1 = resManager.getDrawableDescriptor($r('app.media.file').id) Row() {
let layeredDrawable1 = resManager.getDrawableDescriptor(file) Column() {
} Image((<LayeredDrawableDescriptor> (this.resManager.getDrawableDescriptor($r('app.media.icon').id))))
Image(((<LayeredDrawableDescriptor> (this.resManager.getDrawableDescriptor($r('app.media.icon')
.id))).getForeground()).getPixelMap())
}.height('50%')
}.width('50%')
}
}
``` ```
## DrawableDescriptor.getPixelMap ## DrawableDescriptor.getPixelMap
...@@ -58,8 +67,8 @@ getPixelMap(): image.PixelMap; ...@@ -58,8 +67,8 @@ getPixelMap(): image.PixelMap;
| [image.PixelMap](../apis/js-apis-image.md#pixelmap7) | PixelMap | | [image.PixelMap](../apis/js-apis-image.md#pixelmap7) | PixelMap |
**示例:** **示例:**
```js ```ts
@State pixmap: PixelMap = drawable1.getPixelMap(); pixmap: PixelMap = drawable1.getPixelMap();
``` ```
## LayeredDrawableDescriptor.getPixelMap ## LayeredDrawableDescriptor.getPixelMap
...@@ -76,8 +85,8 @@ getPixelMap(): image.PixelMap; ...@@ -76,8 +85,8 @@ getPixelMap(): image.PixelMap;
| [image.PixelMap](../apis/js-apis-image.md#pixelmap7) | PixelMap | | [image.PixelMap](../apis/js-apis-image.md#pixelmap7) | PixelMap |
**示例:** **示例:**
```js ```ts
@State pixmap: PixelMap = layeredDrawable1.getPixelMap(); pixmap: PixelMap = layeredDrawable1.getPixelMap();
``` ```
## LayeredDrawableDescriptor.getForeground ## LayeredDrawableDescriptor.getForeground
...@@ -94,8 +103,8 @@ getForeground(): DrawableDescriptor; ...@@ -94,8 +103,8 @@ getForeground(): DrawableDescriptor;
| [DrawableDescriptor](#drawabledescriptor) | DrawableDescriptor对象 | | [DrawableDescriptor](#drawabledescriptor) | DrawableDescriptor对象 |
**示例:** **示例:**
```js ```ts
@State drawable: DrawableDescriptor = layeredDrawable1.getForeground(); drawable: DrawableDescriptor = layeredDrawable1.getForeground();
``` ```
## LayeredDrawableDescriptor.getBackground ## LayeredDrawableDescriptor.getBackground
...@@ -112,8 +121,8 @@ getBackground(): DrawableDescriptor; ...@@ -112,8 +121,8 @@ getBackground(): DrawableDescriptor;
| [DrawableDescriptor](#drawabledescriptor) | DrawableDescriptor对象 | | [DrawableDescriptor](#drawabledescriptor) | DrawableDescriptor对象 |
**示例:** **示例:**
```js ```ts
@State drawable: DrawableDescriptor = layeredDrawable1.getBackground(); drawable: DrawableDescriptor = layeredDrawable1.getBackground();
``` ```
## LayeredDrawableDescriptor.getMask ## LayeredDrawableDescriptor.getMask
...@@ -130,6 +139,6 @@ getMask(): DrawableDescriptor; ...@@ -130,6 +139,6 @@ getMask(): DrawableDescriptor;
| [DrawableDescriptor](#drawabledescriptor) | DrawableDescriptor对象 | | [DrawableDescriptor](#drawabledescriptor) | DrawableDescriptor对象 |
**示例:** **示例:**
```js ```ts
@State drawable: DrawableDescriptor = layeredDrawable1.getMask(); drawable: DrawableDescriptor = layeredDrawable1.getMask();
``` ```
...@@ -1091,6 +1091,8 @@ setAVQueueItems(items: Array\<AVQueueItem>): Promise<void\> ...@@ -1091,6 +1091,8 @@ setAVQueueItems(items: Array\<AVQueueItem>): Promise<void\>
**系统能力:** SystemCapability.Multimedia.AVSession.Core **系统能力:** SystemCapability.Multimedia.AVSession.Core
**系统接口:** 该接口为系统接口
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -1114,12 +1116,14 @@ setAVQueueItems(items: Array\<AVQueueItem>): Promise<void\> ...@@ -1114,12 +1116,14 @@ setAVQueueItems(items: Array\<AVQueueItem>): Promise<void\>
**示例:** **示例:**
```js ```js
let imageSource : imageImageSource = image.createImageSource(value.buffer);
let imagePixel : image.PixelMap = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}});
let queueItemDescription_1 = { let queueItemDescription_1 = {
mediaId: '001', mediaId: '001',
title: 'music_name', title: 'music_name',
subtitle: 'music_sub_name', subtitle: 'music_sub_name',
description: 'music_description', description: 'music_description',
icon: PIXELMAP_OBJECT, icon : imagePixel,
iconUri: 'http://www.icon.uri.com', iconUri: 'http://www.icon.uri.com',
extras: {'extras':'any'} extras: {'extras':'any'}
}; };
...@@ -1156,6 +1160,8 @@ setAVQueueItems(items: Array\<AVQueueItem>, callback: AsyncCallback<void\>): voi ...@@ -1156,6 +1160,8 @@ setAVQueueItems(items: Array\<AVQueueItem>, callback: AsyncCallback<void\>): voi
**系统能力:** SystemCapability.Multimedia.AVSession.Core **系统能力:** SystemCapability.Multimedia.AVSession.Core
**系统接口:** 该接口为系统接口
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -1174,12 +1180,14 @@ setAVQueueItems(items: Array\<AVQueueItem>, callback: AsyncCallback<void\>): voi ...@@ -1174,12 +1180,14 @@ setAVQueueItems(items: Array\<AVQueueItem>, callback: AsyncCallback<void\>): voi
**示例:** **示例:**
```js ```js
let imageSource : imageImageSource = image.createImageSource(value.buffer);
let imagePixel : image.PixelMap = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}});
let queueItemDescription_1 = { let queueItemDescription_1 = {
mediaId: '001', mediaId: '001',
title: 'music_name', title: 'music_name',
subtitle: 'music_sub_name', subtitle: 'music_sub_name',
description: 'music_description', description: 'music_description',
icon: PIXELMAP_OBJECT, icon: imagePixel,
iconUri: 'http://www.icon.uri.com', iconUri: 'http://www.icon.uri.com',
extras: {'extras':'any'} extras: {'extras':'any'}
}; };
...@@ -1218,6 +1226,8 @@ setAVQueueTitle(title: string): Promise\<void> ...@@ -1218,6 +1226,8 @@ setAVQueueTitle(title: string): Promise\<void>
**系统能力:** SystemCapability.Multimedia.AVSession.Core **系统能力:** SystemCapability.Multimedia.AVSession.Core
**系统接口:** 该接口为系统接口
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -1257,6 +1267,8 @@ setAVQueueTitle(title: string, callback: AsyncCallback\<void\>): void ...@@ -1257,6 +1267,8 @@ setAVQueueTitle(title: string, callback: AsyncCallback\<void\>): void
**系统能力:** SystemCapability.Multimedia.AVSession.Core **系统能力:** SystemCapability.Multimedia.AVSession.Core
**系统接口:** 该接口为系统接口
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -1434,6 +1446,8 @@ dispatchSessionEvent(event: string, args: {[key: string]: Object}): Promise\<voi ...@@ -1434,6 +1446,8 @@ dispatchSessionEvent(event: string, args: {[key: string]: Object}): Promise\<voi
**系统能力:** SystemCapability.Multimedia.AVSession.Core **系统能力:** SystemCapability.Multimedia.AVSession.Core
**系统接口:** 该接口为系统接口
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -1478,6 +1492,8 @@ dispatchSessionEvent(event: string, args: {[key: string]: Object}, callback: Asy ...@@ -1478,6 +1492,8 @@ dispatchSessionEvent(event: string, args: {[key: string]: Object}, callback: Asy
**系统能力:** SystemCapability.Multimedia.AVSession.Core **系统能力:** SystemCapability.Multimedia.AVSession.Core
**系统接口:** 该接口为系统接口
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -1519,6 +1535,8 @@ setExtras(extras: {[key: string]: Object}): Promise\<void> ...@@ -1519,6 +1535,8 @@ setExtras(extras: {[key: string]: Object}): Promise\<void>
**系统能力:** SystemCapability.Multimedia.AVSession.Core **系统能力:** SystemCapability.Multimedia.AVSession.Core
**系统接口:** 该接口为系统接口
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -2520,7 +2538,7 @@ session.off('outputDeviceChange'); ...@@ -2520,7 +2538,7 @@ session.off('outputDeviceChange');
### off('commonCommand')<sup>10+</sup> ### off('commonCommand')<sup>10+</sup>
off(type: 'commonCommand', callback?: (commonCommand: string, args: {[key:string]: Object}) => void): void off(type: 'commonCommand', callback?: (command: string, args: {[key:string]: Object}) => void): void
取消监听自定义控制命令的变化。 取消监听自定义控制命令的变化。
...@@ -2533,7 +2551,7 @@ off(type: 'commonCommand', callback?: (commonCommand: string, args: {[key:string ...@@ -2533,7 +2551,7 @@ off(type: 'commonCommand', callback?: (commonCommand: string, args: {[key:string
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | | -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
| type | string | 是 | 取消对应的监听事件,支持事件`'commonCommand'`。 | | type | string | 是 | 取消对应的监听事件,支持事件`'commonCommand'`。 |
| callback | (commonCommand: string, args: {[key:string]: Object}) => void | 否 | 回调函数,参数commonCommand是变化的自定义控制命令名,args为自定义控制命令的参数。<br>该参数为可选参数,若不填写该参数,则认为取消所有对commonCommand事件的监听。 | | callback | (command: string, args: {[key:string]: Object}) => void | 否 | 回调函数,参数command是变化的自定义控制命令名,args为自定义控制命令的参数。<br>该参数为可选参数,若不填写该参数,则认为取消所有对command事件的监听。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md) 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)
...@@ -2558,6 +2576,8 @@ session.off('commonCommand'); ...@@ -2558,6 +2576,8 @@ session.off('commonCommand');
**系统能力:** SystemCapability.Multimedia.AVSession.Core **系统能力:** SystemCapability.Multimedia.AVSession.Core
**系统接口:** 该接口为系统接口
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| :-------- | :----- | :--- | :--- | :-------------------------------------- | | :-------- | :----- | :--- | :--- | :-------------------------------------- |
...@@ -3061,6 +3081,22 @@ getExtras(callback: AsyncCallback\<{[key: string]: Object}>): void ...@@ -3061,6 +3081,22 @@ getExtras(callback: AsyncCallback\<{[key: string]: Object}>): void
**示例:** **示例:**
```js ```js
let metadata = {
assetId: "121278",
title: "lose yourself",
artist: "Eminem",
author: "ST",
album: "Slim shady",
writer: "ST",
composer: "ST",
duration: 2222,
mediaImage: "https://www.example.com/example.jpg",
subtitle: "8 Mile",
description: "Rap",
lyric: "https://www.example.com/example.lrc",
previousAssetId: "121277",
nextAssetId: "121279",
};
controller.getExtras(function (err, extras) { controller.getExtras(function (err, extras) {
if (err) { if (err) {
console.info(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`);
...@@ -3602,6 +3638,8 @@ sendCommonCommand(command: string, args: {[key: string]: Object}): Promise\<void ...@@ -3602,6 +3638,8 @@ sendCommonCommand(command: string, args: {[key: string]: Object}): Promise\<void
**系统能力:** SystemCapability.Multimedia.AVSession.Core **系统能力:** SystemCapability.Multimedia.AVSession.Core
**系统接口:** 该接口为系统接口
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -3650,6 +3688,8 @@ sendCommonCommand(command: string, args: {[key: string]: Object}, callback: Asyn ...@@ -3650,6 +3688,8 @@ sendCommonCommand(command: string, args: {[key: string]: Object}, callback: Asyn
**系统能力:** SystemCapability.Multimedia.AVSession.Core **系统能力:** SystemCapability.Multimedia.AVSession.Core
**系统接口:** 该接口为系统接口
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
......
...@@ -26,9 +26,9 @@ import businessAbilityRouter from '@ohos.app.businessAbilityRouter'; ...@@ -26,9 +26,9 @@ import businessAbilityRouter from '@ohos.app.businessAbilityRouter';
此枚举值用于标识过滤条件类型。 此枚举值用于标识过滤条件类型。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core
**系统接口:** 此接口为系统接口。 **系统API:** 此接口为系统接口。
| 名称 | 值 | 说明 | | 名称 | 值 | 说明 |
| ----------- | ---- | ------------------------------------ | | ----------- | ---- | ------------------------------------ |
...@@ -39,9 +39,9 @@ import businessAbilityRouter from '@ohos.app.businessAbilityRouter'; ...@@ -39,9 +39,9 @@ import businessAbilityRouter from '@ohos.app.businessAbilityRouter';
此过滤值用于过滤查询的ability类型。 此过滤值用于过滤查询的ability类型。
**系统能力:** SystemCapability.BundleManager.BundleFrameWork.FreeInstall **系统能力:** SystemCapability.BundleManager.BundleFramework.Core
**系统接口:** 此接口为系统接口。 **系统API:** 此接口为系统接口。
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| ------------ | ------------ | ---- | ---- | -------------------------------------- | | ------------ | ------------ | ---- | ---- | -------------------------------------- |
......
...@@ -550,7 +550,7 @@ on(type: 'cameraStatus', callback: AsyncCallback\<CameraStatusInfo\>): void ...@@ -550,7 +550,7 @@ on(type: 'cameraStatus', callback: AsyncCallback\<CameraStatusInfo\>): void
**示例:** **示例:**
```js ```js
cameraManager.on('cameraStatus', (cameraStatusInfo) => { cameraManager.on('cameraStatus', (err, cameraStatusInfo) => {
console.log(`camera : ${cameraStatusInfo.camera.cameraId}`); console.log(`camera : ${cameraStatusInfo.camera.cameraId}`);
console.log(`status: ${cameraStatusInfo.status}`); console.log(`status: ${cameraStatusInfo.status}`);
}) })
...@@ -1680,7 +1680,7 @@ setMeteringPoint(point: Point): void ...@@ -1680,7 +1680,7 @@ setMeteringPoint(point: Point): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------------- | -------------------------------| ---- | ------------------- | | ------------- | -------------------------------| ---- | ------------------- |
| exposurePoint | [Point](#point) | 是 | 曝光点 | | exposurePoint | [Point](#point) | 是 | 曝光点,x,y设置范围应在[0,1]之内,超过范围,如果小于0设置0,大于1设置1。 |
**返回值:** **返回值:**
...@@ -1755,7 +1755,7 @@ setExposureBias(exposureBias: number): void ...@@ -1755,7 +1755,7 @@ setExposureBias(exposureBias: number): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------| ---- | ------------------- | | -------- | -------------------------------| ---- | ------------------- |
| exposureBias | number | 是 | 曝光补偿,getExposureBiasRange查询支持的范围,接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode) | | exposureBias | number | 是 | 曝光补偿,getExposureBiasRange查询支持的范围,接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](#cameraerrorcode),如果设置超过支持范围的值,自动匹配到就近临界点。 |
**错误码:** **错误码:**
...@@ -1938,7 +1938,7 @@ setFocusPoint(point: Point): void ...@@ -1938,7 +1938,7 @@ setFocusPoint(point: Point): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | ------------------- | | -------- | ----------------------- | ---- | ------------------- |
| Point1 | [Point](#point) | 是 | 焦点。 | | Point1 | [Point](#point) | 是 | 焦点。x,y设置范围应在[0,1]之内,超过范围,如果小于0设置0,大于1设置1。 |
**返回值:** **返回值:**
...@@ -2077,7 +2077,7 @@ setZoomRatio(zoomRatio: number): void ...@@ -2077,7 +2077,7 @@ setZoomRatio(zoomRatio: number): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| --------- | -------------------- | ---- | ------------------- | | --------- | -------------------- | ---- | ------------------- |
| zoomRatio | number | 是 | 可变焦距比,通过getZoomRatioRange获取支持的变焦范围 | | zoomRatio | number | 是 | 可变焦距比,通过getZoomRatioRange获取支持的变焦范围,如果设置超过支持范围的值,自动匹配到就近临界点。 |
**返回值:** **返回值:**
...@@ -2737,7 +2737,7 @@ capture(setting?: PhotoCaptureSetting): Promise\<void\> ...@@ -2737,7 +2737,7 @@ capture(setting?: PhotoCaptureSetting): Promise\<void\>
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------- | ------------------------------------------- | ---- | -------- | | ------- | ------------------------------------------- | ---- | -------- |
| setting | [PhotoCaptureSetting](#photocapturesetting) | 否 | 拍照设置。 | | setting | [PhotoCaptureSetting](#photocapturesetting) | 否 | 拍照设置,传入undefined类型数据按默认无参处理。 |
**返回值:** **返回值:**
......
...@@ -575,3 +575,85 @@ commonEventManager.removeStickyCommonEvent("sticky_event").then(() => { ...@@ -575,3 +575,85 @@ commonEventManager.removeStickyCommonEvent("sticky_event").then(() => {
}); });
``` ```
## CommonEventManager.setStaticSubscriberState<sup>10+</sup>
setStaticSubscriberState(enable: boolean, callback: AsyncCallback<void>): void;
方法介绍:为当前应用设置静态订阅事件使能或去使能状态。使用callback异步回调。
**系统能力:** SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | -------------------------------- |
| enable | bool | 是 | 表示静态订阅事件使能状态。 true:使能 false:去使能 |
| callback | AsyncCallback\<void> | 是 | 表示设置静态订阅事件使能状态的回调方法。 |
**错误码:**
错误码介绍请参考[@ohos.commonEventManager(事件)](../errorcodes/errorcode-CommonEventService.md)
| 错误码ID | 错误信息 |
| -------- | ----------------------------------- |
| 1500007 | The message send error. |
| 1500008 | The CEMS error. |
**示例:**
```ts
CommonEventManager.setStaticSubscriberState(true, (err) => {
if (!err) {
console.info(`Set static subscriber state callback failed, err is null.`);
return;
}
if (err.code) {
console.info(`Set static subscriber state callback failed, errCode: ${err.code}, errMes: ${err.message}`);
return;
}
console.info(`Set static subscriber state callback success`);
});
```
## CommonEventManager.setStaticSubscriberState<sup>10+</sup>
setStaticSubscriberState(enable: boolean): Promise<void>;
方法介绍:为当前应用设置静态订阅事件使能或去使能状态。使用Promise异步回调。
**系统能力:** SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | -------------------------- |
| enable | bool | 是 | 表示静态订阅事件使能状态。true:使能 false:去使能 |
**返回值:**
| 类型 | 说明 |
| -------------- | ---------------------------- |
| Promise\<void> | 表示设置静态订阅事件使能状态的对象。 |
**错误码:**
错误码介绍请参考[@ohos.commonEventManager(事件)](../errorcodes/errorcode-CommonEventService.md)
| 错误码ID | 错误信息 |
| -------- | ----------------------------------- |
| 1500007 | The message send error. |
| 1500008 | The CEMS error. |
**示例:**
```ts
CommonEventManager.setStaticSubscriberState(false).then(() => {
console.info(`Set static subscriber state promise success`);
}).catch ((err) => {
console.info(`Set static subscriber state promise failed, errCode: ${err.code}, errMes: ${err.message}`);
});
```
\ No newline at end of file
...@@ -197,7 +197,7 @@ import featureAbility from '@ohos.ability.featureAbility'; ...@@ -197,7 +197,7 @@ import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context = featureAbility.getContext();
try { try {
data_preferences.deletePreferences(context, 'mystore', function (err, val) { data_preferences.deletePreferences(context, 'mystore', function (err) {
if (err) { if (err) {
console.info("Failed to delete preferences. code =" + err.code + ", message =" + err.message); console.info("Failed to delete preferences. code =" + err.code + ", message =" + err.message);
return; return;
...@@ -217,7 +217,7 @@ import UIAbility from '@ohos.app.ability.UIAbility'; ...@@ -217,7 +217,7 @@ import UIAbility from '@ohos.app.ability.UIAbility';
class EntryAbility extends UIAbility { class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
try { try {
data_preferences.deletePreferences(this.context, 'mystore', function (err, val) { data_preferences.deletePreferences(this.context, 'mystore', function (err) {
if (err) { if (err) {
console.info("Failed to delete preferences. code =" + err.code + ", message =" + err.message); console.info("Failed to delete preferences. code =" + err.code + ", message =" + err.message);
return; return;
...@@ -334,7 +334,7 @@ import featureAbility from '@ohos.ability.featureAbility'; ...@@ -334,7 +334,7 @@ import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context = featureAbility.getContext();
try { try {
data_preferences.removePreferencesFromCache(context, 'mystore', function (err, val) { data_preferences.removePreferencesFromCache(context, 'mystore', function (err) {
if (err) { if (err) {
console.info("Failed to remove preferences. code =" + err.code + ", message =" + err.message); console.info("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
return; return;
...@@ -354,7 +354,7 @@ import UIAbility from '@ohos.app.ability.UIAbility'; ...@@ -354,7 +354,7 @@ import UIAbility from '@ohos.app.ability.UIAbility';
class EntryAbility extends UIAbility { class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
try { try {
data_preferences.removePreferencesFromCache(this.context, 'mystore', function (err, val) { data_preferences.removePreferencesFromCache(this.context, 'mystore', function (err) {
if (err) { if (err) {
console.info("Failed to remove preferences. code =" + err.code + ", message =" + err.message); console.info("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
return; return;
......
...@@ -199,7 +199,7 @@ createDeviceManager(bundleName: string, callback: AsyncCallback&lt;DeviceManager ...@@ -199,7 +199,7 @@ createDeviceManager(bundleName: string, callback: AsyncCallback&lt;DeviceManager
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| --------- | -------------------- | ---- | ---------- | | --------- | -------------------- | ---- | ---------- |
| authType | number | 是 | 认证类型。 | | authType | number | 是 | 认证类型。 |
| extraInfo | {[key:string]&nbsp;:&nbsp;any} | 否 | 认证参数可扩展字段。 | | extraInfo | {[key:string]&nbsp;:&nbsp;any} | 否 | 认证参数可扩展字段。可选,默认为undefined。 |
## AuthInfo ## AuthInfo
...@@ -211,7 +211,7 @@ createDeviceManager(bundleName: string, callback: AsyncCallback&lt;DeviceManager ...@@ -211,7 +211,7 @@ createDeviceManager(bundleName: string, callback: AsyncCallback&lt;DeviceManager
| --------- | -------------------- | ---- | ---------- | | --------- | -------------------- | ---- | ---------- |
| authType | number | 是 | 认证类型。 | | authType | number | 是 | 认证类型。 |
| token | number | 是 | 认证Token。 | | token | number | 是 | 认证Token。 |
| extraInfo | {[key:string]&nbsp;:&nbsp;any} | 否 | 认证信息可扩展字段。 | | extraInfo | {[key:string]&nbsp;:&nbsp;any} | 否 | 认证信息可扩展字段。可选,默认为undefined。 |
## PublishInfo<sup>9+</sup> ## PublishInfo<sup>9+</sup>
...@@ -487,6 +487,8 @@ getDeviceInfo(networkId: string, callback:AsyncCallback&lt;DeviceInfo&gt;): void ...@@ -487,6 +487,8 @@ getDeviceInfo(networkId: string, callback:AsyncCallback&lt;DeviceInfo&gt;): void
```js ```js
try { try {
// 设备网络标识,可以从可信设备列表中获取
let networkId = "xxxxxxx"
dmInstance.getDeviceInfo(networkId, (err, data) => { dmInstance.getDeviceInfo(networkId, (err, data) => {
if (err) { if (err) {
console.error("getDeviceInfo errCode:" + err.code + ",errMessage:" + err.message); console.error("getDeviceInfo errCode:" + err.code + ",errMessage:" + err.message);
...@@ -530,6 +532,8 @@ getDeviceInfo(networkId: string): Promise&lt;DeviceInfo&gt; ...@@ -530,6 +532,8 @@ getDeviceInfo(networkId: string): Promise&lt;DeviceInfo&gt;
**示例:** **示例:**
```js ```js
// 设备网络标识,可以从可信设备列表中获取
let networkId = "xxxxxxx"
dmInstance.getDeviceInfo(networkId).then((data) => { dmInstance.getDeviceInfo(networkId).then((data) => {
console.log('get device info: ' + JSON.stringify(data)); console.log('get device info: ' + JSON.stringify(data));
}).catch((err) => { }).catch((err) => {
...@@ -541,7 +545,7 @@ getDeviceInfo(networkId: string): Promise&lt;DeviceInfo&gt; ...@@ -541,7 +545,7 @@ getDeviceInfo(networkId: string): Promise&lt;DeviceInfo&gt;
startDeviceDiscovery(subscribeInfo: SubscribeInfo): void startDeviceDiscovery(subscribeInfo: SubscribeInfo): void
发现周边设备。 发现周边设备。发现状态持续两分钟,超过两分钟,会停止发现,最大发现数量99个。
**系统能力**:SystemCapability.DistributedHardware.DeviceManager **系统能力**:SystemCapability.DistributedHardware.DeviceManager
...@@ -585,7 +589,7 @@ startDeviceDiscovery(subscribeInfo: SubscribeInfo): void ...@@ -585,7 +589,7 @@ startDeviceDiscovery(subscribeInfo: SubscribeInfo): void
startDeviceDiscovery(subscribeInfo: SubscribeInfo, filterOptions?: string): void startDeviceDiscovery(subscribeInfo: SubscribeInfo, filterOptions?: string): void
发现周边设备。 发现周边设备。发现状态持续两分钟,超过两分钟,会停止发现,最大发现数量99个。
**系统能力**:SystemCapability.DistributedHardware.DeviceManager **系统能力**:SystemCapability.DistributedHardware.DeviceManager
...@@ -594,7 +598,7 @@ startDeviceDiscovery(subscribeInfo: SubscribeInfo, filterOptions?: string): void ...@@ -594,7 +598,7 @@ startDeviceDiscovery(subscribeInfo: SubscribeInfo, filterOptions?: string): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ----- | | ------------- | ------------------------------- | ---- | ----- |
| subscribeInfo | [SubscribeInfo](#subscribeinfo) | 是 | 发现信息。 | | subscribeInfo | [SubscribeInfo](#subscribeinfo) | 是 | 发现信息。 |
| filterOptions | string | 否 | 发现设备过滤信息。| | filterOptions | string | 否 | 发现设备过滤信息。可选,默认为undefined,发现未上线设备。|
**错误码:** **错误码:**
...@@ -673,7 +677,7 @@ stopDeviceDiscovery(subscribeId: number): void ...@@ -673,7 +677,7 @@ stopDeviceDiscovery(subscribeId: number): void
publishDeviceDiscovery(publishInfo: PublishInfo): void publishDeviceDiscovery(publishInfo: PublishInfo): void
发布设备发现。 发布设备发现。发布状态持续两分钟,超过两分钟会停止发布。
**系统能力**:SystemCapability.DistributedHardware.DeviceManager **系统能力**:SystemCapability.DistributedHardware.DeviceManager
...@@ -944,11 +948,11 @@ requestCredentialRegisterInfo(requestInfo: string, callback: AsyncCallback<{regi ...@@ -944,11 +948,11 @@ requestCredentialRegisterInfo(requestInfo: string, callback: AsyncCallback<{regi
"userId" : "123" "userId" : "123"
} }
try { try {
dmClass.requestCredentialRegisterInfo(credentialInfo, (data) => { dmInstance.requestCredentialRegisterInfo(credentialInfo, (data) => {
if (data) { if (data) {
console.info("requestCredentialRegisterInfo result:" + JSON.stringify(data)); console.info("requestCredentialRegisterInfo result:" + JSON.stringify(data));
} else { } else {
console.info.push("requestCredentialRegisterInfo result: data is null"); console.info("requestCredentialRegisterInfo result: data is null");
} }
}); });
} catch (err) { } catch (err) {
...@@ -995,11 +999,11 @@ importCredential(credentialInfo: string, callback: AsyncCallback<{resultInfo: st ...@@ -995,11 +999,11 @@ importCredential(credentialInfo: string, callback: AsyncCallback<{resultInfo: st
] ]
} }
try { try {
dmClass.importCredential(credentialInfo, (data) => { dmInstance.importCredential(credentialInfo, (data) => {
if (data) { if (data) {
console.info("importCredential result:" + JSON.stringify(data)); console.info("importCredential result:" + JSON.stringify(data));
} else { } else {
console.info.push("importCredential result: data is null"); console.info("importCredential result: data is null");
} }
}); });
} catch (err) { } catch (err) {
...@@ -1031,11 +1035,11 @@ deleteCredential(queryInfo: string, callback: AsyncCallback<{resultInfo: string} ...@@ -1031,11 +1035,11 @@ deleteCredential(queryInfo: string, callback: AsyncCallback<{resultInfo: string}
"userId" : "123" "userId" : "123"
} }
try { try {
dmClass.deleteCredential(queryInfo, (data) => { dmInstance.deleteCredential(queryInfo, (data) => {
if (data) { if (data) {
console.info("deleteCredential result:" + JSON.stringify(data)); console.info("deleteCredential result:" + JSON.stringify(data));
} else { } else {
console.info.push("deleteCredential result: data is null"); console.info("deleteCredential result: data is null");
} }
}); });
} catch (err) { } catch (err) {
......
...@@ -360,7 +360,7 @@ continueMission(parameter: ContinueDeviceInfo, options: ContinueCallback, callba ...@@ -360,7 +360,7 @@ continueMission(parameter: ContinueDeviceInfo, options: ContinueCallback, callba
迁移任务,以回调函数的方式返回。 迁移任务,以回调函数的方式返回。
**需要权限**:ohos.permission.MANAGE_MISSIONS and ohos.permission.DISTRIBUTED_DATASYNC **需要权限**:ohos.permission.MANAGE_MISSIONSohos.permission.DISTRIBUTED_DATASYNC
**系统能力**:SystemCapability.Ability.AbilityRuntime.Mission **系统能力**:SystemCapability.Ability.AbilityRuntime.Mission
...@@ -418,7 +418,7 @@ continueMission(parameter: ContinueDeviceInfo, options: ContinueCallback): Promi ...@@ -418,7 +418,7 @@ continueMission(parameter: ContinueDeviceInfo, options: ContinueCallback): Promi
迁移任务,以promise方式返回执行结果。 迁移任务,以promise方式返回执行结果。
**需要权限**:ohos.permission.MANAGE_MISSIONS and ohos.permission.DISTRIBUTED_DATASYNC **需要权限**:ohos.permission.MANAGE_MISSIONSohos.permission.DISTRIBUTED_DATASYNC
**系统能力**:SystemCapability.Ability.AbilityRuntime.Mission **系统能力**:SystemCapability.Ability.AbilityRuntime.Mission
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
> **说明:** > **说明:**
> >
> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块接口需激活为[设备管理员应用](js-apis-enterprise-adminManager.md#adminmanagerenableadmin)后才能调用,实现相应功能。
## 导入模块 ## 导入模块
...@@ -48,7 +49,7 @@ let wantTemp = { ...@@ -48,7 +49,7 @@ let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "EntryAbility", abilityName: "EntryAbility",
}; };
accountManager.disallowAddLocalAccount(admin, true, (error) => { accountManager.disallowAddLocalAccount(wantTemp, true, (error) => {
if (error != null) { if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message); console.log("error code:" + error.code + " error message:" + error.message);
} }
......
...@@ -54,7 +54,7 @@ let enterpriseInfo = { ...@@ -54,7 +54,7 @@ let enterpriseInfo = {
name: "enterprise name", name: "enterprise name",
description: "enterprise description" description: "enterprise description"
} }
adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_NORMAL, error => { adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_SUPER, error => {
if (error != null) { if (error != null) {
console.log("error occurs" + error); console.log("error occurs" + error);
return; return;
...@@ -955,6 +955,6 @@ adminManager.unsubscribeManagedEvent(wantTemp, events).then(() => { ...@@ -955,6 +955,6 @@ adminManager.unsubscribeManagedEvent(wantTemp, events).then(() => {
| -------------------------- | ---- | ------------- | | -------------------------- | ---- | ------------- |
| MANAGED_EVENT_BUNDLE_ADDED | 0 | 应用安装事件。 | | MANAGED_EVENT_BUNDLE_ADDED | 0 | 应用安装事件。 |
| MANAGED_EVENT_BUNDLE_REMOVED | 1 | 应用卸载事件。 | | MANAGED_EVENT_BUNDLE_REMOVED | 1 | 应用卸载事件。 |
| MANAGED_EVENT_APP_START | 2 | 应用启动事件。 | | MANAGED_EVENT_APP_START<sup>10+</sup> | 2 | 应用启动事件。 |
| MANAGED_EVENT_APP_STOP | 3 | 应用停止事件。 | | MANAGED_EVENT_APP_STOP<sup>10+</sup> | 3 | 应用停止事件。 |
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
> **说明:** > **说明:**
> >
> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块接口需激活为[设备管理员应用](js-apis-enterprise-adminManager.md#adminmanagerenableadmin)后才能调用,实现相应功能。
## 导入模块 ## 导入模块
...@@ -49,7 +50,7 @@ let wantTemp = { ...@@ -49,7 +50,7 @@ let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "EntryAbility", abilityName: "EntryAbility",
}; };
let appIds = {"com.example.myapplication"}; let appIds = ["com.example.myapplication"];
applicationManager.addDisallowedRunningBundles(wantTemp, appIds, (error) => { applicationManager.addDisallowedRunningBundles(wantTemp, appIds, (error) => {
if (error != null) { if (error != null) {
...@@ -95,7 +96,7 @@ let wantTemp = { ...@@ -95,7 +96,7 @@ let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "EntryAbility", abilityName: "EntryAbility",
}; };
let appIds = {"com.example.myapplication"}; let appIds = ["com.example.myapplication"];
applicationManager.addDisallowedRunningBundles(wantTemp, appIds, 100, (error) => { applicationManager.addDisallowedRunningBundles(wantTemp, appIds, 100, (error) => {
if (error != null) { if (error != null) {
...@@ -146,7 +147,7 @@ let wantTemp = { ...@@ -146,7 +147,7 @@ let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "EntryAbility", abilityName: "EntryAbility",
}; };
let appIds = {"com.example.myapplication"}; let appIds = ["com.example.myapplication"];
applicationManager.addDisallowedRunningBundles(wantTemp, appIds, 100).then(() => { applicationManager.addDisallowedRunningBundles(wantTemp, appIds, 100).then(() => {
console.log("success"); console.log("success");
...@@ -191,7 +192,7 @@ let wantTemp = { ...@@ -191,7 +192,7 @@ let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "EntryAbility", abilityName: "EntryAbility",
}; };
let appIds = {"com.example.myapplication"}; let appIds = ["com.example.myapplication"];
applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, (error) => { applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, (error) => {
if (error != null) { if (error != null) {
...@@ -237,7 +238,7 @@ let wantTemp = { ...@@ -237,7 +238,7 @@ let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "EntryAbility", abilityName: "EntryAbility",
}; };
let appIds = {"com.example.myapplication"}; let appIds = ["com.example.myapplication"];
applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, 100, (error) => { applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, 100, (error) => {
if (error != null) { if (error != null) {
...@@ -288,7 +289,7 @@ let wantTemp = { ...@@ -288,7 +289,7 @@ let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "EntryAbility", abilityName: "EntryAbility",
}; };
let appIds = {"com.example.myapplication"}; let appIds = ["com.example.myapplication"];
applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, 100).then(() => { applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, 100).then(() => {
console.log("success"); console.log("success");
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
> **说明:** > **说明:**
> >
> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块接口需激活为[设备管理员应用](js-apis-enterprise-adminManager.md#adminmanagerenableadmin)后才能调用,实现相应功能。
## 导入模块 ## 导入模块
...@@ -48,9 +49,9 @@ let wantTemp = { ...@@ -48,9 +49,9 @@ let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "EntryAbility", abilityName: "EntryAbility",
}; };
let appIds = {"com.example.myapplication"}; let appIds = ["com.example.myapplication"];
bundleManager.AddAllowedInstallBundles(wantTemp, appIds, (error) => { bundleManager.addAllowedInstallBundles(wantTemp, appIds, (error) => {
if (error != null) { if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message); console.log("error code:" + error.code + " error message:" + error.message);
} }
...@@ -94,9 +95,9 @@ let wantTemp = { ...@@ -94,9 +95,9 @@ let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "EntryAbility", abilityName: "EntryAbility",
}; };
let appIds = {"com.example.myapplication"}; let appIds = ["com.example.myapplication"];
bundleManager.AddAllowedInstallBundles(wantTemp, appIds, 100, (error) => { bundleManager.addAllowedInstallBundles(wantTemp, appIds, 100, (error) => {
if (error != null) { if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message); console.log("error code:" + error.code + " error message:" + error.message);
} }
...@@ -145,7 +146,7 @@ let wantTemp = { ...@@ -145,7 +146,7 @@ let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "EntryAbility", abilityName: "EntryAbility",
}; };
let appIds = {"com.example.myapplication"}; let appIds = ["com.example.myapplication"];
bundleManager.addAllowedInstallBundles(wantTemp, appIds, 100).then(() => { bundleManager.addAllowedInstallBundles(wantTemp, appIds, 100).then(() => {
console.log("success"); console.log("success");
...@@ -190,7 +191,7 @@ let wantTemp = { ...@@ -190,7 +191,7 @@ let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "EntryAbility", abilityName: "EntryAbility",
}; };
let appIds = {"com.example.myapplication"}; let appIds = ["com.example.myapplication"];
bundleManager.removeAllowedInstallBundles(wantTemp, appIds, (error) => { bundleManager.removeAllowedInstallBundles(wantTemp, appIds, (error) => {
if (error != null) { if (error != null) {
...@@ -236,7 +237,7 @@ let wantTemp = { ...@@ -236,7 +237,7 @@ let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "EntryAbility", abilityName: "EntryAbility",
}; };
let appIds = {"com.example.myapplication"}; let appIds = ["com.example.myapplication"];
bundleManager.removeAllowedInstallBundles(wantTemp, appIds, 100, (error) => { bundleManager.removeAllowedInstallBundles(wantTemp, appIds, 100, (error) => {
if (error != null) { if (error != null) {
...@@ -287,7 +288,7 @@ let wantTemp = { ...@@ -287,7 +288,7 @@ let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "EntryAbility", abilityName: "EntryAbility",
}; };
let appIds = {"com.example.myapplication"}; let appIds = ["com.example.myapplication"];
bundleManager.removeAllowedInstallBundles(wantTemp, appIds, 100).then(() => { bundleManager.removeAllowedInstallBundles(wantTemp, appIds, 100).then(() => {
console.log("success"); console.log("success");
...@@ -467,7 +468,7 @@ let wantTemp = { ...@@ -467,7 +468,7 @@ let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "EntryAbility", abilityName: "EntryAbility",
}; };
let appIds = {"com.example.myapplication"}; let appIds = ["com.example.myapplication"];
bundleManager.AddDisallowedInstallBundles(wantTemp, appIds, (error) => { bundleManager.AddDisallowedInstallBundles(wantTemp, appIds, (error) => {
if (error != null) { if (error != null) {
...@@ -513,7 +514,7 @@ let wantTemp = { ...@@ -513,7 +514,7 @@ let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "EntryAbility", abilityName: "EntryAbility",
}; };
let appIds = {"com.example.myapplication"}; let appIds = ["com.example.myapplication"];
bundleManager.AddDisallowedInstallBundles(wantTemp, appIds, 100, (error) => { bundleManager.AddDisallowedInstallBundles(wantTemp, appIds, 100, (error) => {
if (error != null) { if (error != null) {
...@@ -564,7 +565,7 @@ let wantTemp = { ...@@ -564,7 +565,7 @@ let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "EntryAbility", abilityName: "EntryAbility",
}; };
let appIds = {"com.example.myapplication"}; let appIds = ["com.example.myapplication"];
bundleManager.addDisallowedInstallBundles(wantTemp, appIds, 100).then(() => { bundleManager.addDisallowedInstallBundles(wantTemp, appIds, 100).then(() => {
console.log("success"); console.log("success");
...@@ -609,7 +610,7 @@ let wantTemp = { ...@@ -609,7 +610,7 @@ let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "EntryAbility", abilityName: "EntryAbility",
}; };
let appIds = {"com.example.myapplication"}; let appIds = ["com.example.myapplication"];
bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, (error) => { bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, (error) => {
if (error != null) { if (error != null) {
...@@ -655,7 +656,7 @@ let wantTemp = { ...@@ -655,7 +656,7 @@ let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "EntryAbility", abilityName: "EntryAbility",
}; };
let appIds = {"com.example.myapplication"}; let appIds = ["com.example.myapplication"];
bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, 100, (error) => { bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, 100, (error) => {
if (error != null) { if (error != null) {
...@@ -706,7 +707,7 @@ let wantTemp = { ...@@ -706,7 +707,7 @@ let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "EntryAbility", abilityName: "EntryAbility",
}; };
let appIds = {"com.example.myapplication"}; let appIds = ["com.example.myapplication"];
bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, 100).then(() => { bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, 100).then(() => {
console.log("success"); console.log("success");
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
> **说明**: > **说明**:
> >
> 本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块接口需激活为[设备管理员应用](js-apis-enterprise-adminManager.md#adminmanagerenableadmin)后才能调用,实现相应功能。
## 导入模块 ## 导入模块
...@@ -274,7 +275,7 @@ let wantTemp = { ...@@ -274,7 +275,7 @@ let wantTemp = {
bundleName: "bundleName", bundleName: "bundleName",
abilityName: "abilityName", abilityName: "abilityName",
}; };
dateTimeManager.disallowModifyDateTime(wantTemp).then(() => { dateTimeManager.isModifyDateTimeDisallowed(wantTemp).then(() => {
}).catch((error) => { }).catch((error) => {
console.log("error code:" + error.code + " error message:" + error.message); console.log("error code:" + error.code + " error message:" + error.message);
}) })
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
> **说明**: > **说明**:
> >
> 本模块首批接口从API version 10 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 10 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块接口需激活为[设备管理员应用](js-apis-enterprise-adminManager.md#adminmanagerenableadmin)后才能调用,实现相应功能。
## 导入模块 ## 导入模块
...@@ -14,7 +15,7 @@ import deviceControl from '@ohos.enterprise.deviceControl' ...@@ -14,7 +15,7 @@ import deviceControl from '@ohos.enterprise.deviceControl'
## deviceControl.resetFactory ## deviceControl.resetFactory
resetFactory(admin: Want, callback: AsyncCallback<void>): void resetFactory(admin: Want, callback: AsyncCallback\<void>): void
指定设备管理员应用恢复出厂设置。使用callback异步回调。 指定设备管理员应用恢复出厂设置。使用callback异步回调。
...@@ -56,7 +57,7 @@ deviceControl.resetFactory(wantTemp, (error) => { ...@@ -56,7 +57,7 @@ deviceControl.resetFactory(wantTemp, (error) => {
## deviceControl.resetFactory ## deviceControl.resetFactory
resetFactory(admin: Want): Promise<void> resetFactory(admin: Want): Promise\<void>
恢复出厂设置。使用Promise形式返回设置结果。 恢复出厂设置。使用Promise形式返回设置结果。
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
> **说明:** > **说明:**
> >
> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块接口需激活为[设备管理员应用](js-apis-enterprise-adminManager.md#adminmanagerenableadmin)后才能调用,实现相应功能。
## 导入模块 ## 导入模块
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
> **说明:** > **说明:**
> >
> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块接口需激活为[设备管理员应用](js-apis-enterprise-adminManager.md#adminmanagerenableadmin)后才能调用,实现相应功能。
## 导入模块 ## 导入模块
...@@ -47,7 +48,7 @@ let wantTemp = { ...@@ -47,7 +48,7 @@ let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "EntryAbility", abilityName: "EntryAbility",
}; };
networkManager.getAllNetworkInterfaces(admin, (error, result) => { networkManager.getAllNetworkInterfaces(wantTemp, (error, result) => {
if (error != null) { if (error != null) {
console.log("error code:" + error.code + " error message:" + error.message); console.log("error code:" + error.code + " error message:" + error.message);
return; return;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
> **说明:** > **说明:**
> >
> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块接口需激活为[设备管理员应用](js-apis-enterprise-adminManager.md#adminmanagerenableadmin)后才能调用,实现相应功能。
## 导入模块 ## 导入模块
...@@ -139,7 +140,7 @@ let wantTemp = { ...@@ -139,7 +140,7 @@ let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "EntryAbility", abilityName: "EntryAbility",
}; };
let profile : WifiProfile = { let profile : wifiManager.WifiProfile = {
"ssid": "name", "ssid": "name",
"preSharedKey": "passwd", "preSharedKey": "passwd",
"securityType": wifiManager.WifiSecurityType.WIFI_SEC_TYPE_PSK "securityType": wifiManager.WifiSecurityType.WIFI_SEC_TYPE_PSK
...@@ -194,12 +195,12 @@ let wantTemp = { ...@@ -194,12 +195,12 @@ let wantTemp = {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "EntryAbility", abilityName: "EntryAbility",
}; };
let profile : WifiProfile = { let profile : wifiManager.WifiProfile = {
"ssid": "name", "ssid": "name",
"preSharedKey": "passwd", "preSharedKey": "passwd",
"securityType": wifiManager.WifiSecurityType.WIFI_SEC_TYPE_PSK "securityType": wifiManager.WifiSecurityType.WIFI_SEC_TYPE_PSK
}; };
wifiManager.isWifiActive(wantTemp, profile).then(() => { wifiManager.setWifiProfile(wantTemp, profile).then(() => {
console.log("set wifi success"); console.log("set wifi success");
}).catch(error => { }).catch(error => {
console.log("error code:" + error.code + " error message:" + error.message); console.log("error code:" + error.code + " error message:" + error.message);
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
在连接指定的后台服务时作为入参,用于接收连接过程中的状态变化,如作为[connectServiceExtensionAbility](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextconnectserviceextensionability)的入参,连接指定的ServiceExtensionAbility。 在连接指定的后台服务时作为入参,用于接收连接过程中的状态变化,如作为[connectServiceExtensionAbility](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextconnectserviceextensionability)的入参,连接指定的ServiceExtensionAbility。
> **说明:**
>
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块 ## 导入模块
```ts ```ts
......
...@@ -2,13 +2,16 @@ ...@@ -2,13 +2,16 @@
提供用于匹配满足指定条件的受监视的AbilityStage对象的方法。最近匹配的AbilityStage对象将保存在AbilityStageMonitor对象中。 提供用于匹配满足指定条件的受监视的AbilityStage对象的方法。最近匹配的AbilityStage对象将保存在AbilityStageMonitor对象中。
> **说明:**
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core **系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| ------------------------------------------------------------ | -------- | ---- | ---- | ------------------------------------------------------------ | | ------------------------------------------------------------ | -------- | ---- | ---- | ------------------------------------------------------------ |
| moduleName<sup>9+</sup> | string | 是 | 是 | 要监视的abilityStage的模块名。 | | moduleName | string | 是 | 是 | 要监视的abilityStage的模块名。 |
| srcEntrance<sup>9+</sup> | string | 是 | 是 | 要监视的abilityStage的源路径。 | | srcEntrance | string | 是 | 是 | 要监视的abilityStage的源路径。 |
**示例:** **示例:**
```ts ```ts
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
定义Ability状态信息,可以通过[registerApplicationStateObserver](js-apis-application-appManager.md#appmanagerregisterapplicationstateobserver8)注册生命周期变化监听后,通过[ApplicationStateObserver](js-apis-inner-application-applicationStateObserver.md)的onAbilityStateChanged生命周期回调获取。 定义Ability状态信息,可以通过[registerApplicationStateObserver](js-apis-application-appManager.md#appmanagerregisterapplicationstateobserver8)注册生命周期变化监听后,通过[ApplicationStateObserver](js-apis-inner-application-applicationStateObserver.md)的onAbilityStateChanged生命周期回调获取。
> **说明:**
>
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块 ## 导入模块
```ts ```ts
...@@ -12,13 +16,13 @@ import appManager from '@ohos.application.appManager'; ...@@ -12,13 +16,13 @@ import appManager from '@ohos.application.appManager';
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| ----------------------- | ---------| ---- | ---- | ------------------------- | | ----------------------- | ---------| ---- | ---- | ------------------------- |
| pid<sup>8+</sup> | number | 是 | 否 | 进程ID。 | | pid | number | 是 | 否 | 进程ID。 |
| bundleName<sup>8+</sup> | string | 是 | 否 | 应用Bundle名称。 | | bundleName | string | 是 | 否 | 应用Bundle名称。 |
| abilityName<sup>8+</sup> | string | 是 | 否 | Ability名称。 | | abilityName | string | 是 | 否 | Ability名称。 |
| uid<sup>8+</sup> | number | 是 | 否 | 用户ID。 | | uid | number | 是 | 否 | 用户ID。 |
| state<sup>8+</sup> | number | 是 | 否 | [Ability状态](#ability状态)。 | | state | number | 是 | 否 | [Ability状态](#ability状态)。 |
| moduleName<sup>9+</sup> | string | 是 | 否 | Ability所属的HAP的名称。 | | moduleName<sup>9+</sup> | string | 是 | 否 | Ability所属的HAP的名称。 |
| abilityType<sup>8+</sup> | number | 是 | 否 | [Ability类型](#ability类型):页面或服务等。 | | abilityType | number | 是 | 否 | [Ability类型](#ability类型):页面或服务等。 |
#### Ability状态 #### Ability状态
......
...@@ -309,7 +309,6 @@ getRunningProcessInformation(): Promise\<Array\<ProcessInformation>>; ...@@ -309,7 +309,6 @@ getRunningProcessInformation(): Promise\<Array\<ProcessInformation>>;
**示例:** **示例:**
```ts ```ts
let applicationContext = this.context.getApplicationContext();
applicationContext.getRunningProcessInformation().then((data) => { applicationContext.getRunningProcessInformation().then((data) => {
console.log('The process running information is: ${JSON.stringify(data)}'); console.log('The process running information is: ${JSON.stringify(data)}');
}).catch((error) => { }).catch((error) => {
...@@ -347,7 +346,6 @@ getRunningProcessInformation(callback: AsyncCallback\<Array\<ProcessInformation> ...@@ -347,7 +346,6 @@ getRunningProcessInformation(callback: AsyncCallback\<Array\<ProcessInformation>
**示例:** **示例:**
```ts ```ts
let applicationContext = this.context.getApplicationContext();
applicationContext.getRunningProcessInformation((err, data) => { applicationContext.getRunningProcessInformation((err, data) => {
if (err) { if (err) {
console.error('getRunningProcessInformation faile, err: ${JSON.stringify(err)}'); console.error('getRunningProcessInformation faile, err: ${JSON.stringify(err)}');
...@@ -382,7 +380,6 @@ killAllProcesses(): Promise\<void\>; ...@@ -382,7 +380,6 @@ killAllProcesses(): Promise\<void\>;
**示例:** **示例:**
```ts ```ts
let applicationContext = this.context.getApplicationContext();
applicationContext.killAllProcesses(); applicationContext.killAllProcesses();
``` ```
...@@ -411,7 +408,6 @@ killAllProcesses(callback: AsyncCallback\<void\>); ...@@ -411,7 +408,6 @@ killAllProcesses(callback: AsyncCallback\<void\>);
**示例:** **示例:**
```ts ```ts
let applicationContext = this.context.getApplicationContext();
applicationContext.killAllProcesses(error => { applicationContext.killAllProcesses(error => {
if (error) { if (error) {
console.error('killAllProcesses fail, error: ${JSON.stringify(error)}'); console.error('killAllProcesses fail, error: ${JSON.stringify(error)}');
......
...@@ -2,10 +2,14 @@ ...@@ -2,10 +2,14 @@
定义应用状态监听,可以作为[registerApplicationStateObserver](js-apis-application-appManager.md#appmanagerregisterapplicationstateobserver8)的入参监听当前应用的生命周期变化。 定义应用状态监听,可以作为[registerApplicationStateObserver](js-apis-application-appManager.md#appmanagerregisterapplicationstateobserver8)的入参监听当前应用的生命周期变化。
> **说明:**
>
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块 ## 导入模块
```ts ```ts
import appManager from '@ohos.application.appManager'; import appManager from '@ohos.app.ability.appManager';
``` ```
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core **系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
...@@ -14,16 +18,14 @@ import appManager from '@ohos.application.appManager'; ...@@ -14,16 +18,14 @@ import appManager from '@ohos.application.appManager';
| 名称 | | 类型 | 可读 | 可写 | 说明 | | 名称 | | 类型 | 可读 | 可写 | 说明 |
| ----------------------- | ---------| ---- | ---- | ------------------------- | ------------------------- | | ----------------------- | ---------| ---- | ---- | ------------------------- | ------------------------- |
| onForegroundApplicationChanged<sup>8+</sup> | [AppStateData](js-apis-inner-application-appStateData.md) | AsyncCallback\<void> | 是 | 否 | 应用前后台状态发生变化时执行的回调函数。 | | onForegroundApplicationChanged | [AppStateData](js-apis-inner-application-appStateData.md) | AsyncCallback\<void> | 是 | 否 | 应用前后台状态发生变化时执行的回调函数。 |
| onAbilityStateChanged<sup>8+</sup> | [AbilityStateData](js-apis-inner-application-abilityStateData.md) | AsyncCallback\<void> | 是 | 否 | ability状态发生变化时执行的回调函数。 | | onAbilityStateChanged | [AbilityStateData](js-apis-inner-application-abilityStateData.md) | AsyncCallback\<void> | 是 | 否 | ability状态发生变化时执行的回调函数。 |
| onProcessCreated<sup>8+</sup> | [ProcessData](js-apis-inner-application-processData.md) | AsyncCallback\<void> | 是 | 否 | 进程创建时执行的回调函数。 | | onProcessCreated | [ProcessData](js-apis-inner-application-processData.md) | AsyncCallback\<void> | 是 | 否 | 进程创建时执行的回调函数。 |
| onProcessDied<sup>8+</sup> | [ProcessData](js-apis-inner-application-processData.md) | AsyncCallback\<void> | 是 | 否 | 进程销毁时执行的回调函数。 | | onProcessDied | [ProcessData](js-apis-inner-application-processData.md) | AsyncCallback\<void> | 是 | 否 | 进程销毁时执行的回调函数。 |
| onProcessStateChanged<sup>8+</sup> | [ProcessData](js-apis-inner-application-processData.md) | AsyncCallback\<void> | 是 | 否 | 进程状态更新时执行的回调函数。 | | onProcessStateChanged<sup>9+</sup> | [ProcessData](js-apis-inner-application-processData.md) | AsyncCallback\<void> | 是 | 否 | 进程状态更新时执行的回调函数。 |
**示例:** **示例:**
```ts ```ts
import appManager from '@ohos.app.ability.appManager';
let applicationStateObserver = { let applicationStateObserver = {
onForegroundApplicationChanged(appStateData) { onForegroundApplicationChanged(appStateData) {
console.log('onForegroundApplicationChanged appStateData: ${JSON.stringify(appStateData)}'); console.log('onForegroundApplicationChanged appStateData: ${JSON.stringify(appStateData)}');
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
表示跨设备迁移Mission完成后,返回迁移结果的回调函数,迁移Mission详见:[continueMission接口](js-apis-distributedMissionManager.md#distributedmissionmanagercontinuemission) 表示跨设备迁移Mission完成后,返回迁移结果的回调函数,迁移Mission详见:[continueMission接口](js-apis-distributedMissionManager.md#distributedmissionmanagercontinuemission)
> **说明:**
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## ContinueCallback.onContinueDone ## ContinueCallback.onContinueDone
onContinueDone(result: number): void; onContinueDone(result: number): void;
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
表示发起Mission迁移时所需参数的枚举,迁移Mission详见:[continueMission接口](js-apis-distributedMissionManager.md#distributedmissionmanagercontinuemission) 表示发起Mission迁移时所需参数的枚举,迁移Mission详见:[continueMission接口](js-apis-distributedMissionManager.md#distributedmissionmanagercontinuemission)
> **说明:**
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Mission **系统能力**:SystemCapability.Ability.AbilityRuntime.Mission
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
定义异常监听,可以作为[ErrorManager.on](js-apis-app-ability-errorManager.md#errormanageron)的入参监听当前应用发生的异常。 定义异常监听,可以作为[ErrorManager.on](js-apis-app-ability-errorManager.md#errormanageron)的入参监听当前应用发生的异常。
> **说明:**
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块 ## 导入模块
```ts ```ts
...@@ -40,7 +44,7 @@ try { ...@@ -40,7 +44,7 @@ try {
} }
``` ```
## ErrorObserver.onException ## ErrorObserver.onException<sup>10+</sup>
onException?(errObject: Error): void; onException?(errObject: Error): void;
......
...@@ -23,7 +23,7 @@ import common from '@ohos.app.ability.common'; ...@@ -23,7 +23,7 @@ import common from '@ohos.app.ability.common';
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formBindingData from '@ohos.app.form.formBindingData'; import formBindingData from '@ohos.app.form.formBindingData';
export default class MyFormExtensionAbility extends FormExtensionAbility { class MyFormExtensionAbility extends FormExtensionAbility {
onAddForm(want) { onAddForm(want) {
let formContext = this.context; // 获取FormExtensionContext let formContext = this.context; // 获取FormExtensionContext
// ... // ...
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
作为可以[registerMissionListener](js-apis-distributedMissionManager.md#distributedmissionmanagerregistermissionlistener)的入参,表示开始同步后,建立的回调函数。 作为可以[registerMissionListener](js-apis-distributedMissionManager.md#distributedmissionmanagerregistermissionlistener)的入参,表示开始同步后,建立的回调函数。
> **说明:**
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Mission **系统能力**:SystemCapability.Ability.AbilityRuntime.Mission
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
表示任务的详细信息,可以通过[getMissionInfo](js-apis-app-ability-missionManager.md#missionmanagergetmissioninfo)获取。 表示任务的详细信息,可以通过[getMissionInfo](js-apis-app-ability-missionManager.md#missionmanagergetmissioninfo)获取。
> **说明:**
>
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块 ## 导入模块
```ts ```ts
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
定义系统任务状态监听,可以通过[on](js-apis-app-ability-missionManager.md#missionmanageron)注册。 定义系统任务状态监听,可以通过[on](js-apis-app-ability-missionManager.md#missionmanageron)注册。
> **说明:**
>
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块 ## 导入模块
```ts ```ts
...@@ -16,9 +20,9 @@ import missionManager from '@ohos.app.ability.missionManager'; ...@@ -16,9 +20,9 @@ import missionManager from '@ohos.app.ability.missionManager';
| onMissionDestroyed | function | 否 | 表示当系统销毁任务时回调执行。 | | onMissionDestroyed | function | 否 | 表示当系统销毁任务时回调执行。 |
| onMissionSnapshotChanged | function | 否 | 表示当系统更新任务缩略图时回调执行。 | | onMissionSnapshotChanged | function | 否 | 表示当系统更新任务缩略图时回调执行。 |
| onMissionMovedToFront | function | 否 | 表示当系统将任务移动到前台时回调执行。 | | onMissionMovedToFront | function | 否 | 表示当系统将任务移动到前台时回调执行。 |
| onMissionLabelUpdated | function | 否 | 表示当系统更新任务标签时回调执行。 | | onMissionLabelUpdated<sup>9+</sup> | function | 否 | 表示当系统更新任务标签时回调执行。 |
| onMissionIconUpdated | function | 否 | 表示当系统更新任务图标时回调执行。 | | onMissionIconUpdated<sup>9+</sup> | function | 否 | 表示当系统更新任务图标时回调执行。 |
| onMissionClosed | function | 否 | 表示当系统关闭任务时回调执行。 | | onMissionClosed<sup>9+</sup> | function | 否 | 表示当系统关闭任务时回调执行。 |
**示例:** **示例:**
```ts ```ts
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
作为[startSyncRemoteMissions](js-apis-distributedMissionManager.md#distributedmissionmanagerstartsyncremotemissions)的入参,表示同步时所需参数的枚举。 作为[startSyncRemoteMissions](js-apis-distributedMissionManager.md#distributedmissionmanagerstartsyncremotemissions)的入参,表示同步时所需参数的枚举。
> **说明:**
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Mission **系统能力**:SystemCapability.Ability.AbilityRuntime.Mission
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
......
...@@ -2,10 +2,14 @@ ...@@ -2,10 +2,14 @@
进程数据的对象定义。使用接口[registerApplicationStateObserver](js-apis-application-appManager.md#appmanagerregisterapplicationstateobserver8)注册生命周期变化监听后,当应用或组件的生命周期变化时,系统通过[ApplicationStateObserver](js-apis-inner-application-applicationStateObserver.md)的onProcessCreated等方法回调给开发者。 进程数据的对象定义。使用接口[registerApplicationStateObserver](js-apis-application-appManager.md#appmanagerregisterapplicationstateobserver8)注册生命周期变化监听后,当应用或组件的生命周期变化时,系统通过[ApplicationStateObserver](js-apis-inner-application-applicationStateObserver.md)的onProcessCreated等方法回调给开发者。
> **说明:**
>
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块 ## 导入模块
```ts ```ts
import appManager from '@ohos.app.ability.appManager'; import appManager from '@ohos.application.appManager';
``` ```
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core **系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
...@@ -14,16 +18,16 @@ import appManager from '@ohos.app.ability.appManager'; ...@@ -14,16 +18,16 @@ import appManager from '@ohos.app.ability.appManager';
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| ----------------------- | ---------| ---- | ---- | ------------------------- | | ----------------------- | ---------| ---- | ---- | ------------------------- |
| pid<sup>8+</sup> | number | 是 | 否 | 进程ID。 | | pid | number | 是 | 否 | 进程ID。 |
| bundleName<sup>8+</sup> | string | 是 | 否 | 应用包名。 | | bundleName | string | 是 | 否 | 应用包名。 |
| uid<sup>8+</sup> | number | 是 | 否 | 应用的uid。 | | uid | number | 是 | 否 | 应用的uid。 |
| isContinuousTask<sup>9+</sup> | boolean | 是 | 否 | 是否为长时任务,true表示是,false表示不是 | | isContinuousTask<sup>9+</sup> | boolean | 是 | 否 | 是否为长时任务,true表示是,false表示不是 |
| isKeepAlive<sup>9+</sup> | boolean | 是 | 否 | 是否为常驻进程,true表示是,false表示不是 | | isKeepAlive<sup>9+</sup> | boolean | 是 | 否 | 是否为常驻进程,true表示是,false表示不是 |
| state<sup>9+</sup> | number | 是 | 否 | 应用的状态,取值及对应的状态为:0(刚创建),2(前台),4(后台),5(已终止)。 | | state<sup>9+</sup> | number | 是 | 否 | 应用的状态,取值及对应的状态为:0(刚创建),2(前台),4(后台),5(已终止)。 |
**示例:** **示例:**
```ts ```ts
import appManager from '@ohos.app.ability.appManager'; import appManager from '@ohos.application.appManager';
let applicationStateObserver = { let applicationStateObserver = {
onForegroundApplicationChanged(appStateData) { onForegroundApplicationChanged(appStateData) {
......
...@@ -367,7 +367,7 @@ try { ...@@ -367,7 +367,7 @@ try {
// 执行正常业务 // 执行正常业务
console.info('startAbilityForResult succeed'); console.info('startAbilityForResult succeed');
}); });
} catch (paramError) { } catch (err) {
// 处理入参错误异常 // 处理入参错误异常
console.error(`startAbilityForResult failed, code is ${err.code}, message is ${err.message}`); console.error(`startAbilityForResult failed, code is ${err.code}, message is ${err.message}`);
} }
...@@ -785,7 +785,7 @@ try { ...@@ -785,7 +785,7 @@ try {
// 处理业务逻辑错误 // 处理业务逻辑错误
console.error(`startServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`); console.error(`startServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
}); });
} catch (paramError) { } catch (err) {
// 处理入参错误异常 // 处理入参错误异常
console.error(`startServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`); console.error(`startServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
} }
...@@ -1397,6 +1397,7 @@ let want = { ...@@ -1397,6 +1397,7 @@ let want = {
bundleName: 'com.example.myapplication', bundleName: 'com.example.myapplication',
abilityName: 'ServiceExtensionAbility' abilityName: 'ServiceExtensionAbility'
}; };
let commRemote;
let options = { let options = {
onConnect(elementName, remote) { onConnect(elementName, remote) {
commRemote = remote; commRemote = remote;
...@@ -1466,6 +1467,7 @@ let want = { ...@@ -1466,6 +1467,7 @@ let want = {
abilityName: 'ServiceExtensionAbility' abilityName: 'ServiceExtensionAbility'
}; };
let accountId = 100; let accountId = 100;
let commRemote;
let options = { let options = {
onConnect(elementName, remote) { onConnect(elementName, remote) {
commRemote = remote; commRemote = remote;
...@@ -1522,6 +1524,7 @@ disconnectServiceExtensionAbility(connection: number): Promise\<void>; ...@@ -1522,6 +1524,7 @@ disconnectServiceExtensionAbility(connection: number): Promise\<void>;
```ts ```ts
// connection为connectServiceExtensionAbility中的返回值 // connection为connectServiceExtensionAbility中的返回值
let connection = 1; let connection = 1;
let commRemote;
try { try {
this.context.disconnectServiceExtensionAbility(connection, (err) => { this.context.disconnectServiceExtensionAbility(connection, (err) => {
...@@ -1570,6 +1573,24 @@ disconnectServiceExtensionAbility(connection: number, callback:AsyncCallback\<vo ...@@ -1570,6 +1573,24 @@ disconnectServiceExtensionAbility(connection: number, callback:AsyncCallback\<vo
```ts ```ts
// connection为connectServiceExtensionAbility中的返回值 // connection为connectServiceExtensionAbility中的返回值
let connection = 1; let connection = 1;
let commRemote;
try {
this.context.disconnectServiceExtensionAbility(connection, (err) => {
commRemote = null;
if (err.code) {
// 处理业务逻辑错误
console.error(`disconnectServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
return;
}
// 执行正常业务
console.info('disconnectServiceExtensionAbility succeed');
});
} catch (err) {
commRemote = null;
// 处理入参错误异常
console.error(`disconnectServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
}
try { try {
this.context.disconnectServiceExtensionAbility(connection, (err) => { this.context.disconnectServiceExtensionAbility(connection, (err) => {
...@@ -1683,11 +1704,11 @@ try { ...@@ -1683,11 +1704,11 @@ try {
// 执行正常业务 // 执行正常业务
caller = obj; caller = obj;
console.info('startAbilityByCall succeed'); console.info('startAbilityByCall succeed');
}).catch((error) => { }).catch((err) => {
// 处理业务逻辑错误 // 处理业务逻辑错误
console.error(`startAbilityByCall failed, code is ${err.code}, message is ${err.message}`); console.error(`startAbilityByCall failed, code is ${err.code}, message is ${err.message}`);
}); });
} catch (paramError) { } catch (err) {
// 处理入参错误异常 // 处理入参错误异常
console.error(`startAbilityByCall failed, code is ${err.code}, message is ${err.message}`); console.error(`startAbilityByCall failed, code is ${err.code}, message is ${err.message}`);
} }
...@@ -2071,6 +2092,8 @@ setMissionIcon(icon: image.PixelMap): Promise\<void>; ...@@ -2071,6 +2092,8 @@ setMissionIcon(icon: image.PixelMap): Promise\<void>;
**示例:** **示例:**
```ts ```ts
import image from '@ohos.multimedia.image';
let imagePixelMap; let imagePixelMap;
let color = new ArrayBuffer(0); let color = new ArrayBuffer(0);
let initializationOptions = { let initializationOptions = {
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
作为[trigger](js-apis-app-ability-wantAgent.md#wantagenttrigger)的入参定义触发WantAgent所需要的信息。 作为[trigger](js-apis-app-ability-wantAgent.md#wantagenttrigger)的入参定义触发WantAgent所需要的信息。
> **说明:**
>
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块 ## 导入模块
```ts ```ts
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
定义触发WantAgent所需要的信息,可以作为[getWantAgent](js-apis-app-ability-wantAgent.md#wantagentgetwantagent)的入参创建指定的WantAgent对象。 定义触发WantAgent所需要的信息,可以作为[getWantAgent](js-apis-app-ability-wantAgent.md#wantagentgetwantagent)的入参创建指定的WantAgent对象。
> **说明:**
>
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块 ## 导入模块
```ts ```ts
......
...@@ -112,7 +112,7 @@ struct Index { ...@@ -112,7 +112,7 @@ struct Index {
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------------- | -------------------------------------------------------------------------------------------------- | ---- | ----------------------------------------------- | | -------------- | -------------------------------------------------------------------------------------------------- | ---- | ----------------------------------------------- |
| textContent | string | 是 | 设置被计算文本内容。 | | textContent<sup>10+</sup> | string | 是 | 设置被计算文本内容。 |
| constraintWidth<sup>10+</sup> | number&nbsp;\|&nbsp;string&nbsp;\|&nbsp;[Resource](../arkui-ts/ts-types.md#resource) | 否 | 设置被计算文本布局宽度。<br/>**说明:** 默认单位为vp | | constraintWidth<sup>10+</sup> | number&nbsp;\|&nbsp;string&nbsp;\|&nbsp;[Resource](../arkui-ts/ts-types.md#resource) | 否 | 设置被计算文本布局宽度。<br/>**说明:** 默认单位为vp |
| fontSize | number&nbsp;\|&nbsp;string&nbsp;\|&nbsp;[Resource](../arkui-ts/ts-types.md#resource) | 否 | 设置被计算文本字体大小,fontSize为number类型时,使用fp单位。<br/>默认值:16fp。<br/>**说明:** 不支持设置百分比字符串。 | | fontSize | number&nbsp;\|&nbsp;string&nbsp;\|&nbsp;[Resource](../arkui-ts/ts-types.md#resource) | 否 | 设置被计算文本字体大小,fontSize为number类型时,使用fp单位。<br/>默认值:16fp。<br/>**说明:** 不支持设置百分比字符串。 |
| fontStyle | number&nbsp;\|&nbsp;[FontStyle](../arkui-ts/ts-appendix-enums.md#fontstyle) | 否 | 设置被计算文本字体样式。<br>默认值:FontStyle.Normal | | fontStyle | number&nbsp;\|&nbsp;[FontStyle](../arkui-ts/ts-appendix-enums.md#fontstyle) | 否 | 设置被计算文本字体样式。<br>默认值:FontStyle.Normal |
......
...@@ -3975,6 +3975,87 @@ notificationManager.getSyncNotificationEnabledWithoutApp(userId).then((data) => ...@@ -3975,6 +3975,87 @@ notificationManager.getSyncNotificationEnabledWithoutApp(userId).then((data) =>
}); });
``` ```
## notificationManager.on<sup>10+</sup>
on(type: 'checkNotification', callback: (checkInfo: NotificationCheckInfo) => NotificationCheckResult): void;
注册通知监听回调。通知服务将通知信息回调给校验程序,校验程序返回校验结果决定该通知是否发布,如营销类通知发布频率控制等。
**系统能力**:SystemCapability.Notification.Notification
**系统API**:此接口为系统接口,三方应用不支持调用。
**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER and ohos.permission.NOTIFICATION_AGENT_CONTROLLER
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ----------------------------- | ---- | -------------- |
| type | string | 是 | 回调函数类型名,固定为'checkNotification'。 |
| callback | (checkInfo: [NotificationCheckInfo](#notificationcheckinfo)) => [NotificationCheckResult](#notificationcheckresult) | 是 | 消息验证函数指针。 |
**错误码:**
错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)
| 错误码ID | 错误信息 |
| -------- | --------------- |
| 1600001 | Internal error. |
**示例:**
```ts
try{
notificationManager.on("checkNotification", OnCheckNotification);
} catch (error){
console.info(`notificationManager.on error: ${JSON.stringify(error)}`);
}
function OnCheckNotification(info : notificationManager.NotificationCheckInfo) {
console.info(`====>OnCheckNotification info: ${JSON.stringify(info)}`);
if(info.notificationId == 1){
return { code: 1, message: "testMsg1"}
} else {
return { code: 0, message: "testMsg0"}
}
}
```
## notificationManager.off<sup>10+</sup>
off(type: 'checkNotification', callback?: (checkInfo: NotificationCheckInfo) => NotificationCheckResult): void;
取消通知监听回调。
**系统能力**:SystemCapability.Notification.Notification
**系统API**:此接口为系统接口,三方应用不支持调用。
**需要权限**:ohos.permission.NOTIFICATION_CONTROLLER and ohos.permission.NOTIFICATION_AGENT_CONTROLLER
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ----------------------------- | ---- | -------------- |
| type | string | 是 | 回调函数类型名,固定为'checkNotification'。 |
| callback | (checkInfo: [NotificationCheckInfo](#notificationcheckinfo)) => [NotificationCheckResult](#notificationcheckresult) | 否 | 消息验证函数指针。 |
**错误码:**
错误码详细介绍请参考[errcode-notification](../errorcodes/errorcode-notification.md)
| 错误码ID | 错误信息 |
| -------- | --------------- |
| 1600001 | Internal error. |
**示例:**
```ts
try{
notificationManager.off("checkNotification");
} catch (error){
console.info(`notificationManager.off error: ${JSON.stringify(error)}`);
}
```
## DoNotDisturbDate ## DoNotDisturbDate
...@@ -4067,3 +4148,23 @@ notificationManager.getSyncNotificationEnabledWithoutApp(userId).then((data) => ...@@ -4067,3 +4148,23 @@ notificationManager.getSyncNotificationEnabledWithoutApp(userId).then((data) =>
| TYPE_NORMAL | 0 | 一般通知。 | | TYPE_NORMAL | 0 | 一般通知。 |
| TYPE_CONTINUOUS | 1 | 连续通知。 | | TYPE_CONTINUOUS | 1 | 连续通知。 |
| TYPE_TIMER | 2 | 计划通知。 | | TYPE_TIMER | 2 | 计划通知。 |
## NotificationCheckInfo
用于校验通知的参数。
| 名称 | 类型 | 可读 | 可写 | 说明 |
| -------------------- | -------- | ---------- | ---------- | ---------- |
| bundleName | string | 是 | 否 | bundle名称。 |
| notificationId | number | 是 | 否 | 通知Id。 |
| contentType | [ContentType](#contenttype) | 是 | 否 | 通知类型。 |
## NotificationCheckResult
通知校验结果。
| 名称 | 类型 | 可读 | 可写 | 说明 |
| -------------------- | -------- | ---------- | ---------- | ---------- |
| code | number | 是 | 否 | 0-display, 1-no display。 |
| message | string | 是 | 否 | 结果信息。 |
...@@ -483,9 +483,9 @@ record.convertToText().then((data) => { ...@@ -483,9 +483,9 @@ record.convertToText().then((data) => {
## PasteData ## PasteData
剪贴板内容对象。 剪贴板内容对象。剪贴板内容包含一个或者多个内容条目([PasteDataRecord](#pastedatarecord7))以及属性描述对象([PasteDataProperty](#pastedataproperty7))。
在调用PasteData的接口前,需要先获取一个PasteData对象。 在调用PasteData的接口前,需要先通过[createData()](#pasteboardcreatedata9)[getData()](#getdata9)获取一个PasteData对象。
**系统能力:** SystemCapability.MiscServices.Pasteboard **系统能力:** SystemCapability.MiscServices.Pasteboard
......
...@@ -80,7 +80,7 @@ stopWork(work: WorkInfo, needCancel?: boolean): void ...@@ -80,7 +80,7 @@ stopWork(work: WorkInfo, needCancel?: boolean): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ---------- | --------------------- | ---- | ---------- | | ---------- | --------------------- | ---- | ---------- |
| work | [WorkInfo](#workinfo) | 是 | 指示要停止的工作。 | | work | [WorkInfo](#workinfo) | 是 | 指示要停止的工作。 |
| needCancel | boolean | 是 | 是否需要取消的工作。 | | needCancel | boolean | 否 | 是否需要取消的工作,默认为不取消。 |
**错误码** **错误码**
...@@ -432,7 +432,7 @@ isLastWorkTimeOut(workId: number): Promise\<boolean> ...@@ -432,7 +432,7 @@ isLastWorkTimeOut(workId: number): Promise\<boolean>
| isPersisted | boolean | 否 | 是否持久化保存工作 | | isPersisted | boolean | 否 | 是否持久化保存工作 |
| isDeepIdle | boolean | 否 | 是否要求设备进入空闲状态 | | isDeepIdle | boolean | 否 | 是否要求设备进入空闲状态 |
| idleWaitTime | number | 否 | 空闲等待时间 | | idleWaitTime | number | 否 | 空闲等待时间 |
| parameters | {[key: string]: number | string | boolean} | 否 | 携带参数信息 | | parameters | {[key: string]: number \| string \| boolean} | 否 | 携带参数信息 |
## NetworkType ## NetworkType
触发工作的网络类型。 触发工作的网络类型。
......
...@@ -320,7 +320,7 @@ replaceUrl(options: RouterOptions, mode: RouterMode): Promise&lt;void&gt; ...@@ -320,7 +320,7 @@ replaceUrl(options: RouterOptions, mode: RouterMode): Promise&lt;void&gt;
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | ------- | | --------- | ------- |
| 100001 | if UI execution context not found, only throw in standard system. | | 100001 | if can not get the delegate, only throw in standard system. |
| 200002 | if the uri is not exist. | | 200002 | if the uri is not exist. |
**示例:** **示例:**
...@@ -362,7 +362,7 @@ replaceUrl(options: RouterOptions, mode: RouterMode, callback: AsyncCallback&lt; ...@@ -362,7 +362,7 @@ replaceUrl(options: RouterOptions, mode: RouterMode, callback: AsyncCallback&lt;
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| --------- | ------- | | --------- | ------- |
| 100001 | if can not get the delegate, only throw in standard system. | | 100001 | if UI execution context not found, only throw in standard system. |
| 200002 | if the uri is not exist. | | 200002 | if the uri is not exist. |
**示例:** **示例:**
...@@ -660,8 +660,8 @@ struct Second { ...@@ -660,8 +660,8 @@ struct Second {
private content: string = "这是第二页" private content: string = "这是第二页"
@State text: string = router.getParams()['text'] @State text: string = router.getParams()['text']
@State data: object = router.getParams()['data'] @State data: object = router.getParams()['data']
@State secondData : string = '' @State secondData: string = ''
build() { build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text(`${this.content}`) Text(`${this.content}`)
...@@ -669,14 +669,14 @@ struct Second { ...@@ -669,14 +669,14 @@ struct Second {
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
Text(this.text) Text(this.text)
.fontSize(30) .fontSize(30)
.onClick(()=>{ .onClick(() => {
this.secondData = (this.data.['array'][1]).toString() this.secondData = (this.data.['array'][1]).toString()
}) })
.margin({top:20}) .margin({ top: 20 })
Text(`第一页传来的数值:${this.secondData}`) Text(`第一页传来的数值:${this.secondData}`)
.fontSize(20) .fontSize(20)
.margin({top:20}) .margin({ top: 20 })
.backgroundColor('red') .backgroundColor('red')
} }
.width('100%') .width('100%')
.height('100%') .height('100%')
...@@ -761,9 +761,9 @@ enableAlertBeforeBackPage(options: EnableAlertOptions): void ...@@ -761,9 +761,9 @@ enableAlertBeforeBackPage(options: EnableAlertOptions): void
**示例:** **示例:**
```js ```js
router.enableAlertBeforeBackPage({ router.enableAlertBeforeBackPage({
message: 'Message Info' message: 'Message Info'
}); });
``` ```
## router.disableAlertBeforeBackPage<sup>(deprecated)</sup> ## router.disableAlertBeforeBackPage<sup>(deprecated)</sup>
......
...@@ -123,7 +123,7 @@ off(activity: ActivityType, event: ActivityEvent, callback?: Callback&lt;Activit ...@@ -123,7 +123,7 @@ off(activity: ActivityType, event: ActivityEvent, callback?: Callback&lt;Activit
| -------------------- | -------------------------------------------------- | ---- | ---------------------------- | | -------------------- | -------------------------------------------------- | ---- | ---------------------------- |
| activity | [ActivityType](#activitytype) | 是 | 设备状态能力类型。 | | activity | [ActivityType](#activitytype) | 是 | 设备状态能力类型。 |
| event | [ActivityEvent](#activityevent) | 是 | 事件类型。 | | event | [ActivityEvent](#activityevent) | 是 | 事件类型。 |
| callback | Callback<[ActivityResponse](#activityresponse)\> | 否 | 回调函数,接收上报状态变化事件。 | | callback | Callback<[ActivityResponse](#activityresponse)\> | 否 | 回调函数,接收上报状态变化事件,如果没有传递callback参数,会移除该进程下订阅该类型得所有callback。 |
**示例:** **示例:**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册