• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.dialogRequest (dialogRequest)
2
3The **dialogRequest** module provides APIs related to modal dialog box processing, including obtaining the request information (used to bind a modal dialog box) and request callback (used to set the request result).
4A modal dialog box is a system pop-up box that intercepts events (such as mouse, keyboard, and touchscreen events) triggered for the page displayed under it. The page can be operated only after the modal dialog box is destroyed.
5
6> **NOTE**
7>
8>  - 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.
9>  - The APIs provided by this module are used in ServiceExtensionAbilities. For a ServiceExtensionAbility that implements modal dialog boxes, you can use the APIs to obtain the request information and request callback and return the request result.
10
11## Modules to Import
12
13```ts
14import dialogRequest from '@ohos.app.ability.dialogRequest';
15```
16
17## dialogRequest.getRequestInfo
18
19getRequestInfo(want: Want): RequestInfo
20
21> **NOTE**
22>
23>  This API can be used by a ServiceExtensionAbility. If the ServiceExtensionAbility implements modal dialog boxes, the request information can be obtained from Want. If this API is used in other scenarios, no return value is obtained.
24
25Obtains the request information from Want.
26
27**System capability**: SystemCapability.Ability.AbilityRuntime.Core
28
29**Parameters**
30
31| Name| Type  | Mandatory| Description                       |
32| ---- | ------ | ---- | --------------------------- |
33| want  | [Want](js-apis-app-ability-want.md) | Yes  | Want passed in the request for a modal dialog box.|
34
35**Return value**
36
37| Type  | Description                    |
38| ------ | ------------------------ |
39| [RequestInfo](#requestinfo) | **RequestInfo** object obtained, which is used to bind a modal dialog box.|
40
41**Example**
42
43```ts
44import AbilityConstant from '@ohos.app.ability.AbilityConstant';
45import UIAbility from '@ohos.app.ability.UIAbility';
46import Want from '@ohos.app.ability.Want';
47import dialogRequest from '@ohos.app.ability.dialogRequest';
48
49export default class EntryAbility extends UIAbility {
50  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
51    try {
52      let requestInfo = dialogRequest.getRequestInfo(want);
53    } catch (err) {
54      console.error(`getRequestInfo err= ${JSON.stringify(err)}`);
55    }
56  }
57}
58```
59
60## dialogRequest.getRequestCallback
61
62getRequestCallback(want: Want): RequestCallback
63
64Obtains the request callback from Want.
65
66> **NOTE**
67>
68>  This API can be used by a ServiceExtensionAbility. If the ServiceExtensionAbility implements modal dialog boxes, the request callback can be obtained from Want. If this API is used in other scenarios, no return value is obtained.
69
70**System capability**: SystemCapability.Ability.AbilityRuntime.Core
71
72**Parameters**
73
74| Name| Type  | Mandatory| Description                       |
75| ---- | ------ | ---- | --------------------------- |
76| want  | [Want](js-apis-app-ability-want.md) | Yes  | Want passed in the request for a modal dialog box.|
77
78**Return value**
79
80| Type  | Description                    |
81| ------ | ------------------------ |
82| [RequestCallback](#requestcallback) | **RequestCallback** object obtained, which is used to set the return result.|
83
84**Example**
85
86```ts
87import AbilityConstant from '@ohos.app.ability.AbilityConstant';
88import UIAbility from '@ohos.app.ability.UIAbility';
89import Want from '@ohos.app.ability.Want';
90import dialogRequest from '@ohos.app.ability.dialogRequest';
91
92export default class EntryAbility extends UIAbility {
93  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
94    try {
95      let requestCallback = dialogRequest.getRequestCallback(want);
96    } catch(err) {
97      console.error(`getRequestInfo err= ${JSON.stringify(err)}`);
98    }
99  }
100}
101```
102
103## WindowRect<sup>10+</sup>
104
105Defines the location attributes of a modal dialog box.
106
107**Model restriction**: This API can be used only in the stage model.
108
109**System capability**: SystemCapability.Ability.AbilityRuntime.Core
110
111| Name| Type  | Mandatory| Description                       |
112| ---- | ------ | ---- | --------------------------- |
113| left  | number | Yes  | X-coordinate of the upper left corner of the dialog box.|
114| top  | number | Yes  | Y-coordinate of the upper left corner of the dialog box.|
115| width  | number | Yes  | Width of the dialog box.|
116| height  | number | Yes  | Height of the dialog box.|
117
118## RequestInfo
119
120Defines the request information, which is used as an input parameter for binding the modal dialog box.
121
122**Model restriction**: This API can be used only in the stage model.
123
124**System capability**: SystemCapability.Ability.AbilityRuntime.Core
125
126| Name     | Type      | Mandatory  | Description    |
127| ------------ | ------------------| ------ | ---------------------- |
128| windowRect<sup>10+</sup>            | [WindowRect](#windowrect10)    | No  | Location attributes of a modal dialog box.         |
129
130**Example**
131
132```ts
133import AbilityConstant from '@ohos.app.ability.AbilityConstant';
134import UIAbility from '@ohos.app.ability.UIAbility';
135import Want from '@ohos.app.ability.Want';
136import dialogRequest from '@ohos.app.ability.dialogRequest';
137
138export default class EntryAbility extends UIAbility {
139  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
140    try {
141      let requestInfo = dialogRequest.getRequestInfo(want);
142      console.info(`getRequestInfo windowRect=, ${JSON.stringify(requestInfo.windowRect)}` );
143    } catch(err) {
144      console.error(`getRequestInfo err= ${JSON.stringify(err)}`);
145    }
146  }
147}
148```
149
150## ResultCode
151
152Enumerates the result codes of the request for the modal dialog box.
153
154**System capability**: SystemCapability.Ability.AbilityRuntime.Core
155
156| Name     | Value         | Description    |
157| ------------ | ------------------ | ---------------------- |
158| RESULT_OK            | 0          | The request succeeds.         |
159| RESULT_CANCEL        | 1          | The request fails.         |
160
161## RequestResult
162Defines the result of the request for the modal dialog box. It contains **ResultCode** and **ResultWant**.
163
164### Attributes
165
166**Model restriction**: This API can be used only in the stage model.
167
168**System capability**: SystemCapability.Ability.AbilityRuntime.Core
169
170| Name| Type| Read-only| Mandatory| Description|
171| -------- | -------- | -------- | -------- | -------- |
172| result | [ResultCode](#resultcode) | No| Yes| Result code of the request.|
173| want<sup>10+</sup> | [ResultWant](js-apis-app-ability-want.md)  | No| No| Want information, such as the ability name and bundle name.|
174
175## RequestCallback
176
177Provides a callback for setting the modal dialog box request result.
178
179**Model restriction**: This API can be used only in the stage model.
180
181### RequestCallback.setRequestResult
182
183setRequestResult(result: RequestResult): void
184
185Sets the result of the request for the modal dialog box.
186
187**Model restriction**: This API can be used only in the stage model.
188
189**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
190
191**Parameters**
192
193| Name| Type| Mandatory| Description|
194| -------- | -------- | -------- | -------- |
195| result | [RequestResult](#requestresult) | Yes| Request result to set.|
196
197**Error codes**
198
199| ID| Error Message|
200| ------- | -------------------------------- |
201| 401 | If the input parameter is not valid parameter. |
202
203For details about the error codes, see [Ability Error Codes](errorcode-ability.md).
204
205**Example**
206
207```ts
208import AbilityConstant from '@ohos.app.ability.AbilityConstant';
209import UIAbility from '@ohos.app.ability.UIAbility';
210import Want from '@ohos.app.ability.Want';
211import dialogRequest from '@ohos.app.ability.dialogRequest';
212
213export default class EntryAbility extends UIAbility {
214  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
215    try {
216      let requestCallback = dialogRequest.getRequestCallback(want);
217      let myResult: dialogRequest.RequestResult = {
218        result : dialogRequest.ResultCode.RESULT_CANCEL,
219      };
220      requestCallback.setRequestResult(myResult);
221    } catch(err) {
222      console.error(`getRequestInfo err= ${JSON.stringify(err)}`);
223    }
224  }
225}
226```
227