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