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