From 02769b82a65577b2fba5d77893c87f63dd8f9855 Mon Sep 17 00:00:00 2001 From: Gloria Date: Wed, 24 May 2023 11:41:10 +0800 Subject: [PATCH] Update docs against 17004+17720+17877+17961 Signed-off-by: wusongqing --- .../application-context-stage.md | 16 +- ...is-app-ability-abilityLifecycleCallback.md | 2 - .../apis/js-apis-app-ability-appRecovery.md | 15 +- .../js-apis-app-ability-contextConstant.md | 9 +- .../js-apis-inner-ability-abilityResult.md | 12 +- .../js-apis-inner-ability-connectOptions.md | 12 +- ...apis-inner-ability-dataAbilityOperation.md | 6 + ...js-apis-inner-ability-dataAbilityResult.md | 10 +- ...pis-inner-ability-startAbilityParameter.md | 8 +- .../apis/js-apis-inner-ability-want.md | 11 +- .../apis/js-apis-inner-app-appVersionInfo.md | 6 + .../apis/js-apis-inner-app-context.md | 112 ++++---- .../apis/js-apis-inner-app-processInfo.md | 6 + ...-inner-application-abilityDelegatorArgs.md | 8 +- ...s-inner-application-abilityStageContext.md | 6 + ...s-inner-application-abilityStageMonitor.md | 7 +- ...apis-inner-application-abilityStateData.md | 24 +- ...is-inner-application-applicationContext.md | 12 +- ...er-application-applicationStateObserver.md | 22 +- .../js-apis-inner-application-baseContext.md | 6 + .../apis/js-apis-inner-application-context.md | 6 +- ...js-apis-inner-application-errorObserver.md | 6 +- .../js-apis-inner-application-eventHub.md | 6 + ...apis-inner-application-extensionContext.md | 6 + ...-inner-application-formExtensionContext.md | 2 +- .../js-apis-inner-application-missionInfo.md | 4 + ...-apis-inner-application-missionListener.md | 16 +- .../js-apis-inner-application-processData.md | 18 +- ...is-inner-application-processRunningInfo.md | 6 + ...ner-application-serviceExtensionContext.md | 211 +++++++++++++++ ...apis-inner-application-uiAbilityContext.md | 242 +++++++++++++++++- .../js-apis-inner-wantAgent-triggerInfo.md | 10 + .../js-apis-inner-wantAgent-wantAgentInfo.md | 10 + 33 files changed, 737 insertions(+), 116 deletions(-) diff --git a/en/application-dev/application-models/application-context-stage.md b/en/application-dev/application-models/application-context-stage.md index cc19530d99..3fc6df944c 100644 --- a/en/application-dev/application-models/application-context-stage.md +++ b/en/application-dev/application-models/application-context-stage.md @@ -3,7 +3,7 @@ ## Overview -[Context](../reference/apis/js-apis-inner-application-context.md) is the context of an object in an application. It provides basic information about the application, for example, **resourceManager**, **applicationInfo**, **dir** (application development path), and **area** (encrypted area). It also provides basic methods such as **createBundleContext()** and **getApplicationContext()**. The UIAbility component and ExtensionAbility derived class components have their own **Context** classes, for example, the base class **Context**, **ApplicationContext**, **AbilityStageContext**, **UIAbilityContext**, **ExtensionContext**, and **ServiceExtensionContext**. +[Context](../reference/apis/js-apis-inner-application-context.md) is the context of an object in an application. It provides basic information about the application, for example, **resourceManager**, **applicationInfo**, **dir** (application development path), and **area** (encryption level). It also provides basic methods such as **createBundleContext()** and **getApplicationContext()**. The UIAbility component and ExtensionAbility derived class components have their own **Context** classes, for example, the base class **Context**, **ApplicationContext**, **AbilityStageContext**, **UIAbilityContext**, **ExtensionContext**, and **ServiceExtensionContext**. - The figure below illustrates the inheritance relationship of contexts. @@ -71,7 +71,7 @@ This topic describes how to use the context in the following scenarios: - [Obtaining the Application Development Path](#obtaining-the-application-development-path) -- [Obtaining and Modifying Encryption Areas](#obtaining-and-modifying-encryption-areas) +- [Obtaining and Modifying Encryption Levels](#obtaining-and-modifying-encryption-levels) - [Creating Context of Another Application or Module](#creating-context-of-another-application-or-module) - [Subscribing to UIAbility Lifecycle Changes in a Process](#subscribing-to-uiability-lifecycle-changes-in-a-process) @@ -144,19 +144,19 @@ export default class EntryAbility extends UIAbility { > > The sample code obtains the sandbox path of the application development path. The absolute path can be obtained by running the **find / -name ** command in the hdc shell after file creation or modification. -### Obtaining and Modifying Encryption Areas +### Obtaining and Modifying Encryption Levels -Encrypting application files enhances data security by preventing files from unauthorized access. Different application files require different levels of protection. For private files, such as alarms and wallpapers, the application must place them in the device-level encryption area (EL1) to ensure that they can be accessed before the user enters the password. For sensitive files, such as personal privacy data, the application must place them in the user-level encryption area (EL2). +Encrypting application files enhances data security by preventing files from unauthorized access. Different application files require different levels of protection. For private files, such as alarms and wallpapers, the application must place them in a directory with the device-level encryption (EL1) to ensure that they can be accessed before the user enters the password. For sensitive files, such as personal privacy data, the application must place them in a directory with the user-level encryption (EL2). -In practice, you need to select a proper encrypted area based on scenario-specific requirements to protect application data security. The proper use of EL1 and the EL2 can efficiently improve the security. +In practice, you need to select a proper encryption level based on scenario-specific requirements to protect application data security. The proper use of EL1 and the EL2 can efficiently improve the security. > **NOTE** > -> - AreaMode.EL1: device-level encryption area, which is accessible after the device is powered on. +> - AreaMode.EL1: device-level encryption. Directories with this encryption level are accessible after the device is powered on. > -> - AreaMode.EL2: user-level encryption area, which is accessible only after the device is powered on and the password is entered (for the first time). +> - AreaMode.EL2: user-level encryption. Directories with this encryption level are accessible only after the device is powered on and the password is entered (for the first time). -You can obtain and set the encryption area by reading and writing the [area attribute in Context](../reference/apis/js-apis-inner-application-context.md). +You can obtain and set the encryption level by reading and writing the [area attribute in Context](../reference/apis/js-apis-inner-application-context.md). ```ts import UIAbility from '@ohos.app.ability.UIAbility'; diff --git a/en/application-dev/reference/apis/js-apis-app-ability-abilityLifecycleCallback.md b/en/application-dev/reference/apis/js-apis-app-ability-abilityLifecycleCallback.md index 28c0772d7d..d82597dc64 100644 --- a/en/application-dev/reference/apis/js-apis-app-ability-abilityLifecycleCallback.md +++ b/en/application-dev/reference/apis/js-apis-app-ability-abilityLifecycleCallback.md @@ -7,14 +7,12 @@ The **AbilityLifecycleCallback** module defines the callbacks to receive lifecyc > The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The APIs of this module can be used only in the stage model. - ## Modules to Import ```ts import AbilityLifecycleCallback from '@ohos.app.ability.AbilityLifecycleCallback'; ``` - ## AbilityLifecycleCallback.onAbilityCreate onAbilityCreate(ability: UIAbility): void; diff --git a/en/application-dev/reference/apis/js-apis-app-ability-appRecovery.md b/en/application-dev/reference/apis/js-apis-app-ability-appRecovery.md index d86ca90a45..ebe37268a6 100644 --- a/en/application-dev/reference/apis/js-apis-app-ability-appRecovery.md +++ b/en/application-dev/reference/apis/js-apis-app-ability-appRecovery.md @@ -11,7 +11,6 @@ The **appRecovery** module provides APIs for recovering faulty applications. import appRecovery from '@ohos.app.ability.appRecovery'; ``` - ## appRecovery.RestartFlag Enumerates the application restart flags. This enum is used as an input parameter of [enableAppRecovery](#apprecoveryenableapprecovery). @@ -174,9 +173,17 @@ Saves the ability state, which will be used for recovery. This API can be used t ```ts import appRecovery from '@ohos.app.ability.appRecovery'; -onBackground() { - hilog.info(0x0000, '[demo]', '%{public}s', 'EntryAbility onBackground'); - appRecovery.saveAppState(this.context) +let observer = { + onUnhandledException(errorMsg) { + console.log('onUnhandledException, errorMsg: ', errorMsg); + appRecovery.saveAppState(this.context); + } +}; + +try { + errorManager.on('error', observer); +} catch (paramError) { + console.error('error: ${paramError.code}, ${paramError.message}'); } ``` diff --git a/en/application-dev/reference/apis/js-apis-app-ability-contextConstant.md b/en/application-dev/reference/apis/js-apis-app-ability-contextConstant.md index 0c39c8fa01..080128ea94 100644 --- a/en/application-dev/reference/apis/js-apis-app-ability-contextConstant.md +++ b/en/application-dev/reference/apis/js-apis-app-ability-contextConstant.md @@ -1,10 +1,11 @@ # @ohos.app.ability.contextConstant (ContextConstant) -The **ContextConstant** module defines context-related enums. Currently, it defines only the enum of data encryption levels. +The **ContextConstant** module defines context-related enums. Currently, it defines only the enum of encryption levels. > **NOTE** -> +> > The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> > The APIs of this module can be used only in the stage model. ## Modules to Import @@ -21,5 +22,5 @@ You can obtain the value of this constant by calling the **ContextConstant.AreaM | Name| Value| Description| | -------- | -------- | -------- | -| EL1 | 0 | Device-level encryption area, which is accessible after the device is powered on.| -| EL2 | 1 | User-level encryption area, which is accessible only after the device is powered on and the password is entered (for the first time).| +| EL1 | 0 | Device-level encryption. Directories with this encryption level are accessible after the device is powered on.| +| EL2 | 1 | User-level encryption. Directories with this encryption level are accessible only after the device is powered on and the password is entered (for the first time).| diff --git a/en/application-dev/reference/apis/js-apis-inner-ability-abilityResult.md b/en/application-dev/reference/apis/js-apis-inner-ability-abilityResult.md index 13573de144..6723f4116a 100644 --- a/en/application-dev/reference/apis/js-apis-inner-ability-abilityResult.md +++ b/en/application-dev/reference/apis/js-apis-inner-ability-abilityResult.md @@ -1,14 +1,20 @@ # AbilityResult -The **AbilityResult** module defines the result code and data returned when an ability is terminated after being started. You can use [startAbilityForResult](js-apis-ability-featureAbility.md#featureabilitystartabilityforresult7) to obtain the **AbilityResult** object returned after the started ability is terminated. The startedability returns the **AbilityResult** object by calling [terminateSelfWithResult](js-apis-ability-featureAbility.md#featureabilityterminateselfwithresult7). +The **AbilityResult** module defines the result code and data returned when an ability is terminated after being started. You can use [startAbilityForResult](js-apis-ability-featureAbility.md#featureabilitystartabilityforresult7) to obtain the **AbilityResult** object returned after the started ability is terminated. The started ability returns the **AbilityResult** object by calling [terminateSelfWithResult](js-apis-ability-featureAbility.md#featureabilityterminateselfwithresult7). > **NOTE** > > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. +## Modules to Import + +```ts +import ability from '@ohos.ability.ability'; +``` + **System capability**: SystemCapability.Ability.AbilityBase | Name | Readable | Writable | Type | Mandatory| Description | | ----------- | -------- |-------- | -------------------- | ---- | ------------------------------------------------------------ | -| resultCode | Yes | Yes | number | Yes | Result code returned after the started ability is terminated. | -| want | Yes | Yes | [Want](./js-apis-app-ability-want.md) | No | Data returned after the started ability is terminated. | +| resultCode | Yes | Yes | number | Yes | Result code returned after the started ability is terminated. | +| want | Yes | Yes | [Want](./js-apis-app-ability-want.md) | No | Data returned after the started ability is terminated.| diff --git a/en/application-dev/reference/apis/js-apis-inner-ability-connectOptions.md b/en/application-dev/reference/apis/js-apis-inner-ability-connectOptions.md index d311a6c175..edfc9b732c 100644 --- a/en/application-dev/reference/apis/js-apis-inner-ability-connectOptions.md +++ b/en/application-dev/reference/apis/js-apis-inner-ability-connectOptions.md @@ -2,6 +2,16 @@ **ConnectOptions** can be used as an input parameter to receive status changes during the connection to a background service. For example, it is used as an input parameter of [connectServiceExtensionAbility](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextconnectserviceextensionability) to connect to a ServiceExtensionAbility. +> **NOTE** +> +> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. + +## Modules to Import + +```ts +import common from '@ohos.app.ability.common'; +``` + **System capability**: SystemCapability.Ability.AbilityRuntime.Core | Name | Type | Mandatory | Description | @@ -18,7 +28,7 @@ abilityName: 'MyAbility' }; - let connectOptions = { + let connectOptions: common.ConnectOptions = { onConnect(elementName, remote) { console.log('onConnect elementName: ${elementName}'); }, diff --git a/en/application-dev/reference/apis/js-apis-inner-ability-dataAbilityOperation.md b/en/application-dev/reference/apis/js-apis-inner-ability-dataAbilityOperation.md index 48be29362c..1037dfe2d6 100644 --- a/en/application-dev/reference/apis/js-apis-inner-ability-dataAbilityOperation.md +++ b/en/application-dev/reference/apis/js-apis-inner-ability-dataAbilityOperation.md @@ -7,6 +7,12 @@ The **DataAbilityOperation** module defines the operation on DataAbilities. It c > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The APIs of this module can be used only in the FA model. +## Modules to Import + +```ts +import ability from '@ohos.ability.ability'; +``` + **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel | Name | Template | Mandatory| Description | diff --git a/en/application-dev/reference/apis/js-apis-inner-ability-dataAbilityResult.md b/en/application-dev/reference/apis/js-apis-inner-ability-dataAbilityResult.md index 6dffdaefc0..2a3cb7f384 100644 --- a/en/application-dev/reference/apis/js-apis-inner-ability-dataAbilityResult.md +++ b/en/application-dev/reference/apis/js-apis-inner-ability-dataAbilityResult.md @@ -7,6 +7,12 @@ The **DataAbilityResult** module defines the operation result on DataAbilities. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The APIs of this module can be used only in the FA model. +## Modules to Import + +```ts +import ability from '@ohos.ability.ability'; +``` + **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel | Name | Type | Mandatory | Description | @@ -22,7 +28,7 @@ import featureAbility from '@ohos.ability.featureAbility'; // Perform database operations in batches. function executeBatchOperation() { let dataAbilityUri = ('dataability:///com.example.myapplication.TestDataAbility'); - let DAHelper; + let DAHelper: ability.DataAbilityHelper; try { DAHelper = featureAbility.acquireDataAbilityHelper(dataAbilityUri); if (DAHelper === null) { @@ -61,7 +67,7 @@ function executeBatchOperation() { try { DAHelper.executeBatch(dataAbilityUri, operations).then((data) => { for (let i = 0; i < data.length; i++) { - let dataAbilityResult = data[i]; + let dataAbilityResult: ability.DataAbilityResult = data[i]; console.log('dataAbilityResult.uri: ${dataAbilityResult.uri}'); console.log('dataAbilityResult.count: ${dataAbilityResult.count}'); } diff --git a/en/application-dev/reference/apis/js-apis-inner-ability-startAbilityParameter.md b/en/application-dev/reference/apis/js-apis-inner-ability-startAbilityParameter.md index 80fcf902d8..44903a992f 100644 --- a/en/application-dev/reference/apis/js-apis-inner-ability-startAbilityParameter.md +++ b/en/application-dev/reference/apis/js-apis-inner-ability-startAbilityParameter.md @@ -7,6 +7,12 @@ The **StartAbilityParameter** module defines the parameters for starting an abil > The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The APIs of this module can be used only in the FA model. +## Modules to Import + +```ts +import ability from '@ohos.ability.ability'; +``` + **System capability**: SystemCapability.Ability.AbilityRuntime.FAModel | Name | Type | Mandatory | Description | @@ -30,7 +36,7 @@ let abilityStartSetting ={ [featureAbility.AbilityStartSetting.DISPLAY_ID_KEY] : 1, }; -let startAbilityParameter = { +let startAbilityParameter: ability.StartAbilityParameter = { want : Want, abilityStartSetting : abilityStartSetting }; diff --git a/en/application-dev/reference/apis/js-apis-inner-ability-want.md b/en/application-dev/reference/apis/js-apis-inner-ability-want.md index 0eebe1059e..f8823b905f 100644 --- a/en/application-dev/reference/apis/js-apis-inner-ability-want.md +++ b/en/application-dev/reference/apis/js-apis-inner-ability-want.md @@ -6,6 +6,12 @@ Want is a carrier for information transfer between objects (application componen > > The APIs of this module are supported since API version 6 and deprecated since API version 9. You are advised to use [@ohos.app.ability.Want](js-apis-app-ability-want.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version. +## Modules to Import + +```ts +import Want from '@ohos.app.ability.Want'; +``` + **System capability**: SystemCapability.Ability.AbilityBase | Name | Type | Mandatory| Description | @@ -17,7 +23,7 @@ Want is a carrier for information transfer between objects (application componen | type | string | No | MIME type, that is, the type of the file to open, for example, **'text/xml'** and **'image/*'**. For details about the MIME type definition, see https://www.iana.org/assignments/media-types/media-types.xhtml?utm_source=ld246.com. | | flags | number | No | How the **Want** object will be handled. By default, numbers are passed in. For details, see [flags](js-apis-ability-wantConstant.md#wantconstantflags).| | action | string | No | Action to take, such as viewing and sharing application details. In implicit Want, you can define this field and use it together with **uri** or **parameters** to specify the operation to be performed on the data. For details, see [action](js-apis-ability-wantConstant.md#wantconstantaction). For details about the definition and matching rules of implicit Want, see [Matching Rules of Explicit Want and Implicit Want](../../application-models/explicit-implicit-want-mappings.md). | -| parameters | {[key: string]: Object} | No | Want parameters in the form of custom key-value (KV) pairs. By default, the following keys are carried:
- **ohos.aafwk.callerPid**: PID of the caller.
- **ohos.aafwk.param.callerToken**: token of the caller.
**ohos.aafwk.param.callerUid**: UID in [bundleInfo](js-apis-bundle-BundleInfo.md#bundleinfo), that is, the application UID in the bundle information.
- **component.startup.newRules**: whether to enable the new control rule.
- **moduleName**: module name of the caller. No matter what this field is set to, the correct module name will be sent to the peer.
- **ohos.dlp.params.sandbox**: available only for DLP files. | +| parameters | {[key: string]: Object} | No | Want parameters in the form of custom key-value (KV) pairs. By default, the following keys are carried:
- **ohos.aafwk.callerPid**: PID of the caller.
- **ohos.aafwk.param.callerToken**: token of the caller.
- **ohos.aafwk.param.callerUid**: UID in [bundleInfo](js-apis-bundle-BundleInfo.md#bundleinfo), that is, the application UID in the bundle information.
- **component.startup.newRules**: whether to enable the new control rule.
- **moduleName**: module name of the caller. No matter what this field is set to, the correct module name will be sent to the peer.
- **ohos.dlp.params.sandbox**: available only for DLP files. | | entities | Array\ | No | Additional category information (such as browser and video player) of the target ability. It is a supplement to **action** in implicit Want and is used to filter ability types. For details, see [entity](js-apis-app-ability-wantConstant.md#wantconstantentity). | | moduleName9+ | string | No | Module to which the ability belongs.| @@ -68,5 +74,4 @@ Want is a carrier for information transfer between objects (application componen - For more details and examples, see [Want](../../application-models/want-overview.md). - - + diff --git a/en/application-dev/reference/apis/js-apis-inner-app-appVersionInfo.md b/en/application-dev/reference/apis/js-apis-inner-app-appVersionInfo.md index 39c846bb6e..f5da165225 100644 --- a/en/application-dev/reference/apis/js-apis-inner-app-appVersionInfo.md +++ b/en/application-dev/reference/apis/js-apis-inner-app-appVersionInfo.md @@ -6,6 +6,12 @@ The **AppVersionInfo** module defines the application version information. You c > > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. +## Modules to Import + +```ts +import featureAbility from '@ohos.ability.featureAbility'; +``` + **System capability**: SystemCapability.Ability.AbilityRuntime.Core | Name | Type | Readable| Writable| Description | diff --git a/en/application-dev/reference/apis/js-apis-inner-app-context.md b/en/application-dev/reference/apis/js-apis-inner-app-context.md index 79fcf1af73..fede557dd4 100644 --- a/en/application-dev/reference/apis/js-apis-inner-app-context.md +++ b/en/application-dev/reference/apis/js-apis-inner-app-context.md @@ -8,13 +8,19 @@ The **Context** module provides context for abilities or applications. It allows > > The APIs of this module can be used only in the FA model. +## Modules to Import + +```ts +import featureAbility from '@ohos.ability.featureAbility'; +``` + ## Usage The **Context** object is created in a **featureAbility** and returned through its [getContext](js-apis-ability-featureAbility.md#featureabilitygetcontext) API. Therefore, you must import the **@ohos.ability.featureAbility** package before using the **Context** module. An example is as follows: ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getOrCreateLocalDir().then((data) => { console.info('getOrCreateLocalDir data: ${JSON.stringify(data)}'); }); @@ -40,7 +46,7 @@ If this API is called for the first time, a root directory will be created. ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getOrCreateLocalDir((error, data)=>{ if (error && error.code !== 0) { console.error('getOrCreateLocalDir fail, error: ${JSON.stringify(error)}'); @@ -72,7 +78,7 @@ If this API is called for the first time, a root directory will be created. ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getOrCreateLocalDir().then((data) => { console.info('getOrCreateLocalDir data: ${JSON.stringify(data)}'); }); @@ -99,7 +105,7 @@ Verifies whether a specific PID and UID have the given permission. This API uses ```ts import featureAbility from '@ohos.ability.featureAbility'; import bundle from '@ohos.bundle.bundleManager'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); bundle.getBundleInfo('com.context.test', 1, (err, datainfo) =>{ context.verifyPermission('com.example.permission', {uid:datainfo.appInfo.uid}, (error, data) =>{ if (error && error.code !== 0) { @@ -133,7 +139,7 @@ Verifies whether the current PID and UID have the given permission. This API use ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.verifyPermission('com.example.permission', (error, data) =>{ if (error && error.code !== 0) { console.error('verifyPermission fail, error: ${JSON.stringify(error)}'); @@ -168,7 +174,7 @@ Verifies whether a specific PID and UID have the given permission. This API uses ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); let Permission = {pid:1}; context.verifyPermission('com.context.permission',Permission).then((data) => { console.info('verifyPermission data: ${JSON.stringify(data)}'); @@ -197,7 +203,7 @@ Requests certain permissions from the system. This API uses an asynchronous call ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.requestPermissionsFromUser( ['com.example.permission1', 'com.example.permission2', @@ -241,7 +247,7 @@ Requests certain permissions from the system. This API uses a promise to return ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.requestPermissionsFromUser( ['com.example.permission1', 'com.example.permission2', @@ -274,7 +280,7 @@ Obtains information about the current application. This API uses an asynchronous ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getApplicationInfo((error, data) => { if (error && error.code !== 0) { console.error('getApplicationInfo fail, error: ${JSON.stringify(error)}'); @@ -304,7 +310,7 @@ Obtains information about the current application. This API uses a promise to re ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getApplicationInfo().then((data) => { console.info('getApplicationInfo data: ${JSON.stringify(data)}'); }); @@ -330,7 +336,7 @@ Obtains the bundle name of this ability. This API uses an asynchronous callback ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getBundleName((error, data) => { if (error && error.code !== 0) { console.error('getBundleName fail, error: ${JSON.stringify(error)}'); @@ -360,7 +366,7 @@ Obtains the bundle name of this ability. This API uses a promise to return the r ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getBundleName().then((data) => { console.info('getBundleName data: ${JSON.stringify(data)}'); }); @@ -384,7 +390,7 @@ Obtains the display orientation of this ability. This API uses an asynchronous c ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getDisplayOrientation((error, data) => { if (error && error.code !== 0) { console.error('getDisplayOrientation fail, error: ${JSON.stringify(error)}'); @@ -412,7 +418,7 @@ Obtains the display orientation of this ability. This API uses a promise to retu ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getDisplayOrientation().then((data) => { console.info('getDisplayOrientation data: ${JSON.stringify(data)}'); }); @@ -436,7 +442,7 @@ Obtains the external cache directory of the application. This API uses an asynch ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getExternalCacheDir((error, data) => { if (error && error.code !== 0) { console.error('getExternalCacheDir fail, error: ${JSON.stringify(error)}'); @@ -464,7 +470,7 @@ Obtains the external cache directory of the application. This API uses a promise ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getExternalCacheDir().then((data) => { console.info('getExternalCacheDir data: ${JSON.stringify(data)}'); }); @@ -490,7 +496,7 @@ Sets the display orientation for this ability. This API uses an asynchronous cal ```ts import featureAbility from '@ohos.ability.featureAbility'; import bundle from '@ohos.bundle'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); let orientation = bundle.DisplayOrientation.UNSPECIFIED; context.setDisplayOrientation(orientation, (error) => { console.error('setDisplayOrientation fail, error: ${JSON.stringify(error)}'); @@ -517,18 +523,19 @@ Sets the display orientation for this ability. This API uses a promise to return ```ts import featureAbility from '@ohos.ability.featureAbility'; import bundle from '@ohos.bundle'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); let orientation = bundle.DisplayOrientation.UNSPECIFIED; context.setDisplayOrientation(orientation).then((data) => { console.info('setDisplayOrientation data: ${JSON.stringify(data)}'); }); ``` -## Context.setShowOnLockScreen7+ +## Context.setShowOnLockScreen(deprecated) setShowOnLockScreen(show: boolean, callback: AsyncCallback\): void Sets whether to show this feature at the top of the lock screen so that the feature remains activated. This API uses an asynchronous callback to return the result. +> This API is deprecated since API version 9. You are advised to use [window.setShowOnLockScreen](js-apis-window.md#setShowOnLockScreen9). **System capability**: SystemCapability.Ability.AbilityRuntime.Core @@ -543,18 +550,19 @@ Sets whether to show this feature at the top of the lock screen so that the feat ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); let show = true; context.setShowOnLockScreen(show, (error) => { console.error('setShowOnLockScreen fail, error: ${JSON.stringify(error)}'); }); ``` -## Context.setShowOnLockScreen7+ +## Context.setShowOnLockScreen(deprecated) setShowOnLockScreen(show: boolean): Promise\; Sets whether to show this feature at the top of the lock screen so that the feature remains activated. This API uses a promise to return the result. +> This API is deprecated since API version 9. You are advised to use [window.setShowOnLockScreen](js-apis-window.md#setShowOnLockScreen9). **System capability**: SystemCapability.Ability.AbilityRuntime.Core @@ -574,7 +582,7 @@ Sets whether to show this feature at the top of the lock screen so that the feat ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); let show = true; context.setShowOnLockScreen(show).then((data) => { console.info('setShowOnLockScreen data: ${JSON.stringify(data)}'); @@ -600,7 +608,7 @@ Sets whether to wake up the screen when this feature is restored. This API uses ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); let wakeUp = true; context.setWakeUpScreen(wakeUp, (error) => { console.error('setWakeUpScreen fail, error: ${JSON.stringify(error)}'); @@ -609,7 +617,7 @@ context.setWakeUpScreen(wakeUp, (error) => { ## Context.setWakeUpScreen7+ -setWakeUpScreen(wakeUp: boolean): Promise\; +setWakeUpScreen(wakeUp: boolean): Promise\; Sets whether to wake up the screen when this feature is restored. This API uses a promise to return the result. @@ -631,7 +639,7 @@ Sets whether to wake up the screen when this feature is restored. This API uses ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); let wakeUp = true; context.setWakeUpScreen(wakeUp).then((data) => { console.info('setWakeUpScreen data: ${JSON.stringify(data)}'); @@ -659,7 +667,7 @@ Obtains information about the current process, including the PID and process nam ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getProcessInfo((error, data) => { if (error && error.code !== 0) { console.error('getProcessInfo fail, error: ${JSON.stringify(error)}'); @@ -689,7 +697,7 @@ Obtains information about the current process, including the PID and process nam ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getProcessInfo().then((data) => { console.info('getProcessInfo data: ${JSON.stringify(data)}'); }); @@ -717,7 +725,7 @@ This API is available only to Page abilities. ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getElementName((error, data) => { if (error && error.code !== 0) { console.error('getElementName fail, error: ${JSON.stringify(error)}'); @@ -749,7 +757,7 @@ This API is available only to Page abilities. ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getElementName().then((data) => { console.info('getElementName data: ${JSON.stringify(data)}'); }); @@ -773,7 +781,7 @@ Obtains the name of the current process. This API uses an asynchronous callback ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getProcessName((error, data) => { if (error && error.code !== 0) { console.error('getProcessName fail, error: ${JSON.stringify(error)}'); @@ -803,7 +811,7 @@ Obtains the name of the current process. This API uses a promise to return the r ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getProcessName().then((data) => { console.info('getProcessName data: ${JSON.stringify(data)}'); }); @@ -829,7 +837,7 @@ Obtains the bundle name of the caller ability. This API uses an asynchronous cal ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getCallingBundle((error, data) => { if (error && error.code !== 0) { console.error('getCallingBundle fail, error: ${JSON.stringify(error)}'); @@ -859,7 +867,7 @@ Obtains the bundle name of the caller ability. This API uses a promise to return ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getCallingBundle().then((data) => { console.info('getCallingBundle data: ${JSON.stringify(data)}'); }); @@ -883,7 +891,7 @@ Obtains the cache directory of the application in the internal storage. This API ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getCacheDir((error, data) => { if (error && error.code !== 0) { console.error('getCacheDir fail, error: ${JSON.stringify(error)}'); @@ -911,7 +919,7 @@ Obtains the cache directory of the application in the internal storage. This API ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getCacheDir().then((data) => { console.info('getCacheDir data: ${JSON.stringify(data)}'); }); @@ -935,7 +943,7 @@ Obtains the file directory of the application in the internal storage. This API ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getFilesDir((error, data) => { if (error && error.code !== 0) { console.error('getFilesDir fail, error: ${JSON.stringify(error)}'); @@ -963,7 +971,7 @@ Obtains the file directory of the application in the internal storage. This API ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getFilesDir().then((data) => { console.info('getFilesDir data: ${JSON.stringify(data)}'); }); @@ -989,7 +997,7 @@ If the distributed file path does not exist, the system will create one and retu ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getOrCreateDistributedDir((error, data) => { if (error && error.code !== 0) { console.error('getOrCreateDistributedDir fail, error: ${JSON.stringify(error)}'); @@ -1019,7 +1027,7 @@ If the distributed file path does not exist, the system will create one and retu ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getOrCreateDistributedDir().then((data) => { console.info('getOrCreateDistributedDir data: ${JSON.stringify(data)}'); }); @@ -1043,7 +1051,7 @@ Obtains the application type. This API uses an asynchronous callback to return t ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getAppType((error, data) => { if (error && error.code !== 0) { console.error('getAppType fail, error: ${JSON.stringify(error)}'); @@ -1071,7 +1079,7 @@ Obtains the application type. This API uses a promise to return the result. ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getAppType().then((data) => { console.info('getAppType data: ${JSON.stringify(data)}'); }); @@ -1095,7 +1103,7 @@ Obtains the **ModuleInfo** object of the application. This API uses an asynchron ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getHapModuleInfo((error, data) => { if (error && error.code !== 0) { console.error('getHapModuleInfo fail, error: ${JSON.stringify(error)}'); @@ -1123,7 +1131,7 @@ Obtains the **ModuleInfo** object of the application. This API uses a promise to ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getHapModuleInfo().then((data) => { console.info('getHapModuleInfo data: ${JSON.stringify(data)}'); }); @@ -1147,7 +1155,7 @@ Obtains the version information of the application. This API uses an asynchronou ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getAppVersionInfo((error, data) => { if (error && error.code !== 0) { console.error('getAppVersionInfo fail, error: ${JSON.stringify(error)}'); @@ -1175,7 +1183,7 @@ Obtains the version information of the application. This API uses a promise to r ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getAppVersionInfo().then((data) => { console.info('getAppVersionInfo data: ${JSON.stringify(data)}'); }); @@ -1199,7 +1207,7 @@ Obtains information about this ability. This API uses an asynchronous callback t ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getAbilityInfo((error, data) => { if (error && error.code !== 0) { console.error('getAbilityInfo fail, error: ${JSON.stringify(error)}'); @@ -1227,7 +1235,7 @@ Obtains information about this ability. This API uses a promise to return the re ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.getAbilityInfo().then((data) => { console.info('getAbilityInfo data: ${JSON.stringify(data)}'); }); @@ -1251,7 +1259,7 @@ Obtains the context of the application. ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext().getApplicationContext(); +let context: featureAbility.Context = featureAbility.getContext().getApplicationContext(); ``` ## Context.isUpdatingConfigurations7+ @@ -1272,7 +1280,7 @@ Checks whether the configuration of this ability is being updated. This API uses ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.isUpdatingConfigurations((error, data) => { if (error && error.code !== 0) { console.error('isUpdatingConfigurations fail, error: ${JSON.stringify(error)}'); @@ -1300,7 +1308,7 @@ Checks whether the configuration of this ability is being updated. This API uses ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.isUpdatingConfigurations().then((data) => { console.info('isUpdatingConfigurations data: ${JSON.stringify(data)}'); }); @@ -1324,7 +1332,7 @@ Notifies the system of the time required to draw this page function. This API us ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.printDrawnCompleted((err) => { console.error('printDrawnCompleted err: ${JSON.stringify(err)}'); }); @@ -1348,7 +1356,7 @@ Notifies the system of the time required to draw this page function. This API us ```ts import featureAbility from '@ohos.ability.featureAbility'; -let context = featureAbility.getContext(); +let context: featureAbility.Context = featureAbility.getContext(); context.printDrawnCompleted().then((data) => { console.info('printDrawnCompleted data: ${JSON.stringify(data)}'); }); diff --git a/en/application-dev/reference/apis/js-apis-inner-app-processInfo.md b/en/application-dev/reference/apis/js-apis-inner-app-processInfo.md index 886cc755ef..6bc1f2037c 100644 --- a/en/application-dev/reference/apis/js-apis-inner-app-processInfo.md +++ b/en/application-dev/reference/apis/js-apis-inner-app-processInfo.md @@ -6,6 +6,12 @@ The **ProcessInfo** module defines process information. You can use [getProcessI > > The initial APIs of this module are supported since API version 7. The APIs of this module can be used only in the FA model. Newly added APIs will be marked with a superscript to indicate their earliest API version. +## Modules to Import + +```ts +import featureAbility from '@ohos.ability.featureAbility'; +``` + **System capability**: SystemCapability.Ability.AbilityRuntime.Core | Name| Type| Readable| Writable| Description| diff --git a/en/application-dev/reference/apis/js-apis-inner-application-abilityDelegatorArgs.md b/en/application-dev/reference/apis/js-apis-inner-application-abilityDelegatorArgs.md index b6c5bc7be8..ef67bdbbda 100644 --- a/en/application-dev/reference/apis/js-apis-inner-application-abilityDelegatorArgs.md +++ b/en/application-dev/reference/apis/js-apis-inner-application-abilityDelegatorArgs.md @@ -6,6 +6,12 @@ The **AbilityDelegatorArgs** module provides APIs to obtain an **AbilityDelegato > > 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 +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +``` + ## Usage An **AbilityDelegatorArgs** object is obtained by calling [getArguments](js-apis-app-ability-abilityDelegatorRegistry.md#abilitydelegatorregistrygetarguments) in **AbilityDelegatorRegistry**. @@ -28,5 +34,5 @@ Describes the ability delegator arguments. ```ts import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; -let args = AbilityDelegatorRegistry.getArguments(); +let args: AbilityDelegatorRegistry.AbilityDelegatorArgs = AbilityDelegatorRegistry.getArguments(); ``` diff --git a/en/application-dev/reference/apis/js-apis-inner-application-abilityStageContext.md b/en/application-dev/reference/apis/js-apis-inner-application-abilityStageContext.md index 4d537d5077..bb9604b2a9 100644 --- a/en/application-dev/reference/apis/js-apis-inner-application-abilityStageContext.md +++ b/en/application-dev/reference/apis/js-apis-inner-application-abilityStageContext.md @@ -9,6 +9,12 @@ This module provides APIs for accessing a specific ability stage. You can use th > The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The APIs of this module can be used only in the stage model. +## Modules to Import + +```ts +import common from '@ohos.app.ability.common'; +``` + ## Usage The ability stage context is obtained through an **AbilityStage** instance. diff --git a/en/application-dev/reference/apis/js-apis-inner-application-abilityStageMonitor.md b/en/application-dev/reference/apis/js-apis-inner-application-abilityStageMonitor.md index c462bb3e3e..8e55c316de 100644 --- a/en/application-dev/reference/apis/js-apis-inner-application-abilityStageMonitor.md +++ b/en/application-dev/reference/apis/js-apis-inner-application-abilityStageMonitor.md @@ -2,13 +2,16 @@ The **AbilityStageMonitor** module provides conditions for matching **AbilityStage** instances. The most recently matched **AbilityStage** instance is saved in an **AbilityStageMonitor** instance. +> **NOTE** +> +> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. **System capability**: SystemCapability.Ability.AbilityRuntime.Core | Name | Type | Readable| Writable| Description | | ------------------------------------------------------------ | -------- | ---- | ---- | ------------------------------------------------------------ | -| moduleName9+ | string | Yes | Yes | Module name of the **AbilityStage** instance.| -| srcEntrance9+ | string | Yes | Yes | Source path of the **AbilityStage** instance.| +| moduleName | string | Yes | Yes | Module name of the **AbilityStage** instance.| +| srcEntrance | string | Yes | Yes | Source path of the **AbilityStage** instance.| **Example** ```ts diff --git a/en/application-dev/reference/apis/js-apis-inner-application-abilityStateData.md b/en/application-dev/reference/apis/js-apis-inner-application-abilityStateData.md index eb539bd981..89737dea19 100644 --- a/en/application-dev/reference/apis/js-apis-inner-application-abilityStateData.md +++ b/en/application-dev/reference/apis/js-apis-inner-application-abilityStateData.md @@ -2,17 +2,27 @@ The **AbilityStateData** module defines the ability state information, which can be obtained through the **onAbilityStateChanged** lifecycle callback of [ApplicationStateObserver](js-apis-inner-application-applicationStateObserver.md). The callback can be invoked after a lifecycle change listener is registered through [registerApplicationStateObserver](js-apis-application-appManager.md#appmanagerregisterapplicationstateobserver8). +> **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 +import appManager from '@ohos.application.appManager'; +``` + **System capability**: SystemCapability.Ability.AbilityRuntime.Core | Name | Type | Readable| Writable| Description | | ----------------------- | ---------| ---- | ---- | ------------------------- | -| pid8+ | number | Yes | No | Process ID. | -| bundleName8+ | string | Yes | No | Bundle name. | -| abilityName8+ | string | Yes | No | Ability name. | -| uid8+ | number | Yes | No | User ID. | -| state8+ | number | Yes | No | [Ability state](#ability-states). | +| pid | number | Yes | No | Process ID. | +| bundleName | string | Yes | No | Bundle name. | +| abilityName | string | Yes | No | Ability name. | +| uid | number | Yes | No | User ID. | +| state | number | Yes | No | [Ability state](#ability-states). | | moduleName9+ | string | Yes | No | Name of the HAP file to which the ability belongs. | -| abilityType8+ | number | Yes | No | [Ability type](#ability-types), which can be **page** or **service**.| +| abilityType | number | Yes | No | [Ability type](#ability-types), which can be **page** or **service**.| #### Ability States @@ -29,7 +39,7 @@ The **AbilityStateData** module defines the ability state information, which can #### Ability Types -| Value | Status | Description | +| Value | State | Description | | ---- | ------- | --------------------- | | 0 | UNKNOWN | Unknown type. | | 1 | PAGE | Ability that has the UI. | diff --git a/en/application-dev/reference/apis/js-apis-inner-application-applicationContext.md b/en/application-dev/reference/apis/js-apis-inner-application-applicationContext.md index 10dd9ae028..919496b065 100644 --- a/en/application-dev/reference/apis/js-apis-inner-application-applicationContext.md +++ b/en/application-dev/reference/apis/js-apis-inner-application-applicationContext.md @@ -7,12 +7,18 @@ The **ApplicationContext** module provides application-level context. You can us > The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The APIs of this module can be used only in the stage model. +## Modules to Import + +```ts +import common from '@ohos.app.ability.common'; +``` + ## Usage Before calling any APIs in **ApplicationContext**, obtain an **ApplicationContext** instance through the **context** instance. ```ts -let applicationContext = this.context.getApplicationContext(); +let applicationContext: common.ApplicationContext = this.context.getApplicationContext(); ``` ## ApplicationContext.on(type: 'abilityLifecycle', callback: AbilityLifecycleCallback) @@ -303,7 +309,6 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error **Example** ```ts -let applicationContext = this.context.getApplicationContext(); applicationContext.getRunningProcessInformation().then((data) => { console.log('The process running information is: ${JSON.stringify(data)}'); }).catch((error) => { @@ -341,7 +346,6 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error **Example** ```ts -let applicationContext = this.context.getApplicationContext(); applicationContext.getRunningProcessInformation((err, data) => { if (err) { console.error('getRunningProcessInformation faile, err: ${JSON.stringify(err)}'); @@ -376,7 +380,6 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error **Example** ```ts -let applicationContext = this.context.getApplicationContext(); applicationContext.killAllProcesses(); ``` @@ -405,7 +408,6 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error **Example** ```ts -let applicationContext = this.context.getApplicationContext(); applicationContext.killAllProcesses(error => { if (error) { console.error('killAllProcesses fail, error: ${JSON.stringify(error)}'); diff --git a/en/application-dev/reference/apis/js-apis-inner-application-applicationStateObserver.md b/en/application-dev/reference/apis/js-apis-inner-application-applicationStateObserver.md index 336811e398..1e12c17c77 100644 --- a/en/application-dev/reference/apis/js-apis-inner-application-applicationStateObserver.md +++ b/en/application-dev/reference/apis/js-apis-inner-application-applicationStateObserver.md @@ -2,22 +2,30 @@ The **ApplicationStateObserver** module defines an observer to listen for application state changes. It can be used as an input parameter in [registerApplicationStateObserver](js-apis-application-appManager.md#appmanagerregisterapplicationstateobserver8) to listen for lifecycle changes of the current application. +> **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 +import appManager from '@ohos.app.ability.appManager'; +``` + **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API and cannot be called by third-party applications. | Name | | Type | Readable| Writable| Description | | ----------------------- | ---------| ---- | ---- | ------------------------- | ------------------------- | -| onForegroundApplicationChanged8+ | [AppStateData](js-apis-inner-application-appStateData.md) | AsyncCallback\ | Yes | No | Callback invoked when the foreground or background state of an application changes. | -| onAbilityStateChanged8+ | [AbilityStateData](js-apis-inner-application-abilityStateData.md) | AsyncCallback\ | Yes | No | Callback invoked when the ability state changes. | -| onProcessCreated8+ | [ProcessData](js-apis-inner-application-processData.md) | AsyncCallback\ | Yes | No | Callback invoked when a process is created. | -| onProcessDied8+ | [ProcessData](js-apis-inner-application-processData.md) | AsyncCallback\ | Yes | No | Callback invoked when a process is destroyed. | -| onProcessStateChanged8+ | [ProcessData](js-apis-inner-application-processData.md) | AsyncCallback\ | Yes | No | Callback invoked when the process state is changed. | +| onForegroundApplicationChanged | [AppStateData](js-apis-inner-application-appStateData.md) | AsyncCallback\ | Yes | No | Callback invoked when the foreground or background state of an application changes. | +| onAbilityStateChanged | [AbilityStateData](js-apis-inner-application-abilityStateData.md) | AsyncCallback\ | Yes | No | Callback invoked when the ability state changes. | +| onProcessCreated | [ProcessData](js-apis-inner-application-processData.md) | AsyncCallback\ | Yes | No | Callback invoked when a process is created. | +| onProcessDied | [ProcessData](js-apis-inner-application-processData.md) | AsyncCallback\ | Yes | No | Callback invoked when a process is destroyed. | +| onProcessStateChanged9+ | [ProcessData](js-apis-inner-application-processData.md) | AsyncCallback\ | Yes | No | Callback invoked when the process state is changed. | **Example** ```ts -import appManager from '@ohos.app.ability.appManager'; - let applicationStateObserver = { onForegroundApplicationChanged(appStateData) { console.log('onForegroundApplicationChanged appStateData: ${JSON.stringify(appStateData)}'); diff --git a/en/application-dev/reference/apis/js-apis-inner-application-baseContext.md b/en/application-dev/reference/apis/js-apis-inner-application-baseContext.md index f30e773306..707731bd3f 100644 --- a/en/application-dev/reference/apis/js-apis-inner-application-baseContext.md +++ b/en/application-dev/reference/apis/js-apis-inner-application-baseContext.md @@ -6,6 +6,12 @@ > > 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 +import common from '@ohos.app.ability.common'; +``` + **System capability**: SystemCapability.Ability.AbilityRuntime.Core | Name | Type | Readable | Writable | Description | diff --git a/en/application-dev/reference/apis/js-apis-inner-application-context.md b/en/application-dev/reference/apis/js-apis-inner-application-context.md index 62222885a9..a34482389f 100644 --- a/en/application-dev/reference/apis/js-apis-inner-application-context.md +++ b/en/application-dev/reference/apis/js-apis-inner-application-context.md @@ -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 | Area in which the file to be access is located.| +| area | contextConstant.[AreaMode](js-apis-app-ability-contextConstant.md) | Yes | No | Encryption level of the directory. | ## Context.createBundleContext @@ -41,6 +41,8 @@ Creates the context based on the bundle name. **System capability**: SystemCapability.Ability.AbilityRuntime.Core +**System API**: This is a system API and cannot be called by third-party applications. + **Parameters** | Name | Type | Mandatory | Description | @@ -103,6 +105,8 @@ Creates the context based on the bundle name and module name. **System capability**: SystemCapability.Ability.AbilityRuntime.Core +**System API**: This is a system API and cannot be called by third-party applications. + **Parameters** | Name | Type | Mandatory | Description | diff --git a/en/application-dev/reference/apis/js-apis-inner-application-errorObserver.md b/en/application-dev/reference/apis/js-apis-inner-application-errorObserver.md index 095529fabb..b70c2abaad 100644 --- a/en/application-dev/reference/apis/js-apis-inner-application-errorObserver.md +++ b/en/application-dev/reference/apis/js-apis-inner-application-errorObserver.md @@ -2,6 +2,10 @@ The **ErrorObserver** module defines an observer to listen for application errors. It can be used as an input parameter in [ErrorManager.on](js-apis-app-ability-errorManager.md#errormanageron) to listen for errors that occur in the current application. +> **NOTE** +> +> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. + ## Modules to Import ```ts @@ -40,7 +44,7 @@ try { } ``` -## ErrorObserver.onException +## ErrorObserver.onException10+ onException?(errObject: Error): void; diff --git a/en/application-dev/reference/apis/js-apis-inner-application-eventHub.md b/en/application-dev/reference/apis/js-apis-inner-application-eventHub.md index cda73945ba..624cd79718 100644 --- a/en/application-dev/reference/apis/js-apis-inner-application-eventHub.md +++ b/en/application-dev/reference/apis/js-apis-inner-application-eventHub.md @@ -7,6 +7,12 @@ The **EventHub** module provides APIs to subscribe to, unsubscribe from, and tri > - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The APIs of this module can be used only in the stage model. +## Modules to Import + +```ts +import common from '@ohos.app.ability.common'; +``` + ## Usage Before using any APIs in the **EventHub**, you must obtain an **EventHub** instance through the member variable **context** of the **UIAbility** instance. diff --git a/en/application-dev/reference/apis/js-apis-inner-application-extensionContext.md b/en/application-dev/reference/apis/js-apis-inner-application-extensionContext.md index e4d28bb082..a79bf5961f 100644 --- a/en/application-dev/reference/apis/js-apis-inner-application-extensionContext.md +++ b/en/application-dev/reference/apis/js-apis-inner-application-extensionContext.md @@ -9,6 +9,12 @@ This module provides APIs for accessing resources of a specific Extension abilit > - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The APIs of this module can be used only in the stage model. +## Modules to Import + +```ts +import common from '@ohos.app.ability.common'; +``` + ## Attributes **System capability**: SystemCapability.Ability.AbilityRuntime.Core diff --git a/en/application-dev/reference/apis/js-apis-inner-application-formExtensionContext.md b/en/application-dev/reference/apis/js-apis-inner-application-formExtensionContext.md index 4c84a0f843..e387ee397a 100644 --- a/en/application-dev/reference/apis/js-apis-inner-application-formExtensionContext.md +++ b/en/application-dev/reference/apis/js-apis-inner-application-formExtensionContext.md @@ -23,7 +23,7 @@ Before using the **ServiceExtensionContext** module, you must first obtain a **F import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; import formBindingData from '@ohos.app.form.formBindingData'; -export default class MyFormExtensionAbility extends FormExtensionAbility { +class MyFormExtensionAbility extends FormExtensionAbility { onAddForm(want) { let formContext = this.context; // Obtain a FormExtensionContext instance. // ... diff --git a/en/application-dev/reference/apis/js-apis-inner-application-missionInfo.md b/en/application-dev/reference/apis/js-apis-inner-application-missionInfo.md index 326e60a897..a9d9ff2f55 100644 --- a/en/application-dev/reference/apis/js-apis-inner-application-missionInfo.md +++ b/en/application-dev/reference/apis/js-apis-inner-application-missionInfo.md @@ -2,6 +2,10 @@ The **MissionInfo** module defines detailed information about a mission. The information can be obtained through [getMissionInfo](js-apis-app-ability-missionManager.md#missionmanagergetmissioninfo). +> **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 diff --git a/en/application-dev/reference/apis/js-apis-inner-application-missionListener.md b/en/application-dev/reference/apis/js-apis-inner-application-missionListener.md index 9386b6f5b9..4dfb8ed40a 100644 --- a/en/application-dev/reference/apis/js-apis-inner-application-missionListener.md +++ b/en/application-dev/reference/apis/js-apis-inner-application-missionListener.md @@ -2,6 +2,16 @@ The **MissionListener** module defines the listeners used to observe the mission status. The listeners can be registered by using [on](js-apis-app-ability-missionManager.md#missionmanageron). +> **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 +import missionManager from '@ohos.app.ability.missionManager'; +``` + **System capability**: SystemCapability.Ability.AbilityRuntime.Mission | Name | Type | Mandatory| Description | @@ -10,9 +20,9 @@ The **MissionListener** module defines the listeners used to observe the mission | onMissionDestroyed | function | No | Called when the system destroys the mission.| | onMissionSnapshotChanged | function | No | Called when the system updates the mission snapshot.| | onMissionMovedToFront | function | No | Called when the system moves the mission to the foreground.| -| onMissionLabelUpdated | function | No | Called when the system updates the mission label.| -| onMissionIconUpdated | function | No | Called when the system updates the mission icon.| -| onMissionClosed | function | No | Called when the system closes the mission.| +| onMissionLabelUpdated9+ | function | No | Called when the system updates the mission label.| +| onMissionIconUpdated9+ | function | No | Called when the system updates the mission icon.| +| onMissionClosed9+ | function | No | Called when the system closes the mission.| **Example** ```ts diff --git a/en/application-dev/reference/apis/js-apis-inner-application-processData.md b/en/application-dev/reference/apis/js-apis-inner-application-processData.md index 076fdb4f2c..16427a352d 100644 --- a/en/application-dev/reference/apis/js-apis-inner-application-processData.md +++ b/en/application-dev/reference/apis/js-apis-inner-application-processData.md @@ -2,22 +2,32 @@ The **ProcessData** module defines process data. If a lifecycle change listener is registered by calling [registerApplicationStateObserver](js-apis-application-appManager.md#appmanagerregisterapplicationstateobserver8), the **onProcessCreated** callback in [ApplicationStateObserver](js-apis-inner-application-applicationStateObserver.md) is invoked when the lifecycle of an application or ability changes. +> **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 +import appManager from '@ohos.application.appManager'; +``` + **System capability**: SystemCapability.Ability.AbilityRuntime.Core **System API**: This is a system API and cannot be called by third-party applications. | Name | Type | Readable| Writable| Description | | ----------------------- | ---------| ---- | ---- | ------------------------- | -| pid8+ | number | Yes | No | Process ID. | -| bundleName8+ | string | Yes | No | Bundle name of the application. | -| uid8+ | number | Yes | No | UID of the application. | +| pid | number | Yes | No | Process ID. | +| bundleName | string | Yes | No | Bundle name of the application. | +| uid | number | Yes | No | UID of the application. | | isContinuousTask9+ | boolean | Yes | No | Whether the task is a continuous task. The value **true** means that the task is a continuous task, and **false** means the opposite. | | isKeepAlive9+ | boolean | Yes | No | Whether the process is a resident task. The value **true** means that the process is a resident, and **false** means the opposite. | | state9+ | number | Yes | No | Application state. The value can be **0** (newly created), **2** (foreground), **4** (background), or **5** (terminated). | **Example** ```ts -import appManager from '@ohos.app.ability.appManager'; +import appManager from '@ohos.application.appManager'; let applicationStateObserver = { onForegroundApplicationChanged(appStateData) { diff --git a/en/application-dev/reference/apis/js-apis-inner-application-processRunningInfo.md b/en/application-dev/reference/apis/js-apis-inner-application-processRunningInfo.md index b1441077dc..b746fcbf38 100644 --- a/en/application-dev/reference/apis/js-apis-inner-application-processRunningInfo.md +++ b/en/application-dev/reference/apis/js-apis-inner-application-processRunningInfo.md @@ -6,6 +6,12 @@ The **ProcessRunningInfo** module defines the running information of a process. > - The APIs provided by this module are deprecated since API version 9. You are advised to use [ProcessInformation9+](js-apis-inner-application-processInformation.md) instead. > - The initial APIs of this module are supported since API version 8. +## Modules to Import + +```ts +import appManager from '@ohos.app.ability.appManager'; +``` + ## Attributes **System capability**: SystemCapability.Ability.AbilityRuntime.Mission diff --git a/en/application-dev/reference/apis/js-apis-inner-application-serviceExtensionContext.md b/en/application-dev/reference/apis/js-apis-inner-application-serviceExtensionContext.md index 476d143241..38928f4266 100644 --- a/en/application-dev/reference/apis/js-apis-inner-application-serviceExtensionContext.md +++ b/en/application-dev/reference/apis/js-apis-inner-application-serviceExtensionContext.md @@ -9,6 +9,12 @@ You can use the APIs of this module to start, terminate, connect, and disconnect > - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The APIs of this module can be used only in the stage model. +## Modules to Import + +```ts +import common from '@ohos.app.ability.common'; +``` + ## Usage Before using the **ServiceExtensionContext** module, you must define a child class that inherits from **ServiceExtensionAbility**. @@ -1348,3 +1354,208 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error console.error('error.code: ${paramError.code}, error.message: ${paramError.message}'); } ``` +## UIAbilityContext.startRecentAbility + +startRecentAbility(want: Want, callback: AsyncCallback<void<): void; + +Starts an ability. If the ability has multiple instances, the latest instance is started. This API uses an asynchronous callback to return the result. + +Observe the following when using this API: + - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission. + - If **exported** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. + - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). + +**System capability**: SystemCapability.Ability.AbilityRuntime.Core + +**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.| +| callback | AsyncCallback\ | Yes| Callback used to return the result.| + +**Error codes** + +For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). + +| ID| Error Message| +| ------- | -------------------------------- | +| 16000001 | The specified ability does not exist. | +| 16000002 | Incorrect ability type. | +| 16000004 | Can not start invisible component. | +| 16000005 | The specified process does not have the permission. | +| 16000006 | Cross-user operations are not allowed. | +| 16000008 | The crowdtesting application expires. | +| 16000009 | An ability cannot be started or stopped in Wukong mode. | +| 16000010 | The call with the continuation flag is forbidden. | +| 16000011 | The context does not exist. | +| 16000050 | Internal error. | +| 16000053 | The ability is not on the top of the UI. | +| 16000055 | Installation-free timed out. | +| 16200001 | The caller has been released. | + +**Example** + + ```ts +let want = { + bundleName: 'com.example.myapplication', + abilityName: 'EntryAbility' +}; + +try { + this.context.startRecentAbility(want, (err) => { + if (err.code) { + // Process service logic errors. + console.error(`startRecentAbility failed, code is ${err.code}, message is ${err.message}`); + return; + } + // Carry out normal service processing. + console.info('startRecentAbility succeed'); + }); +} catch (err) { + // Process input parameter errors. + console.error(`startRecentAbility failed failed, code is ${err.code}, message is ${err.message}`); +} + ``` +## UIAbilityContext.startRecentAbility + +startRecentAbility(want: Want, options: StartOptions, callback: AsyncCallback<void<): void; + +Starts an ability with the start options specified. If the ability has multiple instances, the latest instance is started. This API uses an asynchronous callback to return the result. +You can use this API to carry start options. + +Observe the following when using this API: + - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission. + - If **exported** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. + - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). + +**System capability**: SystemCapability.Ability.AbilityRuntime.Core + +**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.| +| options | [StartOptions](js-apis-app-ability-startOptions.md) | Yes| Parameters used for starting the ability.| +| callback | AsyncCallback\ | Yes| Callback used to return the result.| + +**Error codes** + +For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). + +| ID| Error Message| +| ------- | -------------------------------- | +| 16000001 | The specified ability does not exist. | +| 16000002 | Incorrect ability type. | +| 16000004 | Can not start invisible component. | +| 16000005 | The specified process does not have the permission. | +| 16000006 | Cross-user operations are not allowed. | +| 16000008 | The crowdtesting application expires. | +| 16000009 | An ability cannot be started or stopped in Wukong mode. | +| 16000010 | The call with the continuation flag is forbidden. | +| 16000011 | The context does not exist. | +| 16000050 | Internal error. | +| 16000053 | The ability is not on the top of the UI. | +| 16000055 | Installation-free timed out. | +| 16200001 | The caller has been released. | + +**Example** + + ```ts +let want = { + deviceId: '', + bundleName: 'com.example.myapplication', + abilityName: 'EntryAbility' +}; +let options = { + windowMode: 0 +}; + +try { + this.context.startRecentAbility(want, options, (err) => { + if (err.code) { + // Process service logic errors. + console.error(`startRecentAbility failed, code is ${err.code}, message is ${err.message}`); + return; + } + // Carry out normal service processing. + console.info('startRecentAbility succeed'); + }); +} catch (err) { + // Process input parameter errors. + console.error(`startRecentAbility failed failed, code is ${err.code}, message is ${err.message}`); +} + ``` +## UIAbilityContext.startRecentAbility + +startRecentAbility(want: Want, options?: StartOptions): Promise<void<; + +Starts an ability. If the ability has multiple instances, the latest instance is started. +This API uses a promise to return the result. + +Observe the following when using this API: + - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission. + - If **exported** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. + - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). + +**System capability**: SystemCapability.Ability.AbilityRuntime.Core + +**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.| +| options | [StartOptions](js-apis-app-ability-startOptions.md) | No| Parameters used for starting the ability.| + +**Error codes** + +For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). + +| ID| Error Message| +| ------- | -------------------------------- | +| 16000001 | The specified ability does not exist. | +| 16000002 | Incorrect ability type. | +| 16000004 | Can not start invisible component. | +| 16000005 | The specified process does not have the permission. | +| 16000006 | Cross-user operations are not allowed. | +| 16000008 | The crowdtesting application expires. | +| 16000009 | An ability cannot be started or stopped in Wukong mode. | +| 16000010 | The call with the continuation flag is forbidden. | +| 16000011 | The context does not exist. | +| 16000050 | Internal error. | +| 16000053 | The ability is not on the top of the UI. | +| 16000055 | Installation-free timed out. | +| 16200001 | The caller has been released. | + +**Example** + + ```ts +let want = { + bundleName: 'com.example.myapplication', + abilityName: 'EntryAbility' +}; +let options = { + windowMode: 0, +}; + +try { + this.context.startRecentAbility(want, options) + .then(() => { + // Carry out normal service processing. + console.info('startRecentAbility succeed'); + }) + .catch((err) => { + // Process service logic errors. + console.error(`startRecentAbility failed, code is ${err.code}, message is ${err.message}`); + }); +} catch (err) { + // Process input parameter errors. + console.error(`startRecentAbility failed, code is ${err.code}, message is ${err.message}`); +} + ``` diff --git a/en/application-dev/reference/apis/js-apis-inner-application-uiAbilityContext.md b/en/application-dev/reference/apis/js-apis-inner-application-uiAbilityContext.md index 59edfc898f..cbfec0e290 100644 --- a/en/application-dev/reference/apis/js-apis-inner-application-uiAbilityContext.md +++ b/en/application-dev/reference/apis/js-apis-inner-application-uiAbilityContext.md @@ -7,6 +7,12 @@ > - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The APIs of this module can be used only in the stage model. +## Modules to Import + +```ts +import common from '@ohos.app.ability.common'; +``` + ## Attributes **System capability**: SystemCapability.Ability.AbilityRuntime.Core @@ -361,7 +367,7 @@ try { // Carry out normal service processing. console.info('startAbilityForResult succeed'); }); -} catch (paramError) { +} catch (err) { // Process input parameter errors. console.error(`startAbilityForResult failed, code is ${err.code}, message is ${err.message}`); } @@ -779,7 +785,7 @@ try { // Process service logic errors. console.error(`startServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`); }); -} catch (paramError) { +} catch (err) { // Process input parameter errors. console.error(`startServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`); } @@ -1391,6 +1397,7 @@ let want = { bundleName: 'com.example.myapplication', abilityName: 'ServiceExtensionAbility' }; +let commRemote; let options = { onConnect(elementName, remote) { commRemote = remote; @@ -1460,6 +1467,7 @@ let want = { abilityName: 'ServiceExtensionAbility' }; let accountId = 100; +let commRemote; let options = { onConnect(elementName, remote) { commRemote = remote; @@ -1516,6 +1524,7 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error ```ts // connection is the return value of connectServiceExtensionAbility. let connection = 1; +let commRemote; try { this.context.disconnectServiceExtensionAbility(connection, (err) => { @@ -1564,6 +1573,24 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error ```ts // connection is the return value of connectServiceExtensionAbility. let connection = 1; +let commRemote; + +try { + this.context.disconnectServiceExtensionAbility(connection, (err) => { + commRemote = null; + if (err.code) { + // Process service logic errors. + console.error(`disconnectServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`); + return; + } + // Carry out normal service processing. + console.info('disconnectServiceExtensionAbility succeed'); + }); +} catch (err) { + commRemote = null; + // Process input parameter errors. + console.error(`disconnectServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`); +} try { this.context.disconnectServiceExtensionAbility(connection, (err) => { @@ -1677,11 +1704,11 @@ try { // Carry out normal service processing. caller = obj; console.info('startAbilityByCall succeed'); - }).catch((error) => { + }).catch((err) => { // Process service logic errors. console.error(`startAbilityByCall failed, code is ${err.code}, message is ${err.message}`); }); -} catch (paramError) { +} catch (err) { // Process input parameter errors. console.error(`startAbilityByCall failed, code is ${err.code}, message is ${err.message}`); } @@ -2065,6 +2092,8 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error **Example** ```ts + import image from '@ohos.multimedia.image'; + let imagePixelMap; let color = new ArrayBuffer(0); let initializationOptions = { @@ -2283,5 +2312,210 @@ try { } catch (err) { // Process input parameter errors. console.error(`requestDialogService failed, code is ${err.code}, message is ${err.message}`); +} + ``` + ## UIAbilityContext.startRecentAbility + +startRecentAbility(want: Want, callback: AsyncCallback<void<): void; + +Starts an ability. If the ability has multiple instances, the latest instance is started. This API uses an asynchronous callback to return the result. + +Observe the following when using this API: + - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission. + - If **exported** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. + - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). + +**System capability**: SystemCapability.Ability.AbilityRuntime.Core + +**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.| +| callback | AsyncCallback\ | Yes| Callback used to return the result.| + +**Error codes** + +For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). + +| ID| Error Message| +| ------- | -------------------------------- | +| 16000001 | The specified ability does not exist. | +| 16000002 | Incorrect ability type. | +| 16000004 | Can not start invisible component. | +| 16000005 | The specified process does not have the permission. | +| 16000006 | Cross-user operations are not allowed. | +| 16000008 | The crowdtesting application expires. | +| 16000009 | An ability cannot be started or stopped in Wukong mode. | +| 16000010 | The call with the continuation flag is forbidden. | +| 16000011 | The context does not exist. | +| 16000050 | Internal error. | +| 16000053 | The ability is not on the top of the UI. | +| 16000055 | Installation-free timed out. | +| 16200001 | The caller has been released. | + +**Example** + + ```ts +let want = { + bundleName: 'com.example.myapplication', + abilityName: 'EntryAbility' +}; + +try { + this.context.startRecentAbility(want, (err) => { + if (err.code) { + // Process service logic errors. + console.error(`startRecentAbility failed, code is ${err.code}, message is ${err.message}`); + return; + } + // Carry out normal service processing. + console.info('startRecentAbility succeed'); + }); +} catch (err) { + // Process input parameter errors. + console.error(`startRecentAbility failed failed, code is ${err.code}, message is ${err.message}`); +} + ``` +## UIAbilityContext.startRecentAbility + +startRecentAbility(want: Want, options: StartOptions, callback: AsyncCallback<void<): void; + +Starts an ability with the start options specified. If the ability has multiple instances, the latest instance is started. This API uses an asynchronous callback to return the result. +You can use this API to carry start options. + +Observe the following when using this API: + - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission. + - If **exported** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. + - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). + +**System capability**: SystemCapability.Ability.AbilityRuntime.Core + +**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.| +| options | [StartOptions](js-apis-app-ability-startOptions.md) | Yes| Parameters used for starting the ability.| +| callback | AsyncCallback\ | Yes| Callback used to return the result.| + +**Error codes** + +For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). + +| ID| Error Message| +| ------- | -------------------------------- | +| 16000001 | The specified ability does not exist. | +| 16000002 | Incorrect ability type. | +| 16000004 | Can not start invisible component. | +| 16000005 | The specified process does not have the permission. | +| 16000006 | Cross-user operations are not allowed. | +| 16000008 | The crowdtesting application expires. | +| 16000009 | An ability cannot be started or stopped in Wukong mode. | +| 16000010 | The call with the continuation flag is forbidden. | +| 16000011 | The context does not exist. | +| 16000050 | Internal error. | +| 16000053 | The ability is not on the top of the UI. | +| 16000055 | Installation-free timed out. | +| 16200001 | The caller has been released. | + +**Example** + + ```ts +let want = { + deviceId: '', + bundleName: 'com.example.myapplication', + abilityName: 'EntryAbility' +}; +let options = { + windowMode: 0 +}; + +try { + this.context.startRecentAbility(want, options, (err) => { + if (err.code) { + // Process service logic errors. + console.error(`startRecentAbility failed, code is ${err.code}, message is ${err.message}`); + return; + } + // Carry out normal service processing. + console.info('startRecentAbility succeed'); + }); +} catch (err) { + // Process input parameter errors. + console.error(`startRecentAbility failed failed, code is ${err.code}, message is ${err.message}`); +} + ``` +## UIAbilityContext.startRecentAbility + +startRecentAbility(want: Want, options?: StartOptions): Promise<void<; + +Starts an ability. If the ability has multiple instances, the latest instance is started. +This API uses a promise to return the result. + +Observe the following when using this API: + - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission. + - If **exported** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. + - For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). + +**System capability**: SystemCapability.Ability.AbilityRuntime.Core + +**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.| +| options | [StartOptions](js-apis-app-ability-startOptions.md) | No| Parameters used for starting the ability.| + +**Error codes** + +For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). + +| ID| Error Message| +| ------- | -------------------------------- | +| 16000001 | The specified ability does not exist. | +| 16000002 | Incorrect ability type. | +| 16000004 | Can not start invisible component. | +| 16000005 | The specified process does not have the permission. | +| 16000006 | Cross-user operations are not allowed. | +| 16000008 | The crowdtesting application expires. | +| 16000009 | An ability cannot be started or stopped in Wukong mode. | +| 16000010 | The call with the continuation flag is forbidden. | +| 16000011 | The context does not exist. | +| 16000050 | Internal error. | +| 16000053 | The ability is not on the top of the UI. | +| 16000055 | Installation-free timed out. | +| 16200001 | The caller has been released. | + +**Example** + + ```ts +let want = { + bundleName: 'com.example.myapplication', + abilityName: 'EntryAbility' +}; +let options = { + windowMode: 0, +}; + +try { + this.context.startRecentAbility(want, options) + .then(() => { + // Carry out normal service processing. + console.info('startRecentAbility succeed'); + }) + .catch((err) => { + // Process service logic errors. + console.error(`startRecentAbility failed, code is ${err.code}, message is ${err.message}`); + }); +} catch (err) { + // Process input parameter errors. + console.error(`startRecentAbility failed, code is ${err.code}, message is ${err.message}`); } ``` diff --git a/en/application-dev/reference/apis/js-apis-inner-wantAgent-triggerInfo.md b/en/application-dev/reference/apis/js-apis-inner-wantAgent-triggerInfo.md index 5ca299f0ad..6b90099bbd 100644 --- a/en/application-dev/reference/apis/js-apis-inner-wantAgent-triggerInfo.md +++ b/en/application-dev/reference/apis/js-apis-inner-wantAgent-triggerInfo.md @@ -2,6 +2,16 @@ The **TriggerInfo** module defines the information required for triggering the WantAgent. The information is used as an input parameter of [trigger](js-apis-app-ability-wantAgent.md#wantagenttrigger). +> **NOTE** +> +> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. + +## Modules to Import + +```ts +import wantAgent from '@ohos.app.ability.wantAgent'; +``` + **System capability**: SystemCapability.Ability.AbilityRuntime.Core | Name | Type | Mandatory| Description | diff --git a/en/application-dev/reference/apis/js-apis-inner-wantAgent-wantAgentInfo.md b/en/application-dev/reference/apis/js-apis-inner-wantAgent-wantAgentInfo.md index 289a5ebef3..cffcba65b1 100644 --- a/en/application-dev/reference/apis/js-apis-inner-wantAgent-wantAgentInfo.md +++ b/en/application-dev/reference/apis/js-apis-inner-wantAgent-wantAgentInfo.md @@ -2,6 +2,16 @@ The **WantAgentInfo** module defines the information required for triggering a **WantAgent** object. The information can be used as an input parameter in [getWantAgent](js-apis-app-ability-wantAgent.md#wantagentgetwantagent) to obtain a specified **WantAgent** object. +> **NOTE** +> +> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. + +## Modules to Import + +```ts +import wantAgent from '@ohos.app.ability.wantAgent'; +``` + **System capability**: SystemCapability.Ability.AbilityRuntime.Core | Name | Type | Mandatory| Description | -- GitLab