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