From ee86711ce5ea0e7b1cc9d3ced4743c3c1e4e1e8d Mon Sep 17 00:00:00 2001 From: Gloria Date: Tue, 21 Mar 2023 17:29:02 +0800 Subject: [PATCH] Update docs against 16275+16196 Signed-off-by: wusongqing --- .../ability-startup-with-explicit-want.md | 71 ++++++++- ...plication-component-configuration-stage.md | 7 +- .../apis/js-apis-ability-featureAbility.md | 10 +- .../apis/js-apis-ability-particleAbility.md | 4 +- .../reference/apis/js-apis-faultLogger.md | 136 +++++++++--------- 5 files changed, 149 insertions(+), 79 deletions(-) diff --git a/en/application-dev/application-models/ability-startup-with-explicit-want.md b/en/application-dev/application-models/ability-startup-with-explicit-want.md index 9186379f32..cb4642d108 100644 --- a/en/application-dev/application-models/ability-startup-with-explicit-want.md +++ b/en/application-dev/application-models/ability-startup-with-explicit-want.md @@ -1,4 +1,73 @@ # Using Explicit Want to Start an Ability -When a user touches a button in an application, the application often needs to start a UIAbility component to complete a specific task. If the **abilityName** and **bundleName** parameters are specified when starting a UIAbility, the explicit Want is used. For details about how to use the explicit Want, see [Starting UIAbility in the Same Application](uiability-intra-device-interaction.md#starting-uiability-in-the-same-application). +When a user touches a button in an application, the application often needs to start a UIAbility component to complete a specific task. The following describes how to use explicit Want to start a UIAbility component in an application. + + +## How to Develop + +1. In a project of the stage model, create an ability and a page, named **callerAbility** and **Index.ets**, respectively. Use the **windowStage.loadContent()** method in the **onWindowStageCreate** function in the **callerAbility.ts** file to bind the two. + + ```ts + // ... + // callerAbility.ts + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.info('[Demo] EntryAbility onWindowStageCreate') + // Bind callerAbility with a paged named Index + windowStage.loadContent('pages/Index') + } + // ... + ``` + +2. Repeat the preceding operation to create another ability named **calleeAbility**. + +3. Add a button to the **Index.ets** page of **callerAbility**. + + ```ts + // ... + build() { + Row() { + Column() { + Text('hello') + .fontSize(50) + .fontWeight(FontWeight.Bold) + // A new button with will call explicitStartAbility() when clicked. + Button("CLICKME") + .onClick(this.explicitStartAbility) // For details about explicitStartAbility, see the sample code below. + // ... + } + .width('100%') + } + .height('100%') + } + // ... + ``` + +4. Override the **onClick** method and use explicit Want to start **calleeAbility** in the method. The **bundleName** field can be obtained from the **AppScope > app.json5** file of the project. The **abilityName** field can be obtained from the **yourModuleName > src > main > module.json5** file of the corresponding module. + + ```ts + import common from '@ohos.app.ability.common'; + + // ... + async explicitStartAbility() { + try { + // Explicit want with abilityName specified. + let want = { + deviceId: "", + bundleName: "com.example.myapplication", + abilityName: "calleeAbility" + }; + let context = getContext(this) as common.UIAbilityContext; + await context.startAbility(want); + console.info(`explicit start ability succeed`); + } catch (error) { + console.info(`explicit start ability failed with ${error.code}`); + } + } + // ... + ``` + +5. When you touch **CLICKME**, the corresponding page is displayed. + + startAbilityWtExplicitWant diff --git a/en/application-dev/application-models/application-component-configuration-stage.md b/en/application-dev/application-models/application-component-configuration-stage.md index 3564299728..bcf9b09546 100644 --- a/en/application-dev/application-models/application-component-configuration-stage.md +++ b/en/application-dev/application-models/application-component-configuration-stage.md @@ -35,9 +35,7 @@ When developing an application, you may need to configure certain tags to identi On the stage model, you can configure an entry icon and label for each application component. The entry icon and label are displayed on the home screen. - The entry icon is configured by specifying **icon** under **abilities** in the [module.json5 file](../quick-start/module-configuration-file.md). For example, if you want to display the icon of the UIAbility component on the home screen, add **entity.system.home** to **entities** and **action.system.home** to **actions** under **skills**. If this field is configured for multiple UIAbility components of an application, multiple icons are displayed on the home screen, corresponding to their respective UIAbility component. - - The entry label is configured by specifying **label** under **abilities** in the [module.json5 file](../quick-start/module-configuration-file.md). For example, if you want to display the icon of the UIAbility component on the home screen, add **entity.system.home** to **entities** and **action.system.home** to **actions** under **skills**. If this field is configured for multiple UIAbility components of an application, multiple labels are displayed on the home screen, corresponding to their respective UIAbility component. + The entry icon is configured by specifying **icon** under **abilities** in the [module.json5 file](../quick-start/module-configuration-file.md). For example, if you want to display the icon of the UIAbility component on the home screen, add **entity.system.home** to **entities** and **ohos.want.action.home** to **actions** under **skills**. If this field is configured for multiple UIAbility components of an application, multiple icons are displayed on the home screen, corresponding to their respective UIAbility component. ```json { @@ -54,7 +52,7 @@ When developing an application, you may need to configure certain tags to identi "entity.system.home" ], "actions": [ - "action.system.home" + "ohos.want.action.home" ] } ], @@ -63,7 +61,6 @@ When developing an application, you may need to configure certain tags to identi } } ``` - - **Configuring application version declaration** To declare the application version, configure the **versionCode** and **versionName** fields in the [app.json5 file](../quick-start/app-configuration-file.md) in the **AppScope** directory of the project. **versionCode** specifies the version number of the application. The value is a 32-bit non-negative integer. It is used only to determine whether a version is later than another version. A larger value indicates a later version. **versionName** provides the text description of the version number. diff --git a/en/application-dev/reference/apis/js-apis-ability-featureAbility.md b/en/application-dev/reference/apis/js-apis-ability-featureAbility.md index 06a12e5a27..6f62728d9c 100644 --- a/en/application-dev/reference/apis/js-apis-ability-featureAbility.md +++ b/en/application-dev/reference/apis/js-apis-ability-featureAbility.md @@ -99,7 +99,7 @@ featureAbility.startAbility( { want: { - action: 'action.system.home', + action: 'ohos.want.action.home', entities: ['entity.system.home'], type: 'MIMETYPE', flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, @@ -176,7 +176,7 @@ featureAbility.startAbilityForResult( { want: { - action: 'action.system.home', + action: 'ohos.want.action.home', entities: ['entity.system.home'], type: 'MIMETYPE', flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, @@ -230,7 +230,7 @@ featureAbility.startAbilityForResult( { want: { - action: 'action.system.home', + action: 'ohos.want.action.home', entities: ['entity.system.home'], type: 'MIMETYPE', flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, @@ -282,7 +282,7 @@ featureAbility.terminateSelfWithResult( resultCode: 1, want: { - action: 'action.system.home', + action: 'ohos.want.action.home', entities: ['entity.system.home'], type: 'MIMETYPE', flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, @@ -339,7 +339,7 @@ featureAbility.terminateSelfWithResult( resultCode: 1, want: { - action: 'action.system.home', + action: 'ohos.want.action.home', entities: ['entity.system.home'], type: 'MIMETYPE', flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, diff --git a/en/application-dev/reference/apis/js-apis-ability-particleAbility.md b/en/application-dev/reference/apis/js-apis-ability-particleAbility.md index 368e98df65..a772a8571e 100644 --- a/en/application-dev/reference/apis/js-apis-ability-particleAbility.md +++ b/en/application-dev/reference/apis/js-apis-ability-particleAbility.md @@ -47,7 +47,7 @@ particleAbility.startAbility( { want: { - action: 'action.system.home', + action: 'ohos.want.action.home', entities: ['entity.system.home'], type: 'MIMETYPE', flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, @@ -98,7 +98,7 @@ particleAbility.startAbility( { want: { - action: 'action.system.home', + action: 'ohos.want.action.home', entities: ['entity.system.home'], type: 'MIMETYPE', flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, diff --git a/en/application-dev/reference/apis/js-apis-faultLogger.md b/en/application-dev/reference/apis/js-apis-faultLogger.md index ea9be4cbb8..98ddcfd6e2 100644 --- a/en/application-dev/reference/apis/js-apis-faultLogger.md +++ b/en/application-dev/reference/apis/js-apis-faultLogger.md @@ -40,11 +40,9 @@ Defines the data structure of the fault log information. | summary | string | Yes| Summary of the fault.| | fullLog | string | Yes| Full log text.| -## faultLogger.querySelfFaultLog(deprecated) - -querySelfFaultLog(faultType: FaultType, callback: AsyncCallback<Array<FaultLogInfo>>) : void +## faultLogger.query9+ -> **NOTE**
This API is deprecated since API version 9. You are advised to use [faultLogger.query](#faultloggerquery9) instead. +query(faultType: FaultType, callback: AsyncCallback<Array<FaultLogInfo>>) : void Obtains the fault information about the current process. This API uses an asynchronous callback to return the fault information array obtained, which contains a maximum of 10 pieces of fault information. @@ -57,6 +55,14 @@ Obtains the fault information about the current process. This API uses an asynch | faultType | [FaultType](#faulttype) | Yes| Fault type.| | callback | AsyncCallback<Array<[FaultLogInfo](#faultloginfo)>> | Yes| Callback used to return the fault information array.
The value is the fault information array obtained. If the value is **undefined**, an exception occurs during the information retrieval. In this case, an error string will be returned. +**Error codes** + +For details about the error codes, see [FaultLogger Error Codes](../errorcodes/errorcode-faultlogger.md). + +| ID| Error Message| +| --- | --- | +| 10600001 | The service is not started or is faulty | + **Example** ```js @@ -79,14 +85,16 @@ function queryFaultLogCallback(error, value) { } } } -faultLogger.querySelfFaultLog(faultLogger.FaultType.JS_CRASH, queryFaultLogCallback); +try { + faultLogger.query(faultLogger.FaultType.JS_CRASH, queryFaultLogCallback); +} catch (err) { + console.error(`code: ${err.code}, message: ${err.message}`); +} ``` -## faultLogger.querySelfFaultLog(deprecated) - -querySelfFaultLog(faultType: FaultType) : Promise<Array<FaultLogInfo>> +## faultLogger.query9+ -> **NOTE**
This API is deprecated since API version 9. You are advised to use [faultLogger.query](#faultloggerquery9-1) instead. +query(faultType: FaultType) : Promise<Array<FaultLogInfo>> Obtains the fault information about the current process. This API uses a promise to return the fault information array obtained, which contains a maximum of 10 pieces of fault information. @@ -104,32 +112,48 @@ Obtains the fault information about the current process. This API uses a promise | -------- | -------- | | Promise<Array<[FaultLogInfo](#faultloginfo)>> | Promise used to return the fault information array. You can obtain the fault information instance in its **then()** method or use **await**.
The value is the fault information array obtained. If the value is **undefined**, an exception occurs during the information retrieval.| +**Error codes** + +For details about the error codes, see [FaultLogger Error Codes](../errorcodes/errorcode-faultlogger.md). + +| ID| Error Message| +| --- | --- | +| 10600001 | The service is not started or is faulty | + **Example** ```js async function getLog() { - let value = await faultLogger.querySelfFaultLog(faultLogger.FaultType.JS_CRASH); - if (value) { - console.info("value length is " + value.length); - let len = value.length; - for (let i = 0; i < len; i++) { - console.info("log: " + i); - console.info("Log pid: " + value[i].pid); - console.info("Log uid: " + value[i].uid); - console.info("Log type: " + value[i].type); - console.info("Log timestamp: " + value[i].timestamp); - console.info("Log reason: " + value[i].reason); - console.info("Log module: " + value[i].module); - console.info("Log summary: " + value[i].summary); - console.info("Log text: " + value[i].fullLog); + try { + let value = await faultLogger.query(faultLogger.FaultType.JS_CRASH); + if (value) { + console.info("value length is " + value.length); + let len = value.length; + for (let i = 0; i < len; i++) { + console.info("log: " + i); + console.info("Log pid: " + value[i].pid); + console.info("Log uid: " + value[i].uid); + console.info("Log type: " + value[i].type); + console.info("Log timestamp: " + value[i].timestamp); + console.info("Log reason: " + value[i].reason); + console.info("Log module: " + value[i].module); + console.info("Log summary: " + value[i].summary); + console.info("Log text: " + value[i].fullLog); + } } + } catch (err) { + console.error(`code: ${err.code}, message: ${err.message}`); } } ``` -## faultLogger.query9+ +## faultLogger.querySelfFaultLog(deprecated) -query(faultType: FaultType, callback: AsyncCallback<Array<FaultLogInfo>>) : void +querySelfFaultLog(faultType: FaultType, callback: AsyncCallback<Array<FaultLogInfo>>) : void + +> **NOTE** +> +> This API is deprecated since API version 9. You are advised to use [faultLogger.query](#faultloggerquery9) instead. Obtains the fault information about the current process. This API uses an asynchronous callback to return the fault information array obtained, which contains a maximum of 10 pieces of fault information. @@ -142,14 +166,6 @@ Obtains the fault information about the current process. This API uses an asynch | faultType | [FaultType](#faulttype) | Yes| Fault type.| | callback | AsyncCallback<Array<[FaultLogInfo](#faultloginfo)>> | Yes| Callback used to return the fault information array.
The value is the fault information array obtained. If the value is **undefined**, an exception occurs during the information retrieval. In this case, an error string will be returned. -**Error codes** - -For details about the error codes, see [FaultLogger Error Codes](../errorcodes/errorcode-faultlogger.md). - -| ID| Error Message| -| --- | --- | -| 10600001 | The service is not started or is faulty | - **Example** ```js @@ -172,16 +188,16 @@ function queryFaultLogCallback(error, value) { } } } -try { - faultLogger.query(faultLogger.FaultType.JS_CRASH, queryFaultLogCallback); -} catch (err) { - console.error(`code: ${err.code}, message: ${err.message}`); -} +faultLogger.querySelfFaultLog(faultLogger.FaultType.JS_CRASH, queryFaultLogCallback); ``` -## faultLogger.query9+ +## faultLogger.querySelfFaultLog(deprecated) -query(faultType: FaultType) : Promise<Array<FaultLogInfo>> +querySelfFaultLog(faultType: FaultType) : Promise<Array<FaultLogInfo>> + +> **NOTE** +> +> This API is deprecated since API version 9. You are advised to use [faultLogger.query](#faultloggerquery9-1) instead. Obtains the fault information about the current process. This API uses a promise to return the fault information array obtained, which contains a maximum of 10 pieces of fault information. @@ -199,37 +215,25 @@ Obtains the fault information about the current process. This API uses a promise | -------- | -------- | | Promise<Array<[FaultLogInfo](#faultloginfo)>> | Promise used to return the fault information array. You can obtain the fault information instance in its **then()** method or use **await**.
The value is the fault information array obtained. If the value is **undefined**, an exception occurs during the information retrieval.| -**Error codes** - -For details about the error codes, see [FaultLogger Error Codes](../errorcodes/errorcode-faultlogger.md). - -| ID| Error Message| -| --- | --- | -| 10600001 | The service is not started or is faulty | - **Example** ```js async function getLog() { - try { - let value = await faultLogger.query(faultLogger.FaultType.JS_CRASH); - if (value) { - console.info("value length is " + value.length); - let len = value.length; - for (let i = 0; i < len; i++) { - console.info("log: " + i); - console.info("Log pid: " + value[i].pid); - console.info("Log uid: " + value[i].uid); - console.info("Log type: " + value[i].type); - console.info("Log timestamp: " + value[i].timestamp); - console.info("Log reason: " + value[i].reason); - console.info("Log module: " + value[i].module); - console.info("Log summary: " + value[i].summary); - console.info("Log text: " + value[i].fullLog); - } + let value = await faultLogger.querySelfFaultLog(faultLogger.FaultType.JS_CRASH); + if (value) { + console.info("value length is " + value.length); + let len = value.length; + for (let i = 0; i < len; i++) { + console.info("log: " + i); + console.info("Log pid: " + value[i].pid); + console.info("Log uid: " + value[i].uid); + console.info("Log type: " + value[i].type); + console.info("Log timestamp: " + value[i].timestamp); + console.info("Log reason: " + value[i].reason); + console.info("Log module: " + value[i].module); + console.info("Log summary: " + value[i].summary); + console.info("Log text: " + value[i].fullLog); } - } catch (err) { - console.error(`code: ${err.code}, message: ${err.message}`); } } ``` -- GitLab