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

!2405 Done! 2122:Fix spelling errors of ability

Merge pull request !2405 from wusongqing/TR2122
# AbilityConstant
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API version 9.
Provides parameters related to ability launch.
## Modules to Import
```js
import AbilityConstant from '@ohos.application.AbilityConstant';
```
## Attributes
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| launchReason | LaunchReason| Yes| Yes| Ability launch reason.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
| lastExitReason | LastExitReason | Yes| Yes| Reason for the last exit.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
## AbilityConstant.LaunchReason
Enumerates ability launch reasons.
| Name | Value | Description |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| UNKNOWN | 0 | Unknown reason.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
| START_ABILITY | 1 | Ability startup.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
| CALL | 2 | Call.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
| CONTINUATION | 3 | Ability continuation.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
## AbilityConstant.LaunchReason
Enumerates reasons for the last exit.
| Name | Value | Description |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| UNKNOWN | 0 | Unknown reason.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
| ABILITY_NOT_RESPONDING | 1 | The ability does not respond.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
| NORMAL | 2 | Normal status.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
## AbilityConstant.OnContinueResult
Enumerates ability continuation results.
| Name | Value | Description |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| AGREE | 0 | Continuation agreed.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
| REJECT | 1 | Continuation denied.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
| MISMATCH | 2 | Mismatch.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
# Application Context<a name="EN-US_TOPIC_0000001173324607"></a>
## Module to Import<a name="s1959b1529f574b74861e62008289bb21"></a>
```
import app from '@system.app';
```
## Required Permissions<a name="section11257113618419"></a>
None
## app.getInfo<a name="s0e8ff40704e442bc87a848afa47bdfbb"></a>
getInfo\(\): <[AppResponse](#t3e93239d9b134b80957bcdd4acb05291)\>
Obtains the declared information in the **config.json** file of an application.
- Return values
**Table 1** AppResponse
<a name="t3e93239d9b134b80957bcdd4acb05291"></a>
<table><tbody><tr id="recc81d9f995d44aa87ba9d714b756569"><td class="cellrowborder" valign="top" width="19%"><p id="aa3137ce511d140fba6cc93513a7a91e3"><a name="aa3137ce511d140fba6cc93513a7a91e3"></a><a name="aa3137ce511d140fba6cc93513a7a91e3"></a>Name</p>
</td>
<td class="cellrowborder" valign="top" width="13%"><p id="a6b166163db284e5ca8dc0190b36ae40a"><a name="a6b166163db284e5ca8dc0190b36ae40a"></a><a name="a6b166163db284e5ca8dc0190b36ae40a"></a>Type</p>
</td>
<td class="cellrowborder" valign="top" width="68%"><p id="a4ba8ead9ee7b48298d9a6ed10659f13b"><a name="a4ba8ead9ee7b48298d9a6ed10659f13b"></a><a name="a4ba8ead9ee7b48298d9a6ed10659f13b"></a>Description</p>
</td>
</tr>
<tr id="row2557173813243"><td class="cellrowborder" valign="top" width="19%"><p id="p898462584011"><a name="p898462584011"></a><a name="p898462584011"></a>appID<sup id="sup193948321350"><a name="sup193948321350"></a><a name="sup193948321350"></a>6+</sup></p>
</td>
<td class="cellrowborder" valign="top" width="13%"><p id="p698492564013"><a name="p698492564013"></a><a name="p698492564013"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="68%"><p id="p1998432514020"><a name="p1998432514020"></a><a name="p1998432514020"></a>Bundle name of the application. It uniquely identifies the application.</p>
</td>
</tr>
<tr id="r64430cb15b54497f88ea6330b9a7454c"><td class="cellrowborder" valign="top" width="19%"><p id="a7cccea39636b47cd83188d400eed51e3"><a name="a7cccea39636b47cd83188d400eed51e3"></a><a name="a7cccea39636b47cd83188d400eed51e3"></a>appName</p>
</td>
<td class="cellrowborder" valign="top" width="13%"><p id="a2f72300143c441ef9a3fb5dc2f8e4aac"><a name="a2f72300143c441ef9a3fb5dc2f8e4aac"></a><a name="a2f72300143c441ef9a3fb5dc2f8e4aac"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="68%"><p id="a1c9b8d1829ef489e9e0fd1863190d228"><a name="a1c9b8d1829ef489e9e0fd1863190d228"></a><a name="a1c9b8d1829ef489e9e0fd1863190d228"></a>Application name</p>
</td>
</tr>
<tr id="r4f8f612a65b24ae9b75ae53893aeb3b9"><td class="cellrowborder" valign="top" width="19%"><p id="ae036f88e139e4379abdaf4969f0720ea"><a name="ae036f88e139e4379abdaf4969f0720ea"></a><a name="ae036f88e139e4379abdaf4969f0720ea"></a>versionName</p>
</td>
<td class="cellrowborder" valign="top" width="13%"><p id="a1d379931a20144f0b6d98f5396202cd9"><a name="a1d379931a20144f0b6d98f5396202cd9"></a><a name="a1d379931a20144f0b6d98f5396202cd9"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="68%"><p id="a70c91c442f7c41439a90ceb9041252e8"><a name="a70c91c442f7c41439a90ceb9041252e8"></a><a name="a70c91c442f7c41439a90ceb9041252e8"></a>Application version name</p>
</td>
</tr>
<tr id="r89cf0afd5f444bd1b66ace0c31a25cda"><td class="cellrowborder" valign="top" width="19%"><p id="a3a86c086e40e475b8fb26cf43fe9a8d6"><a name="a3a86c086e40e475b8fb26cf43fe9a8d6"></a><a name="a3a86c086e40e475b8fb26cf43fe9a8d6"></a>versionCode</p>
</td>
<td class="cellrowborder" valign="top" width="13%"><p id="abcfd352ff3d84552938de0e2daf0703e"><a name="abcfd352ff3d84552938de0e2daf0703e"></a><a name="abcfd352ff3d84552938de0e2daf0703e"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="68%"><p id="af943e2ec7622407387d25d9331a01245"><a name="af943e2ec7622407387d25d9331a01245"></a><a name="af943e2ec7622407387d25d9331a01245"></a>Application version</p>
</td>
</tr>
</tbody>
</table>
- Example
```
export default {
getInfo(){
var info = app.getInfo();
console.log(JSON.stringify(info));
}
}
```
## app.terminate<a name="section974325124119"></a>
terminate\(\): void
Destroys the current ability.
- Example
```
export default {
terminate(){
app.terminate();
}}
```
# Application Configuration<a name="EN-US_TOPIC_0000001173324675"></a>
## Module to Import<a name="section15536249155915"></a>
```
import configuration from '@system.configuration';
```
## Required Permissions<a name="section8152081004"></a>
None
## configuration.getLocale<a name="section8389829903"></a>
getLocale\(\): <[LocaleResponse](#table1544853546)\>
Obtains the current locale of the application, which is the same as the system locale.
- Return values
**Table 1** LocaleResponse
<a name="table1544853546"></a>
<table><thead align="left"><tr id="row1670755549"><th class="cellrowborder" valign="top" width="17.77177717771777%" id="mcps1.2.4.1.1"><p id="p57013505413"><a name="p57013505413"></a><a name="p57013505413"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="12.5012501250125%" id="mcps1.2.4.1.2"><p id="p9706511540"><a name="p9706511540"></a><a name="p9706511540"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="69.72697269726973%" id="mcps1.2.4.1.3"><p id="p16701957548"><a name="p16701957548"></a><a name="p16701957548"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row15709513545"><td class="cellrowborder" valign="top" width="17.77177717771777%" headers="mcps1.2.4.1.1 "><p id="p1370154548"><a name="p1370154548"></a><a name="p1370154548"></a>language</p>
</td>
<td class="cellrowborder" valign="top" width="12.5012501250125%" headers="mcps1.2.4.1.2 "><p id="p19701653545"><a name="p19701653545"></a><a name="p19701653545"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="69.72697269726973%" headers="mcps1.2.4.1.3 "><p id="p37010510548"><a name="p37010510548"></a><a name="p37010510548"></a>Current language of the application, for example, <strong id="b1260120418488"><a name="b1260120418488"></a><a name="b1260120418488"></a>zh</strong>.</p>
</td>
</tr>
<tr id="row970165135413"><td class="cellrowborder" valign="top" width="17.77177717771777%" headers="mcps1.2.4.1.1 "><p id="p97055105414"><a name="p97055105414"></a><a name="p97055105414"></a>countryOrRegion</p>
</td>
<td class="cellrowborder" valign="top" width="12.5012501250125%" headers="mcps1.2.4.1.2 "><p id="p1770175115413"><a name="p1770175115413"></a><a name="p1770175115413"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="69.72697269726973%" headers="mcps1.2.4.1.3 "><p id="p77015518544"><a name="p77015518544"></a><a name="p77015518544"></a>Country or region, for example, <strong id="b6258316114819"><a name="b6258316114819"></a><a name="b6258316114819"></a>CN</strong>.</p>
</td>
</tr>
<tr id="row6332114185611"><td class="cellrowborder" valign="top" width="17.77177717771777%" headers="mcps1.2.4.1.1 "><p id="p53321542567"><a name="p53321542567"></a><a name="p53321542567"></a>dir</p>
</td>
<td class="cellrowborder" valign="top" width="12.5012501250125%" headers="mcps1.2.4.1.2 "><p id="p1433216410564"><a name="p1433216410564"></a><a name="p1433216410564"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="69.72697269726973%" headers="mcps1.2.4.1.3 "><p id="p33321417565"><a name="p33321417565"></a><a name="p33321417565"></a>Text layout direction. Available values are as follows:</p>
<a name="ul1861816241119"></a><a name="ul1861816241119"></a><ul id="ul1861816241119"><li><strong id="b16720155216481"><a name="b16720155216481"></a><a name="b16720155216481"></a>ltr</strong>: The text direction is from left to right.</li><li><strong id="b1910563194919"><a name="b1910563194919"></a><a name="b1910563194919"></a>rtl</strong>: The text direction is from right to left.</li></ul>
</td>
</tr>
<tr id="row165137101137"><td class="cellrowborder" valign="top" width="17.77177717771777%" headers="mcps1.2.4.1.1 "><p id="p1351311101333"><a name="p1351311101333"></a><a name="p1351311101333"></a>unicodeSetting<sup id="sup1646171814502"><a name="sup1646171814502"></a><a name="sup1646171814502"></a>5+</sup></p>
</td>
<td class="cellrowborder" valign="top" width="12.5012501250125%" headers="mcps1.2.4.1.2 "><p id="p1513121019313"><a name="p1513121019313"></a><a name="p1513121019313"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="69.72697269726973%" headers="mcps1.2.4.1.3 "><p id="p97106183311"><a name="p97106183311"></a><a name="p97106183311"></a>Unicode key set determined by the locale.</p>
<p id="p213145115319"><a name="p213145115319"></a><a name="p213145115319"></a>For example, <strong id="b14471162633518"><a name="b14471162633518"></a><a name="b14471162633518"></a>{"nu":"arab"}</strong> indicates that the current locale uses Arabic numerals.</p>
<p id="p849701364"><a name="p849701364"></a><a name="p849701364"></a>If the current locale does not have a specific key set, an empty set is returned.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
export default {
getLocale() {
const localeInfo = configuration.getLocale();
console.info(localeInfo.language);
}
}
```
# Pop-up Window<a name="EN-US_TOPIC_0000001127125010"></a>
>![](../../public_sys-resources/icon-note.gif) **NOTE:**
>The initial APIs of this module are supported since API version 4. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Module to Import<a name="s1fada83813e64efcbc67e970ced86588"></a>
```
import prompt from '@system.prompt';
```
## Required Permissions<a name="section11257113618419"></a>
None
## prompt.showToast<a name="sc34d255befcf467dab069802dc9e54d8"></a>
showToast\(Object\): void
Displays the toast dialog box.
- Parameter
<a name="t1618141057434ca885c1586184c502e2"></a>
<table><thead align="left"><tr id="r351c10438fad40de99efc195cc88296f"><th class="cellrowborder" valign="top" width="14.000000000000002%" id="mcps1.1.5.1.1"><p id="a1056691df28b470d9af0c2c2f964ff8f"><a name="a1056691df28b470d9af0c2c2f964ff8f"></a><a name="a1056691df28b470d9af0c2c2f964ff8f"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="14.000000000000002%" id="mcps1.1.5.1.2"><p id="aed30d84405424c6cb5cabbbdbe3e35a7"><a name="aed30d84405424c6cb5cabbbdbe3e35a7"></a><a name="aed30d84405424c6cb5cabbbdbe3e35a7"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="10%" id="mcps1.1.5.1.3"><p id="a854ad49fdbd34a1eb98a5757d01f7cfa"><a name="a854ad49fdbd34a1eb98a5757d01f7cfa"></a><a name="a854ad49fdbd34a1eb98a5757d01f7cfa"></a>Mandatory</p>
</th>
<th class="cellrowborder" valign="top" width="62%" id="mcps1.1.5.1.4"><p id="a34deb96a6ac2414eb11e2a7dd2142ebb"><a name="a34deb96a6ac2414eb11e2a7dd2142ebb"></a><a name="a34deb96a6ac2414eb11e2a7dd2142ebb"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="rae51f5fc5bda4e5992851196bad62e8e"><td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.1.5.1.1 "><p id="ab4df9faf190145219b091959f5a62082"><a name="ab4df9faf190145219b091959f5a62082"></a><a name="ab4df9faf190145219b091959f5a62082"></a>message</p>
</td>
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.1.5.1.2 "><p id="a0dad7be0aa3f4033bc91bb4f4331d843"><a name="a0dad7be0aa3f4033bc91bb4f4331d843"></a><a name="a0dad7be0aa3f4033bc91bb4f4331d843"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="10%" headers="mcps1.1.5.1.3 "><p id="a8e32b2d4bba64516b56edaf8d6bdfdfa"><a name="a8e32b2d4bba64516b56edaf8d6bdfdfa"></a><a name="a8e32b2d4bba64516b56edaf8d6bdfdfa"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="62%" headers="mcps1.1.5.1.4 "><p id="a4b2f4463435a4e1c96e831bca8bb40a3"><a name="a4b2f4463435a4e1c96e831bca8bb40a3"></a><a name="a4b2f4463435a4e1c96e831bca8bb40a3"></a>Text to display.</p>
</td>
</tr>
<tr id="r4d2b81c5265a4d2e9029ea49c12f3cda"><td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.1.5.1.1 "><p id="ae2ee7c33807f4c8fa9d454ca7fa679cb"><a name="ae2ee7c33807f4c8fa9d454ca7fa679cb"></a><a name="ae2ee7c33807f4c8fa9d454ca7fa679cb"></a>duration</p>
</td>
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.1.5.1.2 "><p id="aa3100e4a607749cba360f4386b71ada5"><a name="aa3100e4a607749cba360f4386b71ada5"></a><a name="aa3100e4a607749cba360f4386b71ada5"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="10%" headers="mcps1.1.5.1.3 "><p id="ab40203ebb13b4cd5a86d428fa5db381b"><a name="ab40203ebb13b4cd5a86d428fa5db381b"></a><a name="ab40203ebb13b4cd5a86d428fa5db381b"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="62%" headers="mcps1.1.5.1.4 "><p id="aac09f7fe897d4a80ab7160590b544e39"><a name="aac09f7fe897d4a80ab7160590b544e39"></a><a name="aac09f7fe897d4a80ab7160590b544e39"></a>Duration of the toast dialog box. The default value is <strong id="b9361121192413"><a name="b9361121192413"></a><a name="b9361121192413"></a>1500</strong>. The recommended value ranges from 1500 ms to 10000 ms.</p>
<div class="note" id="note116191623191316"><a name="note116191623191316"></a><a name="note116191623191316"></a><span class="notetitle"> NOTE: </span><div class="notebody"><p id="p1961942320133"><a name="p1961942320133"></a><a name="p1961942320133"></a>A value less than 1500 is automatically changed to 1500. The maximum value is 10000 ms.</p>
</div></div>
</td>
</tr>
<tr id="row62011935366"><td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.1.5.1.1 "><p id="p182018316365"><a name="p182018316365"></a><a name="p182018316365"></a>[bottom]<sup id="sup11448750123910"><a name="sup11448750123910"></a><a name="sup11448750123910"></a>5+</sup></p>
</td>
<td class="cellrowborder" valign="top" width="14.000000000000002%" headers="mcps1.1.5.1.2 "><p id="p82011839362"><a name="p82011839362"></a><a name="p82011839362"></a>&lt;length&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="10%" headers="mcps1.1.5.1.3 "><p id="p82021136362"><a name="p82021136362"></a><a name="p82021136362"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="62%" headers="mcps1.1.5.1.4 "><p id="p1120212312365"><a name="p1120212312365"></a><a name="p1120212312365"></a>Distance between the dialog border and the bottom of the screen.</p>
<div class="note" id="note1834105155712"><a name="note1834105155712"></a><a name="note1834105155712"></a><span class="notetitle"> NOTE: </span><div class="notebody"><p id="p10341651115711"><a name="p10341651115711"></a><a name="p10341651115711"></a>This parameter is only supported on phones and tablets.</p>
</div></div>
</td>
</tr>
</tbody>
</table>
- Example
```
export default {
showToast() {
prompt.showToast({
message: 'Message Info',
duration: 2000,
});
}
}
```
## prompt.showDialog<a name="sc6babedb391e4de9af1189ebc9ff5e69"></a>
showDialog\(\): void
Displays the dialog box.
- Parameter
<a name="t629832d7ad1f4f7e9ed380a6320a133e"></a>
<table><thead align="left"><tr id="r166e1186bdbf45fe9775955b02b5e0cf"><th class="cellrowborder" valign="top" width="13.089999999999998%" id="mcps1.1.5.1.1"><p id="a274fde9345af4ec29d72d801d1c9463b"><a name="a274fde9345af4ec29d72d801d1c9463b"></a><a name="a274fde9345af4ec29d72d801d1c9463b"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="11.91%" id="mcps1.1.5.1.2"><p id="af6f12ca9f0dd44e98ee58e6dcc3a1edf"><a name="af6f12ca9f0dd44e98ee58e6dcc3a1edf"></a><a name="af6f12ca9f0dd44e98ee58e6dcc3a1edf"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="10%" id="mcps1.1.5.1.3"><p id="a48d51a6c05b9412b82b6b2a70fd7825b"><a name="a48d51a6c05b9412b82b6b2a70fd7825b"></a><a name="a48d51a6c05b9412b82b6b2a70fd7825b"></a>Mandatory</p>
</th>
<th class="cellrowborder" valign="top" width="65%" id="mcps1.1.5.1.4"><p id="afd08fb662a564651bc3cedbb9a05c0a5"><a name="afd08fb662a564651bc3cedbb9a05c0a5"></a><a name="afd08fb662a564651bc3cedbb9a05c0a5"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="r868a28f8acc34af4916dd4ed453ebd09"><td class="cellrowborder" valign="top" width="13.089999999999998%" headers="mcps1.1.5.1.1 "><p id="a2714800437f24825bf30c198dc6aad56"><a name="a2714800437f24825bf30c198dc6aad56"></a><a name="a2714800437f24825bf30c198dc6aad56"></a>title</p>
</td>
<td class="cellrowborder" valign="top" width="11.91%" headers="mcps1.1.5.1.2 "><p id="a2620a53c20cc4d26af71b5eba3846e19"><a name="a2620a53c20cc4d26af71b5eba3846e19"></a><a name="a2620a53c20cc4d26af71b5eba3846e19"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="10%" headers="mcps1.1.5.1.3 "><p id="af7aacc8736d34a8ca12fb007d74fb110"><a name="af7aacc8736d34a8ca12fb007d74fb110"></a><a name="af7aacc8736d34a8ca12fb007d74fb110"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="65%" headers="mcps1.1.5.1.4 "><p id="a3c44052f536c4baead681acbce5dc790"><a name="a3c44052f536c4baead681acbce5dc790"></a><a name="a3c44052f536c4baead681acbce5dc790"></a>Title of the text to display.</p>
</td>
</tr>
<tr id="r7d02820c4eaa48febfa636322c50c07f"><td class="cellrowborder" valign="top" width="13.089999999999998%" headers="mcps1.1.5.1.1 "><p id="af30a62497b5a41ad930718e1980632d9"><a name="af30a62497b5a41ad930718e1980632d9"></a><a name="af30a62497b5a41ad930718e1980632d9"></a>message</p>
</td>
<td class="cellrowborder" valign="top" width="11.91%" headers="mcps1.1.5.1.2 "><p id="a942a00c302c842269dd974188e8d72cf"><a name="a942a00c302c842269dd974188e8d72cf"></a><a name="a942a00c302c842269dd974188e8d72cf"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="10%" headers="mcps1.1.5.1.3 "><p id="aea0eec373d7d4fe8807a4e3c300487fb"><a name="aea0eec373d7d4fe8807a4e3c300487fb"></a><a name="aea0eec373d7d4fe8807a4e3c300487fb"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="65%" headers="mcps1.1.5.1.4 "><p id="ae42b17323a00403ca1682cb29424b935"><a name="ae42b17323a00403ca1682cb29424b935"></a><a name="ae42b17323a00403ca1682cb29424b935"></a>Text body.</p>
</td>
</tr>
<tr id="r9051c3a4fdfd4242bbbba1362a30c32b"><td class="cellrowborder" valign="top" width="13.089999999999998%" headers="mcps1.1.5.1.1 "><p id="ad7a64f8d6a414ce992ee8ad5b737d820"><a name="ad7a64f8d6a414ce992ee8ad5b737d820"></a><a name="ad7a64f8d6a414ce992ee8ad5b737d820"></a>buttons</p>
</td>
<td class="cellrowborder" valign="top" width="11.91%" headers="mcps1.1.5.1.2 "><p id="ae4ecdedd56eb4bb3a113aa7945576bfc"><a name="ae4ecdedd56eb4bb3a113aa7945576bfc"></a><a name="ae4ecdedd56eb4bb3a113aa7945576bfc"></a>Array</p>
</td>
<td class="cellrowborder" valign="top" width="10%" headers="mcps1.1.5.1.3 "><p id="a348857f0f8674fa88b08c4b43cf59923"><a name="a348857f0f8674fa88b08c4b43cf59923"></a><a name="a348857f0f8674fa88b08c4b43cf59923"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="65%" headers="mcps1.1.5.1.4 "><p id="ab6529e91fe1d4adc8cb3fa2e531369a9"><a name="ab6529e91fe1d4adc8cb3fa2e531369a9"></a><a name="ab6529e91fe1d4adc8cb3fa2e531369a9"></a>Array of buttons in the dialog box. The array structure is <strong id="b12386125113268"><a name="b12386125113268"></a><a name="b12386125113268"></a>{text:'button', color: '#666666'}</strong>. One to three buttons are supported. The first button is of the <strong id="b192581358288"><a name="b192581358288"></a><a name="b192581358288"></a>positiveButton</strong> type, the second is of the <strong id="b117326710282"><a name="b117326710282"></a><a name="b117326710282"></a>negativeButton</strong> type, and the third is of the <strong id="b4971171010297"><a name="b4971171010297"></a><a name="b4971171010297"></a>neutralButton</strong> type.</p>
</td>
</tr>
<tr id="rf2d176102f6547949a74deb1746d440e"><td class="cellrowborder" valign="top" width="13.089999999999998%" headers="mcps1.1.5.1.1 "><p id="abe7e018a2dac47079db426b424b2031f"><a name="abe7e018a2dac47079db426b424b2031f"></a><a name="abe7e018a2dac47079db426b424b2031f"></a>success</p>
</td>
<td class="cellrowborder" valign="top" width="11.91%" headers="mcps1.1.5.1.2 "><p id="a9061f42dad6d4ed8a81a147022ce7c68"><a name="a9061f42dad6d4ed8a81a147022ce7c68"></a><a name="a9061f42dad6d4ed8a81a147022ce7c68"></a>Function</p>
</td>
<td class="cellrowborder" valign="top" width="10%" headers="mcps1.1.5.1.3 "><p id="a05153a00a5ae4a2992deb337387d9cfc"><a name="a05153a00a5ae4a2992deb337387d9cfc"></a><a name="a05153a00a5ae4a2992deb337387d9cfc"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="65%" headers="mcps1.1.5.1.4 "><p id="a986abb2e067742f3b9fe575e7cbd0224"><a name="a986abb2e067742f3b9fe575e7cbd0224"></a><a name="a986abb2e067742f3b9fe575e7cbd0224"></a>Called when the dialog box is displayed. For the return value, see <a href="#t5f0df2fad0544e3eb458936109014414">return values of the success callback</a>.</p>
</td>
</tr>
<tr id="r26d54c4b23944b7bb7950c87b836b1c2"><td class="cellrowborder" valign="top" width="13.089999999999998%" headers="mcps1.1.5.1.1 "><p id="af1a6df8907754b7b95f6a7dd6eef3f81"><a name="af1a6df8907754b7b95f6a7dd6eef3f81"></a><a name="af1a6df8907754b7b95f6a7dd6eef3f81"></a>cancel</p>
</td>
<td class="cellrowborder" valign="top" width="11.91%" headers="mcps1.1.5.1.2 "><p id="ac8d3e854d1034a9da3f463f1d045c06f"><a name="ac8d3e854d1034a9da3f463f1d045c06f"></a><a name="ac8d3e854d1034a9da3f463f1d045c06f"></a>Function</p>
</td>
<td class="cellrowborder" valign="top" width="10%" headers="mcps1.1.5.1.3 "><p id="a5aa033ed47de41c6890699434eb179ab"><a name="a5aa033ed47de41c6890699434eb179ab"></a><a name="a5aa033ed47de41c6890699434eb179ab"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="65%" headers="mcps1.1.5.1.4 "><p id="a08b61cefc2cb4fed83e6ef32d9056fa7"><a name="a08b61cefc2cb4fed83e6ef32d9056fa7"></a><a name="a08b61cefc2cb4fed83e6ef32d9056fa7"></a>Called when the operation is cancelled.</p>
</td>
</tr>
<tr id="r5bd94b2812be49fc9cc884b39815638c"><td class="cellrowborder" valign="top" width="13.089999999999998%" headers="mcps1.1.5.1.1 "><p id="ad7700957c924489f840d376805d97d02"><a name="ad7700957c924489f840d376805d97d02"></a><a name="ad7700957c924489f840d376805d97d02"></a>complete</p>
</td>
<td class="cellrowborder" valign="top" width="11.91%" headers="mcps1.1.5.1.2 "><p id="a3b1e01fd33a04147894a7eb481c6896f"><a name="a3b1e01fd33a04147894a7eb481c6896f"></a><a name="a3b1e01fd33a04147894a7eb481c6896f"></a>Function</p>
</td>
<td class="cellrowborder" valign="top" width="10%" headers="mcps1.1.5.1.3 "><p id="a22ea63d9206e4496a5164158a4e4aa31"><a name="a22ea63d9206e4496a5164158a4e4aa31"></a><a name="a22ea63d9206e4496a5164158a4e4aa31"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="65%" headers="mcps1.1.5.1.4 "><p id="afcf4c75ba59a40c39e0b848df14c4b51"><a name="afcf4c75ba59a40c39e0b848df14c4b51"></a><a name="afcf4c75ba59a40c39e0b848df14c4b51"></a>Called when the dialog box is closed.</p>
</td>
</tr>
</tbody>
</table>
Return values of the **success** callback
<a name="t5f0df2fad0544e3eb458936109014414"></a>
<table><thead align="left"><tr id="rbe130c794ee1413ea7c736dac2a65bbd"><th class="cellrowborder" valign="top" width="13%" id="mcps1.1.4.1.1"><p id="a289c783f320744f18414bb29a696abba"><a name="a289c783f320744f18414bb29a696abba"></a><a name="a289c783f320744f18414bb29a696abba"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="12%" id="mcps1.1.4.1.2"><p id="a0ec0f99d9e094c5b9d097dde27508798"><a name="a0ec0f99d9e094c5b9d097dde27508798"></a><a name="a0ec0f99d9e094c5b9d097dde27508798"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="75%" id="mcps1.1.4.1.3"><p id="a57a576be84d146c38aa95aefcad0e486"><a name="a57a576be84d146c38aa95aefcad0e486"></a><a name="a57a576be84d146c38aa95aefcad0e486"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="r7a357c830bd44c65bfee22ddf64e4710"><td class="cellrowborder" valign="top" width="13%" headers="mcps1.1.4.1.1 "><p id="a4417e83cb4b14c418eeaeff7669c77cd"><a name="a4417e83cb4b14c418eeaeff7669c77cd"></a><a name="a4417e83cb4b14c418eeaeff7669c77cd"></a>index</p>
</td>
<td class="cellrowborder" valign="top" width="12%" headers="mcps1.1.4.1.2 "><p id="a27d628021f0f4a8f91b9a59bd00f7584"><a name="a27d628021f0f4a8f91b9a59bd00f7584"></a><a name="a27d628021f0f4a8f91b9a59bd00f7584"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="75%" headers="mcps1.1.4.1.3 "><p id="aab61e7c297034494ab27e6ca91102568"><a name="aab61e7c297034494ab27e6ca91102568"></a><a name="aab61e7c297034494ab27e6ca91102568"></a>Index of the selected button in the buttons array</p>
</td>
</tr>
</tbody>
</table>
- Example
```
export default {
showDialog() {
prompt.showDialog({
title: 'Title Info',
message: 'Message Info',
buttons: [
{
text: 'button',
color: '#666666',
},
],
success: function(data) {
console.log('dialog success callback,click button : ' + data.index);
},
cancel: function() {
console.log('dialog cancel callback');
},
});
}
}
```
## prompt.showActionMenu<sup>6+</sup><a name="section151752203513"></a>
showActionMenu\(Object\): void
Displays the operation menu.
- Parameters
<a name="table71817293515"></a>
<table><thead align="left"><tr id="row61820263513"><th class="cellrowborder" valign="top" width="13.089999999999998%" id="mcps1.1.5.1.1"><p id="p518192173514"><a name="p518192173514"></a><a name="p518192173514"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="24.8%" id="mcps1.1.5.1.2"><p id="p518132193511"><a name="p518132193511"></a><a name="p518132193511"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="9.46%" id="mcps1.1.5.1.3"><p id="p91872143516"><a name="p91872143516"></a><a name="p91872143516"></a>Mandatory</p>
</th>
<th class="cellrowborder" valign="top" width="52.65%" id="mcps1.1.5.1.4"><p id="p10188253515"><a name="p10188253515"></a><a name="p10188253515"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row10181213517"><td class="cellrowborder" valign="top" width="13.089999999999998%" headers="mcps1.1.5.1.1 "><p id="p41822163517"><a name="p41822163517"></a><a name="p41822163517"></a>title</p>
</td>
<td class="cellrowborder" valign="top" width="24.8%" headers="mcps1.1.5.1.2 "><p id="p1419923354"><a name="p1419923354"></a><a name="p1419923354"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="9.46%" headers="mcps1.1.5.1.3 "><p id="p1419927355"><a name="p1419927355"></a><a name="p1419927355"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="52.65%" headers="mcps1.1.5.1.4 "><p id="p201915217358"><a name="p201915217358"></a><a name="p201915217358"></a>Title of the text to display.</p>
</td>
</tr>
<tr id="row61902173517"><td class="cellrowborder" valign="top" width="13.089999999999998%" headers="mcps1.1.5.1.1 "><p id="p101914223513"><a name="p101914223513"></a><a name="p101914223513"></a>buttons</p>
</td>
<td class="cellrowborder" valign="top" width="24.8%" headers="mcps1.1.5.1.2 "><p id="p4191122359"><a name="p4191122359"></a><a name="p4191122359"></a>Array</p>
</td>
<td class="cellrowborder" valign="top" width="9.46%" headers="mcps1.1.5.1.3 "><p id="p101992133516"><a name="p101992133516"></a><a name="p101992133516"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="52.65%" headers="mcps1.1.5.1.4 "><p id="p191911293517"><a name="p191911293517"></a><a name="p191911293517"></a>Array of buttons in the dialog box. The array structure is <strong id="b195031228114514"><a name="b195031228114514"></a><a name="b195031228114514"></a>{text:'button', color: '#666666'}</strong>. One to six buttons are supported. If there are more than six buttons, the pop-up window will not be displayed.</p>
</td>
</tr>
<tr id="row14194216353"><td class="cellrowborder" valign="top" width="13.089999999999998%" headers="mcps1.1.5.1.1 "><p id="p720192133513"><a name="p720192133513"></a><a name="p720192133513"></a>success</p>
</td>
<td class="cellrowborder" valign="top" width="24.8%" headers="mcps1.1.5.1.2 "><p id="p102012103515"><a name="p102012103515"></a><a name="p102012103515"></a>(data: <a href="#table14215283515">TapIndex</a>) =&gt; void</p>
</td>
<td class="cellrowborder" valign="top" width="9.46%" headers="mcps1.1.5.1.3 "><p id="p52082183517"><a name="p52082183517"></a><a name="p52082183517"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="52.65%" headers="mcps1.1.5.1.4 "><p id="p920321358"><a name="p920321358"></a><a name="p920321358"></a>Called when the operation is successful.</p>
</td>
</tr>
<tr id="row120528354"><td class="cellrowborder" valign="top" width="13.089999999999998%" headers="mcps1.1.5.1.1 "><p id="p15201253516"><a name="p15201253516"></a><a name="p15201253516"></a>cancel</p>
</td>
<td class="cellrowborder" valign="top" width="24.8%" headers="mcps1.1.5.1.2 "><p id="p22213478481"><a name="p22213478481"></a><a name="p22213478481"></a>() =&gt; void</p>
</td>
<td class="cellrowborder" valign="top" width="9.46%" headers="mcps1.1.5.1.3 "><p id="p32010212359"><a name="p32010212359"></a><a name="p32010212359"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="52.65%" headers="mcps1.1.5.1.4 "><p id="p5205218353"><a name="p5205218353"></a><a name="p5205218353"></a>Called when the operation fails.</p>
</td>
</tr>
<tr id="row1320520356"><td class="cellrowborder" valign="top" width="13.089999999999998%" headers="mcps1.1.5.1.1 "><p id="p18206219351"><a name="p18206219351"></a><a name="p18206219351"></a>complete</p>
</td>
<td class="cellrowborder" valign="top" width="24.8%" headers="mcps1.1.5.1.2 "><p id="p1870474764820"><a name="p1870474764820"></a><a name="p1870474764820"></a>() =&gt; void</p>
</td>
<td class="cellrowborder" valign="top" width="9.46%" headers="mcps1.1.5.1.3 "><p id="p112119212353"><a name="p112119212353"></a><a name="p112119212353"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="52.65%" headers="mcps1.1.5.1.4 "><p id="p192110273519"><a name="p192110273519"></a><a name="p192110273519"></a>Called when the operation is complete.</p>
</td>
</tr>
</tbody>
</table>
**Table 1** TapIndex
<a name="table14215283515"></a>
<table><thead align="left"><tr id="row20211228358"><th class="cellrowborder" valign="top" width="13%" id="mcps1.2.4.1.1"><p id="p92112215358"><a name="p92112215358"></a><a name="p92112215358"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="12%" id="mcps1.2.4.1.2"><p id="p12112216351"><a name="p12112216351"></a><a name="p12112216351"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="75%" id="mcps1.2.4.1.3"><p id="p7211420357"><a name="p7211420357"></a><a name="p7211420357"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row162172113511"><td class="cellrowborder" valign="top" width="13%" headers="mcps1.2.4.1.1 "><p id="p6218203514"><a name="p6218203514"></a><a name="p6218203514"></a>tapIndex</p>
</td>
<td class="cellrowborder" valign="top" width="12%" headers="mcps1.2.4.1.2 "><p id="p32220217352"><a name="p32220217352"></a><a name="p32220217352"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="75%" headers="mcps1.2.4.1.3 "><p id="p16221326352"><a name="p16221326352"></a><a name="p16221326352"></a>Index of the selected button in the buttons array, starting from 0.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
export default {
showActionMenu() {
prompt.showActionMenu({
title: 'Title Info',
buttons: [
{
text: 'item1',
color: '#666666',
},
{
text: 'item2',
color: '#000000',
},
],
success: function(data) {
console.log('Operation succeeded. Click button: ' + data.tapIndex);
},
fail: function(data) {
console.log('Operation failed' + data.errMsg);
},
});
}
}
```
# Page Routing<a name="EN-US_TOPIC_0000001127125008"></a>
>![](../../public_sys-resources/icon-notice.gif) **NOTICE:**
>Page routing APIs can be invoked only after page rendering is complete. Do not call the APIs in **onInit** and **onReady** when the page is still in the rendering phase.
## Module to Import<a name="s0e7b1e85a4274f58a8206e0b065bd80c"></a>
```
import router from '@system.router';
```
## Required Permissions<a name="section11257113618419"></a>
None.
## router.push<a name="s938bf8d664f9475485e83d445c0eeeae"></a>
push\(Object\): void
Navigates to a specified page in the application based on the page URL and parameters.
- Parameters
<a name="t382f5b6619614d1b91de120862492040"></a>
<table><thead align="left"><tr id="r6739653f3ffd40a78caee6fdbf769957"><th class="cellrowborder" valign="top" width="8.08%" id="mcps1.1.5.1.1"><p id="a9c0eb79224544625b5727db432b60400"><a name="a9c0eb79224544625b5727db432b60400"></a><a name="a9c0eb79224544625b5727db432b60400"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="9.09%" id="mcps1.1.5.1.2"><p id="adde2d39df4c94fa6a0cd5d789edcb54c"><a name="adde2d39df4c94fa6a0cd5d789edcb54c"></a><a name="adde2d39df4c94fa6a0cd5d789edcb54c"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="9.09%" id="mcps1.1.5.1.3"><p id="a2413542f57b8404f9608a8fd82389d58"><a name="a2413542f57b8404f9608a8fd82389d58"></a><a name="a2413542f57b8404f9608a8fd82389d58"></a>Mandatory</p>
</th>
<th class="cellrowborder" valign="top" width="73.74000000000001%" id="mcps1.1.5.1.4"><p id="abb0e5e4afbab40679842c9fd5d3059a7"><a name="abb0e5e4afbab40679842c9fd5d3059a7"></a><a name="abb0e5e4afbab40679842c9fd5d3059a7"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="re4567a735be2433c92768a242fb60d3e"><td class="cellrowborder" valign="top" width="8.08%" headers="mcps1.1.5.1.1 "><p id="a7df856838e2f40b7825eea82b992e1bb"><a name="a7df856838e2f40b7825eea82b992e1bb"></a><a name="a7df856838e2f40b7825eea82b992e1bb"></a>uri</p>
</td>
<td class="cellrowborder" valign="top" width="9.09%" headers="mcps1.1.5.1.2 "><p id="a7b29f6b362f94f9d94c43a1974a183bf"><a name="a7b29f6b362f94f9d94c43a1974a183bf"></a><a name="a7b29f6b362f94f9d94c43a1974a183bf"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="9.09%" headers="mcps1.1.5.1.3 "><p id="a5f2b65a2289c46fdb759d2bd154aa414"><a name="a5f2b65a2289c46fdb759d2bd154aa414"></a><a name="a5f2b65a2289c46fdb759d2bd154aa414"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="73.74000000000001%" headers="mcps1.1.5.1.4 "><p id="a7c61031878fe4accae87a2f6c74b3b89"><a name="a7c61031878fe4accae87a2f6c74b3b89"></a><a name="a7c61031878fe4accae87a2f6c74b3b89"></a>URI of the destination page, in either of the following formats:</p>
<a name="ul1495111211908"></a><a name="ul1495111211908"></a><ul id="ul1495111211908"><li>Absolute path of the page. The value is available in the <strong id="b13087524598"><a name="b13087524598"></a><a name="b13087524598"></a>pages</strong> list in the <strong id="b1031317527590"><a name="b1031317527590"></a><a name="b1031317527590"></a>config.json</strong> file, for example:<a name="ul067818331541"></a><a name="ul067818331541"></a><ul id="ul067818331541"><li>pages/index/index</li><li>pages/detail/detail</li></ul>
</li><li>Particular path. If the URI is a slash (/), the home page is displayed.</li></ul>
</td>
</tr>
<tr id="row1411921117196"><td class="cellrowborder" valign="top" width="8.08%" headers="mcps1.1.5.1.1 "><p id="p172681322102310"><a name="p172681322102310"></a><a name="p172681322102310"></a>params</p>
</td>
<td class="cellrowborder" valign="top" width="9.09%" headers="mcps1.1.5.1.2 "><p id="p0268102210236"><a name="p0268102210236"></a><a name="p0268102210236"></a>Object</p>
</td>
<td class="cellrowborder" valign="top" width="9.09%" headers="mcps1.1.5.1.3 "><p id="p8268132242318"><a name="p8268132242318"></a><a name="p8268132242318"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="73.74000000000001%" headers="mcps1.1.5.1.4 "><p id="p13268162222310"><a name="p13268162222310"></a><a name="p13268162222310"></a>Data that needs to be passed to the destination page during navigation. After the destination page is displayed, it can use the passed data, for example, <strong id="b450711129286"><a name="b450711129286"></a><a name="b450711129286"></a>this.data1</strong> (<strong id="b105111112132816"><a name="b105111112132816"></a><a name="b105111112132816"></a>data1</strong> is a key in <strong id="b951212125286"><a name="b951212125286"></a><a name="b951212125286"></a>params</strong>). If there is the same key (for example, <strong id="b4486173192819"><a name="b4486173192819"></a><a name="b4486173192819"></a>data1</strong>) on the destination page, the passed <strong id="b148711382820"><a name="b148711382820"></a><a name="b148711382820"></a>data1</strong> value will overwrite the original value on the destination page.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
// Example code for the current page
export default {
pushPage() {
router.push({
uri: 'pages/routerpage2/routerpage2',
params: {
data1: 'message',
data2: {
data3: [123, 456, 789]
},
},
});
}
}
// Example code for the routerpage2 page
export default {
data: {
data1: 'default',
data2: {
data3: [1, 2, 3]
}
},
onInit() {
console.info('showData1:' + this.data1);
console.info('showData3:' + this.data2.data3);
}
}
```
>![](../../public_sys-resources/icon-note.gif) **NOTE:**
>The page routing stack supports a maximum of 32 pages.
## router.replace<a name="s6d485e6ae3064996a4de2f407bc4287d"></a>
replace\(Object\): void
Replaces the current page with another one in the application and destroys the current page.
- Parameter
<a name="t6b1726948831437cb2fabab6c2596bd6"></a>
<table><thead align="left"><tr id="rbac962f43cbb4e6da29b30573fcaf9f5"><th class="cellrowborder" valign="top" width="8%" id="mcps1.1.5.1.1"><p id="a16d15d7a316a40b19b98fbf3e709b198"><a name="a16d15d7a316a40b19b98fbf3e709b198"></a><a name="a16d15d7a316a40b19b98fbf3e709b198"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="10%" id="mcps1.1.5.1.2"><p id="aede000ddf8d44cf3ac35d395531daa72"><a name="aede000ddf8d44cf3ac35d395531daa72"></a><a name="aede000ddf8d44cf3ac35d395531daa72"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="10%" id="mcps1.1.5.1.3"><p id="af57857a2931e4bae9e1c01e953586b93"><a name="af57857a2931e4bae9e1c01e953586b93"></a><a name="af57857a2931e4bae9e1c01e953586b93"></a>Mandatory</p>
</th>
<th class="cellrowborder" valign="top" width="72%" id="mcps1.1.5.1.4"><p id="a69477f180eb04f92be9c7bfad4ea1a22"><a name="a69477f180eb04f92be9c7bfad4ea1a22"></a><a name="a69477f180eb04f92be9c7bfad4ea1a22"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="r907dc0ee7ae94b3aa4f42508bee0c51f"><td class="cellrowborder" valign="top" width="8%" headers="mcps1.1.5.1.1 "><p id="a61f128e79b3d4b6080143f140d8a6f5a"><a name="a61f128e79b3d4b6080143f140d8a6f5a"></a><a name="a61f128e79b3d4b6080143f140d8a6f5a"></a>uri</p>
</td>
<td class="cellrowborder" valign="top" width="10%" headers="mcps1.1.5.1.2 "><p id="aa6161c953b2d4cacb770343bbc7a76b9"><a name="aa6161c953b2d4cacb770343bbc7a76b9"></a><a name="aa6161c953b2d4cacb770343bbc7a76b9"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="10%" headers="mcps1.1.5.1.3 "><p id="ab2f2fcd3ccf94852aa2aa7aa4ad8bd6b"><a name="ab2f2fcd3ccf94852aa2aa7aa4ad8bd6b"></a><a name="ab2f2fcd3ccf94852aa2aa7aa4ad8bd6b"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="72%" headers="mcps1.1.5.1.4 "><p id="ae5f1acce286d407896f0da896d170c60"><a name="ae5f1acce286d407896f0da896d170c60"></a><a name="ae5f1acce286d407896f0da896d170c60"></a>URI of the destination page, in either of the following formats:</p>
<a name="ul15140171014517"></a><a name="ul15140171014517"></a><ul id="ul15140171014517"><li>Absolute path of the page. The value is available in the <strong id="b20876747250"><a name="b20876747250"></a><a name="b20876747250"></a>pages</strong> list in the <strong id="b78818471951"><a name="b78818471951"></a><a name="b78818471951"></a>config.json</strong> file, for example:<a name="ul15140810655"></a><a name="ul15140810655"></a><ul id="ul15140810655"><li>pages/index/index</li><li>pages/detail/detail</li></ul>
</li><li>Particular path. If the URI is a slash (/), the home page is displayed.</li></ul>
</td>
</tr>
<tr id="row43841058103012"><td class="cellrowborder" valign="top" width="8%" headers="mcps1.1.5.1.1 "><p id="p39929943120"><a name="p39929943120"></a><a name="p39929943120"></a>params</p>
</td>
<td class="cellrowborder" valign="top" width="10%" headers="mcps1.1.5.1.2 "><p id="p899219153118"><a name="p899219153118"></a><a name="p899219153118"></a>Object</p>
</td>
<td class="cellrowborder" valign="top" width="10%" headers="mcps1.1.5.1.3 "><p id="p29920903113"><a name="p29920903113"></a><a name="p29920903113"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="72%" headers="mcps1.1.5.1.4 "><p id="p2143918144613"><a name="p2143918144613"></a><a name="p2143918144613"></a>Data that needs to be passed to the destination page during navigation. After the destination page is displayed, it can use the passed data, for example, <strong id="b2097028603"><a name="b2097028603"></a><a name="b2097028603"></a>this.data1</strong> (<strong id="b131829408"><a name="b131829408"></a><a name="b131829408"></a>data1</strong> is a key in <strong id="b1480025986"><a name="b1480025986"></a><a name="b1480025986"></a>params</strong>). If there is the same key (for example, <strong id="b1750090512"><a name="b1750090512"></a><a name="b1750090512"></a>data1</strong>) on the destination page, the passed <strong id="b1441904809"><a name="b1441904809"></a><a name="b1441904809"></a>data1</strong> value will overwrite the original value on the destination page.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
// Example code for the current page
export default {
replacePage() {
router.replace({
uri: 'pages/detail/detail',
params: {
data1: 'message',
},
});
}
}
// Example code for the detail page
export default {
data: {
data1: 'default'
},
onInit() {
console.info('showData1:' + this.data1)
}
}
```
## router.back<a name="s3f958a02dde141e69b7f02f22fb2e401"></a>
back\(Object\): void
Returns to the previous page or a specified page.
- Parameter
<a name="t8645be119aea4edc9abfe4ac4b1a5457"></a>
<table><thead align="left"><tr id="r03b6547f30ab4ad898fe0604563e416f"><th class="cellrowborder" valign="top" width="25%" id="mcps1.1.5.1.1"><p id="a576cd1b8452644d8942cd1c1f478afa4"><a name="a576cd1b8452644d8942cd1c1f478afa4"></a><a name="a576cd1b8452644d8942cd1c1f478afa4"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="25%" id="mcps1.1.5.1.2"><p id="a13d651d4875643ccbcf890ad49a82bdf"><a name="a13d651d4875643ccbcf890ad49a82bdf"></a><a name="a13d651d4875643ccbcf890ad49a82bdf"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="25%" id="mcps1.1.5.1.3"><p id="a114a9b21dba74aaba51710352c28b128"><a name="a114a9b21dba74aaba51710352c28b128"></a><a name="a114a9b21dba74aaba51710352c28b128"></a>Mandatory</p>
</th>
<th class="cellrowborder" valign="top" width="25%" id="mcps1.1.5.1.4"><p id="a536b7faf84754ec9875bd10c5b1bd9ff"><a name="a536b7faf84754ec9875bd10c5b1bd9ff"></a><a name="a536b7faf84754ec9875bd10c5b1bd9ff"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="r121c662a232e4152ba0a678cb7ccc5a9"><td class="cellrowborder" valign="top" width="25%" headers="mcps1.1.5.1.1 "><p id="acca6b999d1fb40b28ee2f82f636aef65"><a name="acca6b999d1fb40b28ee2f82f636aef65"></a><a name="acca6b999d1fb40b28ee2f82f636aef65"></a>uri</p>
</td>
<td class="cellrowborder" valign="top" width="25%" headers="mcps1.1.5.1.2 "><p id="a58c83b28fb4649df96c79f922bdb81f3"><a name="a58c83b28fb4649df96c79f922bdb81f3"></a><a name="a58c83b28fb4649df96c79f922bdb81f3"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="25%" headers="mcps1.1.5.1.3 "><p id="aff1dee2aad364012ae008c45a9a36392"><a name="aff1dee2aad364012ae008c45a9a36392"></a><a name="aff1dee2aad364012ae008c45a9a36392"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="25%" headers="mcps1.1.5.1.4 "><p id="adf355f87a6e545a3b5cdcd5e78fcd8b3"><a name="adf355f87a6e545a3b5cdcd5e78fcd8b3"></a><a name="adf355f87a6e545a3b5cdcd5e78fcd8b3"></a>URI of the page to return to. If the specified page does not exist in the page stack, the app does not respond. If this parameter is not set, the app returns to the previous page.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
// index page
export default {
indexPushPage() {
router.push({
uri: 'pages/detail/detail',
});
}
}
// detail page
export default {
detailPushPage() {
router.push({
uri: 'pages/mall/mall',
});
}
}
// Navigate from the mall page to the detail page through router.back().
export default {
mallBackPage() {
router.back();
}
}
// Navigate from the detail page to the index page through router.back().
export default {
defaultBack() {
router.back();
}
}
// Return to the detail page through router.back().
export default {
backToDetail() {
router.back({uri:'pages/detail/detail'});
}
}
```
>![](../../public_sys-resources/icon-note.gif) **NOTE:**
>In the example, the **uri** field indicates the page route, which is specified by the **pages** list in the **config.json** file.
## router.clear<a name="sa5c3dfd1bb0d4b43906c3d770d6ab2d9"></a>
clear\(\): void
Clears all historical pages and retains only the current page at the top of the stack.
- Example
```
export default {
clearPage() {
router.clear();
}
}
```
## router.getLength<a name="s3f121f4005934fda9a1830a909c92c25"></a>
getLength\(\): string
Obtains the number of pages in the current stack.
- Return values
<a name="t69833877986140cbb7fc7a25b411622b"></a>
<table><thead align="left"><tr id="rad0dfd50874c4a9e8509cc0661ecc869"><th class="cellrowborder" valign="top" width="12.920000000000002%" id="mcps1.1.3.1.1"><p id="add584a11aa0e49928b79176951aa21e1"><a name="add584a11aa0e49928b79176951aa21e1"></a><a name="add584a11aa0e49928b79176951aa21e1"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="87.08%" id="mcps1.1.3.1.2"><p id="af65e00289a1f4616861727b28ffc14f2"><a name="af65e00289a1f4616861727b28ffc14f2"></a><a name="af65e00289a1f4616861727b28ffc14f2"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="r12b8d9cc2831480e8f0f16bd0e992b30"><td class="cellrowborder" valign="top" width="12.920000000000002%" headers="mcps1.1.3.1.1 "><p id="ae731080460894a68b064fba7c893c1e8"><a name="ae731080460894a68b064fba7c893c1e8"></a><a name="ae731080460894a68b064fba7c893c1e8"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="87.08%" headers="mcps1.1.3.1.2 "><p id="affc1140bcdf940de8705c921ccd68da5"><a name="affc1140bcdf940de8705c921ccd68da5"></a><a name="affc1140bcdf940de8705c921ccd68da5"></a>Number of pages in the stack. The maximum value is <strong id="b15825419161611"><a name="b15825419161611"></a><a name="b15825419161611"></a>32</strong>.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
export default {
getLength() {
var size = router.getLength();
console.log('pages stack size = ' + size);
}
}
```
## router.getState<a name="s8843a443a12048e68e33f586aee8dc34"></a>
getState\(\): <[RouterState](#tf9e3eb9ef0aa4d9880f996fe6afa6d1b)\>
Obtains information about the current page state.
- Return values
**Table 1** RouterState
<a name="tf9e3eb9ef0aa4d9880f996fe6afa6d1b"></a>
<table><thead align="left"><tr id="redea81f1cfff4122b733df3049d3d8ba"><th class="cellrowborder" valign="top" width="11%" id="mcps1.2.4.1.1"><p id="ac1f54204219e42e58810bacc1e221e3c"><a name="ac1f54204219e42e58810bacc1e221e3c"></a><a name="ac1f54204219e42e58810bacc1e221e3c"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="11%" id="mcps1.2.4.1.2"><p id="a811d9c5a5a2e402bb2d429d14e07af79"><a name="a811d9c5a5a2e402bb2d429d14e07af79"></a><a name="a811d9c5a5a2e402bb2d429d14e07af79"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="78%" id="mcps1.2.4.1.3"><p id="ab0d65ba7195a4b6aa51a1c8be829da4b"><a name="ab0d65ba7195a4b6aa51a1c8be829da4b"></a><a name="ab0d65ba7195a4b6aa51a1c8be829da4b"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="r654e450f29d34ba2a43c4baf828242bc"><td class="cellrowborder" valign="top" width="11%" headers="mcps1.2.4.1.1 "><p id="aa5d3616785ec46b88eab2b7a0c97c4e3"><a name="aa5d3616785ec46b88eab2b7a0c97c4e3"></a><a name="aa5d3616785ec46b88eab2b7a0c97c4e3"></a>index</p>
</td>
<td class="cellrowborder" valign="top" width="11%" headers="mcps1.2.4.1.2 "><p id="aaa82d880dc7d4221b2a65a202a0b34b4"><a name="aaa82d880dc7d4221b2a65a202a0b34b4"></a><a name="aaa82d880dc7d4221b2a65a202a0b34b4"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="78%" headers="mcps1.2.4.1.3 "><p id="p1979431135"><a name="p1979431135"></a><a name="p1979431135"></a>Index of the current page in the stack.</p>
<div class="note" id="note136715361314"><a name="note136715361314"></a><a name="note136715361314"></a><span class="notetitle"> NOTE: </span><div class="notebody"><p id="p1167137132"><a name="p1167137132"></a><a name="p1167137132"></a>The index starts from 1 from the bottom to the top of the stack.</p>
</div></div>
</td>
</tr>
<tr id="r5d033b0d902e4a83aaf66db1902c5154"><td class="cellrowborder" valign="top" width="11%" headers="mcps1.2.4.1.1 "><p id="ae78d89cb022b4505984ae62d800f246c"><a name="ae78d89cb022b4505984ae62d800f246c"></a><a name="ae78d89cb022b4505984ae62d800f246c"></a>name</p>
</td>
<td class="cellrowborder" valign="top" width="11%" headers="mcps1.2.4.1.2 "><p id="a75e18952ce3a4df3a9dd4af9e20f8df1"><a name="a75e18952ce3a4df3a9dd4af9e20f8df1"></a><a name="a75e18952ce3a4df3a9dd4af9e20f8df1"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="78%" headers="mcps1.2.4.1.3 "><p id="acf2d1680871b4630b121fc51835d5144"><a name="acf2d1680871b4630b121fc51835d5144"></a><a name="acf2d1680871b4630b121fc51835d5144"></a>Name of the current page, that is, the file name.</p>
</td>
</tr>
<tr id="ra0e0c300267144a5806efae3aaa498b7"><td class="cellrowborder" valign="top" width="11%" headers="mcps1.2.4.1.1 "><p id="add88e87efa6242f5a1679e71cf3f31a1"><a name="add88e87efa6242f5a1679e71cf3f31a1"></a><a name="add88e87efa6242f5a1679e71cf3f31a1"></a>path</p>
</td>
<td class="cellrowborder" valign="top" width="11%" headers="mcps1.2.4.1.2 "><p id="a92fb0e8fa14446ea91898b2a8867b2ef"><a name="a92fb0e8fa14446ea91898b2a8867b2ef"></a><a name="a92fb0e8fa14446ea91898b2a8867b2ef"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="78%" headers="mcps1.2.4.1.3 "><p id="a8f4870ec81224a75b82268b19b7c76de"><a name="a8f4870ec81224a75b82268b19b7c76de"></a><a name="a8f4870ec81224a75b82268b19b7c76de"></a>Path of the current page.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
export default {
getState() {
var page = router.getState();
console.log('current index = ' + page.index);
console.log('current name = ' + page.name);
console.log('current path = ' + page.path);
}
}
```
## router.enableAlertBeforeBackPage<sup>6+</sup><a name="section54535465226"></a>
enableAlertBeforeBackPage\(Object\): void
Enables the display of a confirm dialog for returning to the previous page.
- Parameter
<a name="table2013713511258"></a>
<table><thead align="left"><tr id="row11137651102511"><th class="cellrowborder" valign="top" width="15.15%" id="mcps1.1.5.1.1"><p id="p513895122518"><a name="p513895122518"></a><a name="p513895122518"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="20.73%" id="mcps1.1.5.1.2"><p id="p9138195115258"><a name="p9138195115258"></a><a name="p9138195115258"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="11.24%" id="mcps1.1.5.1.3"><p id="p191381851162514"><a name="p191381851162514"></a><a name="p191381851162514"></a>Mandatory</p>
</th>
<th class="cellrowborder" valign="top" width="52.88%" id="mcps1.1.5.1.4"><p id="p1513812515252"><a name="p1513812515252"></a><a name="p1513812515252"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row2013875118251"><td class="cellrowborder" valign="top" width="15.15%" headers="mcps1.1.5.1.1 "><p id="p19138125119252"><a name="p19138125119252"></a><a name="p19138125119252"></a>message</p>
</td>
<td class="cellrowborder" valign="top" width="20.73%" headers="mcps1.1.5.1.2 "><p id="p1138751172512"><a name="p1138751172512"></a><a name="p1138751172512"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="11.24%" headers="mcps1.1.5.1.3 "><p id="p4138651182517"><a name="p4138651182517"></a><a name="p4138651182517"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="52.88%" headers="mcps1.1.5.1.4 "><p id="p93900438261"><a name="p93900438261"></a><a name="p93900438261"></a>Content of the confirm dialog.</p>
</td>
</tr>
<tr id="row15138551132517"><td class="cellrowborder" valign="top" width="15.15%" headers="mcps1.1.5.1.1 "><p id="p15138451162516"><a name="p15138451162516"></a><a name="p15138451162516"></a>success</p>
</td>
<td class="cellrowborder" valign="top" width="20.73%" headers="mcps1.1.5.1.2 "><p id="p413845120256"><a name="p413845120256"></a><a name="p413845120256"></a>() =&gt; void</p>
</td>
<td class="cellrowborder" valign="top" width="11.24%" headers="mcps1.1.5.1.3 "><p id="p16138115122510"><a name="p16138115122510"></a><a name="p16138115122510"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="52.88%" headers="mcps1.1.5.1.4 "><p id="p12138451192519"><a name="p12138451192519"></a><a name="p12138451192519"></a>Called when the operation is successful.</p>
</td>
</tr>
<tr id="row171392051182510"><td class="cellrowborder" valign="top" width="15.15%" headers="mcps1.1.5.1.1 "><p id="p511719107271"><a name="p511719107271"></a><a name="p511719107271"></a>fail</p>
</td>
<td class="cellrowborder" valign="top" width="20.73%" headers="mcps1.1.5.1.2 "><p id="p913910518259"><a name="p913910518259"></a><a name="p913910518259"></a>() =&gt; void</p>
</td>
<td class="cellrowborder" valign="top" width="11.24%" headers="mcps1.1.5.1.3 "><p id="p15139125132515"><a name="p15139125132515"></a><a name="p15139125132515"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="52.88%" headers="mcps1.1.5.1.4 "><p id="p10139165115250"><a name="p10139165115250"></a><a name="p10139165115250"></a>Called when the operation fails.</p>
</td>
</tr>
<tr id="row1958621632720"><td class="cellrowborder" valign="top" width="15.15%" headers="mcps1.1.5.1.1 "><p id="p1858691616275"><a name="p1858691616275"></a><a name="p1858691616275"></a>complete</p>
</td>
<td class="cellrowborder" valign="top" width="20.73%" headers="mcps1.1.5.1.2 "><p id="p10586171622715"><a name="p10586171622715"></a><a name="p10586171622715"></a>() =&gt; void</p>
</td>
<td class="cellrowborder" valign="top" width="11.24%" headers="mcps1.1.5.1.3 "><p id="p158616166272"><a name="p158616166272"></a><a name="p158616166272"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="52.88%" headers="mcps1.1.5.1.4 "><p id="p15586191613271"><a name="p15586191613271"></a><a name="p15586191613271"></a>Called when the operation is complete.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
export default {
enableAlertBeforeBackPage() {
router.enableAlertBeforeBackPage({
message: 'Message Info',
success: function() {
console.log('success');
},
fail: function() {
console.log('fail');
},
});
}
}
```
## router.disableAlertBeforeBackPage<sup>6+</sup><a name="section08671236103317"></a>
disableAlertBeforeBackPage\(Object\): void
Disables the display of a confirm dialog for returning to the previous page.
- Parameters
<a name="table5868103673314"></a>
<table><thead align="left"><tr id="row1286810361332"><th class="cellrowborder" valign="top" width="15.15%" id="mcps1.1.5.1.1"><p id="p17868133623319"><a name="p17868133623319"></a><a name="p17868133623319"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="20.96%" id="mcps1.1.5.1.2"><p id="p1286853611337"><a name="p1286853611337"></a><a name="p1286853611337"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="10.780000000000001%" id="mcps1.1.5.1.3"><p id="p1386873613319"><a name="p1386873613319"></a><a name="p1386873613319"></a>Mandatory</p>
</th>
<th class="cellrowborder" valign="top" width="53.11%" id="mcps1.1.5.1.4"><p id="p9868103633315"><a name="p9868103633315"></a><a name="p9868103633315"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row68681236103317"><td class="cellrowborder" valign="top" width="15.15%" headers="mcps1.1.5.1.1 "><p id="p38681536103317"><a name="p38681536103317"></a><a name="p38681536103317"></a>success</p>
</td>
<td class="cellrowborder" valign="top" width="20.96%" headers="mcps1.1.5.1.2 "><p id="p19449194212534"><a name="p19449194212534"></a><a name="p19449194212534"></a>() =&gt; void</p>
</td>
<td class="cellrowborder" valign="top" width="10.780000000000001%" headers="mcps1.1.5.1.3 "><p id="p1686943693314"><a name="p1686943693314"></a><a name="p1686943693314"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="53.11%" headers="mcps1.1.5.1.4 "><p id="p086920362331"><a name="p086920362331"></a><a name="p086920362331"></a>Called when the operation is successful.</p>
</td>
</tr>
<tr id="row0869183673320"><td class="cellrowborder" valign="top" width="15.15%" headers="mcps1.1.5.1.1 "><p id="p286913367339"><a name="p286913367339"></a><a name="p286913367339"></a>fail</p>
</td>
<td class="cellrowborder" valign="top" width="20.96%" headers="mcps1.1.5.1.2 "><p id="p54408438532"><a name="p54408438532"></a><a name="p54408438532"></a>() =&gt; void</p>
</td>
<td class="cellrowborder" valign="top" width="10.780000000000001%" headers="mcps1.1.5.1.3 "><p id="p1486923633315"><a name="p1486923633315"></a><a name="p1486923633315"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="53.11%" headers="mcps1.1.5.1.4 "><p id="p138698363338"><a name="p138698363338"></a><a name="p138698363338"></a>Called when the operation fails.</p>
</td>
</tr>
<tr id="row1186903613336"><td class="cellrowborder" valign="top" width="15.15%" headers="mcps1.1.5.1.1 "><p id="p88691236153316"><a name="p88691236153316"></a><a name="p88691236153316"></a>complete</p>
</td>
<td class="cellrowborder" valign="top" width="20.96%" headers="mcps1.1.5.1.2 "><p id="p66221444175316"><a name="p66221444175316"></a><a name="p66221444175316"></a>() =&gt; void</p>
</td>
<td class="cellrowborder" valign="top" width="10.780000000000001%" headers="mcps1.1.5.1.3 "><p id="p3869133633316"><a name="p3869133633316"></a><a name="p3869133633316"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="53.11%" headers="mcps1.1.5.1.4 "><p id="p20869203616332"><a name="p20869203616332"></a><a name="p20869203616332"></a>Called when the operation is complete.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
export default {
disableAlertBeforeBackPage() {
router.disableAlertBeforeBackPage({
success: function() {
console.log('success');
},
fail: function() {
console.log('fail');
},
});
}
}
```
# ServiceExtension # ServiceExtensionAbility
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > 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.
Provides APIs related to **ServiceExtension**. Provides APIs related to **ServiceExtension**.
...@@ -10,13 +10,13 @@ Provides APIs related to **ServiceExtension**. ...@@ -10,13 +10,13 @@ Provides APIs related to **ServiceExtension**.
## Modules to Import ## Modules to Import
``` ```
import ServiceExtension from '@ohos.application.ServiceExtension'; import ServiceExtension from '@ohos.application.ServiceExtensionAbility';
``` ```
## Required Permissions ## Required Permissions
None None.
## Attributes ## Attributes
...@@ -26,7 +26,7 @@ None ...@@ -26,7 +26,7 @@ None
| context | [ServiceExtensionContext](js-apis-service-extension-context.md) | Yes| No| Service extension context, which is inherited from **ExtensionContext**.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core| | context | [ServiceExtensionContext](js-apis-service-extension-context.md) | Yes| No| Service extension context, which is inherited from **ExtensionContext**.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
## onCreate ## ServiceExtensionAbility.onCreate
onCreate(want: Want): void; onCreate(want: Want): void;
...@@ -51,7 +51,7 @@ Called when an extension is created to initialize the service logic. ...@@ -51,7 +51,7 @@ Called when an extension is created to initialize the service logic.
``` ```
## onDestroy ## ServiceExtensionAbility.onDestroy
onDestroy(): void; onDestroy(): void;
...@@ -70,7 +70,7 @@ Called when this extension is destroyed to clear resources. ...@@ -70,7 +70,7 @@ Called when this extension is destroyed to clear resources.
``` ```
## onRequest ## ServiceExtensionAbility.onRequest
onRequest(want: Want, startId: number): void; onRequest(want: Want, startId: number): void;
...@@ -96,7 +96,7 @@ Called after **onCreate** is invoked when an ability is started by calling **sta ...@@ -96,7 +96,7 @@ Called after **onCreate** is invoked when an ability is started by calling **sta
``` ```
## onConnect ## ServiceExtensionAbility.onConnect
onConnect(want: Want): rpc.RemoteObject; onConnect(want: Want): rpc.RemoteObject;
...@@ -136,7 +136,7 @@ Called after **onCreate** is invoked when an ability is started by calling **con ...@@ -136,7 +136,7 @@ Called after **onCreate** is invoked when an ability is started by calling **con
``` ```
## onDisconnect ## ServiceExtensionAbility.onDisconnect
onDisconnect(want: Want): void; onDisconnect(want: Want): void;
......
# WantAgent Module
>**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
```js
import WantAgent from '@ohos.wantAgent';
```
## WantAgent.getWantAgent
getWantAgent(info: WantAgentInfo, callback: AsyncCallback\<WantAgent\>): void
Obtains a **WantAgent** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Readable| Writable | Type | Mandatory| Description |
| -------- | --- | ---- | -------------------------- | ---- | ----------------------- |
| info | Yes | No | WantAgentInfo | Yes | Information about the **WantAgent** object to obtain. |
| callback | Yes | No | AsyncCallback\<WantAgent\> | Yes | Callback used to return the **WantAgent** object.|
**Example**
```js
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// getWantAgent callback
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
}
// WantAgentInfo object
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
```
## WantAgent.getWantAgent
getWantAgent(info: WantAgentInfo): Promise\<WantAgent\>
Obtains a **WantAgent** object. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Readable| Writable | Type | Mandatory| Description |
| ---- | --- | ---- | ------------- | ---- | ------------- |
| info | Yes | No | WantAgentInfo | Yes | Information about the **WantAgent** object to obtain.|
**Return value**
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<WantAgent\> | Promise used to return the **WantAgent** object.|
**Example**
```js
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgentInfo object
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
});
```
## WantAgent.getBundleName
getBundleName(agent: WantAgent, callback: AsyncCallback\<string\>): void
Obtains the bundle name of a **WantAgent** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Readable| Writable | Type | Mandatory| Description |
| -------- | --- | ---- | ----------------------- | ---- | --------------------------------- |
| agent | Yes | No | WantAgent | Yes | **WantAgent** object whose bundle name is to be obtained. |
| callback | Yes | No | AsyncCallback\<string\> | Yes | Callback used to return the bundle name.|
**Example**
```js
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object
var wantAgent;
// getWantAgent callback
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
// WantAgentInfo object
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
// getBundleName callback
function getBundleNameCallback(err, data) {
console.info("==========================>getBundleNameCallback=======================>");
}
WantAgent.getBundleName(wantAgent, getBundleNameCallback)
```
## WantAgent.getBundleName
getBundleName(agent: WantAgent): Promise\<string\>
Obtains the bundle name of a **WantAgent** object. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Readable| Writable| Type | Mandatory| Description |
| ----- | --- | ---- | --------- | ---- | ------------- |
| agent | Yes | No | WantAgent | Yes | **WantAgent** object whose bundle name is to be obtained.|
**Return value**
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<string\> | Promise used to return the bundle name.|
**Example**
```js
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object
var wantAgent;
// WantAgentInfo object
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
wantAgent = data;
});
WantAgent.getBundleName(wantAgent).then((data) => {
console.info("==========================>getBundleNameCallback=======================>");
});
```
## WantAgent.getUid
getUid(agent: WantAgent, callback: AsyncCallback\<number\>): void
Obtains the user ID of a **WantAgent** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | --- | ---- | ----------------------- | ---- | ----------------------------------- |
| agent | Yes | No | WantAgent | Yes | **WantAgent** object whose user ID is to be obtained. |
| callback | Yes | No | AsyncCallback\<number\> | Yes | Callback used to return the user ID.|
**Example**
```js
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object
var wantAgent;
// getWantAgent callback
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
// WantAgentInfo object
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
// getUid callback
function getUidCallback(err, data) {
console.info("==========================>getUidCallback=======================>");
}
WantAgent.getUid(wantAgent, getUidCallback)
```
## WantAgent.getUid
getUid(agent: WantAgent): Promise\<number\>
Obtains the user ID of a **WantAgent** object. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Readable| Writable| Type | Mandatory| Description |
| ----- | --- | ---- | --------- | ---- | ------------- |
| agent | Yes | No | WantAgent | Yes | **WantAgent** object whose user ID is to be obtained.|
**Return value**
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<number\> | Promise used to return the user ID.|
**Example**
```js
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object
var wantAgent;
// WantAgentInfo object
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
wantAgent = data;
});
WantAgent.getUid(wantAgent).then((data) => {
console.info("==========================>getUidCallback=======================>");
});
```
## WantAgent.getWant
getWant(agent: WantAgent, callback: AsyncCallback\<Want\>): void
Obtains the want in a **WantAgent** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | --- | ---- | --------------------- | ---- | ------------------------------- |
| agent | Yes | No | WantAgent | Yes | **WantAgent** object whose want is to be obtained. |
| callback | Yes | No | AsyncCallback\<Want\> | Yes | Callback used to return the want.|
**Example**
```js
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object
var wantAgent;
// getWantAgent callback
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
// WantAgentInfo object
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
// getWant callback
function getWantCallback(err, data) {
console.info("==========================>getWantCallback=======================>");
}
WantAgent.getWant(wantAgent, getWantCallback)
```
## WantAgent.getWant
getWant(agent: WantAgent): Promise\<Want\>
Obtains the want in a **WantAgent** object. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Readable| Writable| Type | Mandatory| Description |
| ----- | --- | ---- | --------- | ---- | ------------- |
| agent | Yes | No | WantAgent | Yes | **WantAgent** object whose want is to be obtained.|
**Return value**
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<Want\> | Promise used to return the want.|
**Example**
```js
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object
var wantAgent;
// WantAgentInfo object
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
wantAgent = data;
});
WantAgent.getWant(wantAgent).then((data) => {
console.info("==========================>getWantCallback=======================>");
});
```
## WantAgent.cancel
cancel(agent: WantAgent, callback: AsyncCallback\<void\>): void
Cancels a **WantAgent** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Readable| Writable| Type | Mandatory| Description |
| -------- | --- | ---- | --------------------- | ---- | --------------------------- |
| agent | Yes | No | WantAgent | Yes | **WantAgent** object to cancel. |
| callback | Yes | No | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Example**
```js
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object
var wantAgent;
// getWantAgent callback
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
// WantAgentInfo object
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
// cancel callback
function cancelCallback(err, data) {
console.info("==========================>cancelCallback=======================>");
}
WantAgent.cancel(wantAgent, cancelCallback)
```
## WantAgent.cancel
cancel(agent: WantAgent): Promise\<void\>
Cancels a **WantAgent** object. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Readable| Writable| Type | Mandatory| Description |
| ----- | --- | ---- | --------- | ---- | ------------- |
| agent | Yes | No | WantAgent | Yes | **WantAgent** object to cancel.|
**Example**
```js
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object
var wantAgent;
// WantAgentInfo object
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
wantAgent = data;
});
WantAgent.cancel(wantAgent).then((data) => {
console.info("==========================>cancelCallback=======================>");
});
```
## WantAgent.trigger
trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback\<CompleteData\>): void
Triggers a **WantAgent** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Readable| Writable| Type | Mandatory| Description |
| ----------- | --- | ---- | ----------------------------- | ---- | ------------------------------- |
| agent | Yes | No | WantAgent | Yes | **WantAgent** object to trigger. |
| triggerInfo | Yes | No | TriggerInfo | Yes | **TriggerInfo** object. |
| callback | Yes | No | AsyncCallback\<CompleteData\> | Yes | Callback used to return the result.|
**Example**
```js
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object
var wantAgent;
// getWantAgent callback
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
// WantAgentInfo object
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
// trigger callback
function triggerCallback(err, data) {
console.info("==========================>triggerCallback=======================>");
}
var triggerInfo = {
code:0
}
WantAgent.trigger(wantAgent, triggerInfo, triggerCallback)
```
## WantAgent.equal
equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback\<boolean\>): void
Checks whether two **WantAgent** objects are equal. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Readable| Writable| Type | Mandatory| Description |
| ---------- | --- | ---- | ------------------------ | ---- | --------------------------------------- |
| agent | Yes | No | WantAgent | Yes | The first **WantAgent** object. |
| otherAgent | Yes | No | WantAgent | Yes | The second **WantAgent** object. |
| callback | Yes | No | AsyncCallback\<boolean\> | Yes | Callback used to return the result.|
**Example**
```js
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object
var wantAgent1;
var wantAgent2;
// getWantAgent callback
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent1 = data;
wantAgent2 = data;
} else {
console.info('----getWantAgent failed!----');
}
}
// WantAgentInfo object
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
// equal callback
function equalCallback(err, data) {
console.info("==========================>equalCallback=======================>");
}
WantAgent.equal(wantAgent1, wantAgent2, equalCallback)
```
## WantAgent.equal
equal(agent: WantAgent, otherAgent: WantAgent): Promise\<boolean\>
Checks whether two **WantAgent** objects are equal. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Readable| Writable| Type | Mandatory| Description |
| ---------- | --- | ---- | --------- | ---- | ------------- |
| agent | Yes | No | WantAgent | Yes | The first **WantAgent** object.|
| otherAgent | Yes | No | WantAgent | Yes | The second **WantAgent** object.|
**Return value**
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result.|
**Example**
```js
import WantAgent from '@ohos.wantAgent';
import { OperationType, WantAgentFlags } from '@ohos.wantagent';
// WantAgent object
var wantAgent1;
var wantAgent2;
// WantAgentInfo object
var wantAgentInfo = {
wants: [
{
deviceId: "deviceId",
bundleName: "com.neu.setResultOnAbilityResultTest1",
abilityName: "com.example.test.MainAbility",
action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
}
],
operationType: OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
}
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
console.info("==========================>getWantAgentCallback=======================>");
wantAgent1 = data;
wantAgent2 = data;
});
WantAgent.equal(wantAgent1, wantAgent2).then((data) => {
console.info("==========================>equalCallback=======================>");
});
```
## WantAgentInfo
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Readable| Writable| Type | Mandatory| Description |
| -------------- | --- | ---- | ------------------------------- | ---- | ---------------------- |
| wants | Yes | Yes | Array\<Want\> | Yes | Array of all **Want** objects. |
| operationType | Yes | Yes | wantAgent.OperationType | Yes | Action type. |
| requestCode | Yes | Yes | number | Yes | Request code defined by the user.|
| wantAgentFlags | Yes | Yes | Array<wantAgent.WantAgentFlags> | No | Array of flags for using the **WantAgent** object. |
| extraInfo | Yes | Yes | {[key: string]: any} | No | Extra information. |
## WantAgentFlags
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description |
| ------------------- | -------------- | ------------------------------------------------------------ |
| ONE_TIME_FLAG | WantAgentFlags | The **WantAgent** object can be used only once. |
| NO_BUILD_FLAG | WantAgentFlags | The **WantAgent** object does not exist and hence it is not created. In this case, **null** is returned. |
| CANCEL_PRESENT_FLAG | WantAgentFlags | The existing **WantAgent** object should be canceled before a new object is generated.|
| UPDATE_PRESENT_FLAG | WantAgentFlags | Extra information of the existing **WantAgent** object is replaced with that of the new object.|
| CONSTANT_FLAG | WantAgentFlags | The **WantAgent** object is immutable. |
| REPLACE_ELEMENT | WantAgentFlags | The **element** attribute of the current **Want** can be replaced by the **element** attribute of the **Want** in **WantAgent.trigger()**.|
| REPLACE_ACTION | WantAgentFlags | The **action** attribute of the current **Want** can be replaced by the **action** attribute of the **Want** in **WantAgent.trigger()**.|
| REPLACE_URI | WantAgentFlags | The **uri** attribute of the current **Want** can be replaced by the **uri** attribute of the **Want** in **WantAgent.trigger()**.|
| REPLACE_ENTITIES | WantAgentFlags | The **entities** attribute of the current **Want** can be replaced by the **entities** attribute of the **Want** in **WantAgent.trigger()**.|
| REPLACE_BUNDLE | WantAgentFlags | The **bundleName** attribute of the current **Want** can be replaced by the **bundleName** attribute of **Want** in **WantAgent.trigger()**.|
## OperationType
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description |
| ----------------- | ------------- | ------------------------- |
| UNKNOWN_TYPE | OperationType | Unknown operation type. |
| START_ABILITY | OperationType | Starts an ability with a UI.|
| START_ABILITIES | OperationType | Starts multiple abilities with a UI.|
| START_SERVICE | OperationType | Starts an ability without a UI.|
| SEND_COMMON_EVENT | OperationType | Sends a common event. |
## CompleteData
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Readable| Writable| Type | Mandatory| Description |
| -------------- | --- | ---- | ------------------------------ | ---- | ---------------------- |
| info | Yes | Yes | WantAgent | Yes | A triggered **WantAgent** object. |
| want | Yes | Yes | Want | Yes | An existing triggered **want**. |
| finalCode | Yes | Yes | number | Yes | Request code that triggers the **WantAgent** object.|
| finalData | Yes | Yes | string | No | Final data collected by the common event. |
| extraInfo | Yes | Yes | {[key: string]: any} | No | Extra information. |
## TriggerInfo
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Readable| Writable| Type | Mandatory| Description |
| ---------- | --- | ---- | -------------------- | ---- | ----------- |
| code | Yes | Yes | number | Yes | Result code.|
| want | Yes | Yes | Want | No | Want. |
| permission | Yes | Yes | string | No | Permission. |
| extraInfo | Yes | Yes | {[key: string]: any} | No | Extra information. |
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册