1e41f4b71Sopenharmony_ci# @ohos.app.ability.dialogSession (dialogSession)(系统接口) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_cidialogSession模块用于支持系统应用弹框功能。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明:** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 11开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> 本模块接口仅可在Stage模型下使用。 10e41f4b71Sopenharmony_ci> 11e41f4b71Sopenharmony_ci> 本模块为系统接口。 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci## 导入模块 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci```ts 16e41f4b71Sopenharmony_ciimport { dialogSession } from '@kit.AbilityKit'; 17e41f4b71Sopenharmony_ci``` 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci## DialogAbilityInfo 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci提供会话组件信息,包括包名、模块名、组件名等信息。 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci| 名称 | 类型 | 只读 | 必填 | 说明 | 26e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 27e41f4b71Sopenharmony_ci| bundleName | string | 是 | 是 | 表示包名。 | 28e41f4b71Sopenharmony_ci| moduleName | string | 是 | 是 | 表示模块名。 | 29e41f4b71Sopenharmony_ci| abilityName | string | 是 | 是 | 表示组件名。 | 30e41f4b71Sopenharmony_ci| abilityIconId | number | 是 | 是 | 表示Ability图标ID。 | 31e41f4b71Sopenharmony_ci| abilityLabelId | number | 是 | 是 | 表示Ability标签ID。 | 32e41f4b71Sopenharmony_ci| bundleIconId | number | 是 | 是 | 表示Bundle图标ID。 | 33e41f4b71Sopenharmony_ci| bundleLabelId | number | 是 | 是 | 表示Bundle标签ID。 | 34e41f4b71Sopenharmony_ci| visible<sup>12+</sup> | boolean | 是 | 是 | 表示Ability是否可见。 | 35e41f4b71Sopenharmony_ci| appIndex<sup>12+</sup> | number | 是 | 是 | 表示应用的分身索引。 | 36e41f4b71Sopenharmony_ci| multiAppMode<sup>12+</sup> | [MultiAppMode](./js-apis-bundleManager-applicationInfo.md#multiappmode12) | 是 | 是 | 表示应用的多开模式。| 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci## DialogSessionInfo 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci提供会话信息,包括请求方信息、目标应用列表信息、其他参数。 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci| 名称 | 类型 | 只读 | 必填 | 说明 | 45e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 46e41f4b71Sopenharmony_ci| callerAbilityInfo | [DialogAbilityInfo](#dialogabilityinfo)| 是 | 是 | 表示请求方组件信息。 | 47e41f4b71Sopenharmony_ci| targetAbilityInfos | Array\<[DialogAbilityInfo](#dialogabilityinfo)\> | 是 | 是 | 表示目标应用列表信息。 | 48e41f4b71Sopenharmony_ci| parameters | Record<string, Object> | 是 | 否 | 表示其他参数。 | 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci## getDialogSessionInfo 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_cigetDialogSessionInfo(dialogSessionId: string): [DialogSessionInfo](#dialogsessioninfo) 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci根据dialogSessionId获取会话信息。 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci**系统接口**:该接口为系统接口。 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci**参数:** 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 63e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 64e41f4b71Sopenharmony_ci | dialogSessionId | string | 是 | 用户请求会话ID。 | 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci**返回值:** 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci | 类型 | 说明 | 69e41f4b71Sopenharmony_ci | -------- | -------- | 70e41f4b71Sopenharmony_ci | [DialogSessionInfo](#dialogsessioninfo) | 同步返回会话信息。 | 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci**错误码**: 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 77e41f4b71Sopenharmony_ci| ------- | -------- | 78e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 79e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 3. Parameter verification failed. | 80e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 81e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 82e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci**示例:** 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci```ts 87e41f4b71Sopenharmony_ciimport { dialogSession, Want } from '@kit.AbilityKit'; 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci// want由系统内部指定,dialogSessionId为内置参数 90e41f4b71Sopenharmony_cilet dialogSessionId: string = want?.parameters?.dialogSessionId; 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci// 查询DialogSessionInfo 93e41f4b71Sopenharmony_cilet dialogSessionInfo: dialogSession.DialogSessionInfo = dialogSession.getDialogSessionInfo(dialogSessionId); 94e41f4b71Sopenharmony_ci``` 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci## sendDialogResult 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_cisendDialogResult(dialogSessionId: string, targetWant: Want, isAllowed: boolean, callback: AsyncCallback\<void\>): void 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci发送用户请求。使用callback异步回调。 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci**系统接口**:该接口为系统接口。 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ci**参数:** 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 109e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 110e41f4b71Sopenharmony_ci | dialogSessionId | string | 是 | 用户请求会话ID。 | 111e41f4b71Sopenharmony_ci | targetWant | Want | 是 | 用户请求目标。 | 112e41f4b71Sopenharmony_ci | isAllowed | boolean | 是 | 用户请求结果。 | 113e41f4b71Sopenharmony_ci | callback | AsyncCallback\<void\> | 是 | 回调函数。当发送用户请求成功,err为undefined,否则为错误对象。 | 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci**错误码**: 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ci以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 120e41f4b71Sopenharmony_ci| ------- | -------- | 121e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 122e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 3. Parameter verification failed. | 123e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 124e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 125e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci**示例:** 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci```ts 130e41f4b71Sopenharmony_ciimport { dialogSession, Want } from '@kit.AbilityKit'; 131e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ci// want由系统内部指定,dialogSessionId为内置参数 134e41f4b71Sopenharmony_cilet dialogSessionId: string = want?.parameters?.dialogSessionId; 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ci// 查询DialogSessionInfo 137e41f4b71Sopenharmony_cilet dialogSessionInfo: dialogSession.DialogSessionInfo = dialogSession.getDialogSessionInfo(dialogSessionId); 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_cilet isAllow: boolean = true; 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ci// isAllow为true时,用户请求结果targetWant为dialogSessionInfo.targetAbilityInfos之一 142e41f4b71Sopenharmony_cilet targetWant: Want = { 143e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 144e41f4b71Sopenharmony_ci abilityName: 'EntryAbility' 145e41f4b71Sopenharmony_ci}; 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_citry { 148e41f4b71Sopenharmony_ci dialogSession.sendDialogResult(dialogSessionId, targetWant, isAllow, (err, data) => { 149e41f4b71Sopenharmony_ci if (err) { 150e41f4b71Sopenharmony_ci console.error(`sendDialogResult error, errorCode: ${err.code}`); 151e41f4b71Sopenharmony_ci } else { 152e41f4b71Sopenharmony_ci console.log(`sendDialogResult success`); 153e41f4b71Sopenharmony_ci } 154e41f4b71Sopenharmony_ci }); 155e41f4b71Sopenharmony_ci} catch (err) { 156e41f4b71Sopenharmony_ci console.error(`sendDialogResult error, errorCode: ${(err as BusinessError).code}`); 157e41f4b71Sopenharmony_ci} 158e41f4b71Sopenharmony_ci``` 159e41f4b71Sopenharmony_ci 160e41f4b71Sopenharmony_ci## sendDialogResult 161e41f4b71Sopenharmony_ci 162e41f4b71Sopenharmony_cisendDialogResult(dialogSessionId: string, targetWant: Want, isAllowed: boolean): Promise\<void\> 163e41f4b71Sopenharmony_ci 164e41f4b71Sopenharmony_ci发送用户请求。使用Promise异步回调。 165e41f4b71Sopenharmony_ci 166e41f4b71Sopenharmony_ci**系统接口**:该接口为系统接口。 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_ci**参数:** 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ci | 参数名 | 类型 | 必填 | 说明 | 173e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 174e41f4b71Sopenharmony_ci | dialogSessionId | string | 是 | 用户请求会话ID。 | 175e41f4b71Sopenharmony_ci | targetWant | Want | 是 | 用户请求目标。 | 176e41f4b71Sopenharmony_ci | isAllowed | boolean | 是 | 用户请求结果。 | 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci**返回值:** 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci| 类型 | 说明 | 181e41f4b71Sopenharmony_ci| -------- | -------- | 182e41f4b71Sopenharmony_ci| Promise<void> | 无返回结果的Promise对象。 | 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci**错误码**: 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 189e41f4b71Sopenharmony_ci| ------- | -------- | 190e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 191e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 3. Parameter verification failed. | 192e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 193e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 194e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci**示例:** 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci```ts 199e41f4b71Sopenharmony_ciimport { dialogSession, Want } from '@kit.AbilityKit'; 200e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 201e41f4b71Sopenharmony_ci 202e41f4b71Sopenharmony_ci// want由系统内部指定,dialogSessionId为内置参数 203e41f4b71Sopenharmony_cilet dialogSessionId: string = want?.parameters?.dialogSessionId; 204e41f4b71Sopenharmony_ci 205e41f4b71Sopenharmony_ci// 查询DialogSessionInfo 206e41f4b71Sopenharmony_cilet dialogSessionInfo: dialogSession.DialogSessionInfo = dialogSession.getDialogSessionInfo(dialogSessionId); 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_cilet isAllow: boolean = true; 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ci// isAllow为true时,用户请求结果targetWant为dialogSessionInfo.targetAbilityInfos之一 211e41f4b71Sopenharmony_cilet targetWant: Want = { 212e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 213e41f4b71Sopenharmony_ci abilityName: 'EntryAbility' 214e41f4b71Sopenharmony_ci}; 215e41f4b71Sopenharmony_ci 216e41f4b71Sopenharmony_citry { 217e41f4b71Sopenharmony_ci dialogSession.sendDialogResult(dialogSessionId, targetWant, isAllow) 218e41f4b71Sopenharmony_ci .then((data) => { 219e41f4b71Sopenharmony_ci console.log(`startChildProcess success, pid: ${data}`); 220e41f4b71Sopenharmony_ci }, (err: BusinessError) => { 221e41f4b71Sopenharmony_ci console.error(`startChildProcess error, errorCode: ${err.code}`); 222e41f4b71Sopenharmony_ci }) 223e41f4b71Sopenharmony_ci} catch (err) { 224e41f4b71Sopenharmony_ci console.error(`sendDialogResult error, errorCode: ${(err as BusinessError).code}`); 225e41f4b71Sopenharmony_ci} 226e41f4b71Sopenharmony_ci```