提交 2297e7e4 编写于 作者: zyjhandsome's avatar zyjhandsome

Merge branch 'master' of https://gitee.com/openharmony/docs

......@@ -13,6 +13,9 @@
- Vibrator
- [Vibrator Overview](vibrator-overview.md)
- [Vibrator Development](vibrator-guidelines.md)
- Multimodal Input
- [Input Device Development](inputdevice-guidelines.md)
- [Mouse Pointer Development](pointerstyle-guidelines.md)
- Update Service
- [Sample Server Overview](sample-server-overview.md)
- [Sample Server Development](sample-server-guidelines.md)
# Input Device Development
## When to Use
Input device management provides functions such as listening for device hot swap events and querying the keyboard type of a specified device. For example, as a user enters text, the input method determines whether to launch the virtual keyboard based on whether a physical keyboard is currently inserted. Your application can determine whether a physical keyboard is inserted by listening to device hot swap events.
## Modules to Import
```js
import inputDevice from '@ohos.multimodalInput.inputDevice';
```
## Available APIs
The following table lists the common APIs for input device management. For details about the APIs, see [ohos.multimodalInput.inputDevice](../reference/apis/js-apis-inputdevice.md).
| Instance| API | Description|
| ----------- | ------------------------------------------------------------ | -------------------------- |
| inputDevice | function getDeviceList(callback: AsyncCallback\<Array\<number>>): void; | Obtains the list of input devices.|
| inputDevice | function getKeyboardType(deviceId: number, callback: AsyncCallback\<KeyboardType>): void; | Obtains the keyboard type of the input device.|
| inputDevice | function on(type: "change", listener: Callback\<DeviceListener>): void; | Enables listening for device hot swap events.|
| inputDevice | function off(type: "change", listener?: Callback\<DeviceListener>): void; | Disables listening for device hot swap events.|
## Virtual Keyboard Detection
When a user enters text, the input method determines whether to launch the virtual keyboard based on whether a physical keyboard is currently inserted. Your application can determine whether a physical keyboard is inserted by listening to device hot swap events.
## How to Develop
1. Call the **getDeviceList** API to obtain the list of connected input devices. Call the **getKeyboardType** API to traverse all connected devices to check whether a physical keyboard exists. If a physical keyboard exists, mark the physical keyboard as connected. This step ensures that your application detects all inserted input devices before listening for device hot swap events.
2. Call the **on** API to listen for device hot swap events. If a physical keyboard is inserted, mark the physical keyboard as connected. If a physical keyboard is removed, mark the physical keyboard as disconnected.
3. When a user enters text, check whether a physical keyboard is connected. If a physical keyboard is not connected, launch the virtual keyboard.
```js
import inputDevice from '@ohos.multimodalInput.inputDevice';
let isPhysicalKeyboardExist = true;
try {
// 1. Obtain the list of input devices and check whether a physical keyboard is connected.
inputDevice.getDeviceList().then(data => {
for (let i = 0; i < data.length; ++i) {
inputDevice.getKeyboardType(data[i]).then(res => {
if (type == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD) {
// The physical keyboard is connected.
isPhysicalKeyboardExist = true;
}
});
}
});
// 2. Listen for device hot swap events.
inputDevice.on("change", (data) => {
console.log(`Device event info: ${JSON.stringify(data)}`);
inputDevice.getKeyboardType(data.deviceId, (error, type) => {
console.log("The keyboard type is: " + type);
if (type == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'add') {
// The physical keyboard is inserted.
isPhysicalKeyboardExist = true;
} else if (type == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'remove') {
// The physical keyboard is removed.
isPhysicalKeyboardExist = false;
}
});
});
} catch (error) {
console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
// 3. Determine whether to launch the virtual keyboard based on the value of isPhysicalKeyboardExist.
// TODO
```
# Mouse Pointer Development
## When to Use
Mouse pointer management provides the functions such as displaying or hiding the mouse pointer as well as querying and setting the pointer style. For example, you can determine whether to display or hide the mouse pointer when a user watches a video in full screen, and can switch the mouse pointer to a color picker when a user attempts color pickup.
## Modules to Import
```js
import inputDevice from '@ohos.multimodalInput.pointer';
```
## Available APIs
The following table lists the common APIs for mouse pointer management. For details about the APIs, see [ohos.multimodalInput.pointer](../reference/apis/js-apis-pointer.md).
| Instance | API | Description |
| ------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| pointer | function isPointerVisible(callback: AsyncCallback\<boolean>): void; | Checks the visible status of the mouse pointer. |
| pointer | function setPointerVisible(visible: boolean, callback: AsyncCallback\<void>): void; | Sets the visible status of the mouse pointer. This setting takes effect for the mouse pointer globally.|
| pointer | function setPointerStyle(windowId: number, pointerStyle: PointerStyle, callback: AsyncCallback\<void>): void; | Sets the mouse pointer style. This setting takes effect for the mouse pointer style of a specified window. |
| pointer | function getPointerStyle(windowId: number, callback: AsyncCallback\<PointerStyle>): void; | Obtains the mouse pointer style. |
## Hiding the Mouse Pointer
When watching a video in full-screen mode, a user can hide the mouse pointer for an improved user experience.
## How to Develop
1. Switch to the full-screen playback mode.
2. Hide the mouse pointer.
3. Exit the full-screen playback mode.
4. Display the mouse pointer.
```js
import pointer from '@ohos.multimodalInput.pointer';
// 1. Switch to the full-screen playback mode.
// 2. Hide the mouse pointer.
try {
pointer.setPointerVisible(false, (error) => {
if (error) {
console.log(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
console.log(`Set pointer visible success.`);
});
} catch (error) {
console.log(`The mouse pointer hide attributes is failed. ${JSON.stringify(error, [`code`, `message`])}`);
}
// 3. Exit the full-screen playback mode.
// 4. Display the mouse pointer.
try {
pointer.setPointerVisible(true, (error) => {
if (error) {
console.log(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
console.log(`Set pointer visible success.`);
});
} catch (error) {
console.log(`Set pointer visible failed, ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## Setting the Mouse Pointer Style
When designing a color picker, you can have the mouse pointer switched to the color picker style during color pickup and then switched to the default style on completion of color pickup. This setting takes effect for the pointer style of a specified window in the current application. A total of 39 pointer styles can be set. For details, see [Pointer Style](../reference/apis/js-apis-pointer.md#pointerstyle9).
### How to Develop
1. Enable the color pickup function.
2. Obtain the window ID.
3. Set the mouse pointer to the color picker style.
4. End color pickup.
5. Set the mouse pointer to the default style.
```js
import window from '@ohos.window';
// 1. Enable the color pickup function.
// 2. Obtain the window ID.
window.getTopWindow((error, windowClass) => {
windowClass.getProperties((error, data) => {
var windowId = data.id;
if (windowId < 0) {
console.log(`Invalid windowId`);
return;
}
try {
// 3. Set the mouse pointer to the color picker style.
pointer.setPointerStyle(windowId, pointer.PointerStyle.COLOR_SUCKER).then(() => {
console.log(`Successfully set mouse pointer style`);
});
} catch (error) {
console.log(`Failed to set the pointer style, error=${JSON.stringify(error)}, msg=${JSON.stringify(message)}`);
}
});
});
// 4. End color pickup.
window.getTopWindow((error, windowClass) => {
windowClass.getProperties((error, data) => {
var windowId = data.id;
if (windowId < 0) {
console.log(`Invalid windowId`);
return;
}
try {
// 5. Set the mouse pointer to the default style.
pointer.setPointerStyle(windowId, pointer.PointerStyle.DEFAULT).then(() => {
console.log(`Successfully set mouse pointer style`);
});
} catch (error) {
console.log(`Failed to set the pointer style, error=${JSON.stringify(error)}, msg=${JSON.stringify(message)}`);
}
});
});
```
......@@ -197,12 +197,12 @@ Disables listening for hot swap events of an input device.
**Example**
```js
callback: function(data) {
function callback(data) {
console.log("type: " + data.type + ", deviceId: " + data.deviceId);
}
try {
inputDevice.on("change", this.callback);
inputDevice.on("change", callback);
} catch (error) {
console.info("oninputdevcie " + error.code + " " + error.message)
}
......@@ -212,7 +212,7 @@ inputDevice.on("change", listener);
// Disable this listener.
try {
inputDevice.off("change", this.callback);
inputDevice.off("change", callback);
} catch (error) {
console.info("offinputdevcie " + error.code + " " + error.message)
}
......
......@@ -2,83 +2,192 @@
## Overview
### Function
### Function Introduction
HiSysEvent provides event logging APIs for OpenHarmony to record important information of key processes during system running. Besides, it supports shielding of event logging by event domain, helping you to evaluate the impact of event logging.
### Working Principles
Before logging system events, you need to complete HiSysEvent logging configuration. For details, see [HiSysEvent Logging Configuration](subsys-dfx-hisysevent-logging-config.md).
Before logging system events, you need to configure HiSysEvent logging. For details, see [HiSysEvent Logging Configuration](subsys-dfx-hisysevent-logging-config.md).
## How to Develop
### Use Cases
Use HiSysEvent logging to flush logged event data to disks.
Use HiSysEvent logging to flush logged event data to the event file.
### Available APIs
#### C++ Event Logging APIs
#### C++ Event Logging API
HiSysEvent logging is implemented using the API provided by the **HiSysEvent** class. For details, see the API Reference.
HiSysEvent logging is implemented using the API provided by the **HiSysEvent** class. For details, see the [API Header Files](/base/hiviewdfx/hisysevent/interfaces/native/innerkits/hisysevent/include/).
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> **NOTE**
>
> In OpenHarmony-3.2-Beta3, HiSysEvent logging is open for restricted use to avoid event storms. The **HiSysEvent::Write** API in Table 1 is replaced by the **HiSysEventWrite** API in Table 2. The **HiSysEvent::Write** API has been deprecated. Use the **HiSysEventWrite** API instead for HiSysEvent logging.
**Table 1** C++ event logging API (deprecated)
**Table 1** Description of the C++ event logging API (deprecated)
| API | Description |
| ------------------------------------------------------------ | ---------------------- |
| template&lt;typename... Types&gt; <br>static int Write(const std::string &amp;domain, const std::string &amp;eventName, EventType type, Types... keyValues) | Flushes logged event data to disks.|
| ------------------------------------------------------------ | --------------------- |
| template&lt;typename...&nbsp;Types&gt;&nbsp;<br>static&nbsp;int&nbsp;Write(const&nbsp;std::string&nbsp;&amp;domain,&nbsp;const&nbsp;std::string&nbsp;&amp;eventName,&nbsp;EventType&nbsp;type,&nbsp;Types...&nbsp;keyValues) | Flushes logged event data to the event file.|
**Table 2** C++ event logging API (in use)
| API | Description |
| ------------------------------------------------------------ | ---------------------- |
| HiSysEventWrite(domain, eventName, type, ...) | Flushes logged event data to disks.|
**Table 3** Event types
**Table 2** Description of the C++ event logging API (in use)
| API | Description |
| --------- | ------------ |
| FAULT | Fault event|
| STATISTIC | Statistical event|
| SECURITY | Security event|
| BEHAVIOR | Behavior event|
| API | Description |
| ------------------------------------------------------------ | --------------------- |
| HiSysEventWrite(domain, eventName, type, ...) | Flushes logged event data to the event file.|
**Table 3** Description of EventType enums
| Event Type | Description |
| --------- | ----------- |
| FAULT | Fault event.|
| STATISTIC | Statistical event.|
| SECURITY | Security event.|
| BEHAVIOR | Behavior event.|
#### C Event Logging API
HiSysEvent logging is implemented using the API provided in the following table. For details, see the [API Header Files](/base/hiviewdfx/hisysevent/interfaces/native/innerkits/hisysevent/include/).
**Table 4** Description of the C event logging API
| API | Description |
| ------------------------------------------------------------ | ------------------------ |
| int OH_HiSysEvent_Write(const char\* domain, const char\* name, HiSysEventEventType type, HiSysEventParam params[], size_t size); | Flushes logged event data to the event file.|
**Table 5** Description of HiSysEventEventType enums
| Event Type | Description |
| -------------------- | -------------- |
| HISYSEVENT_FAULT | Fault event.|
| HISYSEVENT_STATISTIC | Statistical event.|
| HISYSEVENT_SECURITY | Security event.|
| HISYSEVENT_BEHAVIOR | Behavior event.|
**Table 6** Description of the HiSysEventParam structure
| Attribute | Type | Description |
| --------- | -------------------- | ---------------------------------- |
| name | char name[] | Event parameter name. |
| t | HiSysEventParamType | Event parameter type. |
| v | HiSysEventParamValue | Event parameter value. |
| arraySize | size_t | Array length when the event parameter value is of the array type.|
**Table 7** Description of HiSysEventParamType enums
| Type | Description |
| ----------------------- | -------------------------- |
| HISYSEVENT_INVALID | Invalid event parameter. |
| HISYSEVENT_BOOL | Event parameter of the bool type. |
| HISYSEVENT_INT8 | Event parameter of the int8_t type. |
| HISYSEVENT_UINT8 | Event parameter of the uint8_t type. |
| HISYSEVENT_INT16 | Event parameter of the int16_t type. |
| HISYSEVENT_UINT16 | Event parameter of the uint16_t type. |
| HISYSEVENT_INT32 | Event parameter of the int32_t type. |
| HISYSEVENT_UINT32 | Event parameter of the uint32_t type. |
| HISYSEVENT_INT64 | Event parameter of the int64_t type. |
| HISYSEVENT_UINT64 | Event parameter of the uint64_t type. |
| HISYSEVENT_FLOAT | Event parameter of the float type. |
| HISYSEVENT_DOUBLE | Event parameter of the double type. |
| HISYSEVENT_STRING | Event parameter of the char* type. |
| HISYSEVENT_BOOL_ARRAY | Event parameter of the bool array type. |
| HISYSEVENT_INT8_ARRAY | Event parameter of the int8_t array type. |
| HISYSEVENT_UINT8_ARRAY | Event parameter of the uint8_t array type. |
| HISYSEVENT_INT16_ARRAY | Event parameter of the int16_t array type. |
| HISYSEVENT_UINT16_ARRAY | Event parameter of the uint16_t array type.|
| HISYSEVENT_INT32_ARRAY | Event parameter of the int32_t array type. |
| HISYSEVENT_UINT32_ARRAY | Event parameter of the uint32_t array type.|
| HISYSEVENT_INT64_ARRAY | Event parameter of the int64_t array type. |
| HISYSEVENT_UINT64_ARRAY | Event parameter of the uint64_t array type.|
| HISYSEVENT_FLOAT_ARRAY | Event parameter of the float array type. |
| HISYSEVENT_DOUBLE_ARRAY | Event parameter of the double array type. |
| HISYSEVENT_STRING_ARRAY | Event parameter of the char* array type. |
**Table 8** Description of the HiSysEventParamValue union
| Attribute| Type| Description |
| -------- | -------- | ------------------------ |
| b | bool | Event parameter value of the bool type. |
| i8 | int8_t | Event parameter value of the int8_t type. |
| ui8 | uint8_t | Event parameter value of the uint8_t type. |
| i16 | int16_t | Event parameter value of the int16_t type. |
| ui16 | uint16_t | Event parameter value of the uint16_t type.|
| i32 | int32_t | Event parameter value of the int32_t type. |
| ui32 | uint32_t | Event parameter value of the uint32_t type.|
| i64 | int64_t | Event parameter value of the int64_t type. |
| ui64 | uint64_t | Event parameter value of the uint64_t type.|
| f | float | Event parameter value of the float type. |
| d | double | Event parameter value of the double type. |
| s | char* | Event parameter value of the char* type. |
| array | void* | Event parameter value of the array type. |
#### Kernel Event Logging APIs
The following table describes the kernel event logging APIs.
Kernel event logging is implemented using the APIs provided in the following table. For details, see the [API Header File](/kernel/linux/linux-5.10/include/dfx/hiview_hisysevent.h).
**Table 4** Kernel event logging APIs
**Table 9** Description of kernel event logging APIs
| API | Description |
| ------------------------------------------------------------ | ------------------------------------ |
| struct hiview_hisysevent *hisysevent_create(const char *domain, const char *name, enum hisysevent_type type); | Creates a **hisysevent** object. |
| void hisysevent_destroy(struct hiview_hisysevent *event); | Destroys a **hisysevent** object. |
| ------------------------------------------------------------ | ----------------------------------- |
| struct hiview_hisysevent *hisysevent_create(const char *domain, const char *name, enum hisysevent_type type); | Creates a **hisysevent** object. |
| void hisysevent_destroy(struct hiview_hisysevent *event); | Destroys a **hisysevent** object. |
| int hisysevent_put_integer(struct hiview_hisysevent *event, const char *key, long long value); | Adds event parameters of the integer type to a **hisysevent** object. |
| int hisysevent_put_string(struct hiview_hisysevent *event, const char *key, const char *value); | Adds event parameters of the string type to a **hisysevent** object.|
| int hisysevent_write(struct hiview_hisysevent *event); | Flushes **hisysevent** object data to disks. |
| int hisysevent_write(struct hiview_hisysevent *event); | Flushes **hisysevent** object data to the event file. |
**Table 5** Kernel event types
**Table 10** Description of hisysevent_type enums
| API | Description |
| --------- | ------------ |
| FAULT | Fault event|
| STATISTIC | Statistical event|
| SECURITY | Security event|
| BEHAVIOR | Behavior event|
| Event Type | Description |
| --------- | ----------- |
| FAULT | Fault event.|
| STATISTIC | Statistical event.|
| SECURITY | Security event.|
| BEHAVIOR | Behavior event.|
### How to Develop
#### C++ Event Logging
1. Call the event logging API wherever needed, with required event parameters passed to the API.
Call the event logging API wherever needed, with required event parameters passed to the API.
```c++
HiSysEventWrite(HiSysEvent::Domain::AAFWK, "START_APP", HiSysEvent::EventType::BEHAVIOR, "APP_NAME", "com.ohos.demo");
```
#### C Event Logging
1. If you want to pass custom event parameters to the event logging API, create an event parameter object based on the event parameter type and add the object to the event parameter array.
```c
// Create an event parameter of the int32_t type.
HiSysEventParam param1 = {
.name = "KEY_INT32",
.t = HISYSEVENT_INT32,
.v = { .i32 = 1 },
.arraySize = 0,
};
// Create an event parameter of the int32_t array type.
int32_t int32Arr[] = { 1, 2, 3 };
HiSysEventParam param2 = {
.name = "KEY_INT32_ARR",
.t = HISYSEVENT_INT32_ARRAY,
.v = { .array = int32Arr },
.arraySize = sizeof(int32Arr) / sizeof(int32Arr[0]),
};
// Add the event parameter object to the created event parameter array.
HiSysEventParam params[] = { param1, param2 };
```
2. Call the event logging API wherever needed, with required event parameters passed to the API.
```c
OH_HiSysEvent_Write("TEST_DOMAIN", "TEST_NAME", HISYSEVENT_BEHAVIOR, params, sizeof(params) / sizeof(params[0]));
```
#### Kernel Event Logging
1. Create a **hisysevent** object based on the specified event domain, event name, and event type.
......@@ -151,7 +260,7 @@ Assume that a service module needs to trigger event logging during application s
external_deps = [ "hisysevent_native:libhisysevent" ]
```
2. In the application startup function **StartAbility()** of the service module, call the event logging API with the event parameters passed in.
2. In the application startup function **StartAbility()** of the service module, call the event logging API with event parameters passed in.
```c++
#include "hisysevent.h"
......@@ -164,6 +273,37 @@ Assume that a service module needs to trigger event logging during application s
}
```
#### C Event Logging
Assume that a service module needs to trigger event logging during application startup to record the application startup event and application bundle name. The following is the complete sample code:
1. Add the HiSysEvent component dependency to the **BUILD.gn** file of the service module.
```c++
external_deps = [ "hisysevent_native:libhisysevent" ]
```
2. In the application startup function **StartAbility()** of the service module, call the event logging API with event parameters passed in.
```c
#include "hisysevent_c.h"
int StartAbility()
{
... // Other service logic
char packageName[] = "com.ohos.demo";
HiSysEventParam param = {
.name = "APP_NAME",
.t = HISYSEVENT_STRING,
.v = { .s = packageName },
.arraySize = 0,
};
HiSysEventParam params[] = { param };
int ret = OH_HiSysEvent_Write("AAFWK", "START_APP", HISYSEVENT_BEHAVIOR, params, sizeof(params) / sizeof(params[0]));
... // Other service logic
}
```
#### Kernel Event Logging
Assume that the kernel service module needs to trigger event logging during device startup to record the device startup event. The following is the complete sample code:
......@@ -200,11 +340,10 @@ Assume that the kernel service module needs to trigger event logging during devi
}
```
#### Shielding of Event Logging by Event Domain
#### Shielding of Event Logging by Event Domain
- If you want to shield event logging for the **AAFWK** and **POWER** domains in a **.cpp** file, define the **DOMAIN_MASKS** macro before including the **hisysevent.h** header file to the **.cpp** file.
```c++
#define DOMAIN_MASKS "AAFWK|POWER"
#include "hisysevent.h"
......@@ -212,14 +351,13 @@ Assume that the kernel service module needs to trigger event logging during devi
HiSysEventWrite(OHOS:HiviewDFX::HiSysEvent::Domain::AAFWK, "JS_ERROR", OHOS:HiviewDFX::HiSysEvent::EventType::FAULT, "MODULE", "com.ohos.module"); // HiSysEvent logging is not performed.
... // Other service logic
HiSysEventWrite(OHOS:HiviewDFX::HiSysEvent::Domain::POWER, "POWER_RUNNINGLOCK", OHOS:HiviewDFX::HiSysEvent::EventType::FAULT, "NAME", "com.ohos.module"); // HiSysEvent logging is not performed.
```
- If you want to shield event logging for the **AAFWK** and **POWER** domains of the entire service module, define the **DOMAIN_MASKS** macro as follows in the **BUILG.gn** file of the service module.
```gn
config("module_a") {
... // Other configuration items
cflags_cc += ["-DDOMAIN_MASKS=\"AAFWK|POWER\""]
... // Other configuration items
cflags_cc += ["-DDOMAIN_MASKS=\"AAFWK|POWER\""]
}
```
......
......@@ -3,6 +3,5 @@
| FA模型接口 | Stage模型接口对应d.ts文件 | Stage模型对应接口 |
| -------- | -------- | -------- |
| [enum&nbsp;WindowType&nbsp;{<br/>TYPE_APP<br/>}](../reference/apis/js-apis-window.md#windowtype7) | \@ohos.window.d.ts | [createSubWindow(name:&nbsp;string,&nbsp;callback:&nbsp;AsyncCallback&lt;Window&gt;):&nbsp;void;](../reference/apis/js-apis-window.md#createsubwindow9)<br/>[createSubWindow(name:&nbsp;string):&nbsp;Promise;](../reference/apis/js-apis-window.md#createsubwindow9-1)<br/>FA模型应用通过window.create(id,&nbsp;WindowType.TYPE_APP)接口创建应用子窗口,Stage模型应用可使用WindowStage.CreateSubWindow()接口代替 |
| [create(id:&nbsp;string,&nbsp;type:&nbsp;WindowType,&nbsp;callback:&nbsp;AsyncCallback&lt;Window&gt;):&nbsp;void;](../reference/apis/js-apis-window.md#windowcreatedeprecated)<br/>[create(id:&nbsp;string,&nbsp;type:&nbsp;WindowType):&nbsp;Promise&lt;Window&gt;;](../reference/apis/js-apis-window.md#windowcreatedeprecated-1) | \@ohos.window.d.ts | [createWindow(config:&nbsp;Configuration,&nbsp;callback:&nbsp;AsyncCallback&lt;Window&gt;):&nbsp;void;](../reference/apis/js-apis-window.md#windowcreatewindow9)<br/>[createWindow(config:&nbsp;Configuration):&nbsp;Promise&lt;Window&gt;;](../reference/apis/js-apis-window.md#windowcreatewindow9-1) |
| [create(id:&nbsp;string,&nbsp;type:&nbsp;WindowType,&nbsp;callback:&nbsp;AsyncCallback&lt;Window&gt;):&nbsp;void;](../reference/apis/js-apis-window.md#windowcreatedeprecated)<br/>[create(id:&nbsp;string,&nbsp;type:&nbsp;WindowType):&nbsp;Promise&lt;Window&gt;;](../reference/apis/js-apis-window.md#windowcreatedeprecated-1) | \@ohos.window.d.ts | [createSubWindow(name:&nbsp;string,&nbsp;callback:&nbsp;AsyncCallback&lt;Window&gt;):&nbsp;void;](../reference/apis/js-apis-window.md#createsubwindow9)<br/>[createSubWindow(name:&nbsp;string):&nbsp;Promise;](../reference/apis/js-apis-window.md#createsubwindow9-1)<br/>FA模型应用通过window.create(id,&nbsp;WindowType.TYPE_APP)接口创建应用子窗口,Stage模型应用可使用WindowStage.CreateSubWindow()接口代替 |
| [getTopWindow(callback:&nbsp;AsyncCallback&lt;Window&gt;):&nbsp;void;](../reference/apis/js-apis-window.md#windowgettopwindowdeprecated)<br/>[getTopWindow():&nbsp;Promise&lt;Window&gt;;](../reference/apis/js-apis-window.md#windowgettopwindowdeprecated-1) | \@ohos.window.d.ts | [getLastWindow(ctx:&nbsp;BaseContext,&nbsp;callback:&nbsp;AsyncCallback&lt;Window&gt;):&nbsp;void;](../reference/apis/js-apis-window.md#windowgetlastwindow9)<br/>[getLastWindow(ctx:&nbsp;BaseContext):&nbsp;Promise&lt;Window&gt;;](../reference/apis/js-apis-window.md#windowgetlastwindow9-1) |
......@@ -363,7 +363,7 @@ startAbilityForResultWithAccount(want: Want, accountId: number, callback: AsyncC
启动一个Ability并在该Ability帐号销毁时返回执行结果(callback形式)。
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -420,7 +420,7 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options: StartOp
启动一个Ability并在该Ability帐号销毁时返回执行结果(callback形式)。
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -481,7 +481,7 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options?: StartO
启动一个Ability并在该Ability帐号销毁时返回执行结果(promise形式)。
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -646,7 +646,7 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
启动一个新的ServiceExtensionAbility(callback形式)。
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -701,7 +701,7 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\
启动一个新的ServiceExtensionAbility(Promise形式)。
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -782,8 +782,14 @@ stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
};
try {
this.context.startAbility(want, (error) => {
if (error.code != 0) {
console.log("start ability fail, err: " + JSON.stringify(err));
}
})
this.context.stopServiceExtensionAbility(want, (error) => {
if (error.code) {
if (error.code != 0) {
// 处理业务逻辑错误
console.log('stopServiceExtensionAbility failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(error.message));
......@@ -832,6 +838,12 @@ stopServiceExtensionAbility(want: Want): Promise\<void>;
};
try {
this.context.startAbility(want, (error) => {
if (error.code != 0) {
console.log("start ability fail, err: " + JSON.stringify(err));
}
})
this.context.stopServiceExtensionAbility(want)
.then((data) => {
// 执行正常业务
......@@ -855,7 +867,7 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
使用帐户停止同一应用程序内的服务(callback形式)。
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -887,6 +899,12 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
var accountId = 100;
try {
this.context.startAbilityWithAccount(want, accountId, (error) => {
if (error.code != 0) {
console.log("start ability fail, err: " + JSON.stringify(err));
}
})
this.context.stopServiceExtensionAbilityWithAccount(want, accountId, (error) => {
if (error.code) {
// 处理业务逻辑错误
......@@ -910,7 +928,7 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<
使用帐户停止同一应用程序内的服务(Promise形式)。
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -941,6 +959,12 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<
var accountId = 100;
try {
this.context.startAbilityWithAccount(want, accountId, (error) => {
if (error.code != 0) {
console.log("start ability fail, err: " + JSON.stringify(err));
}
})
this.context.stopServiceExtensionAbilityWithAccount(want, accountId)
.then((data) => {
// 执行正常业务
......@@ -1207,7 +1231,7 @@ connectServiceExtensionAbilityWithAccount(want: Want, accountId: number, options
使用AbilityInfo.AbilityType.SERVICE模板和account将当前Ability连接到一个Ability。
**需要权限:** ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限:** ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -1451,7 +1475,7 @@ startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<
根据account启动Ability(callback形式)。
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -1507,7 +1531,7 @@ startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, ca
根据account启动Ability(callback形式)。
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -1567,7 +1591,7 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions):
根据account启动Ability(Promise形式)。
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......
......@@ -23,40 +23,66 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant';
| 名称 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| launchReason | [LaunchReason](#abilityconstantlaunchreason)| 是 | 是 | 示启动原因。 |
| lastExitReason | [LastExitReason](#abilityconstantlastexitreason) | 是 | 是 | 表示最后退出原因。 |
| launchReason | [LaunchReason](#abilityconstantlaunchreason)| 是 | 是 | 枚举类型,表示启动原因。 |
| lastExitReason | [LastExitReason](#abilityconstantlastexitreason) | 是 | 是 | 枚举类型,表示最后退出原因。 |
## AbilityConstant.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
| 名称 | 值 | 说明 |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| UNKNOWN | 0 | 未知的状态。 |
| START_ABILITY | 1 | 启动能力。 |
| CALL | 2 | 呼叫。 |
| CONTINUATION | 3 | 继续。 |
| APP_RECOVERY | 4 | 状态恢复。 |
| UNKNOWN | 0 | 未知原因。 |
| START_ABILITY | 1 | 通过[startAbility](js-apis-ability-context.md#abilitycontextstartability)接口启动ability。 |
| CALL | 2 | 通过[startAbilityByCall](js-apis-ability-context.md#abilitycontextstartabilitybycall)接口启动ability。 |
| CONTINUATION | 3 | 跨端设备迁移启动ability。 |
| APP_RECOVERY | 4 | 设置应用恢复后,应用故障时自动恢复启动ability。 |
**示例:**
```ts
import UIAbility form '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onCreate(want, launchParam) {
if (launcherParam.launchReason == AbilityConstant.LaunchReason.START_ABILITY) {
console.log("The ability has been started by the way of startAbility.");
}
}
}
```
## AbilityConstant.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
| 名称 | 值 | 说明 |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| UNKNOWN | 0 | 未知的状态。 |
| ABILITY_NOT_RESPONDING | 1 | 能力没有反应 |
| NORMAL | 2 | 正常的状态。 |
| UNKNOWN | 0 | 未知原因。 |
| ABILITY_NOT_RESPONDING | 1 | ability未响应。 |
| NORMAL | 2 | 正常退出。 |
**示例:**
```ts
import UIAbility form '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onCreate(want, launchParam) {
if (launcherParam.lastExitReason == AbilityConstant.LastExitReason.ABILITY_NOT_RESPONDING) {
console.log("The ability has exit last because the ability was not responding.");
}
}
}
```
## AbilityConstant.OnContinueResult
迁移结果
Ability迁移结果,该类型为枚举,可配合[Ability](js-apis-app-ability-uiAbility.md)[onContinue(wantParam)](js-apis-app-ability-uiAbility.md#uiabilityoncontinue)方法进完成相应的返回
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
......@@ -66,9 +92,21 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant';
| REJECT | 1 | 拒绝。 |
| MISMATCH | 2 | 不匹配。|
**示例:**
```ts
import UIAbility form '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onContinue(wantParam) {
return AbilityConstant.OnConinueResult.AGREE;
}
}
```
## AbilityConstant.WindowMode
启动Ability时的窗口模式。
启动Ability时的窗口模式,该类型为枚举,可配合startAbility使用指定启动Ability的窗口模式
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
......@@ -80,36 +118,81 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant';
| WINDOW_MODE_SPLIT_SECONDARY | 101 | 分屏多窗口次要模式。 |
| WINDOW_MODE_FLOATING | 102 | 自由悬浮形式窗口模式。 |
**示例:**
```ts
let want = {
bundleName: "com.test.example",
abilityName: "MainAbility"
};
let option = {
windowMode: AbilityConstant.WindowMode.WINDOW_MODE_FULLSCREEN
};
// 确保从上下文获取到context
this.context.startAbility(want, option).then(()={
console.log("Succeed to start ability.");
}).catch((error)=>{
console.log("Failed to start ability with error: " + JSON.stringify(error));
});
```
## AbilityConstant.MemoryLevel
内存级别。
内存级别,该类型为枚举,可配合[Ability](js-apis-app-ability-ability.md)[onMemoryLevel(level)](js-apis-app-ability-ability.md#abilityonmemorylevel)方法根据level执行不同内存级别的相应操作
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
| 名称 | 值 | 说明 |
| --- | --- | --- |
| MEMORY_LEVEL_MODERATE | 0 | 内存占用适中。 |
| MEMORY_LEVEL_LOW | 1 | 内存占用低。 |
| --- | --- | --- |
| MEMORY_LEVEL_MODERATE | 0 | 内存占用适中。 |
| MEMORY_LEVEL_LOW | 1 | 内存占用低。 |
| MEMORY_LEVEL_CRITICAL | 2 | 内存占用高。 |
**示例:**
```ts
import UIAbility form '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onMemoryLevel(level) {
if (level == AbilityConstant.MemoryLevel.MEMORY_LEVEL_CRITICAL) {
console.log("The memory of device is critical, please release some memory.");
}
}
}
```
## AbilityConstant.OnSaveResult
保存应用数据的结果。
保存应用数据的结果,该类型为枚举,可配合[Ability](js-apis-app-ability-uiAbility.md)[onSaveState(reason, wantParam)](js-apis-app-ability-uiAbility.md#uiabilityonsavestate)方法完成相应的返回
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
| 名称 | 值 | 说明 |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| ALL_AGREE | 0 | 同意保存状态。 |
| ALL_AGREE | 0 | 总是同意保存状态。 |
| CONTINUATION_REJECT | 1 | 拒绝迁移保存状态。 |
| CONTINUATION_MISMATCH | 2 | 迁移不匹配。|
| RECOVERY_AGREE | 3 | 同意恢复保存状态。 |
| RECOVERY_REJECT | 4 | 拒绝恢复保存状态。|
| ALL_REJECT | 5 | 拒绝保存状态。|
| ALL_REJECT | 5 | 总是拒绝保存状态。|
**示例:**
```ts
import UIAbility form '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onSaveState(reason, wantParam) {
return AbilityConstant.OnSaveResult.ALL_AGREE;
}
}
```
## AbilityConstant.StateType
保存应用数据场景原因。
保存应用数据场景原因,该类型为枚举,可配合[Ability](js-apis-app-ability-uiAbility.md)[onSaveState(reason, wantParam)](js-apis-app-ability-uiAbility.md#uiabilityonsavestate)方法根据reason的不同类型执行相应操作
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
......@@ -117,3 +200,18 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant';
| ----------------------------- | ---- | ------------------------------------------------------------ |
| CONTINUATION | 0 | 迁移保存状态。 |
| APP_RECOVERY | 1 | 应用恢复保存状态。 |
**示例:**
```ts
import UIAbility form '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onSaveState(reason, wantParam) {
if (reason == AbilityConstant.StateType.CONTINUATION) {
console.log("Save the ability data when the ability continuation.");
}
return AbilityConstant.OnSaveResult.ALL_AGREE;
}
}
```
\ No newline at end of file
# @ohos.app.ability.abilityDelegatorRegistry (AbilityDelegatorRegistry)
AbilityDelegatorRegistry模块提供用于存储已注册的AbilityDelegator和AbilityDelegatorArgs对象的全局寄存器的能力,包括获取应用程序的AbilityDelegator对象、获取单元测试参数AbilityDelegatorArgs对象
AbilityDelegatorRegistry[测试框架](../../ability-deprecated/ability-delegator.md)模块,该模块用于获取[AbilityDelegator](js-apis-inner-application-abilityDelegator.md)[AbilityDelegatorArgs](js-apis-inner-application-abilityDelegatorArgs.md)对象,其中[AbilityDelegator](js-apis-inner-application-abilityDelegator.md)对象提供添加用于监视指定ability的生命周期状态更改的AbilityMonitor对象的能力,[AbilityDelegatorArgs](js-apis-inner-application-abilityDelegatorArgs.md)对象提供获取当前测试参数的能力
> **说明:**
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块接口仅可在测试框架中使用。
## 导入模块
```ts
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
```
## AbilityLifecycleState
Ability生命周期状态。
Ability生命周期状态,该类型为枚举,可配合[AbilityDelegator](js-apis-inner-application-abilityDelegator.md)[getAbilityState(ability)](js-apis-inner-application-abilityDelegator.md#getabilitystate9)方法返回不同ability生命周期
**系统能力** :以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
| 名称 | 值 | 说明 |
| ------------- | ---- | --------------------------- |
| UNINITIALIZED | 0 | 表示无效状态。 |
| UNINITIALIZED | 0 | 表示Ability处于无效状态。 |
| CREATE | 1 | 表示Ability处于已创建状态。 |
| FOREGROUND | 2 | 表示Ability处于前台状态。 |
| BACKGROUND | 3 | 表示Ability处于后台状态。 |
......@@ -30,7 +31,7 @@ Ability生命周期状态。
getAbilityDelegator(): AbilityDelegator
获取应用程序的AbilityDelegator对象
获取应用程序的[AbilityDelegator](js-apis-inner-application-abilityDelegator.md)对象,该对象能够使用调度测试框架的相关功能。
**系统能力:** SystemCapability.Ability.AbilityRuntime.Core
......@@ -43,15 +44,29 @@ getAbilityDelegator(): AbilityDelegator
**示例:**
```ts
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
var abilityDelegator;
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let want = {
bundleName: "com.ohos.example",
abilityName: "MainAbility"
}
abilityDelegator.startAbility(want, (err)=>{
if (err.code != 0) {
console.log("Success start ability.");
} else {
console.log("Failed start ability, error: " + JSON.stringify(err));
}
})
```
## AbilityDelegatorRegistry.getArguments
getArguments(): AbilityDelegatorArgs
获取单元测试参数AbilityDelegatorArgs对象
获取单元测试参数[AbilityDelegatorArgs](js-apis-inner-application-abilityDelegatorArgs.md)对象。
**系统能力:** SystemCapability.Ability.AbilityRuntime.Core
......@@ -64,8 +79,11 @@ getArguments(): AbilityDelegatorArgs
**示例:**
```ts
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
var args = AbilityDelegatorRegistry.getArguments();
console.info("getArguments bundleName:" + args.bundleName);
console.info("getArguments parameters:" + JSON.stringify(args.parameters));
console.info("getArguments testCaseNames:" + args.testCaseNames);
console.info("getArguments testRunnerClassName:" + args.testRunnerClassName);
```
# @ohos.app.ability.abilityLifecycleCallback (AbilityLifecycleCallback)
AbilityLifecycleCallback模块提供应用上下文ApplicationContext的生命周期监听方法的回调类的能力,包括onAbilityCreate、onWindowStageCreate、onWindowStageDestroy等方法。
AbilityLifecycleCallback模块提供应用上下文[ApplicationContext](js-apis-inner-application-applicationContext.md)的生命周期发生变化时触发相应回调的能力,包括[onAbilityCreate](#abilitylifecyclecallbackonabilitycreate)[onWindowStageCreate](#abilitylifecyclecallbackonwindowstagecreate)[onWindowStageActive](#abilitylifecyclecallbackonwindowstageactive)[onWindowStageInactive](#abilitylifecyclecallbackonwindowstageinactive)[onWindowStageDestroy](#abilitylifecyclecallbackonwindowstagedestroy)[onAbilityDestroy](#abilitylifecyclecallbackonabilitydestroy)[onAbilityForeground](#abilitylifecyclecallbackonabilityforeground)[onAbilityBackground](#abilitylifecyclecallbackonabilitybackground)[onAbilityContinue](#abilitylifecyclecallbackonabilitycontinue)方法。
> **说明:**
>
......@@ -27,7 +27,7 @@ onAbilityCreate(ability: UIAbility): void;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md#Ability) | 是 | 当前Ability对象 |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
## AbilityLifecycleCallback.onWindowStageCreate
......@@ -42,7 +42,7 @@ onWindowStageCreate(ability: UIAbility, windowStage: window.WindowStage): void;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md#Ability) | 是 | 当前Ability对象 |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | 是 | 当前WindowStage对象 |
......@@ -58,7 +58,7 @@ onWindowStageActive(ability: UIAbility, windowStage: window.WindowStage): void;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md#Ability) | 是 | 当前Ability对象 |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | 是 | 当前WindowStage对象 |
......@@ -74,7 +74,7 @@ onWindowStageInactive(ability: UIAbility, windowStage: window.WindowStage): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md#Ability) | 是 | 当前Ability对象 |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | 是 | 当前WindowStage对象 |
......@@ -90,7 +90,7 @@ onWindowStageDestroy(ability: UIAbility, windowStage: window.WindowStage): void;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md#Ability) | 是 | 当前Ability对象 |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | 是 | 当前WindowStage对象 |
......@@ -106,7 +106,7 @@ onAbilityDestroy(ability: UIAbility): void;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md#Ability) | 是 | 当前Ability对象 |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
## AbilityLifecycleCallback.onAbilityForeground
......@@ -121,7 +121,7 @@ onAbilityForeground(ability: UIAbility): void;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md#Ability) | 是 | 当前Ability对象 |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
## AbilityLifecycleCallback.onAbilityBackground
......@@ -136,7 +136,7 @@ onAbilityBackground(ability: UIAbility): void;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md#Ability) | 是 | 当前Ability对象 |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
## AbilityLifecycleCallback.onAbilityContinue
......@@ -151,61 +151,77 @@ onAbilityContinue(ability: UIAbility): void;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md#Ability) | 是 | 当前Ability对象 |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
**示例:**
```ts
import UIAbility from "@ohos.app.ability.UIAbility";
export default class MyAbility extends UIAbility {
onCreate() {
console.log("MyAbility onCreate")
let AbilityLifecycleCallback = {
onAbilityCreate(ability){
console.log("AbilityLifecycleCallback onAbilityCreate ability:" + JSON.stringify(ability));
},
onWindowStageCreate(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageCreate ability:" + JSON.stringify(ability));
console.log("AbilityLifecycleCallback onWindowStageCreate windowStage:" + JSON.stringify(windowStage));
},
onWindowStageActive(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageActive ability:" + JSON.stringify(ability));
console.log("AbilityLifecycleCallback onWindowStageActive windowStage:" + JSON.stringify(windowStage));
},
onWindowStageInactive(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageInactive ability:" + JSON.stringify(ability));
console.log("AbilityLifecycleCallback onWindowStageInactive windowStage:" + JSON.stringify(windowStage));
},
onWindowStageDestroy(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageDestroy ability:" + JSON.stringify(ability));
console.log("AbilityLifecycleCallback onWindowStageDestroy windowStage:" + JSON.stringify(windowStage));
},
onAbilityDestroy(ability){
console.log("AbilityLifecycleCallback onAbilityDestroy ability:" + JSON.stringify(ability));
},
onAbilityForeground(ability){
console.log("AbilityLifecycleCallback onAbilityForeground ability:" + JSON.stringify(ability));
},
onAbilityBackground(ability){
console.log("AbilityLifecycleCallback onAbilityBackground ability:" + JSON.stringify(ability));
},
onAbilityContinue(ability){
console.log("AbilityLifecycleCallback onAbilityContinue ability:" + JSON.stringify(ability));
}
}
// 1.通过context属性获取applicationContext
let applicationContext = this.context.getApplicationContext();
// 2.通过applicationContext注册监听应用内生命周期
let lifecycleid = applicationContext.on("abilityLifecycle", AbilityLifecycleCallback);
console.log("registerAbilityLifecycleCallback number: " + JSON.stringify(lifecycleid));
},
onDestroy() {
let applicationContext = this.context.getApplicationContext();
applicationContext.off("abilityLifecycle", lifecycleid, (error, data) => {
console.log("unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error));
});
}
}
```
\ No newline at end of file
MyAbilityStage.ts
```ts
import AbilityLifecycleCallback from "@ohos.app.ability.AbilityLifecycleCallback";
import AbilityStage from "@ohos.app.ability.AbilityStage"
// 声明ability生命周期回调
let abilityLifecycleCallback = {
onAbilityCreate(ability){
console.log("AbilityLifecycleCallback onAbilityCreate.");
},
onWindowStageCreate(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageCreate.");
},
onWindowStageActive(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageActive.");
},
onWindowStageInactive(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageInactive.");
},
onWindowStageDestroy(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageDestroy.");
},
onAbilityDestroy(ability){
console.log("AbilityLifecycleCallback onAbilityDestroy.");
},
onAbilityForeground(ability){
console.log("AbilityLifecycleCallback onAbilityForeground.");
},
onAbilityBackground(ability){
console.log("AbilityLifecycleCallback onAbilityBackground.");
},
onAbilityContinue(ability){
console.log("AbilityLifecycleCallback onAbilityContinue.");
}
}
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("MyAbilityStage onCreate");
// 1.通过context属性获取applicationContext
let applicationContext = this.context.getApplicationContext();
// 2.通过applicationContext注册监听应用内生命周期
try {
globalThis.lifecycleId = applicationContext.on("abilityLifecycle", abilityLifecycleCallback);
console.log("registerAbilityLifecycleCallback number: " + JSON.stringify(lifecycleId));
} catch (paramError) {
console.log("error: " + paramError.code + " ," + paramError.message);
}
}
}
```
MyAbility.ts
```ts
import UIAbility from "ohos.app.ability.UIAbility"
export default class MyAbility extends UIAbility {
onDestroy() {
let applicationContext = this.context.getApplicationContext();
// 3.通过applicationContext注销监听应用内生命周期
applicationContext.off("abilityLifecycle", globalThis.lifecycleId, (error) => {
if (error.code != 0) {
console.log("unregisterAbilityLifecycleCallback failed, error: " + JSON.stringify(error));
} else {
console.log("unregisterAbilityLifecycleCallback success.");
}
});
}
}
```
\ No newline at end of file
# @ohos.app.ability.abilityManager (AbilityManager)
AbilityManager模块提供对Ability相关信息和状态信息进行获取、新增、修改等能力。
AbilityManager模块提供获取、新增、修改Ability相关信息和状态信息进行的能力。
> **说明:**
>
......@@ -15,25 +15,25 @@ import abilityManager from '@ohos.app.ability.abilityManager'
## AbilityState
Ability的状态信息
Ability的状态,该类型为枚举,可配合[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)返回Abiltiy的状态
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
**系统API**: 此接口为系统接口,三方应用不支持调用。
**系统API**: 此枚举类型为系统接口内部定义,三方应用不支持调用。
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| INITIAL | 0 | 表示ability为initial状态。|
| FOREGROUND | 9 | 表示ability为foreground状态。 |
| BACKGROUND | 10 | 表示ability为background状态。 |
| FOREGROUNDING | 11 | 表示ability为foregrounding状态。 |
| BACKGROUNDING | 12 | 表示ability为backgrounding状态。 |
| INITIAL | 0 | 表示ability为初始化状态。|
| FOREGROUND | 9 | 表示ability为前台状态。 |
| BACKGROUND | 10 | 表示ability为后台状态。 |
| FOREGROUNDING | 11 | 表示ability为前台调度中状态。 |
| BACKGROUNDING | 12 | 表示ability为后台调度中状态。 |
## updateConfiguration
updateConfiguration(config: Configuration, callback: AsyncCallback\<void>): void
通过修改配置来更新配置(callback形式)。
通过传入修改的配置项来更新配置(callback形式)。
**需要权限**: ohos.permission.UPDATE_CONFIGURATION
......@@ -43,23 +43,32 @@ updateConfiguration(config: Configuration, callback: AsyncCallback\<void>): void
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ---------------------------------------- | ---- | -------------- |
| config | [Configuration](js-apis-app-ability-configuration.md) | 是 | 新的配置项。 |
| callback | AsyncCallback\<void> | 是 | 被指定的回调方法。 |
| config | [Configuration](js-apis-app-ability-configuration.md) | 是 | 新的配置项,仅需配置需要更新的项。 |
| callback | AsyncCallback\<void> | 是 | 以回调方式返回接口运行结果,可进行错误处理或其他自定义处理。 |
**示例**
```ts
var config = {
language: 'chinese'
language: 'Zh-Hans',
colorMode: COLOR_MODE_LIGHT,
direction: DIRECTION_VERTICAL,
screenDensity: SCREEN_DENSITY_SDPI,
displayId: 1,
hasPointerDevice: true,
}
try {
abilityManager.updateConfiguration(config, () => {
console.log('------------ updateConfiguration -----------');
})
abilityManager.updateConfiguration(config, (err) => {
if (err.code != 0) {
console.log("updateConfiguration fail, err: " + JSON.stringify(err));
} else {
console.log("updateConfiguration success.");
}
})
} catch (paramError) {
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
}
```
......@@ -77,30 +86,35 @@ updateConfiguration(config: Configuration): Promise\<void>
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ---------------------------------------- | ---- | -------------- |
| config | [Configuration](js-apis-app-ability-configuration.md) | 是 | 新的配置项。 |
| config | [Configuration](js-apis-app-ability-configuration.md) | 是 | 新的配置项,仅需配置需要更新的项。 |
**返回值:**
| 类型 | 说明 |
| ---------------------------------------- | ------- |
| Promise\<void> | 返回执行结果。 |
| Promise\<void> | 以Promise方式返回接口运行结果息,可进行错误处理或其他自定义处理。 |
**示例**
```ts
var config = {
language: 'chinese'
language: 'Zh-Hans',
colorMode: COLOR_MODE_LIGHT,
direction: DIRECTION_VERTICAL,
screenDensity: SCREEN_DENSITY_SDPI,
displayId: 1,
hasPointerDevice: true,
}
try {
abilityManager.updateConfiguration(config).then(() => {
console.log('updateConfiguration success');
}).catch((err) => {
console.log('updateConfiguration fail');
})
abilityManager.updateConfiguration(config).then(() => {
console.log('updateConfiguration success.');
}).catch((err) => {
console.log('updateConfiguration fail, err: ' + JSON.stringify(err));
})
} catch (paramError) {
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
}
```
......@@ -118,18 +132,22 @@ getAbilityRunningInfos(callback: AsyncCallback\<Array\<AbilityRunningInfo>>): vo
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ---------------------------------------- | ---- | -------------- |
| callback | AsyncCallback\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)>> | 是 | 被指定的回调方法。 |
| callback | AsyncCallback\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)>> | 是 | 以回调方式返回接口运行结果及运行中的ability信息,可进行错误处理或其他自定义处理。 |
**示例**
```ts
try {
abilityManager.getAbilityRunningInfos((err,data) => {
console.log("getAbilityRunningInfos err: " + err + " data: " + JSON.stringify(data));
});
abilityManager.getAbilityRunningInfos((err,data) => {
if (err.code != 0) {
console.log("getAbilityRunningInfos fail, error: " + JSON.stringify(err));
} else {
console.log("getAbilityRunningInfos success, data: " + JSON.stringify(data));
}
});
} catch (paramError) {
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
}
```
......@@ -147,20 +165,20 @@ getAbilityRunningInfos(): Promise\<Array\<AbilityRunningInfo>>
| 类型 | 说明 |
| ---------------------------------------- | ------- |
| Promise\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)>> | 返回执行结果。 |
| Promise\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)>> | 以Promise方式返回接口运行结果及运行中的ability信息,可进行错误处理或其他自定义处理。 |
**示例**
```ts
try {
abilityManager.getAbilityRunningInfos().then((data) => {
console.log("getAbilityRunningInfos data: " + JSON.stringify(data))
}).catch((err) => {
console.log("getAbilityRunningInfos err: " + err)
});
abilityManager.getAbilityRunningInfos().then((data) => {
console.log("getAbilityRunningInfos success, data: " + JSON.stringify(data))
}).catch((err) => {
console.log("getAbilityRunningInfos fail, err: " + JSON.stringify(err));
});
} catch (paramError) {
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
}
```
......@@ -179,7 +197,7 @@ getExtensionRunningInfos(upperLimit: number, callback: AsyncCallback\<Array\<Ext
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ---------------------------------------- | ---- | -------------- |
| upperLimit | number | 是 | 获取消息数量的最大限制。 |
| callback | AsyncCallback\<Array\<[ExtensionRunningInfo](js-apis-inner-application-extensionRunningInfo.md)>> | 是 | 被指定的回调方法。 |
| callback | AsyncCallback\<Array\<[ExtensionRunningInfo](js-apis-inner-application-extensionRunningInfo.md)>> | 是 | 以回调方式返回接口运行结果及运行中的extension信息,可进行错误处理或其他自定义处理。 |
**示例**
......@@ -187,12 +205,16 @@ getExtensionRunningInfos(upperLimit: number, callback: AsyncCallback\<Array\<Ext
var upperLimit = 0;
try {
abilityManager.getExtensionRunningInfos(upperLimit, (err,data) => {
console.log("getExtensionRunningInfos err: " + err + " data: " + JSON.stringify(data));
});
abilityManager.getExtensionRunningInfos(upperLimit, (err,data) => {
if (err.code != 0) {
console.log("getExtensionRunningInfos fail, err: " + JSON.stringify(err));
} else {
console.log("getExtensionRunningInfos success, data: " + JSON.stringify(data));
}
});
} catch (paramError) {
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
}
```
......@@ -216,7 +238,7 @@ getExtensionRunningInfos(upperLimit: number): Promise\<Array\<ExtensionRunningIn
| 类型 | 说明 |
| ---------------------------------------- | ------- |
| Promise\<Array\<[ExtensionRunningInfo](js-apis-inner-application-extensionRunningInfo.md)>> | 返回执行结果。 |
| Promise\<Array\<[ExtensionRunningInfo](js-apis-inner-application-extensionRunningInfo.md)>> | 以Promise方式返回接口运行结果及运行中的extension信息,可进行错误处理或其他自定义处理。 |
**示例**
......@@ -224,14 +246,14 @@ getExtensionRunningInfos(upperLimit: number): Promise\<Array\<ExtensionRunningIn
var upperLimit = 0;
try {
abilityManager.getExtensionRunningInfos(upperLimit).then((data) => {
console.log("getAbilityRunningInfos data: " + JSON.stringify(data));
}).catch((err) => {
console.log("getAbilityRunningInfos err: " + err);
})
abilityManager.getExtensionRunningInfos(upperLimit).then((data) => {
console.log("getExtensionRunningInfos success, data: " + JSON.stringify(data));
}).catch((err) => {
console.log("getExtensionRunningInfos fail, err: " + JSON.stringify(err));
})
} catch (paramError) {
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
console.log('error.code: ' + JSON.stringify(paramError.code) +
' error.message: ' + JSON.stringify(paramError.message));
}
```
......@@ -247,13 +269,17 @@ getTopAbility(callback: AsyncCallback\<ElementName>): void;
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ---------------------------------------- | ---- | -------------- |
| callback | AsyncCallback\<[ElementName](js-apis-bundleManager-elementName.md)> | 是 | 被指定的回调方法。 |
| callback | AsyncCallback\<[ElementName](js-apis-bundleManager-elementName.md)> | 是 | 以回调方式返回接口运行结果及应用名,可进行错误处理或其他自定义处理。 |
**示例**
```ts
abilityManager.getTopAbility((err,data) => {
console.log("getTopAbility err: " + err + " data: " + JSON.stringify(data));
if (err.code != 0) {
console.log("getTopAbility fail, err: " + JSON.stringify(err));
} else {
console.log("getTopAbility success, data: " + JSON.stringify(data));
}
});
```
......@@ -269,14 +295,14 @@ getTopAbility(): Promise\<ElementName>;
| 类型 | 说明 |
| ---------------------------------------- | ------- |
| Promise\<[ElementName](js-apis-bundleManager-elementName.md)>| 返回执行结果。 |
| Promise\<[ElementName](js-apis-bundleManager-elementName.md)>| 以Promise方式返回接口运行结果及应用名,可进行错误处理或其他自定义处理。 |
**示例**
```ts
abilityManager.getTopAbility().then((data) => {
console.log("getTopAbility data: " + JSON.stringify(data));
console.log("getTopAbility success, data: " + JSON.stringify(data));
}).catch((err) => {
console.log("getTopAbility err: " + err);
console.log("getTopAbility fail, err: " + JSON.stringify(err));
})
```
\ No newline at end of file
......@@ -25,13 +25,13 @@ onCreate(): void
**示例:**
```ts
class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("MyAbilityStage.onCreate is called")
}
}
```
```ts
class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("MyAbilityStage.onCreate is called");
}
}
```
## AbilityStage.onAcceptWant
......@@ -56,14 +56,14 @@ onAcceptWant(want: Want): string;
**示例:**
```ts
class MyAbilityStage extends AbilityStage {
onAcceptWant(want) {
console.log("MyAbilityStage.onAcceptWant called");
return "com.example.test";
}
}
```
```ts
class MyAbilityStage extends AbilityStage {
onAcceptWant(want) {
console.log("MyAbilityStage.onAcceptWant called");
return "com.example.test";
}
}
```
## AbilityStage.onConfigurationUpdate
......@@ -82,13 +82,13 @@ onConfigurationUpdate(newConfig: Configuration): void;
**示例:**
```ts
class MyAbilityStage extends AbilityStage {
onConfigurationUpdate(config) {
console.log('onConfigurationUpdate, language:' + config.language);
}
}
```
```ts
class MyAbilityStage extends AbilityStage {
onConfigurationUpdate(config) {
console.log('onConfigurationUpdate, language:' + config.language);
}
}
```
## AbilityStage.onMemoryLevel
......@@ -106,22 +106,22 @@ onMemoryLevel(level: AbilityConstant.MemoryLevel): void;
**示例:**
```ts
class MyAbilityStage extends AbilityStage {
```ts
class MyAbilityStage extends AbilityStage {
onMemoryLevel(level) {
console.log('onMemoryLevel, level:' + JSON.stringify(level));
}
}
```
}
```
## AbilityStage.context
context: AbilityStageContext;
指示有关上下文的配置信息
指示AbilityStage的上下文
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
| 属性名 | 类型 | 说明 |
| ----------- | --------------------------- | ------------------------------------------------------------ |
| context | [AbilityStageContext](js-apis-inner-application-abilityStageContext.md) | 在启动能力阶段进行初始化时回调。 |
| context | [AbilityStageContext](js-apis-inner-application-abilityStageContext.md) | 在Ability启动阶段进行初始化时回调,获取到该Ability的context值。 |
......@@ -14,7 +14,7 @@ import appRecovery from '@ohos.app.ability.appRecovery'
## appRecovery.RestartFlag
[enableAppRecovery](#apprecoveryenableapprecovery)接口重启选项参数
应用重启标志,[enableAppRecovery](#apprecoveryenableapprecovery)接口重启选项参数,该类型为枚举
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
......@@ -28,7 +28,7 @@ import appRecovery from '@ohos.app.ability.appRecovery'
## appRecovery.SaveOccasionFlag
[enableAppRecovery](#apprecoveryenableapprecovery)接口状态保存时机选项参数
保存条件标志,[enableAppRecovery](#apprecoveryenableapprecovery)接口状态保存时的选项参数,该类型为枚举
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
......@@ -39,7 +39,7 @@ import appRecovery from '@ohos.app.ability.appRecovery'
## appRecovery.SaveModeFlag
[enableAppRecovery](#apprecoveryenableapprecovery)接口状态保存方式的参数
状态保存标志,[enableAppRecovery](#apprecoveryenableapprecovery)接口状态保存方式的参数,该类型为枚举
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
......@@ -50,7 +50,7 @@ import appRecovery from '@ohos.app.ability.appRecovery'
## appRecovery.enableAppRecovery
enableAppRecovery(restart?: RestartFlag, saveOccasion?: SaveOccasionFlag, saveMode?: SaveModeFlag) : void;
enableAppRecovery(restart?: [RestartFlag](#apprecoveryrestartflag), saveOccasion?: [SaveOccasionFlag](#apprecoverysaveoccasionflag), saveMode?: [SaveModeFlag](#apprecoverysavemodeflag)) : void;
使能应用恢复功能,参数按顺序填入。
......@@ -60,9 +60,9 @@ enableAppRecovery(restart?: RestartFlag, saveOccasion?: SaveOccasionFlag, saveMo
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| restart | [RestartFlag](#apprecoveryrestartflag) | 否 | 发生对应故障时是否重启,默认为不重启。 |
| saveOccasion | [SaveOccasionFlag](#apprecoverysaveoccasionflag) | 否 | 状态保存时机,默认为故障时保存。 |
| saveMode | [SaveModeFlag](#apprecoverysavemodeflag) | 否 | 状态保存方式, 默认为文件缓存。 |
| restart | [RestartFlag](#apprecoveryrestartflag) | 否 | 枚举类型,发生对应故障时是否重启,默认为不重启。 |
| saveOccasion | [SaveOccasionFlag](#apprecoverysaveoccasionflag) | 否 | 枚举类型,状态保存时机,默认为故障时保存。 |
| saveMode | [SaveModeFlag](#apprecoverysavemodeflag) | 否 | 枚举类型,状态保存方式, 默认为文件缓存。 |
**示例:**
......@@ -94,7 +94,6 @@ var observer = {
appRecovery.restartApp();
}
}
```
## appRecovery.saveAppState
......@@ -109,7 +108,7 @@ saveAppState(): boolean;
| 类型 | 说明 |
| -------- | -------- |
| boolean | 保存成功与否。 |
| boolean | 保存成功与否。true:保存成功,false:保存失败。 |
**示例:**
......
......@@ -482,7 +482,7 @@ killProcessWithAccount(bundleName: string, accountId: number): Promise\<void\>
切断account进程(Promise形式)。
**需要权限**:ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS, ohos.permission.CLEAN_BACKGROUND_PROCESSES
**需要权限**:ohos.permission.CLEAN_BACKGROUND_PROCESSES,ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -520,7 +520,7 @@ killProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCal
**系统API**: 此接口为系统接口,三方应用不支持调用。
**需要权限**:ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS, ohos.permission.CLEAN_BACKGROUND_PROCESSES
**需要权限**:ohos.permission.CLEAN_BACKGROUND_PROCESSES,ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS权限。
**参数:**
......
......@@ -599,7 +599,7 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
启动一个新的ServiceExtensionAbility(callback形式)。
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -666,7 +666,7 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\
启动一个新的ServiceExtensionAbility(Promise形式)。
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -858,7 +858,7 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
使用帐户停止同一应用程序内的服务(callback形式)。
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -921,7 +921,7 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<
使用帐户停止同一应用程序内的服务(Promise形式)。
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......
......@@ -450,7 +450,7 @@ startAbilityForResultWithAccount(want: Want, accountId: number, callback: AsyncC
启动一个Ability并在该Ability销毁时返回执行结果(callback形式)。
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -525,7 +525,7 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options: StartOp
启动一个Ability并在该Ability销毁时返回执行结果(callback形式)。
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -604,7 +604,7 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options?: StartO
启动一个Ability并在该Ability销毁时返回执行结果(promise形式)。
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -807,7 +807,7 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
启动一个新的ServiceExtensionAbility(callback形式)。
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -869,7 +869,7 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\
启动一个新的ServiceExtensionAbility(Promise形式)。
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -1048,7 +1048,7 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
停止同一应用程序内指定账户的服务(callback形式)。
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -1111,7 +1111,7 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<
停止同一应用程序内指定账户的服务(Promise形式)。
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -1450,7 +1450,7 @@ connectServiceExtensionAbilityWithAccount(want: Want, accountId: number, options
将当前Ability连接到一个使用AbilityInfo.AbilityType.SERVICE模板的指定account的Ability。
**需要权限:** ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限:** ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -1710,7 +1710,7 @@ startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<
根据want和accountId启动Ability(callback形式)。
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -1784,7 +1784,7 @@ startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, ca
根据want、accountId及startOptions启动Ability(callback形式)。
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......@@ -1862,7 +1862,7 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions):
根据want、accountId和startOptions启动Ability(Promise形式)。
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**需要权限**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,当accountId为当前用户时,不需要校验该权限。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册