@ohos.app.ability.insightIntentDriver (执行意图调用)(系统接口)

本模块提供执行意图调用的能力,系统根据用户交互等信息执行意图调用。

说明:

本模块首批接口从API version 11开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

本模块接口仅可在Stage模型下使用。

本模块为系统接口。

本模块从API version 20开始支持通过@InsightIntentLink装饰器定义的意图来实现应用跳转。

导入模块

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

ExecuteParam

执行意图调用的参数。

模型约束:此接口仅可在Stage模型下使用。

系统接口:此接口为系统接口。

系统能力:SystemCapability.Ability.AbilityRuntime.Core

名称 类型 只读 可选 说明
bundleName string 意图调用Ability所属的应用名称。
moduleName string 意图调用Ability所属的模块名称。
abilityName string 意图调用Ability名称。 如果通过@InsightIntentLink装饰器定义的意图来实现应用跳转,此字段传空字符串即可。
insightIntentName string 意图调用名称。
insightIntentParam Record<string, Object> 意图调用参数。
executeMode insightIntent.ExecuteMode 意图调用执行模式。 如果通过@InsightIntentLink装饰器定义的意图来实现应用跳转,此字段需填写(可填任意符合定义的值),但实际不会生效。
displayId12+ number 意图调用时指定的物理屏幕id,该参数应为整数,仅在executeMode为UI_ABILITY_FOREGROUND时生效。
uris18+ Array<string> 意图调用时,意图调用方给意图执行方授权的URI列表。 如果通过@InsightIntentLink装饰器定义的意图来实现应用跳转,此字段必选,仅读取数组第一个元素作为openLink的URI。
flags18+ number 意图调用时,意图调用方给意图执行方授权的uris的flags
说明:
该参数仅支持FLAG_AUTH_READ_URI_PERMISSION、FLAG_AUTH_WRITE_URI_PERMISSION、FLAG_AUTH_READ_URI_PERMISSION|FLAG_AUTH_WRITE_URI_PERMISSION。
userId23+ number 目标意图所属的用户ID。
说明:
如果调用方应用的用户ID与目标意图所属的用户ID不同,则需要申请权限ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

InsightIntentInfoFilter23+

意图筛选器,描述目标意图的筛选条件,用于筛选设备上符合条件的意图。

模型约束:此接口仅可在Stage模型下使用。

系统接口:此接口为系统接口。

系统能力:SystemCapability.Ability.AbilityRuntime.Core

名称 类型 只读 可选 说明
intentFlags number 意图信息(InsightIntentInfo)的标识,用于表示查询全量意图信息或者简要意图信息,取值可参考GetInsightIntentFlag
bundleName string 目标意图所属的应用包名称。
moduleName string 目标意图所属的模块名称。
intentName string 目标意图名称。
userId number 目标意图所属的用户ID。
说明:
如果调用方应用的用户ID与目标意图所属的用户ID不同,则需要申请权限ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

InsightIntentType20+

表示通过意图装饰器定义的意图类型,可通过getAllInsightIntentInfo等方法返回的LinkIntentInfo获取。

系统能力:SystemCapability.Ability.AbilityRuntime.Core

名称 说明
LINK @InsightIntentLink @InsightIntentLink类型装饰器。
PAGE @InsightIntentPage @InsightIntentPage类型装饰器。
ENTRY @InsightIntentEntry @InsightIntentEntry类型装饰器。
FUNCTION @InsightIntentFunctionMethod @InsightIntentFunctionMethod类型装饰器。
FORM @InsightIntentForm @InsightIntentForm类型装饰器。

ExecuteModeForConfiguration23+

使用配置文件开发的意图支持的意图执行模式。例如,将insight_intent.json配置文件中的executeMode设置为"foreground",表示支持与UIAbility组件绑定的意图在前台运行。

系统能力:SystemCapability.Ability.AbilityRuntime.Core

名称 说明
FOREGROUND 0 表示支持与UIAbility组件绑定的意图在前台运行。
BACKGROUND 1 表示支持与UIAbility组件绑定的意图在后台运行。

LinkIntentInfo20+

LinkIntentInfo用于描述@InsightIntentLink装饰器支持的参数,例如应用间跳转需要的uri信息。

模型约束:此接口仅可在Stage模型下使用。

系统接口:此接口为系统接口。

系统能力:SystemCapability.Ability.AbilityRuntime.Core

名称 类型 只读 可选 说明
uri string 表示意图的uri信息。

PageIntentInfo20+

PageIntentInfo用于描述@InsightIntentPage装饰器支持的参数,例如目标页面的NavDestination名称。

模型约束:此接口仅可在Stage模型下使用。

系统接口:此接口为系统接口。

系统能力:SystemCapability.Ability.AbilityRuntime.Core

名称 类型 只读 可选 说明
uiAbility string Ability名称。
pagePath string 页面名称。
navigationId string 表示与意图绑定Navigation的id。
navDestinationName string 表示与意图绑定NavDestination组件的名称。

FunctionIntentInfo20+

@InsightIntentFunctionMethod装饰器的参数类型,当前全部属性均继承自IntentDecoratorInfo

模型约束:此接口仅可在Stage模型下使用。

系统接口:此接口为系统接口。

系统能力:SystemCapability.Ability.AbilityRuntime.Core

FormIntentInfo20+

FormIntentInfo用于描述@InsightIntentForm装饰器支持的参数,例如卡片名称。同时,该接口也可用于描述使用配置文件开发的意图所绑定的卡片信息。

模型约束:此接口仅可在Stage模型下使用。

系统接口:此接口为系统接口。

系统能力:SystemCapability.Ability.AbilityRuntime.Core

名称 类型 只读 可选 说明
abilityName string Ability名称。
formName string 表示FormExtensionAbility绑定的卡片名称。

EntryIntentInfo20+

EntryIntentInfo用于描述@InsightIntentEntry装饰器支持的参数,例如意图调用执行模式。

模型约束:此接口仅可在Stage模型下使用。

系统接口:此接口为系统接口。

系统能力:SystemCapability.Ability.AbilityRuntime.Core

名称 类型 只读 可选 说明
abilityName string Ability名称。
executeMode insightIntent.ExecuteMode[] 意图调用执行模式。即拉起绑定的Ability时支持的执行模式。

SubIntentInfoForConfiguration23+

用于描述使用配置文件开发的意图的特有信息。

模型约束:此接口仅可在Stage模型下使用。

系统接口:此接口为系统接口。

系统能力:SystemCapability.Ability.AbilityRuntime.Core

名称 类型 只读 可选 说明
srcEntry string 表示意图执行文件的相对路径,取值为长度不超过127字节的字符串。
inputParams Array<Record<string, Object>> 表示意图参数的数据格式声明,用于意图调用时定义入参的数据格式。
outputParams Array<Record<string, Object>> 表示意图调用返回结果的数据格式声明,用于定义意图调用返回结果的数据格式。
uiAbility UIAbilityIntentInfo 表示意图绑定的UIAbility组件信息,包含"ability"字段和"executeMode"字段。
uiExtension UIExtensionIntentInfo 表示意图绑定的UIExtensionAbility组件信息。
from FormIntentInfo 表示意图绑定的卡片信息。
serviceExtension ServiceExtensionIntentInfo 表示意图绑定的ServiceExtensionAbility组件信息。
entities Record<string, Object> 表示意图包含的实体信息。

UIAbilityIntentInfo23+

用于描述使用配置文件开发的意图所绑定的UIAbility组件信息。

模型约束:此接口仅可在Stage模型下使用。

系统接口:此接口为系统接口。

系统能力:SystemCapability.Ability.AbilityRuntime.Core

名称 类型 只读 可选 说明
abilityName string 意图绑定的UIAbility组件名称。
executeMode ExecuteModeForConfiguration[] 意图调用执行模式。

UIExtensionIntentInfo23+

用于描述使用配置文件开发的意图所绑定的UIExtensionAbility组件信息。

模型约束:此接口仅可在Stage模型下使用。

系统接口:此接口为系统接口。

系统能力:SystemCapability.Ability.AbilityRuntime.Core

名称 类型 只读 可选 说明
abilityName string 意图绑定的UIExtensionAbility组件名称。

ServiceExtensionIntentInfo23+

用于描述使用配置文件开发的意图所绑定的ServiceExtensionAbility组件信息。

模型约束:此接口仅可在Stage模型下使用。

系统接口:此接口为系统接口。

系统能力:SystemCapability.Ability.AbilityRuntime.Core

名称 类型 只读 可选 说明
abilityName string 意图绑定的ServiceExtensionAbility组件名称。

DevelopType23+

用于描述意图的开发方式。

模型约束:此接口仅可在Stage模型下使用。

系统接口:此接口为系统接口。

系统能力:SystemCapability.Ability.AbilityRuntime.Core

名称 说明
CONFIGURATION 'configuration' 使用配置文件开发的意图。
DECORATOR 'decorator' 使用装饰器开发的意图。

EntityInfo20+

EntityInfo继承自IntentEntityDecoratorInfo,用于描述@InsightIntentEntity装饰器定义的意图实体的信息。

模型约束:此接口仅可在Stage模型下使用。

系统接口:此接口为系统接口。

系统能力:SystemCapability.Ability.AbilityRuntime.Core

名称 类型 只读 可选 说明
className string 表示@InsightIntentEntity装饰器修饰的类名。
entityId string 表示意图实体的ID。
entityCategory string 表示意图实体类别。
parameters string 表示意图实体参数的数据格式声明,用于意图调用时定义实体参数的数据格式。
parentClassName string 表示@InsightIntentEntity装饰器修饰的类的父类名。

InsightIntentInfo20+

意图信息,表示设备中意图的具体参数配置。

模型约束:此接口仅可在Stage模型下使用。

系统接口:此接口为系统接口。

系统能力:SystemCapability.Ability.AbilityRuntime.Core

名称 类型 只读 可选 说明
bundleName string 表示应用包名称。
moduleName string 表示模块名称。
intentName string 表示意图名称。
domain string 表示意图垂域,用于将意图按垂直领域分类(例如:视频、音乐、游戏),取值范围参见各垂域的智慧分发特性列表中的垂域字段。
intentVersion string 意图版本号,当意图能力演进时,可通过版本号进行区分和管理。
displayName string 表示在意图框架中显示的意图名称。
displayDescription string 表示在意图框架中显示的意图描述。
schema string 标准意图名称,如果在标准意图列表中存在schema与intentVersion字段均匹配的意图,则按照标准意图处理。
icon string 表示意图图标。
llmDescription string 表示意图的功能,用于大型语言模型理解该意图。
keywords string[] 表示意图的搜索关键字。
intentType InsightIntentType 表示通过意图装饰器定义的意图类型。
说明:
对于使用配置文件开发的意图,该字段返回值默认为@InsightIntentEntry类型装饰器。
subIntentInfo LinkIntentInfo | PageIntentInfo | FunctionIntentInfo | FormIntentInfo | EntryIntentInfo 表示特定意图装饰器的意图信息。
说明:
对于使用配置文件开发的意图,该字段返回值默认为EntryIntentInfo
parameters Record<string, Object> 表示意图参数的数据格式声明,用于意图调用时定义入参的数据格式。
result Record<string, Object> 表示意图调用返回的结果。
entities Array<EntityInfo> 表示意图包含的实体信息。
subIntentInfoForConfiguration23+ SubIntentInfoForConfiguration 表示使用配置文件开发的意图的特有信息。
developType23+ DevelopType 表示意图的开发方式。

GetInsightIntentFlag20+

意图信息(InsightIntentInfo)的标识,用于getAllInsightIntentInfogetInsightIntentInfoByBundleNamegetInsightIntentInfoByIntentName接口查询意图信息。

系统能力:SystemCapability.Ability.AbilityRuntime.Core

名称 说明
GET_FULL_INSIGHT_INTENT 0x00000001 查询InsightIntentInfo中的除entities以外的全量意图信息,详见下表。查询entities信息需要使用GET_ENTITY_INFO。
GET_SUMMARY_INSIGHT_INTENT 0x00000002 查询InsightIntentInfo中的简要意图信息,详见下表。
GET_ENTITY_INFO 0x00000004 查询EntityInfo的信息,不可单独使用,必选结合GET_FULL_INSIGHT_INTENT或者GET_SUMMARY_INSIGHT_INTENT使用。例如GET_FULL_INSIGHT_INTENT | GET_ENTITY_INFO

说明:

  • 对于使用配置文件开发的意图,通过上述接口查询的全量信息和简要信息完全一致。
  • 对于使用装饰器开发的意图,通过上述接口查询的全量信息和简要信息存在差别,详见下表。

表1 全量意图信息与简要意图信息差别

属性 全量意图信息是否包含 简要意图信息是否包含
bundleName
moduleName
intentName
domain
intentVersion
displayName
displayDescription
schema
icon
llmDescription
keywords
intentType
subIntentInfo
parameters
entities
developType23+
subIntentInfoForConfiguration23+

insightIntentDriver.execute

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

执行意图调用的接口。使用callback异步回调。 当调用方在后台时,需要申请ohos.permission.START_ABILITIES_FROM_BACKGROUND权限。 当意图调用执行模式ExecuteMode取值为UI_ABILITY_BACKGROUND时,需要申请ohos.permission.ABILITY_BACKGROUND_COMMUNICATION权限。

模型约束:此接口仅可在Stage模型下使用。

系统接口:此接口为系统接口。

需要权限:ohos.permission.EXECUTE_INSIGHT_INTENT

系统能力:SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
param ExecuteParam 执行意图调用的参数。
callback AsyncCallback<insightIntent.ExecuteResult> 回调函数,返回意图调用执行结果。

错误码

以下错误码详细介绍请参考通用错误码元能力子系统错误码

错误码ID 错误信息
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.

示例:

  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>

执行意图调用的接口。使用Promise异步回调。 当调用方在后台时,需要申请ohos.permission.START_ABILITIES_FROM_BACKGROUND权限。 当意图调用执行模式ExecuteMode取值为UI_ABILITY_BACKGROUND时,需要申请ohos.permission.ABILITY_BACKGROUND_COMMUNICATION权限。

模型约束:此接口仅可在Stage模型下使用。

系统接口:此接口为系统接口。

需要权限:ohos.permission.EXECUTE_INSIGHT_INTENT

系统能力:SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
param ExecuteParam 执行意图调用的参数。

返回值:

类型 说明
Promise<insightIntent.ExecuteResult> Promise对象,返回意图调用执行结果。

错误码

以下错误码详细介绍请参考通用错误码元能力子系统错误码

错误码ID 错误信息
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.

示例:

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

查询当前设备上的所有意图信息。使用Promise异步回调。

模型约束:此接口仅可在Stage模型下使用。

系统接口:此接口为系统接口。

需要权限:ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力:SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
intentFlags number 意图信息(InsightIntentInfo)的标识,用于表示查询全量意图信息或者简要意图信息,参考GetInsightIntentFlag

返回值:

类型 说明
Promise<Array<InsightIntentInfo>> Promise对象,返回意图信息对象数组。

错误码

以下错误码详细介绍请参考通用错误码元能力子系统错误码

错误码ID 错误信息
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.

示例:

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

根据包名查询当前设备上的意图信息。使用Promise异步回调。

模型约束:此接口仅可在Stage模型下使用。

系统接口:此接口为系统接口。

需要权限:ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力:SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
bundleName string 应用包名称。
说明:
若包名不存在,则返回空数组。
intentFlags number 意图信息(InsightIntentInfo)的标识,用于表示查询全量意图信息或者简要意图信息,参考GetInsightIntentFlag

返回值:

类型 说明
Promise<Array<InsightIntentInfo>> Promise对象,返回意图信息对象数组。

错误码

以下错误码详细介绍请参考通用错误码元能力子系统错误码

错误码ID 错误信息
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.

示例:

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

  async function getInfosByBundleName() {
    try {
      let bundleName = "com.example.intent"; // 开发者需自行修改为实际包名
      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>

根据包名、模块名和意图名查询当前设备上的意图信息。使用Promise异步回调。

模型约束:此接口仅可在Stage模型下使用。

系统接口:此接口为系统接口。

需要权限:ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力:SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
bundleName string 应用包名称。
说明:
若包名不存在,则返回空对象。
moduleName string 模块名称。
说明:
若模块名不存在,则返回空对象。
intentName string 意图名称。
说明:
若意图名不存在,则返回空对象。
intentFlags number 意图信息(InsightIntentInfo)的标识,用于表示查询全量意图信息或者简要意图信息,参考GetInsightIntentFlag

返回值:

类型 说明
Promise<InsightIntentInfo> Promise对象,返回意图信息对象。

错误码

以下错误码详细介绍请参考通用错误码元能力子系统错误码

错误码ID 错误信息
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.

示例:

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

  function getInfoByIntentName() {
    try {
      let bundleName = "com.example.intent"; // 开发者需自行修改为实际包名
      let moduleName = "entry"; // 开发者需自行修改为实际模块名
      let intentName = "play"; // 开发者需自行修改为实际意图名
      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>>

根据InsightIntentInfoFilter查询当前设备上的意图信息。使用Promise异步回调。
如果调用方应用的用户ID与目标用户ID不同,则需要申请权限ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS

模型约束:此接口仅可在Stage模型下使用。

系统接口:此接口为系统接口。

需要权限:ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力:SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
filter InsightIntentInfoFilter 意图筛选器,描述目标意图的筛选条件,用于筛选设备上符合条件的意图。

返回值:

类型 说明
Promise<Array<InsightIntentInfo>> Promise对象,返回意图信息对象数组。

错误码

以下错误码详细介绍请参考通用错误码元能力子系统错误码

错误码ID 错误信息
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.

示例:

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', // 开发者需自行修改为实际包名
    moduleName: 'entry', // 开发者需自行修改为实际模块名
    intentName: 'play', // 开发者需自行修改为实际意图名
    userId: 100, // 开发者需自行修改为实际userId
  };

  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));
  }
}