• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.dialogSession (dialogSession)
2
3The **dialogSession** module provides APIs related to the dialog box.
4
5> **NOTE**
6>
7> - The initial APIs of this module are supported since API version 11. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8> - The APIs of this module can be used only in the stage model.
9> - The APIs provided by this module are system APIs.
10
11## Modules to Import
12
13```ts
14import dialogSession from '@ohos.app.ability.dialogSession';
15```
16
17## DialogAbilityInfo
18
19Provides DialogAbility information, including the bundle name, module name, and ability name.
20
21**System capability**: SystemCapability.Ability.AbilityRuntime.Core
22
23| Name| Type| Read-only| Mandatory| Description|
24| -------- | -------- | -------- | -------- | -------- |
25| bundleName | string | Yes| Yes| Bundle name.|
26| moduleName | string | Yes| Yes| Module name.|
27| abilityName | string | Yes| Yes| Ability name.|
28| abilityIconId | number | Yes| Yes| ID of the ability icon.|
29| abilityLabelId | number | Yes| Yes| ID of the ability label.|
30| bundleIconId | number | Yes| Yes| ID of the bundle icon.|
31| bundleLabelId | number | Yes| Yes| ID of the bundle label.|
32
33## DialogSessionInfo
34
35Provides session information, including the requester information, target application list, and other parameters.
36
37**System capability**: SystemCapability.Ability.AbilityRuntime.Core
38
39| Name| Type| Read-only| Mandatory| Description|
40| -------- | -------- | -------- | -------- | -------- |
41| callerAbilityInfo | [DialogAbilityInfo](js-apis-app-ability-dialogSession.md#dialogabilityinfo)| Yes| Yes| Ability information of the requester.|
42| targetAbilityInfos | Array\<[DialogAbilityInfo](js-apis-app-ability-dialogSession.md#dialogabilityinfo)\> | Yes| Yes| Target application list.|
43| parameters | Record<string, Object> | Yes| No| Other parameters.|
44
45## getDialogSessionInfo
46
47getDialogSessionInfo(dialogSessionId: string): [DialogSessionInfo](js-apis-app-ability-dialogSession.md#dialogsessioninfo)
48
49Obtains the session information based on the session ID.
50
51**System API**: This is a system API.
52
53**System capability**: SystemCapability.Ability.AbilityRuntime.Core
54
55**Parameters**
56
57  | Name| Type| Mandatory| Description|
58  | -------- | -------- | -------- | -------- |
59  | dialogSessionId | string | Yes| Session ID.|
60
61**Return value**
62
63  | Type| Description|
64  | -------- | -------- |
65  | [DialogSessionInfo](js-apis-app-ability-dialogSession.md#dialogsessioninfo) | Session information.|
66
67**Error codes**
68
69| ID| Error Message|
70| ------- | -------- |
71| 16000005 | The specified process does not have the permission. |
72| 16000006  | Cross-user operations are not allowed. |
73| 16000050  | Internal error. |
74
75For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
76
77**Example**
78
79```ts
80import dialogSession from '@ohos.app.ability.dialogSession';
81import Want from '@ohos.app.ability.Want';
82
83// want is specified by the system. dialogSessionId is a built-in parameter.
84let dialogSessionId: string = want?.parameters?.dialogSessionId;
85
86// Obtain DialogSessionInfo.
87let dialogSessionInfo: dialogSession.DialogSessionInfo = dialogSession.getDialogSessionInfo(dialogSessionId);
88```
89
90## sendDialogResult
91
92sendDialogResult(dialogSessionId: string, targetWant: Want, isAllowed: boolean, callback: AsyncCallback\<void\>): void
93
94Sends a request for a dialog box. This API uses an asynchronous callback to return the result.
95
96**System API**: This is a system API.
97
98**System capability**: SystemCapability.Ability.AbilityRuntime.Core
99
100**Parameters**
101
102  | Name| Type| Mandatory| Description|
103  | -------- | -------- | -------- | -------- |
104  | dialogSessionId | string | Yes| Session ID.|
105  | targetWant | Want | Yes| Target of the request.|
106  | isAllowed | boolean | Yes| Request result.|
107  | callback | AsyncCallback\<void\> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
108
109**Error codes**
110
111| ID| Error Message|
112| ------- | -------- |
113| 16000005 | The specified process does not have the permission. |
114| 16000006  | Cross-user operations are not allowed. |
115| 16000050  | Internal error. |
116
117For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
118
119**Example**
120
121```ts
122import dialogSession from '@ohos.app.ability.dialogSession';
123import Want from '@ohos.app.ability.Want';
124
125// want is specified by the system. dialogSessionId is a built-in parameter.
126let dialogSessionId: string = want?.parameters?.dialogSessionId;
127
128// Obtain DialogSessionInfo.
129let dialogSessionInfo: dialogSession.DialogSessionInfo = dialogSession.getDialogSessionInfo(dialogSessionId);
130
131let isAllow: Boolean = true;
132
133// When isAllow is true, targetWant is one of dialogSessionInfo.targetAbilityInfos.
134let targetWant: Want = {
135  bundleName: 'com.example.myapplication',
136  abilityName: 'EntryAbility'
137};
138
139try {
140  dialogSession.sendDialogResult(dialogSessionId, targetWant, isAllow, (err, data) => {
141    if (data) {
142      console.log(`sendDialogResult success, data: ${data}`);
143    } else {
144      console.error(`sendDialogResult error, errorCode: ${err.code}`);
145    }
146  });
147} catch (err) {
148  console.error(`sendDialogResult error, errorCode: ${err.code}`);
149}
150```
151
152## sendDialogResult
153
154sendDialogResult(dialogSessionId: string, targetWant: Want, isAllowed: boolean): Promise\<void\>
155
156Sends a request for a dialog box. This API uses a promise to return the result.
157
158**System API**: This is a system API.
159
160**System capability**: SystemCapability.Ability.AbilityRuntime.Core
161
162**Parameters**
163
164  | Name| Type| Mandatory| Description|
165  | -------- | -------- | -------- | -------- |
166  | dialogSessionId | string | Yes| Session ID.|
167  | targetWant | Want | Yes| Target of the request.|
168  | isAllowed | boolean | Yes| Request result.|
169
170**Return value**
171
172| Type| Description|
173| -------- | -------- |
174| Promise&lt;void&gt; | Promise that returns no value.|
175
176**Error codes**
177
178| ID| Error Message|
179| ------- | -------- |
180| 16000005 | The specified process does not have the permission. |
181| 16000006  | Cross-user operations are not allowed. |
182| 16000050  | Internal error. |
183
184For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
185
186**Example**
187
188```ts
189import dialogSession from '@ohos.app.ability.dialogSession';
190import Want from '@ohos.app.ability.Want';
191
192// want is specified by the system. dialogSessionId is a built-in parameter.
193let dialogSessionId: string = want?.parameters?.dialogSessionId;
194
195// Obtain DialogSessionInfo.
196let dialogSessionInfo: dialogSession.DialogSessionInfo = dialogSession.getDialogSessionInfo(dialogSessionId);
197
198let isAllow: Boolean = true;
199
200// When isAllow is true, targetWant is one of dialogSessionInfo.targetAbilityInfos.
201let targetWant: Want = {
202  bundleName: 'com.example.myapplication',
203  abilityName: 'EntryAbility'
204};
205
206try {
207  dialogSession.sendDialogResult(dialogSessionId, targetWant, isAllow)
208    .then((data) => {
209      console.log(`startChildProcess success, pid: ${data}`);
210    }, (err: BusinessError) => {
211      console.error(`startChildProcess error, errorCode: ${err.code}`);
212    })
213} catch (err) {
214  console.error(`sendDialogResult error, errorCode: ${err.code}`);
215}
216```
217