@ohos.app.ability.insightIntentDriver (Intent Call Execution) (System API)

The module provides APIs for executing intent calls. The system executes intent 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 intents defined by the @InsightIntentLink decorator.

Modules to Import

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

ExecuteParam

Defines the parameter used to execute an intent 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

Name Type Read-Only Optional Description
bundleName string No No Name of the bundle to which the ability to be called belongs.
moduleName string No No Name of the module to which the ability belongs.
abilityName string No No Name of the ability to be called. If an intent defined by the @InsightIntentLink decorator is used to implement application redirection, this parameter can be left empty.
insightIntentName string No No Intent name.
insightIntentParam Record<string, Object> No No Intent call parameter.
executeMode insightIntent.ExecuteMode No No Intent execution mode. If an intent 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+ number No Yes Physical screen ID specified during intent call. The value must be an integer. This parameter is valid only when executeMode is set to UI_ABILITY_FOREGROUND.
uris18+ Array<string> No Yes List of URIs authorized by the intent caller to the intent executor during the call. If an intent 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+ number No Yes Flags of the URIs authorized by the intent caller to the intent 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|
userId23+ number No Yes ID of the user to which the intent belongs.
NOTE
If the user ID of the calling application is different from the user ID of the intent, the calling application must request the ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS permission.

InsightIntentInfoFilter23+

Defines an intent filter, which specifies the criteria for selecting target intents. It is used to filter intents on the device that meet these criteria.

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

Name Type Read-Only Optional Description
intentFlags number No No Flag of the intent information (InsightIntentInfo). It is used to query full or brief intent information. For details, see GetInsightIntentFlag.
bundleName string No Yes Bundle name of the application to which the intent belongs.
moduleName string No Yes Module name of the application to which the intent belongs.
intentName string No Yes Intent name.
userId number No Yes ID of the user to which the intent belongs.
NOTE
If the user ID of the calling application is different from the user ID of the intent, the calling application must request the ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS permission.

InsightIntentType20+

Enumerates the intent types defined by the intent decorator. You can obtain the intent type from LinkIntentInfo returned by calling APIs such as getAllInsightIntentInfo.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Name Value Description
LINK @InsightIntentLink A decorator of the @InsightIntentLink type.
PAGE @InsightIntentPage A decorator of the @InsightIntentPage type.
ENTRY @InsightIntentEntry A decorator of the @InsightIntentEntry type.
FUNCTION @InsightIntentFunctionMethod A decorator of the @InsightIntentFunctionMethod type.
FORM @InsightIntentForm A decorator of the @InsightIntentForm type.

ExecuteModeForConfiguration23+

Enumerates the execution modes supported by an intent developed using a configuration file. For example, if executeMode in the insight_intent.json configuration file is set to foreground, the intent bound to the UIAbility can run in the foreground.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Name Value Description
FOREGROUND 0 The intent bound to the UIAbility can run in the foreground.
BACKGROUND 1 The intent bound to the UIAbility can run in the background.

LinkIntentInfo20+

Describes the 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

Name Type Read-Only Optional Description
uri string Yes No URI of an intent.

PageIntentInfo20+

Describes the parameters supported by the @InsightIntentPage decorator, such as the NavDestination name 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

Name Type Read-Only Optional Description
uiAbility string Yes No Ability name.
pagePath string Yes No Page name.
navigationId string Yes No ID of the Navigation component bound to the intent.
navDestinationName string Yes No Name of the NavDestination component bound to the intent.

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

FormIntentInfo20+

Describes the parameters supported by the @InsightIntentForm decorator, such as the widget name. It also describes the widget information bound to the intent developed using a configuration file.

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

Name Type Read-Only Optional Description
abilityName string Yes No Ability name.
formName string Yes No Name of the widget bound to the FormExtensionAbility.

EntryIntentInfo20+

Describes the parameters supported by the @InsightIntentEntry decorator, such as the intent execution mode.

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

Name Type Read-Only Optional Description
abilityName string Yes No Ability name.
executeMode insightIntent.ExecuteMode[] Yes No Intent execution mode. that is, execution mode supported when the bound ability is started.

SubIntentInfoForConfiguration23+

Describes the unique information of the intent developed using a configuration file.

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

Name Type Read-Only Optional Description
srcEntry string Yes No Relative path of the intent execution file. The value is a string of a maximum of 127 bytes.
inputParams Array<Record<string, Object>> Yes Yes Data format of intent parameters, which is used to define the input data format during intent calls.
outputParams Array<Record<string, Object>> Yes Yes Data format for the results returned by intent calls. It defines how the data should be structured.
uiAbility UIAbilityIntentInfo Yes Yes Information about the UIAbility bound to the intent, including the ability and executeMode fields.
uiExtension UIExtensionIntentInfo Yes Yes Information about the UIExtensionAbility bound to the intent.
from FormIntentInfo Yes Yes Information about the widget bound to the intent.
serviceExtension ServiceExtensionIntentInfo Yes Yes Information about the ServiceExtensionAbility bound to the intent.
entities Record<string, Object> Yes Yes Entity information contained in the intent.

UIAbilityIntentInfo23+

Describes the information of the UIAbility bound to the intent developed using a configuration file.

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

Name Type Read-Only Optional Description
abilityName string Yes No Name of the UIAbility bound to the intent.
executeMode ExecuteModeForConfiguration[] Yes No Intent execution mode.

UIExtensionIntentInfo23+

Describes the information of the UIExtensionAbility bound to the intent developed using a configuration file.

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

Name Type Read-Only Optional Description
abilityName string Yes No Name of the UIExtensionAbility bound to the intent.

ServiceExtensionIntentInfo23+

Describes the information of the ServiceExtensionAbility bound to the intent developed using a configuration file.

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

Name Type Read-Only Optional Description
abilityName string Yes No Name of the ServiceExtensionAbility bound to the intent.

DevelopType23+

Enumerates the modes that define how an intent is developed.

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

Name Value Description
CONFIGURATION 'configuration' The intent is developed using a configuration file.
DECORATOR 'decorator' The intent is developed using a decorator.

EntityInfo20+

EntityInfo inherits from IntentEntityDecoratorInfo and is used to describe the information about the intent entity defined by the @InsightIntentEntity decorator.

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

Name Type Read-Only Optional Description
className string Yes No Class name decorated by @InsightIntentEntity.
entityId string Yes No ID of the intent entity.
entityCategory string Yes No Category of the intent entity.
parameters string Yes No Data format of intent entity parameters.
parentClassName string Yes No Parent class name decorated by @InsightIntentEntity.

InsightIntentInfo20+

Defines the intent information, which is the specific parameter configuration of the intent 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

Name Type Read-Only Optional Description
bundleName string Yes No Bundle name of the application.
moduleName string Yes No Module name.
intentName string Yes No Intent name.
domain string Yes No Vertical domain of the intent. It is used to categorize intents 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.
intentVersion string Yes No Version number of the intent. It is used to distinguish and manage intents when their capabilities evolve.
displayName string Yes No Name of the intent displayed in the InsightIntent framework.
displayDescription string Yes No Description of the intent displayed in the InsightIntent framework.
schema string Yes No Standard intent name. If an intent in the standard intent list matches both the schema and intentVersion fields, it is processed as a standard intent.
icon string Yes No Icon of the intent.
llmDescription string Yes No Function of an intent, which helps large language models understand the intent.
keywords string[] Yes No Search keywords for the intent.
intentType InsightIntentType Yes No Type of intent defined by the intent decorator.
NOTE
For intents developed using a configuration file, the return value of this field is @InsightIntentEntry by default.
subIntentInfo LinkIntentInfo | PageIntentInfo | FunctionIntentInfo | FormIntentInfo | EntryIntentInfo Yes No Intent information for specific intent decorators.
NOTE
For intents developed using a configuration file, the return value of this field is EntryIntentInfo by default.
parameters Record<string, Object> Yes No Data format of intent parameters, which is used to define the input data format during intent calls.
result Record<string, Object> Yes No Execution result returned.
entities Array<EntityInfo> Yes No Entity information contained in the intent.
subIntentInfoForConfiguration23+ SubIntentInfoForConfiguration Yes Yes Unique information about the intent developed using a configuration file.
developType23+ DevelopType Yes Yes Development mode of the intent.

GetInsightIntentFlag20+

Enumerates the flags of intent information (InsightIntentInfo). It is used in getAllInsightIntentInfo, getInsightIntentInfoByBundleName, and getInsightIntentInfoByIntentName.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Name Value Description
GET_FULL_INSIGHT_INTENT 0x00000001 Used to query all intent information (except entities) in InsightIntentInfo. To query entities information, use GET_ENTITY_INFO.
GET_SUMMARY_INSIGHT_INTENT 0x00000002 Used to query brief intent information in InsightIntentInfo.
GET_ENTITY_INFO 0x00000004 Used to query EntityInfo. It must be used together with GET_FULL_INSIGHT_INTENT or GET_SUMMARY_INSIGHT_INTENT. Example usage: GET_FULL_INSIGHT_INTENT | GET_ENTITY_INFO.

NOTE

  • For intents developed using a configuration file, the full and brief information queried through the preceding APIs are the same.
  • For intents developed using a decorator, the full and brief information queried through the preceding APIs are different, as described below.

Table 1 Differences between full intent information and brief intent information

Name Included in Full Intent Information Included in Brief Intent Information
bundleName Yes Yes
moduleName Yes Yes
intentName Yes Yes
domain Yes No
intentVersion Yes No
displayName Yes Yes
displayDescription Yes No
schema Yes No
icon Yes No
llmDescription Yes No
keywords Yes No
intentType Yes Yes
subIntentInfo Yes Yes
parameters Yes Yes
entities No No
developType23+ Yes Yes
subIntentInfoForConfiguration23+ No No

insightIntentDriver.execute

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

Executes a call to an intent. 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 intent 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

Name Type Mandatory Description
param ExecuteParam Yes Parameter used to execute the intent call.
callback AsyncCallback<insightIntent.ExecuteResult> Yes Callback used to return the intent call execution result.

Error codes

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

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

Name Type Mandatory Description
param ExecuteParam Yes Parameter used to execute the intent call.

Return value

Type Description
Promise<insightIntent.ExecuteResult> Promise used to return the intent call execution result.

Error codes

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

ID Error Message
201 Permission denied.
202 Not system application.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
16000001 The specified ability does not exist.
16000002 Incorrect ability type.
16000004 Cannot start an invisible component.
16000005 The specified process does not have the permission.
16000006 Cross-user operations are not allowed.
16000008 The crowdtesting application expires.
16000009 An ability cannot be started or stopped in Wukong mode.
16000010 The call with the continuation and prepare continuation flag is forbidden.
16000011 The context does not exist.
16000012 The application is controlled.
16000013 The application is controlled by EDM.
16000050 Internal error.
16000053 The ability is not on the top of the UI.
16000055 Installation-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 intents 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.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
intentFlags number Yes Flag of the intent information (InsightIntentInfo). It is used to query full or brief intent information. For details, see GetInsightIntentFlag.

Return value

Type Description
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.

ID Error Message
201 Permission denied.
202 Not system application.
16000050 Internal error. Possible causes: 1. Failed to connect to the system service; 2. The system service failed to communicate with dependency module.

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 | insightIntentDriver.GetInsightIntentFlag.GET_ENTITY_INFO).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 intent 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.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name of the application.
NOTE
If the bundle name does not exist, an empty array is returned.
intentFlags number Yes Flag of the intent information (InsightIntentInfo). It is used to query full or brief intent information. For details, see GetInsightIntentFlag.

Return value

Type Description
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.

ID Error Message
201 Permission denied.
202 Not system application.
16000050 Internal error. Possible causes: 1. Failed to connect to the system service; 2. The system service failed to communicate with dependency module.

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 | insightIntentDriver.GetInsightIntentFlag.GET_ENTITY_INFO).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 intent information on the current device based on the bundle name, module name, and intent 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.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name of the application.
NOTE
If the bundle name does not exist, an empty object is returned.
moduleName string Yes Module name
NOTE
If the module name does not exist, an empty object is returned.
intentName string Yes Intent name.
NOTE
If the intent name does not exist, an empty object is returned.
intentFlags number Yes Flag of the intent information (InsightIntentInfo). It is used to query full or brief intent information. For details, see GetInsightIntentFlag.

Return value

Type Description
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.

ID Error Message
201 Permission denied.
202 Not system application.
16000050 Internal error. Possible causes: 1. Failed to connect to the system service; 2. The system service failed to communicate with dependency module.

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 intent name.
      insightIntentDriver.getInsightIntentInfoByIntentName(
        bundleName, moduleName, intentName, insightIntentDriver.GetInsightIntentFlag.GET_FULL_INSIGHT_INTENT | insightIntentDriver.GetInsightIntentFlag.GET_ENTITY_INFO)
      .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));
    }
  }

insightIntentDriver.getInsightIntentInfoByFilter23+

getInsightIntentInfoByFilter(filter: InsightIntentInfoFilter): Promise<Array<InsightIntentInfo>>

Obtains the intent information on the current device based on the given intent filter. This API uses a promise to return the result.
If the user ID of the calling application is different from the user ID of the intent, the calling application must request the ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS permission.

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

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
filter InsightIntentInfoFilter Yes Intent filter, which specifies the criteria for selecting a target intent. It is used to filter intents on the device that meet these criteria.

Return value

Type Description
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.

ID Error Message
201 Permission denied.
202 Not system application.
16000050 Internal error. Possible causes: 1. Connect to system service failed; 2.Send restart message to system service failed; 3.System service failed to communicate with dependency module.

Example

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

function getInfoByFilter() {
  let filter: insightIntentDriver.InsightIntentInfoFilter = {
    intentFlags: insightIntentDriver.GetInsightIntentFlag.GET_FULL_INSIGHT_INTENT | insightIntentDriver.GetInsightIntentFlag.GET_ENTITY_INFO,
    bundleName: 'com.example.intent', // Use the actual bundle name.
    moduleName: 'entry', // Use the actual module name.
    intentName: 'play', // Use the actual intent name.
    userId: 100, // Use the actual user ID.
  };

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