1e41f4b71Sopenharmony_ci# @ohos.app.ability.InsightIntentContext (意图调用执行上下文)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci本模块提供意图调用执行上下文,意图调用执行上下文是意图调用执行基类的属性,为意图调用执行基类提供基础能力。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **说明:**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 11开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci> 本模块接口仅可在Stage模型下使用。
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci## 导入模块
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_ci启动Ability,仅当Ability与意图调用执行基类具有相同包名才能被拉起。使用callback异步回调。
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci**模型约束**:此接口仅可在Stage模型下使用。
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci**参数:**
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 |
32e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
33e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | 是 | 启动Ability的want信息。 |
34e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当启动Ability成功,err为undefined,否则为错误对象。 |
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci**错误码:**
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
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_ci以上错误码详细介绍请参考[元能力子系统错误码](errorcode-ability.md)。
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci**示例:**
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_ci启动Ability,仅当Ability与意图调用执行基类具有相同包名才能被拉起。使用Promise异步回调。
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci**模型约束**:此接口仅可在Stage模型下使用。
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_ci**参数:**
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 |
113e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
114e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | 是 | 启动Ability的want信息。 |
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci**返回值:**
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci| 类型 | 说明 |
119e41f4b71Sopenharmony_ci| -------- | -------- |
120e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。 |
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci**错误码:**
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
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_ci以上错误码详细介绍请参考[元能力子系统错误码](errorcode-ability.md)。
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_ci**示例:**
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