openharmony 鸿蒙 js-apis-app-ability-dialogSession-sys

2025-06-12 浏览 (1)

@ohos.app.ability.dialogSession (dialogSession) (System API)

The dialogSession module provides APIs related to the dialog box.

NOTE

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.

The APIs of this module can be used only in the stage model.

The APIs provided by this module are system APIs.

Modules to Import

import { dialogSession } from '@kit.AbilityKit';

DialogAbilityInfo

Provides DialogAbility information, including the bundle name, module name, and ability name.

System capability: SystemCapability.Ability.AbilityRuntime.Core

NameTypeRead-onlyMandatoryDescription
bundleNamestringYesYesBundle name.
moduleNamestringYesYesModule name.
abilityNamestringYesYesAbility name.
abilityIconIdnumberYesYesID of the ability icon.
abilityLabelIdnumberYesYesID of the ability label.
bundleIconIdnumberYesYesID of the bundle icon.
bundleLabelIdnumberYesYesID of the bundle label.
visible12+booleanYesYesWhether the ability is visible. The value true means that the ability is visible, and false means the opposite.
appIndex12+numberYesYesIndex of the application clone.
multiAppMode12+MultiAppModeYesYesMulti-app mode.

DialogSessionInfo

Provides session information, including the requester information, target application list, and other parameters.

System capability: SystemCapability.Ability.AbilityRuntime.Core

NameTypeRead-onlyMandatoryDescription
callerAbilityInfoDialogAbilityInfoYesYesAbility information of the requester.
targetAbilityInfosArray<DialogAbilityInfo>YesYesTarget application list.
parametersRecord<string, Object>YesNoOther parameters.

getDialogSessionInfo

getDialogSessionInfo(dialogSessionId: string): DialogSessionInfo

Obtains the session information based on the session ID.

System API: This is a system API.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

NameTypeMandatoryDescription
dialogSessionIdstringYesSession ID.

Return value

TypeDescription
DialogSessionInfoSession information.

Error codes

For details about the error codes, see Universal Error Codes and Ability Error Codes.

IDError Message
202Not System App. Interface caller is not a system app.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 3. Parameter verification failed.
16000005The specified process does not have the permission.
16000006Cross-user operations are not allowed.
16000050Internal error.

Example

import { dialogSession, Want } from '@kit.AbilityKit';

// want is specified by the system. dialogSessionId is a built-in parameter.
let dialogSessionId: string = want?.parameters?.dialogSessionId;

// Obtain DialogSessionInfo.
let dialogSessionInfo: dialogSession.DialogSessionInfo = dialogSession.getDialogSessionInfo(dialogSessionId);

sendDialogResult

sendDialogResult(dialogSessionId: string, targetWant: Want, isAllowed: boolean, callback: AsyncCallback<void>): void

Sends a request for a dialog box. This API uses an asynchronous callback to return the result.

System API: This is a system API.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

NameTypeMandatoryDescription
dialogSessionIdstringYesSession ID.
targetWantWantYesTarget of the request.
isAllowedbooleanYesWhether the target ability can be started. The value true means that the target ability can be started, and false means the opposite.
callbackAsyncCallback<void>YesCallback used to return the result. If the operation is successful, err is undefined. Otherwise, err is an error object.

Error codes

For details about the error codes, see Universal Error Codes and Ability Error Codes.

IDError Message
202Not System App. Interface caller is not a system app.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 3. Parameter verification failed.
16000005The specified process does not have the permission.
16000006Cross-user operations are not allowed.
16000050Internal error.

Example

import { dialogSession, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

// want is specified by the system. dialogSessionId is a built-in parameter.
let dialogSessionId: string = want?.parameters?.dialogSessionId;

// Obtain DialogSessionInfo.
let dialogSessionInfo: dialogSession.DialogSessionInfo = dialogSession.getDialogSessionInfo(dialogSessionId);

let isAllow: boolean = true;

// When isAllow is true, targetWant is one of dialogSessionInfo.targetAbilityInfos.
let targetWant: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility'
};

try {
  dialogSession.sendDialogResult(dialogSessionId, targetWant, isAllow, (err, data) => {
    if (err) {
      console.error(`sendDialogResult error, errorCode: ${err.code}`);
    } else {
      console.log(`sendDialogResult success`);
    }
  });
} catch (err) {
  console.error(`sendDialogResult error, errorCode: ${(err as BusinessError).code}`);
}

sendDialogResult

sendDialogResult(dialogSessionId: string, targetWant: Want, isAllowed: boolean): Promise<void>

Sends a request for a dialog box. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

NameTypeMandatoryDescription
dialogSessionIdstringYesSession ID.
targetWantWantYesTarget of the request.
isAllowedbooleanYesWhether the target ability can be started. The value true means that the target ability can be started, and false means the opposite.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Ability Error Codes.

IDError Message
202Not System App. Interface caller is not a system app.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 3. Parameter verification failed.
16000005The specified process does not have the permission.
16000006Cross-user operations are not allowed.
16000050Internal error.

Example

import { dialogSession, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

// want is specified by the system. dialogSessionId is a built-in parameter.
let dialogSessionId: string = want?.parameters?.dialogSessionId;

// Obtain DialogSessionInfo.
let dialogSessionInfo: dialogSession.DialogSessionInfo = dialogSession.getDialogSessionInfo(dialogSessionId);

let isAllow: boolean = true;

// When isAllow is true, targetWant is one of dialogSessionInfo.targetAbilityInfos.
let targetWant: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility'
};

try {
  dialogSession.sendDialogResult(dialogSessionId, targetWant, isAllow)
    .then((data) => {
      console.log(`startChildProcess success, pid: ${data}`);
    }, (err: BusinessError) => {
      console.error(`startChildProcess error, errorCode: ${err.code}`);
    })
} catch (err) {
  console.error(`sendDialogResult error, errorCode: ${(err as BusinessError).code}`);
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Ability Kit

harmony 鸿蒙AbilityAccessControl

harmony 鸿蒙AbilityBase

harmony 鸿蒙AbilityBase_Element

harmony 鸿蒙AbilityRuntime

harmony 鸿蒙bundle

harmony 鸿蒙OH_NativeBundle_ApplicationInfo

harmony 鸿蒙OH_NativeBundle_ElementName

harmony 鸿蒙ability_access_control.h

harmony 鸿蒙ability_base_common.h

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/PruYuf