提交 e92fba48 编写于 作者: G Gloria

Update docs against 20267+20681+20189+20678+20527+20597+20353+20507+20944+20892+20325+20348

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 67d5f551
......@@ -46,7 +46,7 @@ Enumerates the action constants of the **Want** object. **action** specifies the
| ACTION_FILE_SELECT<sup>7+</sup> | ohos.action.fileSelect | Action of selecting a file. |
| PARAMS_STREAM<sup>7+</sup> | ability.params.stream | URI of the data stream associated with the target when the data is sent. The value must be an array of the string type. |
| ACTION_APP_ACCOUNT_OAUTH <sup>8+</sup> | ohos.account.appAccount.action.oauth | Action of providing the OAuth service. |
| DLP_PARAMS_INDEX<sup>9+</sup> |ohos.dlp.params.index |Action of obtaining the DLP index.<br>**System API**: This is a system API and cannot be called by third-party applications. |
## wantConstant.Entity
......@@ -84,6 +84,6 @@ Enumerates the entity constants of the **Want** object. **entity** specifies add
| FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | Indicates that ability continuation is reversible.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| FLAG_INSTALL_ON_DEMAND | 0x00000800 | Indicates that the specific ability will be installed if it has not been installed. |
| FLAG_INSTALL_WITH_BACKGROUND_MODE | 0x80000000 | Indicates that the specific ability will be installed in the background if it has not been installed. |
| FLAG_ABILITY_CLEAR_MISSION | 0x00008000 | Clears other operation missions. This flag can be set for **Want** in the [startAbility](js-apis-ability-featureAbility.md#startability) API passed to the FeatureAbility module. It must be used together with **flag_ABILITY_NEW_MISSION**. |
| FLAG_ABILITY_CLEAR_MISSION | 0x00008000 | Clears other operation missions. This flag can be set for **Want** in the [startAbility](js-apis-ability-featureAbility.md#startability) API passed to the FeatureAbility module. It must be used together with **flag_ABILITY_NEW_MISSION**.|
| FLAG_ABILITY_NEW_MISSION | 0x10000000 | Creates a mission on the history mission stack. |
| FLAG_ABILITY_MISSION_TOP | 0x20000000 | Reuses an ability instance if it is on the top of an existing mission stack; creates an ability instance otherwise.|
# @ohos.app.ability.appManager (appManager)
The **appManager** module implements application management. You can use the APIs of this module to query whether the application is undergoing a stability test, whether the application is running on a RAM constrained device, the memory size of the application, and information about the running process.
The **appManager** module implements application management. You can use the APIs of this module to query whether the application is undergoing a stability test, whether the application is running on a RAM constrained device, the memory usage of the application, and information about the running process.
> **NOTE**
>
......@@ -22,9 +22,9 @@ Checks whether this application is undergoing a stability test. This API uses an
**Parameters**
| Type| Description|
| -------- | -------- |
|AsyncCallback&lt;boolean&gt; |Callback used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is undergoing a stability test, and **false** means the opposite.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes|Callback used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is undergoing a stability test, and **false** means the opposite. |
**Error codes**
......@@ -59,9 +59,9 @@ Checks whether this application is undergoing a stability test. This API uses a
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is undergoing a stability test, and **false** means the opposite.|
| Type| Description|
| -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is undergoing a stability test, and **false** means the opposite.|
**Error codes**
......@@ -94,9 +94,9 @@ Checks whether this application is running on a RAM constrained device. This API
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is running on a RAM constrained device, and **false** means the opposite.|
| Type| Description|
| -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is running on a RAM constrained device, and **false** means the opposite.|
**Error codes**
......@@ -128,9 +128,9 @@ Checks whether this application is running on a RAM constrained device. This API
**Parameters**
| Type| Description|
| -------- | -------- |
| AsyncCallback&lt;boolean&gt; |Callback used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is running on a RAM constrained device, and **false** means the opposite.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes|Callback used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is running on a RAM constrained device, and **false** means the opposite. |
**Error codes**
......@@ -158,15 +158,15 @@ appManager.isRamConstrainedDevice((err, data) => {
getAppMemorySize(): Promise\<number>;
Obtains the memory size of this application. This API uses a promise to return the result.
Obtains the memory usage of this application. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;number&gt; | Promise used to return the API call result and the memory size. You can perform error handling or custom processing in this callback.|
| Type| Description|
| -------- | -------- |
| Promise&lt;number&gt; | Promise used to return the API call result and the memory size. You can perform error handling or custom processing in this callback.|
**Error codes**
......@@ -192,15 +192,15 @@ appManager.getAppMemorySize().then((data) => {
getAppMemorySize(callback: AsyncCallback\<number>): void;
Obtains the memory size of this application. This API uses an asynchronous callback to return the result.
Obtains the memory usage of this application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Type| Description|
| -------- | -------- |
|AsyncCallback&lt;number&gt; |Callback used to return the API call result and the memory size. You can perform error handling or custom processing in this callback.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;number&gt; | Yes|Callback used to return the API call result and the memory size. You can perform error handling or custom processing in this callback.|
**Error codes**
......@@ -272,9 +272,9 @@ Obtains information about the running processes. This API uses an asynchronous c
**Parameters**
| Type| Description|
| -------- | -------- |
|AsyncCallback\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | Callback used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | Yes|Callback used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.|
**Error codes**
......@@ -325,7 +325,8 @@ Checks whether the shared library is in use. This API uses a promise to return t
**Error codes**
| ID | Error Message |
| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
......@@ -366,7 +367,8 @@ Checks whether the shared library is in use. This API uses an asynchronous callb
**Error codes**
| ID | Error Message |
| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
......@@ -762,7 +764,7 @@ Kills a process by bundle name and account ID. This API uses a promise to return
>
> The **ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS** permission is not required when **accountId** specifies the current user.
**Required permissions**: ohos.permission.CLEAN_BACKGROUND_PROCESSES and ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and ohos.permission.CLEAN_BACKGROUND_PROCESSES
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
......@@ -812,7 +814,7 @@ Kills a process by bundle name and account ID. This API uses an asynchronous cal
>
> The **ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS** permission is not required when **accountId** specifies the current user.
**Required permissions**: ohos.permission.CLEAN_BACKGROUND_PROCESSES and ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and ohos.permission.CLEAN_BACKGROUND_PROCESSES
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
......@@ -820,11 +822,11 @@ Kills a process by bundle name and account ID. This API uses an asynchronous cal
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Bundle name.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| callback | AsyncCallback\<void\> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Bundle name.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| callback | AsyncCallback\<void\> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.|
**Error codes**
......@@ -1043,6 +1045,286 @@ try {
}
```
## appManager.getProcessMemoryByPid<sup>10+</sup>
getProcessMemoryByPid(pid: number, callback: AsyncCallback\<number>): void;
Obtains the memory usage of a process. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| pid | number | Yes| Process ID. For details, see [getRunningProcessInfoByBundleName](js-apis-app-ability-appManager.md#appmanagergetrunningprocessinfobybundlename10).|
| callback | AsyncCallback\<number> | Yes| Callback used to return the API call result and the memory size (in KB). You can perform error handling or custom processing in this callback.|
**Error codes**
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |
**Example**
```ts
import appManager from '@ohos.app.ability.appManager';
let pid = 0;
function getProcessMemoryByPidCallback(err, data) {
if (err) {
console.error('getProcessMemoryByPidCallback fail, err: ${JSON.stringify(err)}');
} else {
console.log('getProcessMemoryByPidCallback success.');
}
}
try {
appManager.getProcessMemoryByPid(pid, getProcessMemoryByPidCallback);
} catch (paramError) {
console.error('error: ${paramError.code}, ${paramError.message}');
}
```
## appManager.getProcessMemoryByPid<sup>10+</sup>
getProcessMemoryByPid(pid: number): Promise\<number>;
Obtains the memory usage of a process. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| pid | number | Yes| Process ID. For details, see [getRunningProcessInfoByBundleName](js-apis-app-ability-appManager.md#appmanagergetrunningprocessinfobybundlename10). |
**Return value**
| Type| Description|
| -------- | -------- |
| Promise\<number> | Promise used to return the API call result and the memory size (in KB). You can perform error handling or custom processing in this callback.|
**Error codes**
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |
**Example**
```ts
import appManager from '@ohos.app.ability.appManager';
let pid = 0;
try {
appManager.getProcessMemoryByPid(pid).then((data) => {
console.log('getProcessMemoryByPid success.');
}).catch((err) => {
console.error('getProcessMemoryByPid fail, err: ${JSON.stringify(err)}');
});
} catch (paramError) {
console.error('error: ${paramError.code}, ${paramError.message}');
}
```
## appManager.getRunningProcessInfoByBundleName<sup>10+</sup>
getRunningProcessInfoByBundleName(bundleName: string, callback: AsyncCallback\<Array\<ProcessInformation>>): void;
Obtains information about the running processes by bundle name. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Bundle name.|
| callback | AsyncCallback\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | Yes| Callback used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.|
**Error codes**
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |
**Example**
```ts
import appManager from '@ohos.app.ability.appManager';
let bundleName = "bundleName";
function getRunningProcessInfoByBundleNameCallback(err, data) {
if (err) {
console.error('getRunningProcessInfoByBundleNameCallback fail, err: ${JSON.stringify(err)}');
} else {
console.log('getRunningProcessInfoByBundleNameCallback success.');
}
}
try {
appManager.getRunningProcessInfoByBundleName(bundleName, getRunningProcessInfoByBundleNameCallback);
} catch (paramError) {
console.error('error: ${paramError.code}, ${paramError.message}');
}
```
## appManager.getRunningProcessInfoByBundleName<sup>10+</sup>
getRunningProcessInfoByBundleName(bundleName: string): Promise\<Array\<ProcessInformation>>;
Obtains information about the running processes by bundle name. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Bundle name.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | Promise used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.|
**Error codes**
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |
**Example**
```ts
import appManager from '@ohos.app.ability.appManager';
let bundleName = "bundleName";
try {
appManager.getRunningProcessInfoByBundleName(bundleName).then((data) => {
console.log('getRunningProcessInfoByBundleName success.');
}).catch((err) => {
console.error('getRunningProcessInfoByBundleName fail, err: ${JSON.stringify(err)}');
});
} catch (paramError) {
console.error('error: ${paramError.code}, ${paramError.message}');
}
```
## appManager.getRunningProcessInfoByBundleName<sup>10+</sup>
getRunningProcessInfoByBundleName(bundleName: string, userId: number, callback: AsyncCallback\<Array\<ProcessInformation>>): void;
Obtains information about the running processes by bundle name and user ID. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Bundle name.|
| userId | number | Yes| User ID.|
| callback | AsyncCallback\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | Yes| Callback used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.|
**Error codes**
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |
**Example**
```ts
import appManager from '@ohos.app.ability.appManager';
let bundleName = "bundleName";
let userId = 0;
function getRunningProcessInfoByBundleNameCallback(err, data) {
if (err) {
console.error('getRunningProcessInfoByBundleNameCallback fail, err: ${JSON.stringify(err)}');
} else {
console.log('getRunningProcessInfoByBundleNameCallback success.');
}
}
try {
appManager.getRunningProcessInfoByBundleName(bundleName, userId, getRunningProcessInfoByBundleNameCallback);
} catch (paramError) {
console.error('error: ${paramError.code}, ${paramError.message}');
}
```
## appManager.getRunningProcessInfoByBundleName<sup>10+</sup>
getRunningProcessInfoByBundleName(bundleName: string, userId: number): Promise\<Array\<ProcessInformation>>;
Obtains information about the running processes by bundle name and user ID. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Bundle name.|
| userId | number | Yes| User ID.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | Promise used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.|
**Error codes**
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
| ID| Error Message|
| ------- | -------- |
| 16000050 | Internal error. |
**Example**
```ts
import appManager from '@ohos.app.ability.appManager';
let bundleName = "bundleName";
let userId = 0;
try {
appManager.getRunningProcessInfoByBundleName(bundleName, userId).then((data) => {
console.log('getRunningProcessInfoByBundleName success.');
}).catch((err) => {
console.error('getRunningProcessInfoByBundleName fail, err: ${JSON.stringify(err)}');
});
} catch (paramError) {
console.error('error: ${paramError.code}, ${paramError.message}');
}
```
## ApplicationState
Enumerates the application states. This enum can be used together with [AbilityStateData](js-apis-inner-application-appStateData.md) to return the application state.
......
......@@ -262,7 +262,8 @@ Defines the request information, which is used as an input parameter for binding
console.info(TAG, `onRequest, want: ${want.abilityName}`);
try {
var requestInfo = dialogRequest.getRequestInfo(want);
window.bindDialogTarget(requestInfo, () => {
let windowClass = null;
windowClass.bindDialogTarget(requestInfo, () => {
console.info('Dialog Window Need Destroy.');
}, (err) => {
if (err.code) {
......
......@@ -259,7 +259,7 @@ revokeQuickFix(bundleName: string, callback: AsyncCallback\<void>): void;
Revokes quick fix. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INSTALL_BUNDLE and ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED and ohos.permission.INSTALL_BUNDLE
**System capability**: SystemCapability.Ability.AbilityRuntime.QuickFix
......@@ -304,7 +304,7 @@ revokeQuickFix(bundleName: string): Promise\<void>;
Revokes quick fix. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INSTALL_BUNDLE and ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED and ohos.permission.INSTALL_BUNDLE
**System capability**: SystemCapability.Ability.AbilityRuntime.QuickFix
......
......@@ -362,7 +362,7 @@ Triggered when this UIAbility is about to terminate in case that the system para
onPrepareToTerminate() {
// Define a pre-termination operation,
// for example, starting another UIAbility and performing asynchronous termination based on the startup result.
let want:Want = {
let want = {
bundleName: "com.example.myapplication",
moduleName: "entry",
abilityName: "SecondAbility"
......@@ -444,7 +444,7 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
return true;
}
};
let method = 'call_Function'; // Notification message string negotiated by the two abilities.
let method = 'call_Function'; // Notification message string negotiated by the two UIAbilities.
let caller;
export default class MainUIAbility extends UIAbility {
onWindowStageCreate(windowStage) {
......
......@@ -31,7 +31,7 @@ Obtains a **WantAgent** object. This API uses an asynchronous callback to return
| ID | Error Message |
|-----------|--------------------|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000007 | Service busy, there are concurrent tasks, waiting for retry.|
| 16000151 | Invalid wantagent object.|
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
......@@ -110,7 +110,7 @@ Obtains a **WantAgent** object. This API uses a promise to return the result. If
| ID | Error Message |
|-----------|--------------------|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000007 | Service busy, there are concurrent tasks, waiting for retry.|
| 16000151 | Invalid wantagent object.|
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
......@@ -179,7 +179,7 @@ Obtains the bundle name of a **WantAgent** object. This API uses an asynchronous
| ID | Error Message |
|-----------|--------------------|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000007 | Service busy, there are concurrent tasks, waiting for retry.|
| 16000151 | Invalid wantagent object.|
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
......@@ -271,7 +271,7 @@ Obtains the bundle name of a **WantAgent** object. This API uses a promise to re
| ID | Error Message |
|-----------|--------------------|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000007 | Service busy, there are concurrent tasks, waiting for retry.|
| 16000151 | Invalid wantagent object.|
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
......@@ -354,7 +354,7 @@ Obtains the user ID of a **WantAgent** object. This API uses an asynchronous cal
| ID | Error Message |
|-----------|--------------------|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000007 | Service busy, there are concurrent tasks, waiting for retry.|
| 16000151 | Invalid wantagent object.|
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
......@@ -447,7 +447,7 @@ Obtains the user ID of a **WantAgent** object. This API uses a promise to return
| ID | Error Message |
|-----------|--------------------|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000007 | Service busy, there are concurrent tasks, waiting for retry.|
| 16000151 | Invalid wantagent object.|
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
......@@ -531,7 +531,7 @@ Obtains the want in a **WantAgent** object. This API uses an asynchronous callba
| ID | Error Message |
|-----------|--------------------|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000007 | Service busy, there are concurrent tasks, waiting for retry.|
| 16000015 | Service timeout.|
| 16000151 | Invalid wantagent object.|
......@@ -626,7 +626,7 @@ Obtains the want in a **WantAgent** object. This API uses a promise to return th
| ID | Error Message |
|-----------|--------------------|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000007 | Service busy, there are concurrent tasks, waiting for retry.|
| 16000015 | Service timeout.|
| 16000151 | Invalid wantagent object.|
......@@ -710,7 +710,7 @@ Cancels a **WantAgent** object. This API uses an asynchronous callback to return
| ID | Error Message |
|-----------|--------------------|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000007 | Service busy, there are concurrent tasks, waiting for retry.|
| 16000151 | Invalid wantagent object.|
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
......@@ -802,7 +802,7 @@ Cancels a **WantAgent** object. This API uses a promise to return the result.
| ID | Error Message |
|-----------|--------------------|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000007 | Service busy, there are concurrent tasks, waiting for retry.|
| 16000151 | Invalid wantagent object.|
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
......@@ -960,7 +960,7 @@ Checks whether two **WantAgent** objects are equal to determine whether the same
| Name | Type | Mandatory| Description |
| ---------- | ------------------------ | ---- | --------------------------------------- |
| agent | WantAgent | Yes | The first **WantAgent** object. |
| otherAgent | WantAgent | Yes | The second **WantAgent** object. |
| otherAgent | WantAgent | Yes | The second **WantAgent** object. |
| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.|
**Example**
......@@ -1041,7 +1041,7 @@ Checks whether two **WantAgent** objects are equal to determine whether the same
| Name | Type | Mandatory| Description |
| ---------- | --------- | ---- | ------------- |
| agent | WantAgent | Yes | The first **WantAgent** object.|
| otherAgent | WantAgent | Yes | The second **WantAgent** object. |
| otherAgent | WantAgent | Yes | The second **WantAgent** object.|
**Return value**
......@@ -1127,7 +1127,7 @@ Obtains the operation type of a **WantAgent** object. This API uses an asynchron
| ID | Error Message |
|-----------|--------------------|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000007 | Service busy, there are concurrent tasks, waiting for retry.|
| 16000015 | Service timeout.|
| 16000151 | Invalid wantagent object.|
......@@ -1218,7 +1218,7 @@ Obtains the operation type of a **WantAgent** object. This API uses a promise to
| ID | Error Message |
|-----------|--------------------|
| 16000007 | Service busyness. There are concurrent tasks, waiting for retry.|
| 16000007 | Service busy, there are concurrent tasks, waiting for retry.|
| 16000015 | Service timeout.|
| 16000151 | Invalid wantagent object.|
......
......@@ -21,8 +21,8 @@ Defines the subscription information about the widget update by proxy.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Subscriber ID of the widget update by proxy. The value is the same as that of the data publisher.|
| subscriberId | string | No| Subscription condition of the widget update by proxy. The default value is the current widget ID (specified by **formId**).|
| key<sup>10+</sup> | string | Yes| Subscriber ID of the widget update by proxy. The value is the same as that of the data publisher.|
| subscriberId<sup>10+</sup> | string | No| Subscription condition of the widget update by proxy. The default value is the current widget ID (specified by **formId**).|
## FormBindingData
......
......@@ -1685,7 +1685,7 @@ formHost.on('formRemove', callback, bundleName);
## off('formRemove')<sup>10+</sup>
off(type: "formRemove", observerCallback?: Callback&lt;formInfo.RunningFormInfo&gt;, bundleName?: string): void
off(type: "formRemove", observerCallback?: Callback&lt;formInfo.RunningFormInfo&gt;, bundleName?: string): void
Unsubscribes from widget removal events. This API uses an asynchronous callback to return the result.
......@@ -2337,7 +2337,7 @@ try {
## getRunningFormInfoById<sup>10+</sup>
function getRunningFormInfoById(formId: string): Promise&lt;formInfo.RunningFormInfo&gt;
getRunningFormInfoById(formId: string): Promise&lt;formInfo.RunningFormInfo&gt;
Obtains the information about widget hosts based on the widget ID. This API uses a promise to return the result.
......@@ -2482,7 +2482,7 @@ Unsubscribes from events indicating that a widget becomes visible.
| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type | string | Yes | Event type. This value **'notifyVisible'** indicates a widget visibility event.|
| callback | Callback &lt;Array&lt;[formInfo.RunningFormInfo](js-apis-app-form-formInfo.md)&gt;&gt; | No | Callback registered during the subscription. By default, all the subscriptions to the specified event are canceled.<br> To cancel the subscription with a given callback, this parameter must be set to the same value as **callback** in **on('notifyVisible')**.|
| bundleName | string | No | Name of the bundle that functions as the widget host, on which the widget visibility state changes are subscribed.<br>To cancel the subscription for a given bundle name, this parameter must be set to the same value as **bundleName** in **on('notifyVisible')**. |
| bundleName | string | No | Name of the bundle that functions as the widget host, on which the widget visibility state changes are subscribed.<br>To cancel the subscription for a given bundle name, this parameter must be set to the same value as **bundleName** in **on('notifyVisible')**.|
**Example**
......
......@@ -25,8 +25,8 @@ Describes widget information.
| abilityName | string | Yes | No | Name of the ability to which the widget belongs. |
| name | string | Yes | No | Widget name. |
| description | string | Yes | No | Description of the widget. |
| descriptionId | number | Yes | No | ID of the widget description. |
| type | [FormType](#formtype) | Yes | No | Type of the widget. Currently, only JS widgets are supported.|
| descriptionId<sup>10+</sup> | number | Yes | No | ID of the widget description. |
| type | [FormType](#formtype) | Yes | No | Type of the widget. Currently, JS and ArkTS widgets are supported.|
| jsComponentName | string | Yes | No | Name of the component used in the JS widget. |
| colorMode | [ColorMode](#colormode) | Yes | No | Color mode of the widget. |
| isDefault | boolean | Yes | No | Whether the widget is the default one. |
......@@ -38,6 +38,7 @@ Describes widget information.
| defaultDimension | number | Yes | No | Default dimension of the widget. |
| supportDimensions | Array&lt;number&gt; | Yes | No | Dimensions supported by the widget. For details, see [FormDimension](#formdimension). |
| customizeData | {[key: string]: [value: string]} | Yes | No | Custom data of the widget. |
| isDynamic<sup>10+</sup> | boolean | Yes | No | Whether the widget is a dynamic widget.<br>ArkTS widgets are classified into dynamic and static widgets. JS widgets are all dynamic widgets. |
## FormType
......@@ -154,12 +155,12 @@ Defines the information about the widget host.
| Name | Type | Readable | Writable | Description |
| ----------- | -------- | -------- | -------------------- | ------------------------------------------------------------ |
| formId | string | Yes | No | Widget ID. |
| bundleName | string | Yes | No | Name of the bundle to which the widget provider belongs. |
| bundleName<sup>10+</sup> | string | Yes | No | Name of the bundle to which the widget provider belongs. |
| hostBundleName | string | Yes | No | Name of the bundle to which the widget host belongs. |
| visibilityType | [VisibilityType](#visibilitytype) | Yes | No | Visibility types of the widget. |
| moduleName | string | Yes | No | Name of the module to which the widget belongs. |
| abilityName | string | Yes | No | Name of the ability to which the widget belongs. |
| formName | string | Yes | No | Widget name. |
| moduleName<sup>10+</sup> | string | Yes | No | Name of the module to which the widget belongs. |
| abilityName<sup>10+</sup> | string | Yes | No | Name of the ability to which the widget belongs. |
| formName<sup>10+</sup> | string | Yes | No | Widget name. |
| dimension | number | Yes | No | Widget specifications. |
## formProviderFilter<sup>10+</sup>
......
......@@ -10,7 +10,7 @@ The **Configuration** module defines environment change information. **Configura
## Modules to Import
```ts
import Configuration from '@ohos.app.application.Configuration';
import Configuration from '@ohos.application.Configuration';
```
**System capability**: SystemCapability.Ability.AbilityBase
......
......@@ -31,8 +31,6 @@ Sets the next refresh time for a widget. This API uses an asynchronous callback
**Example**
```ts
import formProvider from '@ohos.app.form.formProvider';
let formId = '12400633174999288';
formProvider.setFormNextRefreshTime(formId, 5, (error, data) => {
if (error.code) {
......@@ -65,8 +63,6 @@ Sets the next refresh time for a widget. This API uses a promise to return the r
**Example**
```ts
import formProvider from '@ohos.app.form.formProvider';
let formId = '12400633174999288';
formProvider.setFormNextRefreshTime(formId, 5).then(() => {
console.log('formProvider setFormNextRefreshTime success');
......@@ -95,7 +91,6 @@ Updates a widget. This API uses an asynchronous callback to return the result.
```ts
import formBindingData from '@ohos.app.form.formBindingData';
import formProvider from '@ohos.app.form.formProvider';
let formId = '12400633174999288';
let obj = formBindingData.createFormBindingData({temperature:'22c', time:'22:00'});
......@@ -131,7 +126,6 @@ Updates a widget. This API uses a promise to return the result.
```ts
import formBindingData from '@ohos.application.formBindingData';
import formProvider from '@ohos.app.form.formProvider';
let formId = '12400633174999288';
let obj = formBindingData.createFormBindingData({temperature:'22c', time:'22:00'});
......
......@@ -1367,17 +1367,17 @@ context.printDrawnCompleted().then((data) => {
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Readable/Writable| Type | Mandatory | Description |
| ---- | ---- | ------ | ---- | ----- |
| pid | Read-only | number | No | Process ID.|
| uid | Read-only | number | No | User ID.|
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----- |
| pid |number | No | Process ID.|
| uid |number | No | User ID.|
## PermissionRequestResult<sup>7+</sup>
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Readable/Writable| Type | Mandatory | Description |
| ----------- | ---- | -------------- | ---- | ---------- |
| requestCode | Read-only | number | Yes | Request code passed.|
| permissions | Read-only | Array\<string> | Yes | Permissions requested. |
| authResults | Read-only | Array\<number> | Yes | Permission request result. |
| Name | Type | Mandatory | Description |
| ----------- |-------------- | ---- | ---------- |
| requestCode | number | Yes | Request code passed.|
| permissions | Array\<string> | Yes | Permissions requested. |
| authResults | Array\<number> | Yes | Permission request result. |
......@@ -14,7 +14,7 @@ import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry
## Usage
An **AbilityDelegator** object is obtained by calling [getAbilityDelegator](js-apis-app-ability-abilityDelegatorRegistry.md#abilitydelegatorregistrygetabilitydelegator) in **AbilityDelegatorRegistry**.
An **AbilityDelegator** object is obtained by calling [getAbilityDelegator](js-apis-app-ability-abilityDelegatorRegistry.md#abilitydelegatorregistrygetabilitydelegator) in **AbilityDelegatorRegistry**. This API can be used only in the test environment.
```ts
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
```
......@@ -263,7 +263,7 @@ Waits a period of time for the **Ability** instance that matches the **AbilityMo
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| monitor | [AbilityMonitor](js-apis-inner-application-abilityMonitor.md#AbilityMonitor) | Yes | [AbilityMonitor](js-apis-inner-application-abilityMonitor.md#AbilityMonitor) instance.|
| timeout | number | No | Maximum waiting time, in milliseconds. |
| timeout | number | Yes | Maximum waiting time, in milliseconds. |
| callback | AsyncCallback\<[UIAbility](js-apis-app-ability-uiAbility.md)> | Yes | Callback used to return the result. |
**Error codes**
......@@ -506,6 +506,8 @@ Starts an ability. This API uses an asynchronous callback to return the result.
| 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000010 | The call with the continuation flag is forbidden. |
| 16000011 | The context does not exist. |
| 16000012 | The application is controlled. |
| 16000013 | The application is controlled by EDM. |
| 16000050 | Internal error. |
| 16000053 | The ability is not on the top of the UI. |
| 16000055 | Installation-free timed out. |
......@@ -561,6 +563,8 @@ Starts an ability. This API uses a promise to return the result.
| 16000009 | An ability cannot be started or stopped in Wukong mode. |
| 16000010 | The call with the continuation flag is forbidden. |
| 16000011 | The context does not exist. |
| 16000012 | The application is controlled. |
| 16000013 | The application is controlled by EDM. |
| 16000050 | Internal error. |
| 16000053 | The ability is not on the top of the UI. |
| 16000055 | Installation-free timed out. |
......@@ -838,6 +842,8 @@ executeShellCommand(cmd: string, callback: AsyncCallback\<ShellCmdResult>): void
Executes a shell command. This API uses an asynchronous callback to return the result.
Only the following shell commands are supported: aa, bm, cp, mkdir, rm, uinput, hilog, ppwd, echo, uitest, acm, hidumper, wukong, pkill, ps, and pidof.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
......@@ -865,6 +871,8 @@ executeShellCommand(cmd: string, timeoutSecs: number, callback: AsyncCallback\<S
Executes a shell command with the timeout period specified. This API uses an asynchronous callback to return the result.
Only the following shell commands are supported: aa, bm, cp, mkdir, rm, uinput, hilog, ppwd, echo, uitest, acm, hidumper, wukong, pkill, ps, and pidof.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
......@@ -872,7 +880,7 @@ Executes a shell command with the timeout period specified. This API uses an asy
| Name | Type | Mandatory| Description |
| ----------- | ------------------------------------------------------------ | ---- | ----------------------------- |
| cmd | string | Yes | Shell command string. |
| timeoutSecs | number | No | Command timeout period, in seconds.|
| timeoutSecs | number | Yes | Command timeout period, in seconds.|
| callback | AsyncCallback\<[ShellCmdResult](js-apis-inner-application-shellCmdResult.md#ShellCmdResult)> | Yes | Callback used to return the result. |
**Example**
......@@ -894,6 +902,8 @@ executeShellCommand(cmd: string, timeoutSecs?: number): Promise\<ShellCmdResult>
Executes a shell command with the timeout period specified. This API uses a promise to return the result.
Only the following shell commands are supported: aa, bm, cp, mkdir, rm, uinput, hilog, ppwd, echo, uitest, acm, hidumper, wukong, pkill, ps, and pidof.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
......
......@@ -2,6 +2,10 @@
The **AppStateData** module defines the application state data, which can be obtained through [getForegroundApplications](js-apis-app-ability-appManager.md#appmanagergetforegroundapplications).
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
......
......@@ -134,7 +134,7 @@ export default class EntryAbility extends UIAbility {
## ApplicationContext.off(type: 'abilityLifecycle', callbackId: number)
off(type: 'abilityLifecycle', callbackId: **number**): **void**;
off(type: 'abilityLifecycle', callbackId: number): Promise\<void>;
Deregisters the listener that monitors the ability lifecycle of the application.
......@@ -279,18 +279,119 @@ export default class MyAbility extends Ability {
}
```
## ApplicationContext.on(type: 'applicationStateChange', callback: ApplicationStateChangeCallback)<sup>10+</sup>
on(type: 'applicationStateChange', callback: ApplicationStateChangeCallback): **void**;
Registers a listener for application foreground/background state changes. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ---------------- |
| type | string | Yes | Event type. The value is fixed at **'applicationStateChange'**, indicating that the application switches from the foreground to the background or vice versa.|
| callback | [ApplicationStateChangeCallback](#js-apis-app-ability-applicationStateChangeCallback.md) | Yes | Callback used to return the result. |
**Example**
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
export default class MyAbility extends UIAbility {
onCreate() {
console.log('MyAbility onCreate');
globalThis.applicationStateChangeCallback = {
onApplicationForeground() {
console.info('applicationStateChangeCallback onApplicationForeground');
},
onApplicationBackground() {
console.info('applicationStateChangeCallback onApplicationBackground');
}
}
globalThis.applicationContext = this.context.getApplicationContext();
// 1. Obtain an applicationContext object.
let applicationContext = globalThis.applicationContext;
// 2. Use applicationContext to subscribe to the 'applicationStateChange' event.
applicationContext.on('applicationStateChange', globalThis.ApplicationStateChangeCallback);
console.log('Resgiter applicationStateChangeCallback');
}
}
```
## ApplicationContext.off(type: 'applicationStateChange', callback: AsyncCallback\<void>)<sup>10+</sup>
off(type: 'applicationStateChange', callback: AsyncCallback<**void**>): **void**;
Deregisters the listener for application foreground/background state changes based on a given callback.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | -------------------------------- |
| type | string | Yes | Event type. The value is fixed at **'applicationStateChange'**, indicating that the application switches from the foreground to the background or vice versa. |
| callback | AsyncCallback\<void> | No | Callback that has been used for the registration|
**Example**
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
export default class EntryAbility extends UIAbility {
onDestroy() {
globalThis.applicationStateChangeCallback = {
onApplicationForeground() {
console.info('applicationStateChangeCallback onApplicationForeground');
},
onApplicationBackground() {
console.info('applicationStateChangeCallback onApplicationBackground');
}
}
let applicationContext = this.context.getApplicationContext();
applicationContext.off('applicationStateChange', globalThis.ApplicationStateChangeCallback);
}
}
```
## ApplicationContext.off(type: 'applicationStateChange')<sup>10+</sup>
off(type: 'applicationStateChange'): **void**;
Deregisters all the listeners for application foreground/background state changes.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------- | ---- | -------------------- |
| type | string | Yes | Event type. The value is fixed at **'applicationStateChange'**, indicating that the application switches from the foreground to the background or vice versa.|
**Example**
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
export default class MyAbility extends UIAbility {
onDestroy() {
let applicationContext = this.context.getApplicationContext();
applicationContext.off('applicationStateChange');
}
}
```
## ApplicationContext.getRunningProcessInformation<sup>9+</sup>
getRunningProcessInformation(): Promise\<Array\<ProcessInformation>>;
Obtains information about the running processes. This API uses a promise to return the result.
**Required permissions**: ohos.permission.GET_RUNNING_INFO
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Return value**
| Type| Description|
......@@ -322,12 +423,8 @@ getRunningProcessInformation(callback: AsyncCallback\<Array\<ProcessInformation>
Obtains information about the running processes. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.GET_RUNNING_INFO
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Return value**
| Type| Description|
......
......@@ -29,7 +29,7 @@ import common from '@ohos.app.ability.common';
| bundleCodeDir | string | Yes | No | Bundle code directory. Do not access resource files by concatenating paths. Use the [resourceManager API](js-apis-resource-manager.md) instead.|
| distributedFilesDir | string | Yes | No | Distributed file directory.|
| eventHub | [EventHub](js-apis-inner-application-eventHub.md) | Yes | No | Event hub that implements event subscription, unsubscription, and triggering.|
| area | contextConstant.[AreaMode](js-apis-app-ability-contextConstant.md) | Yes | No | Encryption level of the directory. |
| area | contextConstant.[AreaMode](js-apis-app-ability-contextConstant.md) | Yes | No | Encryption level of the directory.|
## Context.createBundleContext
......@@ -155,3 +155,77 @@ try {
console.error('getApplicationContext failed, error.code: ${error.code}, error.message: ${error.message}');
}
```
## Context.getGroupDir<sup>10+</sup>
getGroupDir(groupId: string): Promise\<string>;
Obtains the shared directory based on a group ID. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------- | ---- | ------------- |
| groupId | string | Yes | Group ID, which is assigned by the system when an atomic service application project is created.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise\<string> | Promise used to return the result. If no shared directory exists, null is returned. Only the encryption level EL2 is supported.|
**Error codes**
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
| ID| Error Message|
| ------- | -------- |
| 16000011 | The context does not exist. |
**Example**
```ts
let groupId = "1";
context.getGroupDir(groupId).then(data => {
console.log("getGroupDir result:" + data);
}).catch((err) => {
console.error('error: ${JSON.stringify(err)}');
});
```
## Context.getGroupDir<sup>10+</sup>
getGroupDir(groupId: string, callback: AsyncCallback\<string>);
Obtains the shared directory based on a group ID. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------- | ---- | ------------- |
| groupId | string | Yes | Group ID, which is assigned by the system when an atomic service application project is created.|
| callback | AsyncCallback\<string> | Yes | Callback used to return the result. If no shared directory exists, null is returned. Only the encryption level EL2 is supported.|
**Error codes**
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
| ID| Error Message|
| ------- | -------- |
| 16000011 | The context does not exist. |
**Example**
```ts
context.getGroupDir("1", (err, data) => {
if (err) {
console.error('getGroupDir faile, err: ${JSON.stringify(err)}');
} else {
console.log('getGroupDir result is: ${JSON.stringify(data)}');
}
});
```
......@@ -24,7 +24,7 @@ Called when an unhandled exception occurs in the JS runtime.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| errMsg | string | No| Message and error stack trace about the exception.|
| errMsg | string | Yes| Message and error stack trace about the exception.|
**Example**
......
......@@ -124,7 +124,7 @@ Triggers an event.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| event | string | Yes| Event name.|
| ...args | Object[] | Yes| Variable parameters, which are passed to the callback when the event is triggered.|
| ...args | Object[] | No| Variable parameters, which are passed to the callback when the event is triggered.|
**Example**
......@@ -146,7 +146,7 @@ export default class EntryAbility extends UIAbility {
}
eventFunc(argOne, argTwo) {
console.log('eventFunc is called, ${argOne}, ${argTwo}');
console.log(`eventFunc is called, ${argOne}, ${argTwo}`);
}
}
```
......@@ -21,6 +21,8 @@ Import the **abilityManager** module and obtain the ExtensionAbility running inf
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: The following APIs are system APIs and cannot be called by third-party applications.
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| extension | [ElementName](js-apis-bundleManager-elementName.md) | Yes| No| ExtensionAbility information.|
......
......@@ -15,29 +15,7 @@ You can use the APIs of this module to start FormExtensionAbilities.
import common from '@ohos.app.ability.common';
```
## Usage
Before using the **ServiceExtensionContext** module, you must first obtain a **FormExtensionAbility** instance.
```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formBindingData from '@ohos.app.form.formBindingData';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onAddForm(want) {
let formContext = this.context; // Obtain a FormExtensionContext instance.
// ...
let dataObj1 = {
temperature: '11c',
'time': '11:00'
};
let obj1 = formBindingData.createFormBindingData(dataObj1);
return obj1;
}
};
```
## startAbility
## FormExtensionContext.startAbility
startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void
......@@ -57,7 +35,8 @@ Starts an ability. This API uses an asynchronous callback to return the result.
| 16500100 | Failed to obtain the configuration information. |
| 16500101 | The application is not a system application. |
| 16501000 | An internal functional error occurred. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
**Parameters**
......@@ -94,7 +73,7 @@ export default class MyFormExtensionAbility extends FormExtensionAbility {
};
```
## startAbility
## FormExtensionContext.startAbility
startAbility(want: Want): Promise&lt;void&gt;
......@@ -126,7 +105,8 @@ Starts an ability. This API uses a promise to return the result.
| 16500100 | Failed to obtain the configuration information. |
| 16500101 | The application is not a system application. |
| 16501000 | An internal functional error occurred. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|
For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).
**Example**
......@@ -153,3 +133,204 @@ export default class MyFormExtensionAbility extends FormExtensionAbility {
}
};
```
## FormExtensionContext.connectServiceExtensionAbility<sup>10+</sup>
connectServiceExtensionAbility(want: Want, options: ConnectOptions): number;
Connects this ability to a ServiceExtensionAbility.
**System capability**: SystemCapability.Ability.Form
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-want.md) | Yes| Want information about the target ability, such as the ability name and bundle name.|
| options | [ConnectOptions](js-apis-inner-ability-connectOptions.md) | Yes| Callback used to return the information indicating that the connection is successful, interrupted, or failed.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Returns a connect ID, which will be used for the disconnection.|
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 16000001 | The specified ability does not exist. |
| 16000002 | Incorrect ability type. |
| 16000004 | Can not start invisible component. |
| 16000006 | Cross-user operations are not allowed. |
| 16000008 | The crowdtesting application expires. |
| 16000053 | The ability is not on the top of the UI. |
| 16000055 | Installation-free timed out. |
| 16000011 | The context does not exist. |
| 16000050 | Internal error. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
let commRemote = null;
export default class MyFormExtensionAbility extends FormExtensionAbility {
onFormEvent(formId, message) {
// Call connectServiceExtensionAbility() when the message event is triggered.
console.log(`FormExtensionAbility onFormEvent, formId:${formId}, message:${message}`);
let want = {
deviceId: '',
bundleName: 'com.example.formstartability',
abilityName: 'EntryAbility',
parameters: {
'message': message
}
};
let options = {
onConnect(elementName, remote) {
commRemote = remote; // remote is used to communicate with the ServiceExtensionAbility.
console.log('----------- onConnect -----------');
},
onDisconnect(elementName) { console.log('----------- onDisconnect -----------') },
onFailed(code) { console.error('----------- onFailed -----------') }
};
let connection = null;
try {
connection = this.context.connectServiceExtensionAbility(want, options);
} catch (paramError) {
// Process input parameter errors.
console.error(`error.code: ${paramError.code}, error.message: ${paramError.message}`);
}
}
};
```
## FormExtensionContext.disconnectServiceExtensionAbility<sup>10+</sup>
disconnectServiceExtensionAbility(connection: number, callback:AsyncCallback&lt;void&gt;): void;
Disconnects this ability from a ServiceExtensionAbility and after the successful disconnection, sets the remote object returned upon the connection to void. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.Form
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| connection | number | Yes| Connection ID returned after **connectServiceExtensionAbility** is called.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 16000011 | The context does not exist. |
| 16000050 | Internal error. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
// commRemote is the remote object returned in the onConnect() callback. The value null is meaningless and is only an example.
let commRemote = null;
export default class MyFormExtensionAbility extends FormExtensionAbility {
onFormEvent(formId, message) {
// In actual use, connection is the return value of connectServiceExtensionAbility(). The value 1 is meaningless and is only an example.
let connection = 1;
try {
this.context.disconnectServiceExtensionAbility(connection, (error) => {
commRemote = null;
if (error.code) {
// Process service logic errors.
console.error(
`disconnectServiceExtensionAbility failed, error.code: ${error.code}, error.message: ${error.message}`);
return;
}
// Carry out normal service processing.
console.log('disconnectServiceExtensionAbility succeed');
});
} catch (paramError) {
commRemote = null;
// Process input parameter errors.
console.error(`error.code: ${paramError.code}, error.message: ${paramError.message}`);
}
}
};
```
## FormExtensionContext.disconnectServiceExtensionAbility<sup>10+</sup>
disconnectServiceExtensionAbility(connection: number): Promise&lt;void&gt;;
Disconnects this ability from a ServiceExtensionAbility and after the successful disconnection, sets the remote object returned upon the connection to void. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.Form
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| connection | number | Yes| Connection ID returned after **connectServiceExtensionAbility** is called.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
| ID| Error Message|
| ------- | -------------------------------- |
| 16000011 | The context does not exist. |
| 16000050 | Internal error. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
// commRemote is the remote object returned in the onConnect() callback. The value null is meaningless and is only an example.
let commRemote = null;
export default class MyFormExtensionAbility extends FormExtensionAbility {
onFormEvent(formId, message) {
//In actual use, connection is the return value of connectServiceExtensionAbility(). The value 1 is meaningless and is only an example.
let connection = 1;
try {
this.context.disconnectServiceExtensionAbility(connection)
.then((data) => {
commRemote = null;
// Carry out normal service processing.
console.log('disconnectServiceExtensionAbility succeed');
})
.catch((error) => {
commRemote = null;
// Process service logic errors.
console.error(
`disconnectServiceExtensionAbility failed, error.code: ${error.code}, error.message: ${error.message}`);
});
} catch (paramError) {
commRemote = null;
// Process input parameter errors.
console.error(`error.code: ${paramError.code}, error.message: ${paramError.message}`);
}
}
};
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册