1e41f4b71Sopenharmony_ci# @ohos.app.ability.insightIntentDriver (Executing InsightIntent Calls) (System API)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **insightIntentDriver** module provides APIs for executing InsightIntent calls. The system executes InsightIntent calls based on user interaction and more.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> 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.
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci> The APIs of this module can be used only in the stage model.
10e41f4b71Sopenharmony_ci>
11e41f4b71Sopenharmony_ci> The APIs provided by this module are system APIs.
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci## Modules to Import
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci```ts
16e41f4b71Sopenharmony_ciimport { insightIntentDriver } from '@kit.AbilityKit';
17e41f4b71Sopenharmony_ci```
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci## ExecuteParam
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ciDefines the parameter used to execute an InsightIntent call.
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model.
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications.
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description|
30e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
31e41f4b71Sopenharmony_ci| bundleName | string | Yes| Name of the bundle to which the ability to be called belongs.|
32e41f4b71Sopenharmony_ci| moduleName | string | Yes| Name of the module to which the ability belongs.|
33e41f4b71Sopenharmony_ci| abilityName | string | Yes| Name of the ability to be called.|
34e41f4b71Sopenharmony_ci| insightIntentName | string | Yes| InsightIntent name.|
35e41f4b71Sopenharmony_ci| insightIntentParam | string | Yes| InsightIntent call parameter.|
36e41f4b71Sopenharmony_ci| executeMode | [insightIntent.ExecuteMode](js-apis-app-ability-insightIntent.md#executemode) | Yes| InsightIntent call execution mode.|
37e41f4b71Sopenharmony_ci| displayId<sup>12+</sup> | number | No| Physical 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**.|
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci## insightIntentDriver.execute
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ciexecute(param: ExecuteParam, callback: AsyncCallback<insightIntent.ExecuteResult>): void
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ciExecutes a call to an InsightIntent. This API uses an asynchronous callback to return the result.
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model.
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications.
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.EXECUTE_INSIGHT_INTENT
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci**Parameters**
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci  | Name| Type| Mandatory| Description|
56e41f4b71Sopenharmony_ci  | -------- | -------- | -------- | -------- |
57e41f4b71Sopenharmony_ci  | param | [ExecuteParam](#executeparam) | Yes| Parameter used to execute the InsightIntent call.|
58e41f4b71Sopenharmony_ci  | callback | AsyncCallback<[insightIntent.ExecuteResult](js-apis-app-ability-insightIntent.md#executeresult)> | Yes| Callback used to return the InsightIntent call execution result.|
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci**Error codes**
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci| ID| Error Message|
65e41f4b71Sopenharmony_ci| -------- | -------- |
66e41f4b71Sopenharmony_ci| 201      | Permission denied. |
67e41f4b71Sopenharmony_ci| 202      | Not system application. |
68e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
69e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. |
70e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. |
71e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. |
72e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. |
73e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. |
74e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. |
75e41f4b71Sopenharmony_ci| 16000009 | An ability cannot be started or stopped in Wukong mode. |
76e41f4b71Sopenharmony_ci| 16000010 | The call with the continuation flag is forbidden. |
77e41f4b71Sopenharmony_ci| 16000011 | The context does not exist.        |
78e41f4b71Sopenharmony_ci| 16000012 | The application is controlled.        |
79e41f4b71Sopenharmony_ci| 16000013 | The application is controlled by EDM.       |
80e41f4b71Sopenharmony_ci| 16000050 | Internal error. |
81e41f4b71Sopenharmony_ci| 16000053 | The ability is not on the top of the UI. |
82e41f4b71Sopenharmony_ci| 16000055 | Installation-free timed out. |
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci**Example**
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci```ts
87e41f4b71Sopenharmony_ci  import { insightIntentDriver, insightIntent } from '@kit.AbilityKit';
88e41f4b71Sopenharmony_ci  import { hilog } from '@kit.PerformanceAnalysisKit';
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci  function executeInsightIntentAsync() {
91e41f4b71Sopenharmony_ci    let param: insightIntentDriver.ExecuteParam = {
92e41f4b71Sopenharmony_ci      bundleName: 'com.ohos.intentexecutedemo',
93e41f4b71Sopenharmony_ci      moduleName: 'entry',
94e41f4b71Sopenharmony_ci      abilityName: 'EntryAbility',
95e41f4b71Sopenharmony_ci      insightIntentName: 'PlayMusic',
96e41f4b71Sopenharmony_ci      insightIntentParam: {
97e41f4b71Sopenharmony_ci        songName: 'City Of Stars',
98e41f4b71Sopenharmony_ci      },
99e41f4b71Sopenharmony_ci      executeMode: insightIntent.ExecuteMode.UI_ABILITY_FOREGROUND,
100e41f4b71Sopenharmony_ci    };
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci    try {
103e41f4b71Sopenharmony_ci      insightIntentDriver.execute(param, (error, data: insightIntent.ExecuteResult) => {
104e41f4b71Sopenharmony_ci        if (error) {
105e41f4b71Sopenharmony_ci          hilog.error(0x0000, 'testTag', 'execute insight intent failed with %{public}s', JSON.stringify(error));
106e41f4b71Sopenharmony_ci        } else {
107e41f4b71Sopenharmony_ci          hilog.info(0x0000, 'testTag', '%{public}s', 'execute insight intent succeed');
108e41f4b71Sopenharmony_ci        }
109e41f4b71Sopenharmony_ci        hilog.info(0x0000, 'testTag', 'execute insight intent return %{public}d', data.code);
110e41f4b71Sopenharmony_ci        hilog.info(0x0000, 'testTag', 'execute insight intent result %{public}s', JSON.stringify(data.result));
111e41f4b71Sopenharmony_ci      })
112e41f4b71Sopenharmony_ci    } catch (error) {
113e41f4b71Sopenharmony_ci      hilog.error(0x0000, 'testTag', 'execute insight intent error caught %{public}s', JSON.stringify(error));
114e41f4b71Sopenharmony_ci    }
115e41f4b71Sopenharmony_ci  }
116e41f4b71Sopenharmony_ci```
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci## insightIntentDriver.execute
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ciexecute(param: ExecuteParam): Promise<insightIntent.ExecuteResult>
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ciExecutes a call to an InsightIntent. This API uses a promise to return the result.
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model.
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications.
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.EXECUTE_INSIGHT_INTENT
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci**Parameters**
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ci  | Name| Type| Mandatory| Description|
135e41f4b71Sopenharmony_ci  | -------- | -------- | -------- | -------- |
136e41f4b71Sopenharmony_ci  | param | [ExecuteParam](#executeparam) | Yes| Parameter used to execute the InsightIntent call.|
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ci**Return value**
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ci| Type| Description|
141e41f4b71Sopenharmony_ci| -------- | -------- |
142e41f4b71Sopenharmony_ci| Promise<[insightIntent.ExecuteResult](js-apis-app-ability-insightIntent.md#executeresult)> | Promise used to return the InsightIntent call execution result.|
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ci**Error codes**
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ci| ID| Error Message|
149e41f4b71Sopenharmony_ci| -------- | -------- |
150e41f4b71Sopenharmony_ci| 201      | Permission denied. |
151e41f4b71Sopenharmony_ci| 202      | Not system application. |
152e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
153e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. |
154e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. |
155e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. |
156e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. |
157e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. |
158e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. |
159e41f4b71Sopenharmony_ci| 16000009 | An ability cannot be started or stopped in Wukong mode. |
160e41f4b71Sopenharmony_ci| 16000010 | The call with the continuation flag is forbidden. |
161e41f4b71Sopenharmony_ci| 16000011 | The context does not exist.        |
162e41f4b71Sopenharmony_ci| 16000012 | The application is controlled.        |
163e41f4b71Sopenharmony_ci| 16000013 | The application is controlled by EDM.       |
164e41f4b71Sopenharmony_ci| 16000050 | Internal error. |
165e41f4b71Sopenharmony_ci| 16000053 | The ability is not on the top of the UI. |
166e41f4b71Sopenharmony_ci| 16000055 | Installation-free timed out. |
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ci**Example**
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci```ts
171e41f4b71Sopenharmony_ci  import { insightIntentDriver, insightIntent } from '@kit.AbilityKit';
172e41f4b71Sopenharmony_ci  import { hilog } from '@kit.PerformanceAnalysisKit';
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci  async function executeSearchMusicIntentPromise() {
175e41f4b71Sopenharmony_ci    let param: insightIntentDriver.ExecuteParam = {
176e41f4b71Sopenharmony_ci      bundleName: 'com.ohos.intentexecutedemo',
177e41f4b71Sopenharmony_ci      moduleName: 'entry',
178e41f4b71Sopenharmony_ci      abilityName: 'EntryAbility',
179e41f4b71Sopenharmony_ci      insightIntentName: 'PlayMusic',
180e41f4b71Sopenharmony_ci      insightIntentParam: {
181e41f4b71Sopenharmony_ci        songName: 'City Of Stars',
182e41f4b71Sopenharmony_ci      },
183e41f4b71Sopenharmony_ci      executeMode: insightIntent.ExecuteMode.UI_ABILITY_FOREGROUND,
184e41f4b71Sopenharmony_ci    };
185e41f4b71Sopenharmony_ci
186e41f4b71Sopenharmony_ci    try {
187e41f4b71Sopenharmony_ci      let resultData: insightIntent.ExecuteResult = await insightIntentDriver.execute(param);
188e41f4b71Sopenharmony_ci      hilog.info(0x0000, 'testTag', 'execute insight intent return %{public}d', resultData.code);
189e41f4b71Sopenharmony_ci      hilog.info(0x0000, 'testTag', 'execute insight intent result %{public}s', JSON.stringify(resultData.result));
190e41f4b71Sopenharmony_ci    } catch (error) {
191e41f4b71Sopenharmony_ci      hilog.error(0x0000, 'testTag', 'execute insight intent error caught %{public}s', JSON.stringify(error));
192e41f4b71Sopenharmony_ci    }
193e41f4b71Sopenharmony_ci  }
194e41f4b71Sopenharmony_ci```
195