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