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