1e41f4b71Sopenharmony_ci# @ohos.app.ability.InsightIntentContext (InsightIntent Call Execution Context)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **InsightIntentContext** module provides the InsightIntent call execution context, which is a property of the base class for InsightIntent call execution and provides basic capabilities for the base class.
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## Modules to Import
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci```ts
14e41f4b71Sopenharmony_ciimport { InsightIntentContext } from '@kit.AbilityKit';
15e41f4b71Sopenharmony_ci```
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci## InsightIntentContext.startAbility
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_cistartAbility(want: Want, callback: AsyncCallback\<void\>): void
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ciStarts an ability. The ability can be started only when it has the same bundle name as the base class for InsightIntent call execution. This API uses an asynchronous callback to return the result.
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model.
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci**Parameters**
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description|
32e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
33e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.|
34e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the ability is started, **err** is **undefined**. Otherwise, **err** is an error object.|
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci**Error codes**
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci| ID| Error Message|
41e41f4b71Sopenharmony_ci| -------- | -------- |
42e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
43e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. |
44e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. |
45e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. |
46e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. |
47e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. |
48e41f4b71Sopenharmony_ci| 16000009 | An ability cannot be started or stopped in Wukong mode. |
49e41f4b71Sopenharmony_ci| 16000011 | The context does not exist.        |
50e41f4b71Sopenharmony_ci| 16000012 | The application is controlled.        |
51e41f4b71Sopenharmony_ci| 16000013 | The application is controlled by EDM.       |
52e41f4b71Sopenharmony_ci| 16000050 | Internal error. |
53e41f4b71Sopenharmony_ci| 16000053 | The ability is not on the top of the UI. |
54e41f4b71Sopenharmony_ci| 16000055 | Installation-free timed out. |
55e41f4b71Sopenharmony_ci| 16000061 | Can not start component belongs to other bundle. |
56e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. |
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ciFor details about the error codes, see [Ability Error Codes](errorcode-ability.md).
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci**Example**
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ci  ```ts
63e41f4b71Sopenharmony_ci  import { InsightIntentExecutor, insightIntent, Want } from '@kit.AbilityKit';
64e41f4b71Sopenharmony_ci  import { window } from '@kit.ArkUI';
65e41f4b71Sopenharmony_ci  import { hilog } from '@kit.PerformanceAnalysisKit';
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci  export default class IntentExecutorImpl extends InsightIntentExecutor {
68e41f4b71Sopenharmony_ci    onExecuteInUIAbilityForegroundMode(name: string, param: Record<string, Object>, pageLoader: window.WindowStage): insightIntent.ExecuteResult {
69e41f4b71Sopenharmony_ci      let want: Want = {
70e41f4b71Sopenharmony_ci        bundleName: 'com.ohos.intentexecutedemo',
71e41f4b71Sopenharmony_ci        moduleName: 'entry',
72e41f4b71Sopenharmony_ci        abilityName: 'AnotherAbility',
73e41f4b71Sopenharmony_ci      };
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci      try {
76e41f4b71Sopenharmony_ci        this.context.startAbility(want, (error) => {
77e41f4b71Sopenharmony_ci          if (error) {
78e41f4b71Sopenharmony_ci            hilog.error(0x0000, 'testTag', 'Start ability failed with %{public}s', JSON.stringify(error));
79e41f4b71Sopenharmony_ci          } else {
80e41f4b71Sopenharmony_ci            hilog.info(0x0000, 'testTag', '%{public}s', 'Start ability succeed');
81e41f4b71Sopenharmony_ci          }
82e41f4b71Sopenharmony_ci        })
83e41f4b71Sopenharmony_ci      } catch (error) {
84e41f4b71Sopenharmony_ci        hilog.error(0x0000, 'testTag', 'Start ability error caught %{public}s', JSON.stringify(error));
85e41f4b71Sopenharmony_ci      }
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci      let result: insightIntent.ExecuteResult = {
88e41f4b71Sopenharmony_ci        code: 0,
89e41f4b71Sopenharmony_ci        result: {
90e41f4b71Sopenharmony_ci          message: 'Execute insight intent succeed.',
91e41f4b71Sopenharmony_ci        }
92e41f4b71Sopenharmony_ci      };
93e41f4b71Sopenharmony_ci      return result;
94e41f4b71Sopenharmony_ci    }
95e41f4b71Sopenharmony_ci  }
96e41f4b71Sopenharmony_ci  ```
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci## InsightIntentContext.startAbility
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_cistartAbility(want: Want): Promise\<void\>
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ciStarts an ability. The ability can be started only when it has the same bundle name as the base class for InsightIntent call execution. This API uses a promise to return the result.
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model.
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_ci**Parameters**
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description|
113e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
114e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.|
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci**Return value**
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci| Type| Description|
119e41f4b71Sopenharmony_ci| -------- | -------- |
120e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | Promise that returns no value.|
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci**Error codes**
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci| ID| Error Message|
127e41f4b71Sopenharmony_ci| -------- | -------- |
128e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
129e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. |
130e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. |
131e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. |
132e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. |
133e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. |
134e41f4b71Sopenharmony_ci| 16000009 | An ability cannot be started or stopped in Wukong mode. |
135e41f4b71Sopenharmony_ci| 16000011 | The context does not exist.        |
136e41f4b71Sopenharmony_ci| 16000012 | The application is controlled.        |
137e41f4b71Sopenharmony_ci| 16000013 | The application is controlled by EDM.       |
138e41f4b71Sopenharmony_ci| 16000050 | Internal error. |
139e41f4b71Sopenharmony_ci| 16000053 | The ability is not on the top of the UI. |
140e41f4b71Sopenharmony_ci| 16000055 | Installation-free timed out. |
141e41f4b71Sopenharmony_ci| 16000061 | Can not start component belongs to other bundle. |
142e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. |
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ciFor details about the error codes, see [Ability Error Codes](errorcode-ability.md).
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_ci**Example**
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ci  ```ts
149e41f4b71Sopenharmony_ci  import { InsightIntentExecutor, insightIntent, Want } from '@kit.AbilityKit';
150e41f4b71Sopenharmony_ci  import { window } from '@kit.ArkUI';
151e41f4b71Sopenharmony_ci  import { hilog } from '@kit.PerformanceAnalysisKit';
152e41f4b71Sopenharmony_ci
153e41f4b71Sopenharmony_ci  export default class IntentExecutorImpl extends InsightIntentExecutor {
154e41f4b71Sopenharmony_ci    async onExecuteInUIAbilityForegroundMode(name: string, param: Record<string, Object>, pageLoader: window.WindowStage): Promise<insightIntent.ExecuteResult> {
155e41f4b71Sopenharmony_ci      let want: Want = {
156e41f4b71Sopenharmony_ci        bundleName: 'com.ohos.intentexecutedemo',
157e41f4b71Sopenharmony_ci        moduleName: 'entry',
158e41f4b71Sopenharmony_ci        abilityName: 'AnotherAbility',
159e41f4b71Sopenharmony_ci      };
160e41f4b71Sopenharmony_ci
161e41f4b71Sopenharmony_ci      try {
162e41f4b71Sopenharmony_ci        await this.context.startAbility(want);
163e41f4b71Sopenharmony_ci        hilog.info(0x0000, 'testTag', '%{public}s', 'Start ability finished');
164e41f4b71Sopenharmony_ci      } catch (error) {
165e41f4b71Sopenharmony_ci        hilog.error(0x0000, 'testTag', 'Start ability error caught %{public}s', JSON.stringify(error));
166e41f4b71Sopenharmony_ci      }
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ci      let result: insightIntent.ExecuteResult = {
169e41f4b71Sopenharmony_ci        code: 0,
170e41f4b71Sopenharmony_ci        result: {
171e41f4b71Sopenharmony_ci          message: 'Execute insight intent succeed.',
172e41f4b71Sopenharmony_ci        }
173e41f4b71Sopenharmony_ci      };
174e41f4b71Sopenharmony_ci      return result;
175e41f4b71Sopenharmony_ci    }
176e41f4b71Sopenharmony_ci  }
177e41f4b71Sopenharmony_ci  ```
178