1# @ohos.app.ability.insightIntentDriver (执行意图调用)(系统接口) 2 3<!--Kit: Ability Kit--> 4<!--Subsystem: Ability--> 5<!--Owner: @linjunjie6--> 6<!--Designer: @li-weifeng2--> 7<!--Tester: @lixueqing513--> 8<!--Adviser: @huipeizi--> 9 10本模块提供执行意图调用的能力,系统根据用户交互等信息执行意图调用。 11 12> **说明:** 13> 14> 本模块首批接口从API version 11开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 15> 16> 本模块接口仅可在Stage模型下使用。 17> 18> 本模块为系统接口。 19> 20> 本模块从API version 20开始支持通过[@InsightIntentLink](js-apis-app-ability-InsightIntentDecorator.md#insightintentlink)装饰器定义的意图来实现应用跳转。 21 22## 导入模块 23 24```ts 25import { insightIntentDriver } from '@kit.AbilityKit'; 26``` 27 28## ExecuteParam 29 30执行意图调用的参数。 31 32**模型约束**:此接口仅可在Stage模型下使用。 33 34**系统接口**:此接口为系统接口。 35 36**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 37 38| 名称 | 类型 | 只读 | 可选 | 说明 | 39| -------- | -------- | --- |----- | -------- | 40| bundleName | string | 否 | 否 | 意图调用Ability所属的应用名称。 | 41| moduleName | string | 否 | 否 | 意图调用Ability所属的模块名称。 | 42| abilityName | string | 否 | 否 | 意图调用Ability名称。 如果通过[@InsightIntentLink](js-apis-app-ability-InsightIntentDecorator.md#insightintentlink)装饰器定义的意图来实现应用跳转,此字段传空字符串即可。 | 43| insightIntentName | string | 否 | 否 | 意图调用名称。 | 44| insightIntentParam | Record\<string, Object> | 否 | 否 | 意图调用参数。 | 45| executeMode | [insightIntent.ExecuteMode](js-apis-app-ability-insightIntent.md#executemode) | 否 | 否 | 意图调用执行模式。 如果通过[@InsightIntentLink](js-apis-app-ability-InsightIntentDecorator.md#insightintentlink)装饰器定义的意图来实现应用跳转,此字段需填写(可填任意符合定义的值),但实际不会生效。 | 46| displayId<sup>12+</sup> | number | 否 | 是 | 意图调用时指定的物理屏幕id,该参数应为整数,仅在executeMode为UI_ABILITY_FOREGROUND时生效。 | 47| uris<sup>18+</sup> | Array<string> | 否 | 是 | 意图调用时,意图调用方给意图执行方授权的URI列表。 如果通过[@InsightIntentLink](js-apis-app-ability-InsightIntentDecorator.md#insightintentlink)装饰器定义的意图来实现应用跳转,此字段必选,仅读取数组第一个元素作为[openLink](js-apis-inner-application-uiAbilityContext.md#openlink12)的URI。 | 48| flags<sup>18+</sup> | number | 否 | 是 | 意图调用时,意图调用方给意图执行方授权的uris的[flags](js-apis-app-ability-wantConstant.md#flags)。 <br/>**说明:**<br/>该参数仅支持FLAG_AUTH_READ_URI_PERMISSION、FLAG_AUTH_WRITE_URI_PERMISSION、FLAG_AUTH_READ_URI_PERMISSION\|FLAG_AUTH_WRITE_URI_PERMISSION。| 49 50## InsightIntentType<sup>20+<sup> 51 52表示通过意图装饰器定义的意图类型,可通过[getAllInsightIntentInfo](#insightintentdrivergetallinsightintentinfo20)等方法返回的[LinkIntentInfo](#linkintentinfo20)获取。 53 54**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 55 56| 名称 | 值 | 说明 | 57| -------- | -------- | -------- | 58| LINK | @InsightIntentLink | [@InsightIntentLink](./js-apis-app-ability-InsightIntentDecorator.md#insightintentlink)类型装饰器。 | 59| PAGE | @InsightIntentPage | [@InsightIntentPage](./js-apis-app-ability-InsightIntentDecorator.md#insightintentpage)类型装饰器。 | 60| ENTRY | @InsightIntentEntry | [@InsightIntentEntry](./js-apis-app-ability-InsightIntentDecorator.md#insightintententry)类型装饰器。 | 61| FUNCTION | @InsightIntentFunctionMethod | [@InsightIntentFunctionMethod](./js-apis-app-ability-InsightIntentDecorator.md#insightintentfunctionmethod)类型装饰器。 | 62| FORM | @InsightIntentForm | [@InsightIntentForm](./js-apis-app-ability-InsightIntentDecorator.md#insightintentform)类型装饰器。 | 63 64## LinkIntentInfo<sup>20+<sup> 65 66LinkIntentInfo继承自[IntentDecoratorInfo](./js-apis-app-ability-InsightIntentDecorator.md#intentdecoratorinfo),用于描述[@InsightIntentLink](./js-apis-app-ability-InsightIntentDecorator.md#insightintentlink)装饰器支持的参数,例如应用间跳转需要的uri信息。 67 68**模型约束**:此接口仅可在Stage模型下使用。 69 70**系统接口**:此接口为系统接口。 71 72**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 73 74| 名称 | 类型 | 只读 | 可选 | 说明 | 75| -------- | -------- | -------- | -------- |-------- | 76| uri | string | 是 | 否 | 表示意图的uri信息。 | 77 78## PageIntentInfo<sup>20+<sup> 79 80PageIntentInfo继承自[IntentDecoratorInfo](./js-apis-app-ability-InsightIntentDecorator.md#intentdecoratorinfo),用于描述[@InsightIntentPage](./js-apis-app-ability-InsightIntentDecorator.md#insightintentpage)装饰器支持的参数,例如目标页面的[NavDestination](../apis-arkui/arkui-ts/ts-basic-components-navigation.md#navdestination10)名称。 81 82**模型约束**:此接口仅可在Stage模型下使用。 83 84**系统接口**:此接口为系统接口。 85 86**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 87 88| 名称 | 类型 | 只读 | 可选 | 说明 | 89| -------- | -------- | -------- | -------- |-------- | 90| uiAbility | string | 是 | 否 | Ability名称。 | 91| pageRouterName | string | 是 | 否 | 页面名称。 | 92| navigationId | string | 是 | 否 | 表示与意图绑定[Navigation](../apis-arkui/arkui-ts/ts-basic-components-navigation.md)的id。 | 93| navDestination | string | 是 | 否 | 表示与意图绑定[NavDestination组件](../apis-arkui/arkui-ts/ts-basic-components-navigation.md#navdestination10)的名称。 | 94 95## FunctionIntentInfo<sup>20+<sup> 96 97[@InsightIntentFunctionMethod](./js-apis-app-ability-InsightIntentDecorator.md#insightintentfunctionmethod)装饰器的参数类型,当前全部属性均继承自[IntentDecoratorInfo](./js-apis-app-ability-InsightIntentDecorator.md#intentdecoratorinfo)。 98 99**模型约束**:此接口仅可在Stage模型下使用。 100 101**系统接口**:此接口为系统接口。 102 103**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 104 105## EntityInfo<sup>20+<sup> 106 107EntityInfo继承自[IntentEntityDecoratorInfo](./js-apis-app-ability-InsightIntentDecorator.md#intententitydecoratorinfo),用于描述[@InsightIntentEntity](./js-apis-app-ability-InsightIntentDecorator.md#insightintententity)装饰器定义的意图实体的信息。 108 109**模型约束**:此接口仅可在Stage模型下使用。 110 111**系统接口**:此接口为系统接口。 112 113**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 114 115| 名称 | 类型 | 只读 | 可选 | 说明 | 116| -------- | -------- | -------- | -------- |-------- | 117| className | string | 是 | 否 | 表示[@InsightIntentEntity](./js-apis-app-ability-InsightIntentDecorator.md#insightintententity)装饰器修饰的类名。 | 118| entityId | string | 是 | 否 | 表示意图实体的ID。 | 119| entityCategory | string | 是 | 否 | 表示意图实体类别。 | 120| parameters | string | 是 | 否 | 表示意图实体参数的数据格式声明,用于意图调用时定义实体参数的数据格式。 | 121| parentClassName | string | 是 | 否 | 表示[@InsightIntentEntity](./js-apis-app-ability-InsightIntentDecorator.md#insightintententity)装饰器修饰的类的父类名。 | 122 123## InsightIntentInfo<sup>20+<sup> 124 125意图信息,表示设备中意图的具体参数配置。 126 127**模型约束**:此接口仅可在Stage模型下使用。 128 129**系统接口**:此接口为系统接口。 130 131**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 132 133| 名称 | 类型 | 只读 | 可选 | 说明 | 134| -------- | -------- | -------- | -------- |-------- | 135| bundleName | string | 是 | 否 | 表示应用包名称。 | 136| moduleName | string | 是 | 否 | 表示模块名称。 | 137| intentName | string | 是 | 否 | 表示意图名称。 | 138| domain | string | 是 | 否 | 表示意图垂域,用于将意图按垂直领域分类(例如:视频、音乐、游戏),取值范围参见[各垂域的智慧分发特性列表](https://developer.huawei.com/consumer/cn/doc/service/intents-ai-distribution-characteristic-0000001901922213#section2656133582215)中的垂域字段。 | 139| intentVersion | string | 是 | 否 | 意图版本号,当意图能力演进时,可通过版本号进行区分和管理。| 140| displayName | string | 是 | 否 | 表示在意图框架中显示的意图名称。 | 141| displayDescription | string | 是 | 否 | 表示在意图框架中显示的意图描述。 | 142| schema | string | 是 | 否 | 标准意图名称,如果在标准意图列表中存在schema与intentVersion字段均匹配的意图,则按照标准意图处理。 | 143| icon | string | 是 | 否 | 表示意图图标。 | 144| llmDescription | string | 是 | 否 | 表示意图的功能,用于大型语言模型理解该意图。 | 145| keywords | Array<string> | 是 | 否 | 表示意图的搜索关键字。 | 146| intentType | [InsightIntentType](#insightintenttype20) | 是 | 否 | 表示通过意图装饰器定义的意图类型。 | 147| subIntentInfo | [LinkIntentInfo](#linkintentinfo20) \| [PageIntentInfo](#pageintentinfo20) \| [FunctionIntentInfo](#functionintentinfo20) | 是 | 否 | 表示特定意图装饰器的意图信息。 | 148| parameters | Record<string, Object> | 是 | 否 | 表示意图参数的数据格式声明,用于意图调用时定义入参的数据格式。 | 149| entities | Array<[EntityInfo](#entityinfo20)> | 是 | 否 | 表示意图包含的实体信息。 | 150 151## GetInsightIntentFlag<sup>20+<sup> 152 153意图信息([InsightIntentInfo](#insightintentinfo20))的标识,用于[getAllInsightIntentInfo](#insightintentdrivergetinsightintentinfobybundlename20)、[getInsightIntentInfoByBundleName](#insightintentdrivergetinsightintentinfobybundlename20)和[getInsightIntentInfoByIntentName](#insightintentdrivergetinsightintentinfobyintentname20)接口查询意图信息。 154 155**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 156 157| 名称 | 值 | 说明 | 158| -------- | -------- | -------- | 159| GET_FULL_INSIGHT_INTENT | 0x00000001 | 查询[InsightIntentInfo](#insightintentinfo20)中的除entities以外的全量意图信息,详见下表。查询entities信息需要使用GET_ENTITY_INFO。 | 160| GET_SUMMARY_INSIGHT_INTENT | 0x00000002 | 查询[InsightIntentInfo](#insightintentinfo20)中的简要意图信息,详见下表。 | 161| GET_ENTITY_INFO | 0x00000004 | 查询[EntityInfo](#entityinfo20)的信息,不可单独使用,必选结合GET_FULL_INSIGHT_INTENT或者GET_SUMMARY_INSIGHT_INTENT使用。例如`GET_FULL_INSIGHT_INTENT \| GET_ENTITY_INFO`。 | 162 163**表1** 全量意图信息与简要意图信息差别 164 165| 属性 | 全量意图信息是否包含 | 简要意图信息是否包含 | 166| -------- | -------- | -------- | 167| bundleName | 是 | 是 | 168| moduleName | 是 | 是 | 169| intentName | 是 | 是 | 170| domain | 是 | 否 | 171| intentVersion | 是 | 否 | 172| displayName | 是 | 是 | 173| displayDescription | 是 | 否 | 174| schema | 是 | 否 | 175| icon | 是 | 否 | 176| llmDescription | 是 | 否 | 177| keywords | 是 | 否 | 178| intentType | 是 | 是 | 179| subIntentInfo | 是 | 是 | 180| parameters | 是 | 是 | 181| entities | 否 | 否 | 182 183## insightIntentDriver.execute 184 185execute(param: ExecuteParam, callback: AsyncCallback<insightIntent.ExecuteResult>): void 186 187执行意图调用的接口。使用callback异步回调。 188当调用方在后台时,需要申请`ohos.permission.START_ABILITIES_FROM_BACKGROUND`权限。 189当意图调用执行模式[ExecuteMode](js-apis-app-ability-insightIntent.md#executemode)取值为UI_ABILITY_BACKGROUND时,需要申请`ohos.permission.ABILITY_BACKGROUND_COMMUNICATION`权限。 190 191**模型约束**:此接口仅可在Stage模型下使用。 192 193**系统接口**:此接口为系统接口。 194 195**需要权限**:ohos.permission.EXECUTE_INSIGHT_INTENT 196 197**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 198 199**参数:** 200 201 | 参数名 | 类型 | 必填 | 说明 | 202 | -------- | -------- | -------- | -------- | 203 | param | [ExecuteParam](#executeparam) | 是 | 执行意图调用的参数。 | 204 | callback | AsyncCallback<[insightIntent.ExecuteResult](js-apis-app-ability-insightIntent.md#executeresult)> | 是 | 回调函数,返回意图调用执行结果。 | 205 206**错误码**: 207 208以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 209 210| 错误码ID | 错误信息 | 211| -------- | -------- | 212| 201 | Permission denied. | 213| 202 | Not system application. | 214| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 215| 16000001 | The specified ability does not exist. | 216| 16000002 | Incorrect ability type. | 217| 16000004 | Cannot start an invisible component. | 218| 16000005 | The specified process does not have the permission. | 219| 16000006 | Cross-user operations are not allowed. | 220| 16000008 | The crowdtesting application expires. | 221| 16000009 | An ability cannot be started or stopped in Wukong mode. | 222| 16000010 | The call with the continuation and prepare continuation flag is forbidden. | 223| 16000011 | The context does not exist. | 224| 16000012 | The application is controlled. | 225| 16000013 | The application is controlled by EDM. | 226| 16000050 | Internal error. | 227| 16000053 | The ability is not on the top of the UI. | 228| 16000055 | Installation-free timed out. | 229 230**示例:** 231 232```ts 233 import { insightIntentDriver, insightIntent } from '@kit.AbilityKit'; 234 import { hilog } from '@kit.PerformanceAnalysisKit'; 235 236 function executeInsightIntentAsync() { 237 let param: insightIntentDriver.ExecuteParam = { 238 bundleName: 'com.ohos.intentexecutedemo', 239 moduleName: 'entry', 240 abilityName: 'EntryAbility', 241 insightIntentName: 'PlayMusic', 242 insightIntentParam: { 243 songName: 'City Of Stars', 244 }, 245 executeMode: insightIntent.ExecuteMode.UI_ABILITY_FOREGROUND, 246 }; 247 248 try { 249 insightIntentDriver.execute(param, (error, data: insightIntent.ExecuteResult) => { 250 if (error) { 251 hilog.error(0x0000, 'testTag', 'execute insight intent failed with %{public}s', JSON.stringify(error)); 252 } else { 253 hilog.info(0x0000, 'testTag', '%{public}s', 'execute insight intent succeed'); 254 } 255 hilog.info(0x0000, 'testTag', 'execute insight intent return %{public}d', data.code); 256 hilog.info(0x0000, 'testTag', 'execute insight intent result %{public}s', JSON.stringify(data.result)); 257 }) 258 } catch (error) { 259 hilog.error(0x0000, 'testTag', 'execute insight intent error caught %{public}s', JSON.stringify(error)); 260 } 261 } 262``` 263 264## insightIntentDriver.execute 265 266execute(param: ExecuteParam): Promise<insightIntent.ExecuteResult> 267 268执行意图调用的接口。使用Promise异步回调。 269当调用方在后台时,需要申请`ohos.permission.START_ABILITIES_FROM_BACKGROUND`权限。 270当意图调用执行模式[ExecuteMode](js-apis-app-ability-insightIntent.md#executemode)取值为UI_ABILITY_BACKGROUND时,需要申请`ohos.permission.ABILITY_BACKGROUND_COMMUNICATION`权限。 271 272**模型约束**:此接口仅可在Stage模型下使用。 273 274**系统接口**:此接口为系统接口。 275 276**需要权限**:ohos.permission.EXECUTE_INSIGHT_INTENT 277 278**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 279 280**参数:** 281 282 | 参数名 | 类型 | 必填 | 说明 | 283 | -------- | -------- | -------- | -------- | 284 | param | [ExecuteParam](#executeparam) | 是 | 执行意图调用的参数。 | 285 286**返回值:** 287 288| 类型 | 说明 | 289| -------- | -------- | 290| Promise<[insightIntent.ExecuteResult](js-apis-app-ability-insightIntent.md#executeresult)> | Promise对象,返回意图调用执行结果。 | 291 292**错误码**: 293 294以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 295 296| 错误码ID | 错误信息 | 297| -------- | -------- | 298| 201 | Permission denied. | 299| 202 | Not system application. | 300| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 301| 16000001 | The specified ability does not exist. | 302| 16000002 | Incorrect ability type. | 303| 16000004 | Cannot start an invisible component. | 304| 16000005 | The specified process does not have the permission. | 305| 16000006 | Cross-user operations are not allowed. | 306| 16000008 | The crowdtesting application expires. | 307| 16000009 | An ability cannot be started or stopped in Wukong mode. | 308| 16000010 | The call with the continuation and prepare continuation flag is forbidden. | 309| 16000011 | The context does not exist. | 310| 16000012 | The application is controlled. | 311| 16000013 | The application is controlled by EDM. | 312| 16000050 | Internal error. | 313| 16000053 | The ability is not on the top of the UI. | 314| 16000055 | Installation-free timed out. | 315 316**示例:** 317 318```ts 319 import { insightIntentDriver, insightIntent } from '@kit.AbilityKit'; 320 import { hilog } from '@kit.PerformanceAnalysisKit'; 321 322 async function executeSearchMusicIntentPromise() { 323 let param: insightIntentDriver.ExecuteParam = { 324 bundleName: 'com.ohos.intentexecutedemo', 325 moduleName: 'entry', 326 abilityName: 'EntryAbility', 327 insightIntentName: 'PlayMusic', 328 insightIntentParam: { 329 songName: 'City Of Stars', 330 }, 331 executeMode: insightIntent.ExecuteMode.UI_ABILITY_FOREGROUND, 332 }; 333 334 try { 335 let resultData: insightIntent.ExecuteResult = await insightIntentDriver.execute(param); 336 hilog.info(0x0000, 'testTag', 'execute insight intent return %{public}d', resultData.code); 337 hilog.info(0x0000, 'testTag', 'execute insight intent result %{public}s', JSON.stringify(resultData.result)); 338 } catch (error) { 339 hilog.error(0x0000, 'testTag', 'execute insight intent error caught %{public}s', JSON.stringify(error)); 340 } 341 } 342``` 343 344## insightIntentDriver.getAllInsightIntentInfo<sup>20+<sup> 345 346getAllInsightIntentInfo(intentFlags: number): Promise<Array\<[InsightIntentInfo](#insightintentinfo20)>> 347 348查询当前设备上的所有意图信息。使用Promise异步回调。 349 350**模型约束**:此接口仅可在Stage模型下使用。 351 352**系统接口**:此接口为系统接口。 353 354**需要权限**:ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 355 356**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 357 358**参数:** 359 360 | 参数名 | 类型 | 必填 | 说明 | 361 | -------- | -------- | -------- | -------- | 362 | intentFlags | number | 是 | 意图信息([InsightIntentInfo](#insightintentinfo20))的标识,用于表示查询全量意图信息或者简要意图信息,参考[GetInsightIntentFlag](#getinsightintentflag20)。 | 363 364**返回值:** 365 366| 类型 | 说明 | 367| -------- | -------- | 368| Promise<Array\<[InsightIntentInfo](#insightintentinfo20)>> | Promise对象,返回意图信息对象数组。 | 369 370**错误码**: 371 372以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 373 374| 错误码ID | 错误信息 | 375| -------- | -------- | 376| 201 | Permission denied. | 377| 202 | Not system application. | 378| 16000050 | Internal error. | 379 380**示例:** 381 382```ts 383 import { insightIntentDriver } from '@kit.AbilityKit'; 384 import { BusinessError } from '@kit.BasicServicesKit'; 385 import { hilog } from '@kit.PerformanceAnalysisKit'; 386 387 async function getInfos() { 388 try { 389 insightIntentDriver.getAllInsightIntentInfo(insightIntentDriver.GetInsightIntentFlag.GET_FULL_INSIGHT_INTENT | insightIntentDriver.GetInsightIntentFlag.GET_ENTITY_INFO).then((data) => { 390 hilog.info(0x0000, 'testTag', 'getAllInsightIntentInfo return %{public}s', JSON.stringify(data)); 391 }).catch((err: BusinessError) => { 392 hilog.info(0x0000, 'testTag', 'getAllInsightIntentInfo errCode: %{public}d', err.code); 393 hilog.info(0x0000, 'testTag', 'getAllInsightIntentInfo errMessage: %{public}s', err.message); 394 }); 395 } catch (error) { 396 hilog.error(0x0000, 'testTag', 'getAllInsightIntentInfo error caught %{public}s', JSON.stringify(error)); 397 } 398 } 399``` 400 401## insightIntentDriver.getInsightIntentInfoByBundleName<sup>20+<sup> 402 403getInsightIntentInfoByBundleName(bundleName: string, intentFlags: number): Promise<Array\<[InsightIntentInfo](#insightintentinfo20)>> 404 405根据包名查询当前设备上的意图信息。使用Promise异步回调。 406 407**模型约束**:此接口仅可在Stage模型下使用。 408 409**系统接口**:此接口为系统接口。 410 411**需要权限**:ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 412 413**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 414 415**参数:** 416 417 | 参数名 | 类型 | 必填 | 说明 | 418 | -------- | -------- | -------- | -------- | 419 | bundleName | string | 是 | 应用包名称。 <br/>**说明:**<br/> 若包名不存在,则返回空数组。 | 420 | intentFlags | number | 是 | 意图信息([InsightIntentInfo](#insightintentinfo20))的标识,用于表示查询全量意图信息或者简要意图信息,参考[GetInsightIntentFlag](#getinsightintentflag20)。 | 421 422**返回值:** 423 424| 类型 | 说明 | 425| -------- | -------- | 426| Promise<Array\<[InsightIntentInfo](#insightintentinfo20)>> | Promise对象,返回意图信息对象数组。 | 427 428**错误码**: 429 430以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 431 432| 错误码ID | 错误信息 | 433| -------- | -------- | 434| 201 | Permission denied. | 435| 202 | Not system application. | 436| 16000050 | Internal error. | 437 438**示例:** 439 440```ts 441 import { insightIntentDriver } from '@kit.AbilityKit'; 442 import { BusinessError } from '@kit.BasicServicesKit'; 443 import { hilog } from '@kit.PerformanceAnalysisKit'; 444 445 async function getInfosByBundleName() { 446 try { 447 let bundleName = "com.example.intent"; // 开发者需自行修改为实际包名 448 insightIntentDriver.getInsightIntentInfoByBundleName(bundleName, insightIntentDriver.GetInsightIntentFlag.GET_FULL_INSIGHT_INTENT | insightIntentDriver.GetInsightIntentFlag.GET_ENTITY_INFO).then((data) => { 449 hilog.info(0x0000, 'testTag', 'getInsightIntentInfoByBundleName return %{public}s', JSON.stringify(data)); 450 }).catch((err: BusinessError) => { 451 hilog.info(0x0000, 'testTag', 'getInsightIntentInfoByBundleName errCode: %{public}d', err.code); 452 hilog.info(0x0000, 'testTag', 'getInsightIntentInfoByBundleName errMessage: %{public}s', err.message); 453 }); 454 } catch (error) { 455 hilog.error(0x0000, 'testTag', 'getInsightIntentInfoByBundleName error caught %{public}s', JSON.stringify(error)); 456 } 457 } 458``` 459 460## insightIntentDriver.getInsightIntentInfoByIntentName<sup>20+<sup> 461 462getInsightIntentInfoByIntentName(bundleName: string, moduleName: string, intentName: string, intentFlags: number): Promise<[InsightIntentInfo](#insightintentinfo20)> 463 464根据包名、模块名和意图名查询当前设备上的意图信息。使用Promise异步回调。 465 466**模型约束**:此接口仅可在Stage模型下使用。 467 468**系统接口**:此接口为系统接口。 469 470**需要权限**:ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 471 472**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 473 474**参数:** 475 476 | 参数名 | 类型 | 必填 | 说明 | 477 | -------- | -------- | -------- | -------- | 478 | bundleName | string | 是 | 应用包名称。<br/>**说明:**<br/> 若包名不存在,则返回空对象。| 479 | moduleName | string | 是 | 模块名称。<br/>**说明:**<br/> 若模块名不存在,则返回空对象。| 480 | intentName | string | 是 | 意图名称。<br/>**说明:**<br/> 若意图名不存在,则返回空对象。| 481 | intentFlags | number | 是 | 意图信息([InsightIntentInfo](#insightintentinfo20))的标识,用于表示查询全量意图信息或者简要意图信息,参考[GetInsightIntentFlag](#getinsightintentflag20)。 | 482 483**返回值:** 484 485| 类型 | 说明 | 486| -------- | -------- | 487| Promise<[InsightIntentInfo](#insightintentinfo20)> | Promise对象,返回意图信息对象。 | 488 489**错误码**: 490 491以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 492 493| 错误码ID | 错误信息 | 494| -------- | -------- | 495| 201 | Permission denied. | 496| 202 | Not system application. | 497| 16000050 | Internal error. | 498 499**示例:** 500 501```ts 502 import { insightIntentDriver } from '@kit.AbilityKit'; 503 import { BusinessError } from '@kit.BasicServicesKit'; 504 import { hilog } from '@kit.PerformanceAnalysisKit'; 505 506 function getInfoByIntentName() { 507 try { 508 let bundleName = "com.example.intent"; // 开发者需自行修改为实际包名 509 let moduleName = "entry"; // 开发者需自行修改为实际模块名 510 let intentName = "play"; // 开发者需自行修改为实际意图名 511 insightIntentDriver.getInsightIntentInfoByIntentName( 512 bundleName, moduleName, intentName, insightIntentDriver.GetInsightIntentFlag.GET_FULL_INSIGHT_INTENT | insightIntentDriver.GetInsightIntentFlag.GET_ENTITY_INFO) 513 .then((data) => { 514 hilog.info(0x0000, 'testTag', 'getInsightIntentInfoByIntentName return %{public}s', JSON.stringify(data)); 515 }).catch((err: BusinessError) => { 516 hilog.info(0x0000, 'testTag', 'getInsightIntentInfoByIntentName errCode: %{public}d', err.code); 517 hilog.info(0x0000, 'testTag', 'getInsightIntentInfoByIntentName errMessage: %{public}s', err.message); 518 }); 519 } catch (error) { 520 hilog.error(0x0000, 'testTag', 'getInsightIntentInfoByIntentName error caught %{public}s', JSON.stringify(error)); 521 } 522 } 523``` 524