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

2025-06-12 浏览 (1)

@ohos.app.ability.insightIntentDriver (Executing InsightIntent Calls) (System API)

The insightIntentDriver module provides APIs for executing InsightIntent calls. The system executes InsightIntent calls based on user interaction and more.

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.

Starting from API version 20, this module supports application navigation using InsightIntents defined by the @InsightIntentLink decorator.

Modules to Import

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

ExecuteParam

Defines the parameter used to execute an InsightIntent call.

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

System capability: SystemCapability.Ability.AbilityRuntime.Core

NameTypeMandatoryDescription
bundleNamestringYesName of the bundle to which the ability to be called belongs.
moduleNamestringYesName of the module to which the ability belongs.
abilityNamestringYesName of the ability to be called. If an InsightIntent defined by the @InsightIntentLink decorator is used to implement application redirection, this parameter can be left empty.
insightIntentNamestringYesInsightIntent name.
insightIntentParamRecord<string, Object>YesInsightIntent call parameter.
executeModeinsightIntent.ExecuteModeYesInsightIntent call execution mode. If an InsightIntent defined by the @InsightIntentLink decorator is used to implement application redirection, this parameter must be filled (with any value that conforms to the definition), although it will not actually take effect.
displayId12+numberNoPhysical screen ID specified during InsightIntent call. The value must be an integer. This parameter is valid only when executeMode is set to UI_ABILITY_FOREGROUND.
uris18+Array<string>NoList of URIs authorized by the InsightIntent caller to the InsightIntent executor during the call. If an InsightIntent defined by the @InsightIntentLink decorator is used to implement application redirection, this field is mandatory. Only the first element in the array is read as the URI of openLink.
flags18+numberNoFlags of the URIs authorized by the InsightIntent caller to the InsightIntent executor during the call.
NOTE
This parameter supports only FLAG_AUTH_READ_URI_PERMISSION, FLAG_AUTH_WRITE_URI_PERMISSION, and FLAG_AUTH_READ_URI_PERMISSION|

LinkIntentInfo20+

LinkIntentInfo inherits from IntentDecoratorInfo. It is used to describe parameters supported by the @InsightIntentLink decorator, such as the URI required for application redirection.

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

System capability: SystemCapability.Ability.AbilityRuntime.Core

NameTypeRead-OnlyOptionalDescription
uristringYesNoURI of an InsightIntent.

PageIntentInfo20+

PageIntentInfo inherits from IntentDecoratorInfo. It is used to describe parameters supported by the @InsightIntentPage decorator, such as the name of NavDestination of the target page.

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

System capability: SystemCapability.Ability.AbilityRuntime.Core

NameTypeRead-OnlyOptionalDescription
uiAbilitystringYesNoAbility name.
pageRouterNamestringYesNoPage name.
navigationIdstringYesNoID of the Navigation component bound to the InsightIntent.
navDestinationstringYesNoName of the NavDestination component bound to the InsightIntent.

FunctionIntentInfo20+

Defines the parameter type of the @InsightIntentFunctionMethod decorator. All parameters inherit from IntentDecoratorInfo.

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

System capability: SystemCapability.Ability.AbilityRuntime.Core

InsightIntentInfo20+

Defines the InsightIntent information, which is the specific parameter configuration of the InsightIntent in the device.

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

System capability: SystemCapability.Ability.AbilityRuntime.Core

NameTypeRead-OnlyOptionalDescription
bundleNamestringYesNoBundle name of the application.
moduleNamestringYesNoModule name.
intentNamestringYesNoInsightIntent name.
domainstringYesNoVertical domain of the InsightIntent. It is used to categorize InsightIntents by vertical fields (for example, video, music, and games). For details about the value range, see the vertical domain fields in smart distribution features in different vertical domains.
intentVersionstringYesNoVersion number of the InsightIntent. It is used to distinguish and manage InsightIntents when their capabilities evolve.
displayNamestringYesNoName of the InsightIntent displayed in the InsightIntent framework.
displayDescriptionstringYesNoDescription of the InsightIntent displayed in the InsightIntent framework.
schemastringYesNoStandard InsightIntent name. If an InsightIntent in the standard InsightIntent list matches both the schema and intentVersion fields, it is processed as a standard InsightIntent.
iconstringYesNoIcon of the InsightIntent.
llmDescriptionstringYesNoFunction of an InsightIntent, which helps large language models understand the InsightIntent.
keywordsArray<string>YesNoSearch keywords for the InsightIntent.
intentTypestringYesNoType of InsightIntent defined by the InsightIntent decorator.
subIntentInfoLinkIntentInfo |PageIntentInfo |FunctionIntentInfoYesNoInsightIntent information for specific InsightIntent decorators.
parametersRecord<string, Object>YesNoData format of InsightIntent parameters, which is used to define the input data format during InsightIntent calls.

GetInsightIntentFlag20+

Enumerates the flags of the InsightIntent information (InsightIntentInfo). It is used by getAllInsightIntentInfo, getInsightIntentInfoByBundleName, and getInsightIntentInfoByIntentName to query full or brief InsightIntent information.

System capability: SystemCapability.Ability.AbilityRuntime.Core

NameValueDescription
GET_FULL_INSIGHT_INTENT1Queries all information in InsightIntentInfo.
GET_SUMMARY_INSIGHT_INTENT2Queries certain information in InsightIntentInfo. For details, see Table 1.

Table 1 Differences between full InsightIntent information and brief InsightIntent information

NameIncluded in Full InsightIntent InformationIncluded in Brief InsightIntent Information
bundleNameYesYes
moduleNameYesYes
intentNameYesYes
domainYesNo
intentVersionYesNo
displayNameYesYes
displayDescriptionYesNo
schemaYesNo
iconYesNo
llmDescriptionYesNo
keywordsYesNo
intentTypeYesYes
subIntentInfoYesYes
parametersYesYes

insightIntentDriver.execute

execute(param: ExecuteParam, callback: AsyncCallback<insightIntent.ExecuteResult>): void

Executes a call to an InsightIntent. This API uses an asynchronous callback to return the result.

When the caller is in the background, the ohos.permission.START_ABILITIES_FROM_BACKGROUND permission is required.

When ExecuteMode of the InsightIntent call is set to UI_ABILITY_BACKGROUND, the ohos.permission.ABILITY_BACKGROUND_COMMUNICATION permission is required.

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Required permissions: ohos.permission.EXECUTE_INSIGHT_INTENT

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

NameTypeMandatoryDescription
paramExecuteParamYesParameter used to execute the InsightIntent call.
callbackAsyncCallback<insightIntent.ExecuteResult>YesCallback used to return the InsightIntent call execution result.

Error codes

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

IDError Message
201Permission denied.
202Not system application.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
16000001The specified ability does not exist.
16000002Incorrect ability type.
16000004Failed to start the invisible ability.
16000005The specified process does not have the permission.
16000006Cross-user operations are not allowed.
16000008The crowdtesting application expires.
16000009An ability cannot be started or stopped in Wukong mode.
16000010The call with the continuation flag is forbidden.
16000011The context does not exist.
16000012The application is controlled.
16000013The application is controlled by EDM.
16000050Internal error.
16000053The ability is not on the top of the UI.
16000055Installation-free timed out.

Example

  import { insightIntentDriver, insightIntent } from '@kit.AbilityKit';
  import { hilog } from '@kit.PerformanceAnalysisKit';

  function executeInsightIntentAsync() {
    let param: insightIntentDriver.ExecuteParam = {
      bundleName: 'com.ohos.intentexecutedemo',
      moduleName: 'entry',
      abilityName: 'EntryAbility',
      insightIntentName: 'PlayMusic',
      insightIntentParam: {
        songName: 'City Of Stars',
      },
      executeMode: insightIntent.ExecuteMode.UI_ABILITY_FOREGROUND,
    };

    try {
      insightIntentDriver.execute(param, (error, data: insightIntent.ExecuteResult) => {
        if (error) {
          hilog.error(0x0000, 'testTag', 'execute insight intent failed with %{public}s', JSON.stringify(error));
        } else {
          hilog.info(0x0000, 'testTag', '%{public}s', 'execute insight intent succeed');
        }
        hilog.info(0x0000, 'testTag', 'execute insight intent return %{public}d', data.code);
        hilog.info(0x0000, 'testTag', 'execute insight intent result %{public}s', JSON.stringify(data.result));
      })
    } catch (error) {
      hilog.error(0x0000, 'testTag', 'execute insight intent error caught %{public}s', JSON.stringify(error));
    }
  }

insightIntentDriver.execute

execute(param: ExecuteParam): Promise<insightIntent.ExecuteResult>

Executes a call to an InsightIntent. This API uses a promise to return the result.

When the caller is in the background, the ohos.permission.START_ABILITIES_FROM_BACKGROUND permission is required.

When ExecuteMode of the InsightIntent call is set to UI_ABILITY_BACKGROUND, the ohos.permission.ABILITY_BACKGROUND_COMMUNICATION permission is required.

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Required permissions: ohos.permission.EXECUTE_INSIGHT_INTENT

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

NameTypeMandatoryDescription
paramExecuteParamYesParameter used to execute the InsightIntent call.

Return value

TypeDescription
Promise<insightIntent.ExecuteResult>Promise used to return the InsightIntent call execution result.

Error codes

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

IDError Message
201Permission denied.
202Not system application.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
16000001The specified ability does not exist.
16000002Incorrect ability type.
16000004Failed to start the invisible ability.
16000005The specified process does not have the permission.
16000006Cross-user operations are not allowed.
16000008The crowdtesting application expires.
16000009An ability cannot be started or stopped in Wukong mode.
16000010The call with the continuation flag is forbidden.
16000011The context does not exist.
16000012The application is controlled.
16000013The application is controlled by EDM.
16000050Internal error.
16000053The ability is not on the top of the UI.
16000055Installation-free timed out.

Example

  import { insightIntentDriver, insightIntent } from '@kit.AbilityKit';
  import { hilog } from '@kit.PerformanceAnalysisKit';

  async function executeSearchMusicIntentPromise() {
    let param: insightIntentDriver.ExecuteParam = {
      bundleName: 'com.ohos.intentexecutedemo',
      moduleName: 'entry',
      abilityName: 'EntryAbility',
      insightIntentName: 'PlayMusic',
      insightIntentParam: {
        songName: 'City Of Stars',
      },
      executeMode: insightIntent.ExecuteMode.UI_ABILITY_FOREGROUND,
    };

    try {
      let resultData: insightIntent.ExecuteResult = await insightIntentDriver.execute(param);
      hilog.info(0x0000, 'testTag', 'execute insight intent return %{public}d', resultData.code);
      hilog.info(0x0000, 'testTag', 'execute insight intent result %{public}s', JSON.stringify(resultData.result));
    } catch (error) {
      hilog.error(0x0000, 'testTag', 'execute insight intent error caught %{public}s', JSON.stringify(error));
    }
  }

insightIntentDriver.getAllInsightIntentInfo20+

getAllInsightIntentInfo(intentFlags: number): Promise<Array<InsightIntentInfo>>

Obtains the information about all InsightIntents on the current device. This API uses a promise to return the result.

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Required permissions: ohos.permission.EXECUTE_INSIGHT_INTENT

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

NameTypeMandatoryDescription
intentFlagsnumberYesFlag of the InsightIntent information (InsightIntentInfo). It is used to query full or brief InsightIntent information.

Return value

TypeDescription
Promise<Array<InsightIntentInfo>>Promise used to return an array holding InsightIntentInfo objects.

Error codes

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

IDError Message
201Permission denied.
202Not system application.
16000050Internal error.

Example

  import { insightIntentDriver } from '@kit.AbilityKit';
  import { BusinessError } from '@kit.BasicServicesKit';
  import { hilog } from '@kit.PerformanceAnalysisKit';

  async function getInfos() {
    try {
      insightIntentDriver.getAllInsightIntentInfo(insightIntentDriver.GetInsightIntentFlag.GET_FULL_INSIGHT_INTENT).then((data) => {
        hilog.info(0x0000, 'testTag', 'getAllInsightIntentInfo return %{public}s', JSON.stringify(data));
      }).catch((err: BusinessError) => {
        hilog.info(0x0000, 'testTag', 'getAllInsightIntentInfo errCode: %{public}d', err.code);
        hilog.info(0x0000, 'testTag', 'getAllInsightIntentInfo errMessage: %{public}s', err.message);
      });
    } catch (error) {
      hilog.error(0x0000, 'testTag', 'getAllInsightIntentInfo error caught %{public}s', JSON.stringify(error));
    }
  }

insightIntentDriver.getInsightIntentInfoByBundleName20+

getInsightIntentInfoByBundleName(bundleName: string, intentFlags: number): Promise<Array<InsightIntentInfo>>

Obtains the InsightIntent information on the current device based on the given bundle name. This API uses a promise to return the result.

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Required permissions: ohos.permission.EXECUTE_INSIGHT_INTENT

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name of the application.
NOTE
If the bundle name does not exist, an empty array is returned.
intentFlagsnumberYesFlag of the InsightIntent information (InsightIntentInfo). It is used to query full or brief InsightIntent information.

Return value

TypeDescription
Promise<Array<InsightIntentInfo>>Promise used to return an array holding InsightIntentInfo objects.

Error codes

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

IDError Message
201Permission denied.
202Not system application.
16000050Internal error.

Example

  import { insightIntentDriver } from '@kit.AbilityKit';
  import { BusinessError } from '@kit.BasicServicesKit';
  import { hilog } from '@kit.PerformanceAnalysisKit';

  async function getInfosByBundleName() {
    try {
      let bundleName = "com.example.intent"; // Use the actual bundle name.
      insightIntentDriver.getInsightIntentInfoByBundleName(bundleName, insightIntentDriver.GetInsightIntentFlag.GET_FULL_INSIGHT_INTENT).then((data) => {
        hilog.info(0x0000, 'testTag', 'getInsightIntentInfoByBundleName return %{public}s', JSON.stringify(data));
      }).catch((err: BusinessError) => {
        hilog.info(0x0000, 'testTag', 'getInsightIntentInfoByBundleName errCode: %{public}d', err.code);
        hilog.info(0x0000, 'testTag', 'getInsightIntentInfoByBundleName errMessage: %{public}s', err.message);
      });
    } catch (error) {
      hilog.error(0x0000, 'testTag', 'getInsightIntentInfoByBundleName error caught %{public}s', JSON.stringify(error));
    }
  }

insightIntentDriver.getInsightIntentInfoByIntentName20+

getInsightIntentInfoByIntentName(bundleName: string, moduleName: string, intentName: string, intentFlags: number): Promise<InsightIntentInfo>

Obtains the InsightIntent information on the current device based on the bundle name, module name, and InsightIntent name. This API uses a promise to return the result.

Model restriction: This API can be used only in the stage model.

System API: This is a system API.

Required permissions: ohos.permission.EXECUTE_INSIGHT_INTENT

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name of the application.
NOTE
If the bundle name does not exist, an empty object is returned.
moduleNamestringYesModule name
NOTE
If the module name does not exist, an empty object is returned.
intentNamestringYesInsightIntent name.
NOTE
If the InsightIntent name does not exist, an empty object is returned.
intentFlagsnumberYesFlag of the InsightIntent information (InsightIntentInfo). It is used to query full or brief InsightIntent information.

Return value

TypeDescription
Promise<InsightIntentInfo>Promise used to return the InsightIntentInfo object.

Error codes

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

IDError Message
201Permission denied.
202Not system application.
16000050Internal error.

Example

  import { insightIntentDriver } from '@kit.AbilityKit';
  import { BusinessError } from '@kit.BasicServicesKit';
  import { hilog } from '@kit.PerformanceAnalysisKit';

  function getInfoByIntentName() {
    try {
      let bundleName = "com.example.intent"; // Use the actual bundle name.
      let moduleName = "entry"; // Use the actual module name.
      let intentName = "play"; // Use the actual InsightIntent name.
      insightIntentDriver.getInsightIntentInfoByIntentName(
        bundleName, moduleName, intentName, insightIntentDriver.GetInsightIntentFlag.GET_FULL_INSIGHT_INTENT)
      .then((data) => {
        hilog.info(0x0000, 'testTag', 'getInsightIntentInfoByIntentName return %{public}s', JSON.stringify(data));
      }).catch((err: BusinessError) => {
        hilog.info(0x0000, 'testTag', 'getInsightIntentInfoByIntentName errCode: %{public}d', err.code);
        hilog.info(0x0000, 'testTag', 'getInsightIntentInfoByIntentName errMessage: %{public}s', err.message);
      });
    } catch (error) {
      hilog.error(0x0000, 'testTag', 'getInsightIntentInfoByIntentName error caught %{public}s', JSON.stringify(error));
    }
  }

你可能感兴趣的鸿蒙文章

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/2k2EoN