未验证 提交 a2291d62 编写于 作者: O openharmony_ci 提交者: Gitee

!16346 翻译完成:16275+16196 包管理配置文件修改 + 回流发现的格式问题修改

Merge pull request !16346 from wusongqing/TR16275
# Using Explicit Want to Start an Ability # 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.
<img src="figures/startAbilityWtExplicitWant.PNG" alt="startAbilityWtExplicitWant" style="zoom: 80%;" />
...@@ -35,9 +35,7 @@ When developing an application, you may need to configure certain tags to identi ...@@ -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. 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 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.
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.
```json ```json
{ {
...@@ -54,7 +52,7 @@ When developing an application, you may need to configure certain tags to identi ...@@ -54,7 +52,7 @@ When developing an application, you may need to configure certain tags to identi
"entity.system.home" "entity.system.home"
], ],
"actions": [ "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 ...@@ -63,7 +61,6 @@ When developing an application, you may need to configure certain tags to identi
} }
} }
``` ```
- **Configuring application version declaration** - **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. 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.
......
...@@ -99,7 +99,7 @@ featureAbility.startAbility( ...@@ -99,7 +99,7 @@ featureAbility.startAbility(
{ {
want: want:
{ {
action: 'action.system.home', action: 'ohos.want.action.home',
entities: ['entity.system.home'], entities: ['entity.system.home'],
type: 'MIMETYPE', type: 'MIMETYPE',
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
...@@ -176,7 +176,7 @@ featureAbility.startAbilityForResult( ...@@ -176,7 +176,7 @@ featureAbility.startAbilityForResult(
{ {
want: want:
{ {
action: 'action.system.home', action: 'ohos.want.action.home',
entities: ['entity.system.home'], entities: ['entity.system.home'],
type: 'MIMETYPE', type: 'MIMETYPE',
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
...@@ -230,7 +230,7 @@ featureAbility.startAbilityForResult( ...@@ -230,7 +230,7 @@ featureAbility.startAbilityForResult(
{ {
want: want:
{ {
action: 'action.system.home', action: 'ohos.want.action.home',
entities: ['entity.system.home'], entities: ['entity.system.home'],
type: 'MIMETYPE', type: 'MIMETYPE',
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
...@@ -282,7 +282,7 @@ featureAbility.terminateSelfWithResult( ...@@ -282,7 +282,7 @@ featureAbility.terminateSelfWithResult(
resultCode: 1, resultCode: 1,
want: want:
{ {
action: 'action.system.home', action: 'ohos.want.action.home',
entities: ['entity.system.home'], entities: ['entity.system.home'],
type: 'MIMETYPE', type: 'MIMETYPE',
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
...@@ -339,7 +339,7 @@ featureAbility.terminateSelfWithResult( ...@@ -339,7 +339,7 @@ featureAbility.terminateSelfWithResult(
resultCode: 1, resultCode: 1,
want: want:
{ {
action: 'action.system.home', action: 'ohos.want.action.home',
entities: ['entity.system.home'], entities: ['entity.system.home'],
type: 'MIMETYPE', type: 'MIMETYPE',
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
......
...@@ -47,7 +47,7 @@ particleAbility.startAbility( ...@@ -47,7 +47,7 @@ particleAbility.startAbility(
{ {
want: want:
{ {
action: 'action.system.home', action: 'ohos.want.action.home',
entities: ['entity.system.home'], entities: ['entity.system.home'],
type: 'MIMETYPE', type: 'MIMETYPE',
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
...@@ -98,7 +98,7 @@ particleAbility.startAbility( ...@@ -98,7 +98,7 @@ particleAbility.startAbility(
{ {
want: want:
{ {
action: 'action.system.home', action: 'ohos.want.action.home',
entities: ['entity.system.home'], entities: ['entity.system.home'],
type: 'MIMETYPE', type: 'MIMETYPE',
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
......
...@@ -40,11 +40,9 @@ Defines the data structure of the fault log information. ...@@ -40,11 +40,9 @@ Defines the data structure of the fault log information.
| summary | string | Yes| Summary of the fault.| | summary | string | Yes| Summary of the fault.|
| fullLog | string | Yes| Full log text.| | fullLog | string | Yes| Full log text.|
## faultLogger.querySelfFaultLog<sup>(deprecated)</sup> ## faultLogger.query<sup>9+</sup>
querySelfFaultLog(faultType: FaultType, callback: AsyncCallback&lt;Array&lt;FaultLogInfo&gt;&gt;) : void
> **NOTE**<br>This API is deprecated since API version 9. You are advised to use [faultLogger.query](#faultloggerquery9) instead. query(faultType: FaultType, callback: AsyncCallback&lt;Array&lt;FaultLogInfo&gt;&gt;) : 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. 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 ...@@ -57,6 +55,14 @@ Obtains the fault information about the current process. This API uses an asynch
| faultType | [FaultType](#faulttype) | Yes| Fault type.| | faultType | [FaultType](#faulttype) | Yes| Fault type.|
| callback | AsyncCallback&lt;Array&lt;[FaultLogInfo](#faultloginfo)&gt;&gt; | Yes| Callback used to return the fault information array.<br>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. | callback | AsyncCallback&lt;Array&lt;[FaultLogInfo](#faultloginfo)&gt;&gt; | Yes| Callback used to return the fault information array.<br>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** **Example**
```js ```js
...@@ -79,14 +85,16 @@ function queryFaultLogCallback(error, value) { ...@@ -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<sup>(deprecated)</sup> ## faultLogger.query<sup>9+</sup>
querySelfFaultLog(faultType: FaultType) : Promise&lt;Array&lt;FaultLogInfo&gt;&gt;
> **NOTE**<br>This API is deprecated since API version 9. You are advised to use [faultLogger.query](#faultloggerquery9-1) instead. query(faultType: FaultType) : Promise&lt;Array&lt;FaultLogInfo&gt;&gt;
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. 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 ...@@ -104,32 +112,48 @@ Obtains the fault information about the current process. This API uses a promise
| -------- | -------- | | -------- | -------- |
| Promise&lt;Array&lt;[FaultLogInfo](#faultloginfo)&gt;&gt; | Promise used to return the fault information array. You can obtain the fault information instance in its **then()** method or use **await**.<br>The value is the fault information array obtained. If the value is **undefined**, an exception occurs during the information retrieval.| | Promise&lt;Array&lt;[FaultLogInfo](#faultloginfo)&gt;&gt; | Promise used to return the fault information array. You can obtain the fault information instance in its **then()** method or use **await**.<br>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** **Example**
```js ```js
async function getLog() { async function getLog() {
let value = await faultLogger.querySelfFaultLog(faultLogger.FaultType.JS_CRASH); try {
if (value) { let value = await faultLogger.query(faultLogger.FaultType.JS_CRASH);
console.info("value length is " + value.length); if (value) {
let len = value.length; console.info("value length is " + value.length);
for (let i = 0; i < len; i++) { let len = value.length;
console.info("log: " + i); for (let i = 0; i < len; i++) {
console.info("Log pid: " + value[i].pid); console.info("log: " + i);
console.info("Log uid: " + value[i].uid); console.info("Log pid: " + value[i].pid);
console.info("Log type: " + value[i].type); console.info("Log uid: " + value[i].uid);
console.info("Log timestamp: " + value[i].timestamp); console.info("Log type: " + value[i].type);
console.info("Log reason: " + value[i].reason); console.info("Log timestamp: " + value[i].timestamp);
console.info("Log module: " + value[i].module); console.info("Log reason: " + value[i].reason);
console.info("Log summary: " + value[i].summary); console.info("Log module: " + value[i].module);
console.info("Log text: " + value[i].fullLog); 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.query<sup>9+</sup> ## faultLogger.querySelfFaultLog<sup>(deprecated)</sup>
query(faultType: FaultType, callback: AsyncCallback&lt;Array&lt;FaultLogInfo&gt;&gt;) : void querySelfFaultLog(faultType: FaultType, callback: AsyncCallback&lt;Array&lt;FaultLogInfo&gt;&gt;) : 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. 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 ...@@ -142,14 +166,6 @@ Obtains the fault information about the current process. This API uses an asynch
| faultType | [FaultType](#faulttype) | Yes| Fault type.| | faultType | [FaultType](#faulttype) | Yes| Fault type.|
| callback | AsyncCallback&lt;Array&lt;[FaultLogInfo](#faultloginfo)&gt;&gt; | Yes| Callback used to return the fault information array.<br>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. | callback | AsyncCallback&lt;Array&lt;[FaultLogInfo](#faultloginfo)&gt;&gt; | Yes| Callback used to return the fault information array.<br>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** **Example**
```js ```js
...@@ -172,16 +188,16 @@ function queryFaultLogCallback(error, value) { ...@@ -172,16 +188,16 @@ function queryFaultLogCallback(error, value) {
} }
} }
} }
try { faultLogger.querySelfFaultLog(faultLogger.FaultType.JS_CRASH, queryFaultLogCallback);
faultLogger.query(faultLogger.FaultType.JS_CRASH, queryFaultLogCallback);
} catch (err) {
console.error(`code: ${err.code}, message: ${err.message}`);
}
``` ```
## faultLogger.query<sup>9+</sup> ## faultLogger.querySelfFaultLog<sup>(deprecated)</sup>
query(faultType: FaultType) : Promise&lt;Array&lt;FaultLogInfo&gt;&gt; querySelfFaultLog(faultType: FaultType) : Promise&lt;Array&lt;FaultLogInfo&gt;&gt;
> **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. 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 ...@@ -199,37 +215,25 @@ Obtains the fault information about the current process. This API uses a promise
| -------- | -------- | | -------- | -------- |
| Promise&lt;Array&lt;[FaultLogInfo](#faultloginfo)&gt;&gt; | Promise used to return the fault information array. You can obtain the fault information instance in its **then()** method or use **await**.<br>The value is the fault information array obtained. If the value is **undefined**, an exception occurs during the information retrieval.| | Promise&lt;Array&lt;[FaultLogInfo](#faultloginfo)&gt;&gt; | Promise used to return the fault information array. You can obtain the fault information instance in its **then()** method or use **await**.<br>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** **Example**
```js ```js
async function getLog() { async function getLog() {
try { let value = await faultLogger.querySelfFaultLog(faultLogger.FaultType.JS_CRASH);
let value = await faultLogger.query(faultLogger.FaultType.JS_CRASH); if (value) {
if (value) { console.info("value length is " + value.length);
console.info("value length is " + value.length); let len = value.length;
let len = value.length; for (let i = 0; i < len; i++) {
for (let i = 0; i < len; i++) { console.info("log: " + i);
console.info("log: " + i); console.info("Log pid: " + value[i].pid);
console.info("Log pid: " + value[i].pid); console.info("Log uid: " + value[i].uid);
console.info("Log uid: " + value[i].uid); console.info("Log type: " + value[i].type);
console.info("Log type: " + value[i].type); console.info("Log timestamp: " + value[i].timestamp);
console.info("Log timestamp: " + value[i].timestamp); console.info("Log reason: " + value[i].reason);
console.info("Log reason: " + value[i].reason); console.info("Log module: " + value[i].module);
console.info("Log module: " + value[i].module); console.info("Log summary: " + value[i].summary);
console.info("Log summary: " + value[i].summary); console.info("Log text: " + value[i].fullLog);
console.info("Log text: " + value[i].fullLog);
}
} }
} catch (err) {
console.error(`code: ${err.code}, message: ${err.message}`);
} }
} }
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册