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