1e41f4b71Sopenharmony_ci# ServiceExtensionContext (System API) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe ServiceExtensionContext module, inherited from **ExtensionContext**, provides context for the ServiceExtensionAbility. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ciYou can use the APIs of this module to start, terminate, connect, and disconnect an ability. 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci> **NOTE** 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 10e41f4b71Sopenharmony_ci> - The APIs of this module can be used only in the stage model. 11e41f4b71Sopenharmony_ci> - The APIs of this module must be used in the main thread, but not in sub-threads such as Worker and TaskPool. 12e41f4b71Sopenharmony_ci> - The APIs provided by this module are system APIs. 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci## Modules to Import 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci```ts 17e41f4b71Sopenharmony_ciimport { common } from '@kit.AbilityKit'; 18e41f4b71Sopenharmony_ci``` 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci## Usage 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ciBefore using the **ServiceExtensionContext** module, you must define a child class that inherits from **ServiceExtensionAbility**. 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci**Example** 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci```ts 27e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility } from '@kit.AbilityKit'; 28e41f4b71Sopenharmony_ciimport { rpc } from '@kit.IPCKit'; 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_cilet commRemote: rpc.IRemoteObject | null; // Release the instance when the connection is disconnected. 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 33e41f4b71Sopenharmony_ci onCreate() { 34e41f4b71Sopenharmony_ci let context = this.context; // Obtain a ServiceExtensionContext instance. 35e41f4b71Sopenharmony_ci } 36e41f4b71Sopenharmony_ci} 37e41f4b71Sopenharmony_ci``` 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci## ServiceExtensionContext.startAbility 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_cistartAbility(want: Want, callback: AsyncCallback<void>): void; 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ciStarts an ability. This API uses an asynchronous callback to return the result. 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci**Parameters** 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 52e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 53e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability, such as the ability name and bundle name.| 54e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci**Error codes** 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci| ID| Error Message| 61e41f4b71Sopenharmony_ci| ------- | -------- | 62e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 63e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 64e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 65e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 66e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 67e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 68e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 69e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. | 70e41f4b71Sopenharmony_ci| 16000009 | An ability cannot be started or stopped in Wukong mode. | 71e41f4b71Sopenharmony_ci| 16000010 | The call with the continuation flag is forbidden. | 72e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 73e41f4b71Sopenharmony_ci| 16000012 | The application is controlled. | 74e41f4b71Sopenharmony_ci| 16000013 | The application is controlled by EDM. | 75e41f4b71Sopenharmony_ci| 16000019 | No matching ability is found. | 76e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 77e41f4b71Sopenharmony_ci| 16000053 | The ability is not on the top of the UI. | 78e41f4b71Sopenharmony_ci| 16000055 | Installation-free timed out. | 79e41f4b71Sopenharmony_ci| 16000071 | App clone is not supported. | 80e41f4b71Sopenharmony_ci| 16000072 | App clone or multi-instance is not supported. | 81e41f4b71Sopenharmony_ci| 16000073 | The app clone index is invalid. | 82e41f4b71Sopenharmony_ci| 16000076 | The app instance key is invalid. | 83e41f4b71Sopenharmony_ci| 16000077 | The number of app instances reaches the limit. | 84e41f4b71Sopenharmony_ci| 16000078 | The multi-instance is not supported. | 85e41f4b71Sopenharmony_ci| 16000079 | The APP_INSTANCE_KEY cannot be specified. | 86e41f4b71Sopenharmony_ci| 16000080 | Creating an instance is not supported. | 87e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. | 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci**Example** 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci```ts 92e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want } from '@kit.AbilityKit'; 93e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 96e41f4b71Sopenharmony_ci onCreate() { 97e41f4b71Sopenharmony_ci let want: Want = { 98e41f4b71Sopenharmony_ci bundleName: 'com.example.myapp', 99e41f4b71Sopenharmony_ci abilityName: 'MyAbility' 100e41f4b71Sopenharmony_ci }; 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci try { 103e41f4b71Sopenharmony_ci this.context.startAbility(want, (error: BusinessError) => { 104e41f4b71Sopenharmony_ci if (error.code) { 105e41f4b71Sopenharmony_ci // Process service logic errors. 106e41f4b71Sopenharmony_ci console.error(`startAbility failed, error.code: ${error.code}, error.message: ${error.message}`); 107e41f4b71Sopenharmony_ci return; 108e41f4b71Sopenharmony_ci } 109e41f4b71Sopenharmony_ci // Carry out normal service processing. 110e41f4b71Sopenharmony_ci console.log('startAbility succeed'); 111e41f4b71Sopenharmony_ci }); 112e41f4b71Sopenharmony_ci } catch (paramError) { 113e41f4b71Sopenharmony_ci // Process input parameter errors. 114e41f4b71Sopenharmony_ci console.error(`error.code: ${paramError.code}, error.message: ${paramError.message}`); 115e41f4b71Sopenharmony_ci } 116e41f4b71Sopenharmony_ci } 117e41f4b71Sopenharmony_ci} 118e41f4b71Sopenharmony_ci``` 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci## ServiceExtensionContext.startAbility 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_cistartAbility(want: Want, options?: StartOptions): Promise\<void>; 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ciStarts an ability. This API uses a promise to return the result. 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ci**Parameters** 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 133e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 134e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability, such as the ability name and bundle name.| 135e41f4b71Sopenharmony_ci| options | [StartOptions](js-apis-app-ability-startOptions.md) | No| Parameters used for starting the ability.| 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci**Return value** 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci| Type| Description| 140e41f4b71Sopenharmony_ci| -------- | -------- | 141e41f4b71Sopenharmony_ci| Promise<void> | Promise used to return the result.| 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci**Error codes** 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci| ID| Error Message| 148e41f4b71Sopenharmony_ci| ------- | -------- | 149e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 150e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 151e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 152e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 153e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 154e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 155e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 156e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. | 157e41f4b71Sopenharmony_ci| 16000009 | An ability cannot be started or stopped in Wukong mode. | 158e41f4b71Sopenharmony_ci| 16000010 | The call with the continuation flag is forbidden. | 159e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 160e41f4b71Sopenharmony_ci| 16000012 | The application is controlled. | 161e41f4b71Sopenharmony_ci| 16000013 | The application is controlled by EDM. | 162e41f4b71Sopenharmony_ci| 16000019 | No matching ability is found. | 163e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 164e41f4b71Sopenharmony_ci| 16000053 | The ability is not on the top of the UI. | 165e41f4b71Sopenharmony_ci| 16000055 | Installation-free timed out. | 166e41f4b71Sopenharmony_ci| 16000071 | App clone is not supported. | 167e41f4b71Sopenharmony_ci| 16000072 | App clone or multi-instance is not supported. | 168e41f4b71Sopenharmony_ci| 16000073 | The app clone index is invalid. | 169e41f4b71Sopenharmony_ci| 16000076 | The app instance key is invalid. | 170e41f4b71Sopenharmony_ci| 16000077 | The number of app instances reaches the limit. | 171e41f4b71Sopenharmony_ci| 16000078 | The multi-instance is not supported. | 172e41f4b71Sopenharmony_ci| 16000079 | The APP_INSTANCE_KEY cannot be specified. | 173e41f4b71Sopenharmony_ci| 16000080 | Creating an instance is not supported. | 174e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. | 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci**Example** 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci```ts 179e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want, StartOptions } from '@kit.AbilityKit'; 180e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 183e41f4b71Sopenharmony_ci onCreate() { 184e41f4b71Sopenharmony_ci let want: Want = { 185e41f4b71Sopenharmony_ci bundleName: 'com.example.myapp', 186e41f4b71Sopenharmony_ci abilityName: 'MyAbility' 187e41f4b71Sopenharmony_ci }; 188e41f4b71Sopenharmony_ci let options: StartOptions = { 189e41f4b71Sopenharmony_ci windowMode: 0, 190e41f4b71Sopenharmony_ci }; 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ci try { 193e41f4b71Sopenharmony_ci this.context.startAbility(want, options) 194e41f4b71Sopenharmony_ci .then((data: void) => { 195e41f4b71Sopenharmony_ci // Carry out normal service processing. 196e41f4b71Sopenharmony_ci console.log('startAbility succeed'); 197e41f4b71Sopenharmony_ci }) 198e41f4b71Sopenharmony_ci .catch((error: BusinessError) => { 199e41f4b71Sopenharmony_ci // Process service logic errors. 200e41f4b71Sopenharmony_ci console.error(`startAbility failed, error.code: ${error.code}, error.message: ${error.message}`); 201e41f4b71Sopenharmony_ci }); 202e41f4b71Sopenharmony_ci } catch (paramError) { 203e41f4b71Sopenharmony_ci // Process input parameter errors. 204e41f4b71Sopenharmony_ci console.error(`error.code: ${paramError.code}, error.message: ${paramError.message}`); 205e41f4b71Sopenharmony_ci } 206e41f4b71Sopenharmony_ci } 207e41f4b71Sopenharmony_ci} 208e41f4b71Sopenharmony_ci``` 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ci## ServiceExtensionContext.startAbility 211e41f4b71Sopenharmony_ci 212e41f4b71Sopenharmony_cistartAbility(want: Want, options: StartOptions, callback: AsyncCallback<void>): void 213e41f4b71Sopenharmony_ci 214e41f4b71Sopenharmony_ciStarts an ability with the start options specified. This API uses an asynchronous callback to return the result. 215e41f4b71Sopenharmony_ci 216e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 217e41f4b71Sopenharmony_ci 218e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 219e41f4b71Sopenharmony_ci 220e41f4b71Sopenharmony_ci**Parameters** 221e41f4b71Sopenharmony_ci 222e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 223e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 224e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 225e41f4b71Sopenharmony_ci| options | [StartOptions](js-apis-app-ability-startOptions.md) | Yes| Parameters used for starting the ability.| 226e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 227e41f4b71Sopenharmony_ci 228e41f4b71Sopenharmony_ci**Error codes** 229e41f4b71Sopenharmony_ci 230e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 231e41f4b71Sopenharmony_ci 232e41f4b71Sopenharmony_ci| ID| Error Message| 233e41f4b71Sopenharmony_ci| ------- | -------- | 234e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 235e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 236e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 237e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 238e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 239e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 240e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 241e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. | 242e41f4b71Sopenharmony_ci| 16000009 | An ability cannot be started or stopped in Wukong mode. | 243e41f4b71Sopenharmony_ci| 16000010 | The call with the continuation flag is forbidden. | 244e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 245e41f4b71Sopenharmony_ci| 16000012 | The application is controlled. | 246e41f4b71Sopenharmony_ci| 16000013 | The application is controlled by EDM. | 247e41f4b71Sopenharmony_ci| 16000019 | No matching ability is found. | 248e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 249e41f4b71Sopenharmony_ci| 16000053 | The ability is not on the top of the UI. | 250e41f4b71Sopenharmony_ci| 16000055 | Installation-free timed out. | 251e41f4b71Sopenharmony_ci| 16000071 | App clone is not supported. | 252e41f4b71Sopenharmony_ci| 16000072 | App clone or multi-instance is not supported. | 253e41f4b71Sopenharmony_ci| 16000073 | The app clone index is invalid. | 254e41f4b71Sopenharmony_ci| 16000076 | The app instance key is invalid. | 255e41f4b71Sopenharmony_ci| 16000077 | The number of app instances reaches the limit. | 256e41f4b71Sopenharmony_ci| 16000078 | The multi-instance is not supported. | 257e41f4b71Sopenharmony_ci| 16000079 | The APP_INSTANCE_KEY cannot be specified. | 258e41f4b71Sopenharmony_ci| 16000080 | Creating an instance is not supported. | 259e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. | 260e41f4b71Sopenharmony_ci 261e41f4b71Sopenharmony_ci**Example** 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_ci```ts 264e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want, StartOptions } from '@kit.AbilityKit'; 265e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 266e41f4b71Sopenharmony_ci 267e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 268e41f4b71Sopenharmony_ci onCreate() { 269e41f4b71Sopenharmony_ci let want: Want = { 270e41f4b71Sopenharmony_ci deviceId: '', 271e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 272e41f4b71Sopenharmony_ci abilityName: 'EntryAbility' 273e41f4b71Sopenharmony_ci }; 274e41f4b71Sopenharmony_ci let options: StartOptions = { 275e41f4b71Sopenharmony_ci windowMode: 0 276e41f4b71Sopenharmony_ci }; 277e41f4b71Sopenharmony_ci 278e41f4b71Sopenharmony_ci try { 279e41f4b71Sopenharmony_ci this.context.startAbility(want, options, (error: BusinessError) => { 280e41f4b71Sopenharmony_ci if (error.code) { 281e41f4b71Sopenharmony_ci // Process service logic errors. 282e41f4b71Sopenharmony_ci console.error(`startAbility failed, error.code: ${error.code}, error.message: ${error.message}`); 283e41f4b71Sopenharmony_ci return; 284e41f4b71Sopenharmony_ci } 285e41f4b71Sopenharmony_ci // Carry out normal service processing. 286e41f4b71Sopenharmony_ci console.log('startAbility succeed'); 287e41f4b71Sopenharmony_ci }); 288e41f4b71Sopenharmony_ci } catch (paramError) { 289e41f4b71Sopenharmony_ci // Process input parameter errors. 290e41f4b71Sopenharmony_ci console.error(`error.code: ${paramError.code}, error.message: ${paramError.message}`); 291e41f4b71Sopenharmony_ci } 292e41f4b71Sopenharmony_ci } 293e41f4b71Sopenharmony_ci} 294e41f4b71Sopenharmony_ci``` 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci## ServiceExtensionContext.startAbilityWithAccount 297e41f4b71Sopenharmony_ci 298e41f4b71Sopenharmony_cistartAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<void>): void; 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ciStarts an ability with the account ID specified. This API uses an asynchronous callback to return the result. 301e41f4b71Sopenharmony_ci 302e41f4b71Sopenharmony_ci> **NOTE** 303e41f4b71Sopenharmony_ci> 304e41f4b71Sopenharmony_ci> For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 305e41f4b71Sopenharmony_ci 306e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 309e41f4b71Sopenharmony_ci 310e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 311e41f4b71Sopenharmony_ci 312e41f4b71Sopenharmony_ci**Parameters** 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 315e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 316e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 317e41f4b71Sopenharmony_ci| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getcreatedosaccountscountdeprecated).| 318e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.| 319e41f4b71Sopenharmony_ci 320e41f4b71Sopenharmony_ci**Error codes** 321e41f4b71Sopenharmony_ci 322e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_ci| ID| Error Message| 325e41f4b71Sopenharmony_ci| ------- | -------- | 326e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 327e41f4b71Sopenharmony_ci| 202 | The application is not system-app, can not use system-api. | 328e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 329e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 330e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 331e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 332e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 333e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 334e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. | 335e41f4b71Sopenharmony_ci| 16000009 | An ability cannot be started or stopped in Wukong mode. | 336e41f4b71Sopenharmony_ci| 16000010 | The call with the continuation flag is forbidden. | 337e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 338e41f4b71Sopenharmony_ci| 16000012 | The application is controlled. | 339e41f4b71Sopenharmony_ci| 16000013 | The application is controlled by EDM. | 340e41f4b71Sopenharmony_ci| 16000019 | No matching ability is found. | 341e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 342e41f4b71Sopenharmony_ci| 16000053 | The ability is not on the top of the UI. | 343e41f4b71Sopenharmony_ci| 16000055 | Installation-free timed out. | 344e41f4b71Sopenharmony_ci| 16000071 | App clone is not supported. | 345e41f4b71Sopenharmony_ci| 16000072 | App clone or multi-instance is not supported. | 346e41f4b71Sopenharmony_ci| 16000073 | The app clone index is invalid. | 347e41f4b71Sopenharmony_ci| 16000076 | The app instance key is invalid. | 348e41f4b71Sopenharmony_ci| 16000077 | The number of app instances reaches the limit. | 349e41f4b71Sopenharmony_ci| 16000078 | The multi-instance is not supported. | 350e41f4b71Sopenharmony_ci| 16000079 | The APP_INSTANCE_KEY cannot be specified. | 351e41f4b71Sopenharmony_ci| 16000080 | Creating an instance is not supported. | 352e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. | 353e41f4b71Sopenharmony_ci 354e41f4b71Sopenharmony_ci**Example** 355e41f4b71Sopenharmony_ci 356e41f4b71Sopenharmony_ci```ts 357e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want, StartOptions } from '@kit.AbilityKit'; 358e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 359e41f4b71Sopenharmony_ci 360e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 361e41f4b71Sopenharmony_ci onCreate() { 362e41f4b71Sopenharmony_ci let want: Want = { 363e41f4b71Sopenharmony_ci deviceId: '', 364e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 365e41f4b71Sopenharmony_ci abilityName: 'EntryAbility' 366e41f4b71Sopenharmony_ci }; 367e41f4b71Sopenharmony_ci let accountId = 100; 368e41f4b71Sopenharmony_ci 369e41f4b71Sopenharmony_ci try { 370e41f4b71Sopenharmony_ci this.context.startAbilityWithAccount(want, accountId, (error: BusinessError) => { 371e41f4b71Sopenharmony_ci if (error.code) { 372e41f4b71Sopenharmony_ci // Process service logic errors. 373e41f4b71Sopenharmony_ci console.error(`startAbilityWithAccount failed, error.code: ${error.code}, error.message: ${error.message}`); 374e41f4b71Sopenharmony_ci return; 375e41f4b71Sopenharmony_ci } 376e41f4b71Sopenharmony_ci // Carry out normal service processing. 377e41f4b71Sopenharmony_ci console.log('startAbilityWithAccount succeed'); 378e41f4b71Sopenharmony_ci }); 379e41f4b71Sopenharmony_ci } catch (paramError) { 380e41f4b71Sopenharmony_ci // Process input parameter errors. 381e41f4b71Sopenharmony_ci console.error(`error.code: ${paramError.code}, error.message: ${paramError.message}`); 382e41f4b71Sopenharmony_ci } 383e41f4b71Sopenharmony_ci } 384e41f4b71Sopenharmony_ci} 385e41f4b71Sopenharmony_ci``` 386e41f4b71Sopenharmony_ci 387e41f4b71Sopenharmony_ci## ServiceExtensionContext.startAbilityWithAccount 388e41f4b71Sopenharmony_ci 389e41f4b71Sopenharmony_cistartAbilityWithAccount(want: Want, accountId: number, options: StartOptions, callback: AsyncCallback\<void\>): void; 390e41f4b71Sopenharmony_ci 391e41f4b71Sopenharmony_ciStarts an ability with the account ID and start options specified. This API uses an asynchronous callback to return the result. 392e41f4b71Sopenharmony_ci 393e41f4b71Sopenharmony_ci> **NOTE** 394e41f4b71Sopenharmony_ci> 395e41f4b71Sopenharmony_ci> For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 398e41f4b71Sopenharmony_ci 399e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 400e41f4b71Sopenharmony_ci 401e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 402e41f4b71Sopenharmony_ci 403e41f4b71Sopenharmony_ci**Parameters** 404e41f4b71Sopenharmony_ci 405e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 406e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 407e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 408e41f4b71Sopenharmony_ci| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getcreatedosaccountscountdeprecated).| 409e41f4b71Sopenharmony_ci| options | [StartOptions](js-apis-app-ability-startOptions.md) | Yes| Parameters used for starting the ability.| 410e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.| 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ci**Error codes** 413e41f4b71Sopenharmony_ci 414e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 415e41f4b71Sopenharmony_ci 416e41f4b71Sopenharmony_ci| ID| Error Message| 417e41f4b71Sopenharmony_ci| ------- | -------- | 418e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 419e41f4b71Sopenharmony_ci| 202 | The application is not system-app, can not use system-api. | 420e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 421e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 422e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 423e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 424e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 425e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 426e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. | 427e41f4b71Sopenharmony_ci| 16000009 | An ability cannot be started or stopped in Wukong mode. | 428e41f4b71Sopenharmony_ci| 16000010 | The call with the continuation flag is forbidden. | 429e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 430e41f4b71Sopenharmony_ci| 16000012 | The application is controlled. | 431e41f4b71Sopenharmony_ci| 16000013 | The application is controlled by EDM. | 432e41f4b71Sopenharmony_ci| 16000019 | No matching ability is found. | 433e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 434e41f4b71Sopenharmony_ci| 16000053 | The ability is not on the top of the UI. | 435e41f4b71Sopenharmony_ci| 16000055 | Installation-free timed out. | 436e41f4b71Sopenharmony_ci| 16000071 | App clone is not supported. | 437e41f4b71Sopenharmony_ci| 16000072 | App clone or multi-instance is not supported. | 438e41f4b71Sopenharmony_ci| 16000073 | The app clone index is invalid. | 439e41f4b71Sopenharmony_ci| 16000076 | The app instance key is invalid. | 440e41f4b71Sopenharmony_ci| 16000077 | The number of app instances reaches the limit. | 441e41f4b71Sopenharmony_ci| 16000078 | The multi-instance is not supported. | 442e41f4b71Sopenharmony_ci| 16000079 | The APP_INSTANCE_KEY cannot be specified. | 443e41f4b71Sopenharmony_ci| 16000080 | Creating an instance is not supported. | 444e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. | 445e41f4b71Sopenharmony_ci 446e41f4b71Sopenharmony_ci**Example** 447e41f4b71Sopenharmony_ci 448e41f4b71Sopenharmony_ci```ts 449e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want, StartOptions } from '@kit.AbilityKit'; 450e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 451e41f4b71Sopenharmony_ci 452e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 453e41f4b71Sopenharmony_ci onCreate() { 454e41f4b71Sopenharmony_ci let want: Want = { 455e41f4b71Sopenharmony_ci deviceId: '', 456e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 457e41f4b71Sopenharmony_ci abilityName: 'EntryAbility' 458e41f4b71Sopenharmony_ci }; 459e41f4b71Sopenharmony_ci let accountId = 100; 460e41f4b71Sopenharmony_ci let options: StartOptions = { 461e41f4b71Sopenharmony_ci windowMode: 0 462e41f4b71Sopenharmony_ci }; 463e41f4b71Sopenharmony_ci 464e41f4b71Sopenharmony_ci try { 465e41f4b71Sopenharmony_ci this.context.startAbilityWithAccount(want, accountId, options, (error: BusinessError) => { 466e41f4b71Sopenharmony_ci if (error.code) { 467e41f4b71Sopenharmony_ci // Process service logic errors. 468e41f4b71Sopenharmony_ci console.error(`startAbilityWithAccount failed, error.code: ${error.code}, error.message: ${error.message}`); 469e41f4b71Sopenharmony_ci return; 470e41f4b71Sopenharmony_ci } 471e41f4b71Sopenharmony_ci // Carry out normal service processing. 472e41f4b71Sopenharmony_ci console.log('startAbilityWithAccount succeed'); 473e41f4b71Sopenharmony_ci }); 474e41f4b71Sopenharmony_ci } catch (paramError) { 475e41f4b71Sopenharmony_ci // Process input parameter errors. 476e41f4b71Sopenharmony_ci console.error(`error.code: ${(paramError as BusinessError).code}, error.message: ${(paramError as BusinessError).message}`); 477e41f4b71Sopenharmony_ci } 478e41f4b71Sopenharmony_ci } 479e41f4b71Sopenharmony_ci} 480e41f4b71Sopenharmony_ci``` 481e41f4b71Sopenharmony_ci 482e41f4b71Sopenharmony_ci 483e41f4b71Sopenharmony_ci## ServiceExtensionContext.startAbilityWithAccount 484e41f4b71Sopenharmony_ci 485e41f4b71Sopenharmony_cistartAbilityWithAccount(want: Want, accountId: number, options?: StartOptions): Promise\<void>; 486e41f4b71Sopenharmony_ci 487e41f4b71Sopenharmony_ciStarts an ability with the account ID specified. This API uses a promise to return the result. 488e41f4b71Sopenharmony_ci 489e41f4b71Sopenharmony_ci> **NOTE** 490e41f4b71Sopenharmony_ci> 491e41f4b71Sopenharmony_ci> For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 492e41f4b71Sopenharmony_ci 493e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 494e41f4b71Sopenharmony_ci 495e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 496e41f4b71Sopenharmony_ci 497e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 498e41f4b71Sopenharmony_ci 499e41f4b71Sopenharmony_ci**Parameters** 500e41f4b71Sopenharmony_ci 501e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 502e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 503e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 504e41f4b71Sopenharmony_ci| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getcreatedosaccountscountdeprecated-1).| 505e41f4b71Sopenharmony_ci| options | [StartOptions](js-apis-app-ability-startOptions.md) | No| Parameters used for starting the ability.| 506e41f4b71Sopenharmony_ci 507e41f4b71Sopenharmony_ci**Return value** 508e41f4b71Sopenharmony_ci 509e41f4b71Sopenharmony_ci| Type| Description| 510e41f4b71Sopenharmony_ci| -------- | -------- | 511e41f4b71Sopenharmony_ci| Promise<void> | Promise used to return the result.| 512e41f4b71Sopenharmony_ci 513e41f4b71Sopenharmony_ci**Error codes** 514e41f4b71Sopenharmony_ci 515e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 516e41f4b71Sopenharmony_ci 517e41f4b71Sopenharmony_ci| ID| Error Message| 518e41f4b71Sopenharmony_ci| ------- | -------- | 519e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 520e41f4b71Sopenharmony_ci| 202 | The application is not system-app, can not use system-api. | 521e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 522e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 523e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 524e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 525e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 526e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 527e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. | 528e41f4b71Sopenharmony_ci| 16000009 | An ability cannot be started or stopped in Wukong mode. | 529e41f4b71Sopenharmony_ci| 16000010 | The call with the continuation flag is forbidden. | 530e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 531e41f4b71Sopenharmony_ci| 16000012 | The application is controlled. | 532e41f4b71Sopenharmony_ci| 16000013 | The application is controlled by EDM. | 533e41f4b71Sopenharmony_ci| 16000019 | No matching ability is found. | 534e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 535e41f4b71Sopenharmony_ci| 16000053 | The ability is not on the top of the UI. | 536e41f4b71Sopenharmony_ci| 16000055 | Installation-free timed out. | 537e41f4b71Sopenharmony_ci| 16000071 | App clone is not supported. | 538e41f4b71Sopenharmony_ci| 16000072 | App clone or multi-instance is not supported. | 539e41f4b71Sopenharmony_ci| 16000073 | The app clone index is invalid. | 540e41f4b71Sopenharmony_ci| 16000076 | The app instance key is invalid. | 541e41f4b71Sopenharmony_ci| 16000077 | The number of app instances reaches the limit. | 542e41f4b71Sopenharmony_ci| 16000078 | The multi-instance is not supported. | 543e41f4b71Sopenharmony_ci| 16000079 | The APP_INSTANCE_KEY cannot be specified. | 544e41f4b71Sopenharmony_ci| 16000080 | Creating an instance is not supported. | 545e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. | 546e41f4b71Sopenharmony_ci 547e41f4b71Sopenharmony_ci**Example** 548e41f4b71Sopenharmony_ci 549e41f4b71Sopenharmony_ci```ts 550e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want, StartOptions } from '@kit.AbilityKit'; 551e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 552e41f4b71Sopenharmony_ci 553e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 554e41f4b71Sopenharmony_ci onCreate() { 555e41f4b71Sopenharmony_ci let want: Want = { 556e41f4b71Sopenharmony_ci deviceId: '', 557e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 558e41f4b71Sopenharmony_ci abilityName: 'EntryAbility' 559e41f4b71Sopenharmony_ci }; 560e41f4b71Sopenharmony_ci let accountId = 100; 561e41f4b71Sopenharmony_ci let options: StartOptions = { 562e41f4b71Sopenharmony_ci windowMode: 0 563e41f4b71Sopenharmony_ci }; 564e41f4b71Sopenharmony_ci 565e41f4b71Sopenharmony_ci try { 566e41f4b71Sopenharmony_ci this.context.startAbilityWithAccount(want, accountId, options) 567e41f4b71Sopenharmony_ci .then((data: void) => { 568e41f4b71Sopenharmony_ci // Carry out normal service processing. 569e41f4b71Sopenharmony_ci console.log('startAbilityWithAccount succeed'); 570e41f4b71Sopenharmony_ci }) 571e41f4b71Sopenharmony_ci .catch((error: BusinessError) => { 572e41f4b71Sopenharmony_ci // Process service logic errors. 573e41f4b71Sopenharmony_ci console.error(`startAbilityWithAccount failed, error.code: ${error.code}, error.message: ${error.message}`); 574e41f4b71Sopenharmony_ci }); 575e41f4b71Sopenharmony_ci } catch (paramError) { 576e41f4b71Sopenharmony_ci // Process input parameter errors. 577e41f4b71Sopenharmony_ci console.error(`error.code: ${(paramError as BusinessError).code}, error.message: ${(paramError as BusinessError).message}`); 578e41f4b71Sopenharmony_ci } 579e41f4b71Sopenharmony_ci } 580e41f4b71Sopenharmony_ci} 581e41f4b71Sopenharmony_ci``` 582e41f4b71Sopenharmony_ci 583e41f4b71Sopenharmony_ci## ServiceExtensionContext.startServiceExtensionAbility 584e41f4b71Sopenharmony_ci 585e41f4b71Sopenharmony_cistartServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void; 586e41f4b71Sopenharmony_ci 587e41f4b71Sopenharmony_ciStarts a new ServiceExtensionAbility. This API uses an asynchronous callback to return the result. 588e41f4b71Sopenharmony_ci 589e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 590e41f4b71Sopenharmony_ci 591e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 592e41f4b71Sopenharmony_ci 593e41f4b71Sopenharmony_ci**Parameters** 594e41f4b71Sopenharmony_ci 595e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 596e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 597e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 598e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.| 599e41f4b71Sopenharmony_ci 600e41f4b71Sopenharmony_ci**Error codes** 601e41f4b71Sopenharmony_ci 602e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 603e41f4b71Sopenharmony_ci 604e41f4b71Sopenharmony_ci| ID| Error Message| 605e41f4b71Sopenharmony_ci| ------- | -------- | 606e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 607e41f4b71Sopenharmony_ci| 202 | The application is not system-app, can not use system-api. | 608e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 609e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 610e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 611e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 612e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 613e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 614e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. | 615e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 616e41f4b71Sopenharmony_ci| 16000012 | The application is controlled. | 617e41f4b71Sopenharmony_ci| 16000013 | The application is controlled by EDM. | 618e41f4b71Sopenharmony_ci| 16000019 | No matching ability is found. | 619e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 620e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. | 621e41f4b71Sopenharmony_ci 622e41f4b71Sopenharmony_ci**Example** 623e41f4b71Sopenharmony_ci 624e41f4b71Sopenharmony_ci```ts 625e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want } from '@kit.AbilityKit'; 626e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 627e41f4b71Sopenharmony_ci 628e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 629e41f4b71Sopenharmony_ci onCreate() { 630e41f4b71Sopenharmony_ci let want: Want = { 631e41f4b71Sopenharmony_ci deviceId: '', 632e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 633e41f4b71Sopenharmony_ci abilityName: 'EntryAbility' 634e41f4b71Sopenharmony_ci }; 635e41f4b71Sopenharmony_ci 636e41f4b71Sopenharmony_ci try { 637e41f4b71Sopenharmony_ci this.context.startServiceExtensionAbility(want, (error: BusinessError) => { 638e41f4b71Sopenharmony_ci if (error.code) { 639e41f4b71Sopenharmony_ci // Process service logic errors. 640e41f4b71Sopenharmony_ci console.error(`startServiceExtensionAbility failed, error.code: ${error.code}, error.message: ${error.message}`); 641e41f4b71Sopenharmony_ci return; 642e41f4b71Sopenharmony_ci } 643e41f4b71Sopenharmony_ci // Carry out normal service processing. 644e41f4b71Sopenharmony_ci console.log('startServiceExtensionAbility succeed'); 645e41f4b71Sopenharmony_ci }); 646e41f4b71Sopenharmony_ci } catch (paramError) { 647e41f4b71Sopenharmony_ci // Process input parameter errors. 648e41f4b71Sopenharmony_ci console.error(`error.code: ${(paramError as BusinessError).code}, error.message: ${(paramError as BusinessError).message}`); 649e41f4b71Sopenharmony_ci } 650e41f4b71Sopenharmony_ci } 651e41f4b71Sopenharmony_ci} 652e41f4b71Sopenharmony_ci``` 653e41f4b71Sopenharmony_ci 654e41f4b71Sopenharmony_ci## ServiceExtensionContext.startServiceExtensionAbility 655e41f4b71Sopenharmony_ci 656e41f4b71Sopenharmony_cistartServiceExtensionAbility(want: Want): Promise\<void>; 657e41f4b71Sopenharmony_ci 658e41f4b71Sopenharmony_ciStarts a new ServiceExtensionAbility. This API uses a promise to return the result. 659e41f4b71Sopenharmony_ci 660e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 661e41f4b71Sopenharmony_ci 662e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 663e41f4b71Sopenharmony_ci 664e41f4b71Sopenharmony_ci**Parameters** 665e41f4b71Sopenharmony_ci 666e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 667e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 668e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 669e41f4b71Sopenharmony_ci 670e41f4b71Sopenharmony_ci**Return value** 671e41f4b71Sopenharmony_ci 672e41f4b71Sopenharmony_ci| Type| Description| 673e41f4b71Sopenharmony_ci| -------- | -------- | 674e41f4b71Sopenharmony_ci| Promise<void> | Promise used to return the result.| 675e41f4b71Sopenharmony_ci 676e41f4b71Sopenharmony_ci**Error codes** 677e41f4b71Sopenharmony_ci 678e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 679e41f4b71Sopenharmony_ci 680e41f4b71Sopenharmony_ci| ID| Error Message| 681e41f4b71Sopenharmony_ci| ------- | -------- | 682e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 683e41f4b71Sopenharmony_ci| 202 | The application is not system-app, can not use system-api. | 684e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 685e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 686e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 687e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 688e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 689e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 690e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. | 691e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 692e41f4b71Sopenharmony_ci| 16000012 | The application is controlled. | 693e41f4b71Sopenharmony_ci| 16000013 | The application is controlled by EDM. | 694e41f4b71Sopenharmony_ci| 16000019 | No matching ability is found. | 695e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 696e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. | 697e41f4b71Sopenharmony_ci 698e41f4b71Sopenharmony_ci**Example** 699e41f4b71Sopenharmony_ci 700e41f4b71Sopenharmony_ci```ts 701e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want } from '@kit.AbilityKit'; 702e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 703e41f4b71Sopenharmony_ci 704e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 705e41f4b71Sopenharmony_ci onCreate() { 706e41f4b71Sopenharmony_ci let want: Want = { 707e41f4b71Sopenharmony_ci deviceId: '', 708e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 709e41f4b71Sopenharmony_ci abilityName: 'EntryAbility' 710e41f4b71Sopenharmony_ci }; 711e41f4b71Sopenharmony_ci 712e41f4b71Sopenharmony_ci try { 713e41f4b71Sopenharmony_ci this.context.startServiceExtensionAbility(want) 714e41f4b71Sopenharmony_ci .then((data) => { 715e41f4b71Sopenharmony_ci // Carry out normal service processing. 716e41f4b71Sopenharmony_ci console.log('startServiceExtensionAbility succeed'); 717e41f4b71Sopenharmony_ci }) 718e41f4b71Sopenharmony_ci .catch((error: BusinessError) => { 719e41f4b71Sopenharmony_ci // Process service logic errors. 720e41f4b71Sopenharmony_ci console.error(`startServiceExtensionAbility failed, error.code: ${error.code}, error.message: ${error.message}`); 721e41f4b71Sopenharmony_ci }); 722e41f4b71Sopenharmony_ci } catch (paramError) { 723e41f4b71Sopenharmony_ci // Process input parameter errors. 724e41f4b71Sopenharmony_ci console.error(`error.code: ${(paramError as BusinessError).code}, error.message: ${(paramError as BusinessError).message}`); 725e41f4b71Sopenharmony_ci } 726e41f4b71Sopenharmony_ci } 727e41f4b71Sopenharmony_ci} 728e41f4b71Sopenharmony_ci``` 729e41f4b71Sopenharmony_ci 730e41f4b71Sopenharmony_ci## ServiceExtensionContext.startServiceExtensionAbilityWithAccount 731e41f4b71Sopenharmony_ci 732e41f4b71Sopenharmony_cistartServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<void>): void; 733e41f4b71Sopenharmony_ci 734e41f4b71Sopenharmony_ciStarts a new ServiceExtensionAbility with the account ID specified. This API uses an asynchronous callback to return the result. 735e41f4b71Sopenharmony_ci 736e41f4b71Sopenharmony_ci> **NOTE** 737e41f4b71Sopenharmony_ci> 738e41f4b71Sopenharmony_ci> For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 739e41f4b71Sopenharmony_ci> Permission verification is not required when **accountId** specifies the current user. 740e41f4b71Sopenharmony_ci 741e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 742e41f4b71Sopenharmony_ci 743e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 744e41f4b71Sopenharmony_ci 745e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 746e41f4b71Sopenharmony_ci 747e41f4b71Sopenharmony_ci**Parameters** 748e41f4b71Sopenharmony_ci 749e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 750e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 751e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 752e41f4b71Sopenharmony_ci| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getcreatedosaccountscountdeprecated).| 753e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.| 754e41f4b71Sopenharmony_ci 755e41f4b71Sopenharmony_ci**Error codes** 756e41f4b71Sopenharmony_ci 757e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 758e41f4b71Sopenharmony_ci 759e41f4b71Sopenharmony_ci| ID| Error Message| 760e41f4b71Sopenharmony_ci| ------- | -------- | 761e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 762e41f4b71Sopenharmony_ci| 202 | The application is not system-app, can not use system-api. | 763e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 764e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 765e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 766e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 767e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 768e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 769e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. | 770e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 771e41f4b71Sopenharmony_ci| 16000012 | The application is controlled. | 772e41f4b71Sopenharmony_ci| 16000013 | The application is controlled by EDM. | 773e41f4b71Sopenharmony_ci| 16000019 | No matching ability is found. | 774e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 775e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. | 776e41f4b71Sopenharmony_ci 777e41f4b71Sopenharmony_ci**Example** 778e41f4b71Sopenharmony_ci 779e41f4b71Sopenharmony_ci```ts 780e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want } from '@kit.AbilityKit'; 781e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 782e41f4b71Sopenharmony_ci 783e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 784e41f4b71Sopenharmony_ci onCreate() { 785e41f4b71Sopenharmony_ci let want: Want = { 786e41f4b71Sopenharmony_ci deviceId: '', 787e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 788e41f4b71Sopenharmony_ci abilityName: 'EntryAbility' 789e41f4b71Sopenharmony_ci }; 790e41f4b71Sopenharmony_ci let accountId = 100; 791e41f4b71Sopenharmony_ci 792e41f4b71Sopenharmony_ci try { 793e41f4b71Sopenharmony_ci this.context.startServiceExtensionAbilityWithAccount(want, accountId, (error: BusinessError) => { 794e41f4b71Sopenharmony_ci if (error.code) { 795e41f4b71Sopenharmony_ci // Process service logic errors. 796e41f4b71Sopenharmony_ci console.error(`startServiceExtensionAbilityWithAccount failed, error.code: ${error.code}, error.message: ${error.message}`); 797e41f4b71Sopenharmony_ci return; 798e41f4b71Sopenharmony_ci } 799e41f4b71Sopenharmony_ci // Carry out normal service processing. 800e41f4b71Sopenharmony_ci console.log('startServiceExtensionAbilityWithAccount succeed'); 801e41f4b71Sopenharmony_ci }); 802e41f4b71Sopenharmony_ci } catch (paramError) { 803e41f4b71Sopenharmony_ci // Process input parameter errors. 804e41f4b71Sopenharmony_ci console.error(`error.code: ${(paramError as BusinessError).code}, error.message: ${(paramError as BusinessError).message}`); 805e41f4b71Sopenharmony_ci } 806e41f4b71Sopenharmony_ci } 807e41f4b71Sopenharmony_ci} 808e41f4b71Sopenharmony_ci``` 809e41f4b71Sopenharmony_ci 810e41f4b71Sopenharmony_ci## ServiceExtensionContext.startServiceExtensionAbilityWithAccount 811e41f4b71Sopenharmony_ci 812e41f4b71Sopenharmony_cistartServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<void>; 813e41f4b71Sopenharmony_ci 814e41f4b71Sopenharmony_ciStarts a new ServiceExtensionAbility with the account ID specified. This API uses a promise to return the result. 815e41f4b71Sopenharmony_ci 816e41f4b71Sopenharmony_ci> **NOTE** 817e41f4b71Sopenharmony_ci> 818e41f4b71Sopenharmony_ci> For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 819e41f4b71Sopenharmony_ci> Permission verification is not required when **accountId** specifies the current user. 820e41f4b71Sopenharmony_ci 821e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 822e41f4b71Sopenharmony_ci 823e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 824e41f4b71Sopenharmony_ci 825e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 826e41f4b71Sopenharmony_ci 827e41f4b71Sopenharmony_ci**Parameters** 828e41f4b71Sopenharmony_ci 829e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 830e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 831e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 832e41f4b71Sopenharmony_ci| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getcreatedosaccountscountdeprecated-1).| 833e41f4b71Sopenharmony_ci 834e41f4b71Sopenharmony_ci**Return value** 835e41f4b71Sopenharmony_ci 836e41f4b71Sopenharmony_ci| Type| Description| 837e41f4b71Sopenharmony_ci| -------- | -------- | 838e41f4b71Sopenharmony_ci| Promise<void> | Promise used to return the result.| 839e41f4b71Sopenharmony_ci 840e41f4b71Sopenharmony_ci**Error codes** 841e41f4b71Sopenharmony_ci 842e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 843e41f4b71Sopenharmony_ci 844e41f4b71Sopenharmony_ci| ID| Error Message| 845e41f4b71Sopenharmony_ci| ------- | -------- | 846e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 847e41f4b71Sopenharmony_ci| 202 | The application is not system-app, can not use system-api. | 848e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 849e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 850e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 851e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 852e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 853e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 854e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. | 855e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 856e41f4b71Sopenharmony_ci| 16000012 | The application is controlled. | 857e41f4b71Sopenharmony_ci| 16000013 | The application is controlled by EDM. | 858e41f4b71Sopenharmony_ci| 16000019 | No matching ability is found. | 859e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 860e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. | 861e41f4b71Sopenharmony_ci 862e41f4b71Sopenharmony_ci**Example** 863e41f4b71Sopenharmony_ci 864e41f4b71Sopenharmony_ci```ts 865e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want } from '@kit.AbilityKit'; 866e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 867e41f4b71Sopenharmony_ci 868e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 869e41f4b71Sopenharmony_ci onCreate() { 870e41f4b71Sopenharmony_ci let want: Want = { 871e41f4b71Sopenharmony_ci deviceId: '', 872e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 873e41f4b71Sopenharmony_ci abilityName: 'EntryAbility' 874e41f4b71Sopenharmony_ci }; 875e41f4b71Sopenharmony_ci let accountId = 100; 876e41f4b71Sopenharmony_ci 877e41f4b71Sopenharmony_ci try { 878e41f4b71Sopenharmony_ci this.context.startServiceExtensionAbilityWithAccount(want, accountId) 879e41f4b71Sopenharmony_ci .then((data: void) => { 880e41f4b71Sopenharmony_ci // Carry out normal service processing. 881e41f4b71Sopenharmony_ci console.log('startServiceExtensionAbilityWithAccount succeed'); 882e41f4b71Sopenharmony_ci }) 883e41f4b71Sopenharmony_ci .catch((error: BusinessError) => { 884e41f4b71Sopenharmony_ci // Process service logic errors. 885e41f4b71Sopenharmony_ci console.error(`startServiceExtensionAbilityWithAccount failed, error.code: ${error.code}, error.message: ${error.message}`); 886e41f4b71Sopenharmony_ci }); 887e41f4b71Sopenharmony_ci } catch (paramError) { 888e41f4b71Sopenharmony_ci // Process input parameter errors. 889e41f4b71Sopenharmony_ci console.error(`error.code: ${(paramError as BusinessError).code}, error.message: ${(paramError as BusinessError).message}`); 890e41f4b71Sopenharmony_ci } 891e41f4b71Sopenharmony_ci } 892e41f4b71Sopenharmony_ci} 893e41f4b71Sopenharmony_ci``` 894e41f4b71Sopenharmony_ci 895e41f4b71Sopenharmony_ci## ServiceExtensionContext.startAbilityAsCaller<sup>10+<sup> 896e41f4b71Sopenharmony_ci 897e41f4b71Sopenharmony_cistartAbilityAsCaller(want: Want, callback: AsyncCallback\<void>): void; 898e41f4b71Sopenharmony_ci 899e41f4b71Sopenharmony_ciStarts an ability with the caller information specified. The caller information is carried in **want** and identified at the system service layer. The ability can obtain the caller information from the **want** parameter in the **onCreate** lifecycle callback. When this API is used to start an ability, the caller information carried in **want** is not overwritten by the current application information. The system service layer can obtain the initial caller information. This API uses an asynchronous callback to return the result. 900e41f4b71Sopenharmony_ci 901e41f4b71Sopenharmony_ci> **NOTE** 902e41f4b71Sopenharmony_ci> 903e41f4b71Sopenharmony_ci> For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 904e41f4b71Sopenharmony_ci 905e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 906e41f4b71Sopenharmony_ci 907e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 908e41f4b71Sopenharmony_ci 909e41f4b71Sopenharmony_ci**Parameters** 910e41f4b71Sopenharmony_ci 911e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 912e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 913e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 914e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the ability is started, **err** is **undefined**; otherwise, **err** is an error object.| 915e41f4b71Sopenharmony_ci 916e41f4b71Sopenharmony_ci**Error codes** 917e41f4b71Sopenharmony_ci 918e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 919e41f4b71Sopenharmony_ci 920e41f4b71Sopenharmony_ci| ID| Error Message| 921e41f4b71Sopenharmony_ci| ------- | -------- | 922e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 923e41f4b71Sopenharmony_ci| 202 | The application is not system-app, can not use system-api. | 924e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 925e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 926e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 927e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 928e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 929e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 930e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. | 931e41f4b71Sopenharmony_ci| 16000009 | An ability cannot be started or stopped in Wukong mode. | 932e41f4b71Sopenharmony_ci| 16000010 | The call with the continuation flag is forbidden. | 933e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 934e41f4b71Sopenharmony_ci| 16000012 | The application is controlled. | 935e41f4b71Sopenharmony_ci| 16000013 | The application is controlled by EDM. | 936e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 937e41f4b71Sopenharmony_ci| 16000053 | The ability is not on the top of the UI. | 938e41f4b71Sopenharmony_ci| 16000055 | Installation-free timed out. | 939e41f4b71Sopenharmony_ci| 16000071 | App clone is not supported. | 940e41f4b71Sopenharmony_ci| 16000072 | App clone or multi-instance is not supported. | 941e41f4b71Sopenharmony_ci| 16000073 | The app clone index is invalid. | 942e41f4b71Sopenharmony_ci| 16000076 | The app instance key is invalid. | 943e41f4b71Sopenharmony_ci| 16000077 | The number of app instances reaches the limit. | 944e41f4b71Sopenharmony_ci| 16000078 | The multi-instance is not supported. | 945e41f4b71Sopenharmony_ci| 16000079 | The APP_INSTANCE_KEY cannot be specified. | 946e41f4b71Sopenharmony_ci| 16000080 | Creating an instance is not supported. | 947e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. | 948e41f4b71Sopenharmony_ci 949e41f4b71Sopenharmony_ci**Example** 950e41f4b71Sopenharmony_ci 951e41f4b71Sopenharmony_ci```ts 952e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want } from '@kit.AbilityKit'; 953e41f4b71Sopenharmony_ci 954e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 955e41f4b71Sopenharmony_ci onCreate(want: Want) { 956e41f4b71Sopenharmony_ci // want contains the information about the caller who starts the application. 957e41f4b71Sopenharmony_ci let localWant: Want = want; 958e41f4b71Sopenharmony_ci localWant.bundleName = 'com.example.demo'; 959e41f4b71Sopenharmony_ci localWant.moduleName = 'entry'; 960e41f4b71Sopenharmony_ci localWant.abilityName = 'TestAbility'; 961e41f4b71Sopenharmony_ci 962e41f4b71Sopenharmony_ci // Start a new ability using the caller information. 963e41f4b71Sopenharmony_ci this.context.startAbilityAsCaller(localWant, (err) => { 964e41f4b71Sopenharmony_ci if (err && err.code != 0) { 965e41f4b71Sopenharmony_ci console.error('startAbilityAsCaller failed, err:' + JSON.stringify(err)); 966e41f4b71Sopenharmony_ci } else { 967e41f4b71Sopenharmony_ci console.log('startAbilityAsCaller success.'); 968e41f4b71Sopenharmony_ci } 969e41f4b71Sopenharmony_ci }) 970e41f4b71Sopenharmony_ci } 971e41f4b71Sopenharmony_ci} 972e41f4b71Sopenharmony_ci``` 973e41f4b71Sopenharmony_ci 974e41f4b71Sopenharmony_ci## ServiceExtensionContext.startAbilityAsCaller<sup>10+<sup> 975e41f4b71Sopenharmony_ci 976e41f4b71Sopenharmony_cistartAbilityAsCaller(want: Want, options: StartOptions, callback: AsyncCallback\<void>): void; 977e41f4b71Sopenharmony_ci 978e41f4b71Sopenharmony_ciStarts an ability with the caller information and start options specified. The caller information is carried in **want** and identified at the system service layer. The ability can obtain the caller information from the **want** parameter in the **onCreate** lifecycle callback. When this API is used to start an ability, the caller information carried in **want** is not overwritten by the current application information. The system service layer can obtain the initial caller information. This API uses an asynchronous callback to return the result. 979e41f4b71Sopenharmony_ci 980e41f4b71Sopenharmony_ci> **NOTE** 981e41f4b71Sopenharmony_ci> 982e41f4b71Sopenharmony_ci> For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 983e41f4b71Sopenharmony_ci 984e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 985e41f4b71Sopenharmony_ci 986e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 987e41f4b71Sopenharmony_ci 988e41f4b71Sopenharmony_ci**Parameters** 989e41f4b71Sopenharmony_ci 990e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 991e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 992e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 993e41f4b71Sopenharmony_ci| options | [StartOptions](js-apis-app-ability-startOptions.md) | Yes| Parameters used for starting the ability.| 994e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the ability is started, **err** is **undefined**; otherwise, **err** is an error object.| 995e41f4b71Sopenharmony_ci 996e41f4b71Sopenharmony_ci**Error codes** 997e41f4b71Sopenharmony_ci 998e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 999e41f4b71Sopenharmony_ci 1000e41f4b71Sopenharmony_ci| ID| Error Message| 1001e41f4b71Sopenharmony_ci| ------- | -------- | 1002e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 1003e41f4b71Sopenharmony_ci| 202 | The application is not system-app, can not use system-api. | 1004e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1005e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 1006e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 1007e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 1008e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 1009e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. | 1010e41f4b71Sopenharmony_ci| 16000009 | An ability cannot be started or stopped in Wukong mode. | 1011e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 1012e41f4b71Sopenharmony_ci| 16000012 | The application is controlled. | 1013e41f4b71Sopenharmony_ci| 16000013 | The application is controlled by EDM. | 1014e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1015e41f4b71Sopenharmony_ci| 16000053 | The ability is not on the top of the UI. | 1016e41f4b71Sopenharmony_ci| 16000055 | Installation-free timed out. | 1017e41f4b71Sopenharmony_ci| 16000071 | App clone is not supported. | 1018e41f4b71Sopenharmony_ci| 16000072 | App clone or multi-instance is not supported. | 1019e41f4b71Sopenharmony_ci| 16000073 | The app clone index is invalid. | 1020e41f4b71Sopenharmony_ci| 16000076 | The app instance key is invalid. | 1021e41f4b71Sopenharmony_ci| 16000077 | The number of app instances reaches the limit. | 1022e41f4b71Sopenharmony_ci| 16000078 | The multi-instance is not supported. | 1023e41f4b71Sopenharmony_ci| 16000079 | The APP_INSTANCE_KEY cannot be specified. | 1024e41f4b71Sopenharmony_ci| 16000080 | Creating an instance is not supported. | 1025e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. | 1026e41f4b71Sopenharmony_ci 1027e41f4b71Sopenharmony_ci**Example** 1028e41f4b71Sopenharmony_ci 1029e41f4b71Sopenharmony_ci```ts 1030e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want, StartOptions } from '@kit.AbilityKit'; 1031e41f4b71Sopenharmony_ci 1032e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 1033e41f4b71Sopenharmony_ci onCreate(want: Want) { 1034e41f4b71Sopenharmony_ci // want contains the information about the caller who starts the application. 1035e41f4b71Sopenharmony_ci let localWant: Want = want; 1036e41f4b71Sopenharmony_ci localWant.bundleName = 'com.example.demo'; 1037e41f4b71Sopenharmony_ci localWant.moduleName = 'entry'; 1038e41f4b71Sopenharmony_ci localWant.abilityName = 'TestAbility'; 1039e41f4b71Sopenharmony_ci 1040e41f4b71Sopenharmony_ci let option: StartOptions = { 1041e41f4b71Sopenharmony_ci displayId: 0 1042e41f4b71Sopenharmony_ci } 1043e41f4b71Sopenharmony_ci 1044e41f4b71Sopenharmony_ci // Start a new ability using the caller information. 1045e41f4b71Sopenharmony_ci this.context.startAbilityAsCaller(localWant, option, (err) => { 1046e41f4b71Sopenharmony_ci if (err && err.code != 0) { 1047e41f4b71Sopenharmony_ci console.error('startAbilityAsCaller failed, err:' + JSON.stringify(err)); 1048e41f4b71Sopenharmony_ci } else { 1049e41f4b71Sopenharmony_ci console.log('startAbilityAsCaller success.'); 1050e41f4b71Sopenharmony_ci } 1051e41f4b71Sopenharmony_ci }) 1052e41f4b71Sopenharmony_ci } 1053e41f4b71Sopenharmony_ci} 1054e41f4b71Sopenharmony_ci``` 1055e41f4b71Sopenharmony_ci 1056e41f4b71Sopenharmony_ci## ServiceExtensionContext.startAbilityAsCaller<sup>10+<sup> 1057e41f4b71Sopenharmony_ci 1058e41f4b71Sopenharmony_cistartAbilityAsCaller(want: Want, options?: StartOptions): Promise\<void>; 1059e41f4b71Sopenharmony_ci 1060e41f4b71Sopenharmony_ciStarts an ability with the caller information specified. The caller information is carried in **want** and identified at the system service layer. The ability can obtain the caller information from the **want** parameter in the **onCreate** lifecycle callback. When this API is used to start an ability, the caller information carried in **want** is not overwritten by the current application information. The system service layer can obtain the initial caller information. This API uses a promise to return the result. 1061e41f4b71Sopenharmony_ci 1062e41f4b71Sopenharmony_ci> **NOTE** 1063e41f4b71Sopenharmony_ci> 1064e41f4b71Sopenharmony_ci> For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 1065e41f4b71Sopenharmony_ci 1066e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1067e41f4b71Sopenharmony_ci 1068e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 1069e41f4b71Sopenharmony_ci 1070e41f4b71Sopenharmony_ci**Parameters** 1071e41f4b71Sopenharmony_ci 1072e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1073e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1074e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 1075e41f4b71Sopenharmony_ci| options | [StartOptions](js-apis-app-ability-startOptions.md) | No| Parameters used for starting the ability.| 1076e41f4b71Sopenharmony_ci 1077e41f4b71Sopenharmony_ci**Return value** 1078e41f4b71Sopenharmony_ci 1079e41f4b71Sopenharmony_ci| Type| Description| 1080e41f4b71Sopenharmony_ci| -------- | -------- | 1081e41f4b71Sopenharmony_ci| Promise<void> | Promise that returns no value.| 1082e41f4b71Sopenharmony_ci 1083e41f4b71Sopenharmony_ci**Error codes** 1084e41f4b71Sopenharmony_ci 1085e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1086e41f4b71Sopenharmony_ci 1087e41f4b71Sopenharmony_ci| ID| Error Message| 1088e41f4b71Sopenharmony_ci| ------- | -------- | 1089e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 1090e41f4b71Sopenharmony_ci| 202 | The application is not system-app, can not use system-api. | 1091e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1092e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 1093e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 1094e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 1095e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 1096e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 1097e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. | 1098e41f4b71Sopenharmony_ci| 16000009 | An ability cannot be started or stopped in Wukong mode. | 1099e41f4b71Sopenharmony_ci| 16000010 | The call with the continuation flag is forbidden. | 1100e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 1101e41f4b71Sopenharmony_ci| 16000012 | The application is controlled. | 1102e41f4b71Sopenharmony_ci| 16000013 | The application is controlled by EDM. | 1103e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1104e41f4b71Sopenharmony_ci| 16000053 | The ability is not on the top of the UI. | 1105e41f4b71Sopenharmony_ci| 16000055 | Installation-free timed out. | 1106e41f4b71Sopenharmony_ci| 16000071 | App clone is not supported. | 1107e41f4b71Sopenharmony_ci| 16000072 | App clone or multi-instance is not supported. | 1108e41f4b71Sopenharmony_ci| 16000073 | The app clone index is invalid. | 1109e41f4b71Sopenharmony_ci| 16000076 | The app instance key is invalid. | 1110e41f4b71Sopenharmony_ci| 16000077 | The number of app instances reaches the limit. | 1111e41f4b71Sopenharmony_ci| 16000078 | The multi-instance is not supported. | 1112e41f4b71Sopenharmony_ci| 16000079 | The APP_INSTANCE_KEY cannot be specified. | 1113e41f4b71Sopenharmony_ci| 16000080 | Creating an instance is not supported. | 1114e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. | 1115e41f4b71Sopenharmony_ci 1116e41f4b71Sopenharmony_ci**Example** 1117e41f4b71Sopenharmony_ci 1118e41f4b71Sopenharmony_ci```ts 1119e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want, StartOptions } from '@kit.AbilityKit'; 1120e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1121e41f4b71Sopenharmony_ci 1122e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 1123e41f4b71Sopenharmony_ci onCreate(want: Want) { 1124e41f4b71Sopenharmony_ci // want contains the information about the caller who starts the application. 1125e41f4b71Sopenharmony_ci let localWant: Want = want; 1126e41f4b71Sopenharmony_ci localWant.bundleName = 'com.example.demo'; 1127e41f4b71Sopenharmony_ci localWant.moduleName = 'entry'; 1128e41f4b71Sopenharmony_ci localWant.abilityName = 'TestAbility'; 1129e41f4b71Sopenharmony_ci 1130e41f4b71Sopenharmony_ci let option: StartOptions = { 1131e41f4b71Sopenharmony_ci displayId: 0 1132e41f4b71Sopenharmony_ci }; 1133e41f4b71Sopenharmony_ci 1134e41f4b71Sopenharmony_ci // Start a new ability using the caller information. 1135e41f4b71Sopenharmony_ci this.context.startAbilityAsCaller(localWant, option) 1136e41f4b71Sopenharmony_ci .then(() => { 1137e41f4b71Sopenharmony_ci console.log('startAbilityAsCaller success.'); 1138e41f4b71Sopenharmony_ci }) 1139e41f4b71Sopenharmony_ci .catch((err: BusinessError) => { 1140e41f4b71Sopenharmony_ci console.error('startAbilityAsCaller failed, err:' + JSON.stringify(err)); 1141e41f4b71Sopenharmony_ci }) 1142e41f4b71Sopenharmony_ci } 1143e41f4b71Sopenharmony_ci} 1144e41f4b71Sopenharmony_ci``` 1145e41f4b71Sopenharmony_ci 1146e41f4b71Sopenharmony_ci## ServiceExtensionContext.stopServiceExtensionAbility 1147e41f4b71Sopenharmony_ci 1148e41f4b71Sopenharmony_cistopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void; 1149e41f4b71Sopenharmony_ci 1150e41f4b71Sopenharmony_ciStops a ServiceExtensionAbility in the same application. This API uses an asynchronous callback to return the result. 1151e41f4b71Sopenharmony_ci 1152e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1153e41f4b71Sopenharmony_ci 1154e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 1155e41f4b71Sopenharmony_ci 1156e41f4b71Sopenharmony_ci**Parameters** 1157e41f4b71Sopenharmony_ci 1158e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1159e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1160e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 1161e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.| 1162e41f4b71Sopenharmony_ci 1163e41f4b71Sopenharmony_ci**Error codes** 1164e41f4b71Sopenharmony_ci 1165e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1166e41f4b71Sopenharmony_ci 1167e41f4b71Sopenharmony_ci| ID| Error Message| 1168e41f4b71Sopenharmony_ci| ------- | -------- | 1169e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 1170e41f4b71Sopenharmony_ci| 202 | The application is not system-app, can not use system-api. | 1171e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1172e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 1173e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 1174e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 1175e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 1176e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 1177e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 1178e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1179e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. | 1180e41f4b71Sopenharmony_ci 1181e41f4b71Sopenharmony_ci**Example** 1182e41f4b71Sopenharmony_ci 1183e41f4b71Sopenharmony_ci```ts 1184e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want } from '@kit.AbilityKit'; 1185e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1186e41f4b71Sopenharmony_ci 1187e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 1188e41f4b71Sopenharmony_ci onCreate() { 1189e41f4b71Sopenharmony_ci let want: Want = { 1190e41f4b71Sopenharmony_ci deviceId: '', 1191e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 1192e41f4b71Sopenharmony_ci abilityName: 'EntryAbility' 1193e41f4b71Sopenharmony_ci }; 1194e41f4b71Sopenharmony_ci 1195e41f4b71Sopenharmony_ci try { 1196e41f4b71Sopenharmony_ci this.context.stopServiceExtensionAbility(want, (error: BusinessError) => { 1197e41f4b71Sopenharmony_ci if (error.code) { 1198e41f4b71Sopenharmony_ci // Process service logic errors. 1199e41f4b71Sopenharmony_ci console.error(`stopServiceExtensionAbility failed, error.code: ${error.code}, error.message: ${error.message}`); 1200e41f4b71Sopenharmony_ci return; 1201e41f4b71Sopenharmony_ci } 1202e41f4b71Sopenharmony_ci // Carry out normal service processing. 1203e41f4b71Sopenharmony_ci console.log('stopServiceExtensionAbility succeed'); 1204e41f4b71Sopenharmony_ci }); 1205e41f4b71Sopenharmony_ci } catch (paramError) { 1206e41f4b71Sopenharmony_ci // Process input parameter errors. 1207e41f4b71Sopenharmony_ci console.error(`error.code: ${(paramError as BusinessError).code}, error.message: ${(paramError as BusinessError).message}`); 1208e41f4b71Sopenharmony_ci } 1209e41f4b71Sopenharmony_ci } 1210e41f4b71Sopenharmony_ci} 1211e41f4b71Sopenharmony_ci``` 1212e41f4b71Sopenharmony_ci 1213e41f4b71Sopenharmony_ci## ServiceExtensionContext.stopServiceExtensionAbility 1214e41f4b71Sopenharmony_ci 1215e41f4b71Sopenharmony_cistopServiceExtensionAbility(want: Want): Promise\<void>; 1216e41f4b71Sopenharmony_ci 1217e41f4b71Sopenharmony_ciStops a ServiceExtensionAbility in the same application. This API uses a promise to return the result. 1218e41f4b71Sopenharmony_ci 1219e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1220e41f4b71Sopenharmony_ci 1221e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 1222e41f4b71Sopenharmony_ci 1223e41f4b71Sopenharmony_ci**Parameters** 1224e41f4b71Sopenharmony_ci 1225e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1226e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1227e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 1228e41f4b71Sopenharmony_ci 1229e41f4b71Sopenharmony_ci**Return value** 1230e41f4b71Sopenharmony_ci 1231e41f4b71Sopenharmony_ci| Type| Description| 1232e41f4b71Sopenharmony_ci| -------- | -------- | 1233e41f4b71Sopenharmony_ci| Promise<void> | Promise used to return the result.| 1234e41f4b71Sopenharmony_ci 1235e41f4b71Sopenharmony_ci**Error codes** 1236e41f4b71Sopenharmony_ci 1237e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1238e41f4b71Sopenharmony_ci 1239e41f4b71Sopenharmony_ci| ID| Error Message| 1240e41f4b71Sopenharmony_ci| ------- | -------- | 1241e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 1242e41f4b71Sopenharmony_ci| 202 | The application is not system-app, can not use system-api. | 1243e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1244e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 1245e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 1246e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 1247e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 1248e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 1249e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 1250e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1251e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. | 1252e41f4b71Sopenharmony_ci 1253e41f4b71Sopenharmony_ci**Example** 1254e41f4b71Sopenharmony_ci 1255e41f4b71Sopenharmony_ci```ts 1256e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want } from '@kit.AbilityKit'; 1257e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1258e41f4b71Sopenharmony_ci 1259e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 1260e41f4b71Sopenharmony_ci onCreate() { 1261e41f4b71Sopenharmony_ci let want: Want = { 1262e41f4b71Sopenharmony_ci deviceId: '', 1263e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 1264e41f4b71Sopenharmony_ci abilityName: 'EntryAbility' 1265e41f4b71Sopenharmony_ci }; 1266e41f4b71Sopenharmony_ci 1267e41f4b71Sopenharmony_ci try { 1268e41f4b71Sopenharmony_ci this.context.stopServiceExtensionAbility(want) 1269e41f4b71Sopenharmony_ci .then(() => { 1270e41f4b71Sopenharmony_ci // Carry out normal service processing. 1271e41f4b71Sopenharmony_ci console.log('stopServiceExtensionAbility succeed'); 1272e41f4b71Sopenharmony_ci }) 1273e41f4b71Sopenharmony_ci .catch((error: BusinessError) => { 1274e41f4b71Sopenharmony_ci // Process service logic errors. 1275e41f4b71Sopenharmony_ci console.error(`stopServiceExtensionAbility failed, error.code: ${error.code}, error.message: ${error.message}`); 1276e41f4b71Sopenharmony_ci }); 1277e41f4b71Sopenharmony_ci } catch (paramError) { 1278e41f4b71Sopenharmony_ci // Process input parameter errors. 1279e41f4b71Sopenharmony_ci console.error(`error.code: ${(paramError as BusinessError).code}, error.message: ${(paramError as BusinessError).message}`); 1280e41f4b71Sopenharmony_ci } 1281e41f4b71Sopenharmony_ci } 1282e41f4b71Sopenharmony_ci} 1283e41f4b71Sopenharmony_ci``` 1284e41f4b71Sopenharmony_ci 1285e41f4b71Sopenharmony_ci## ServiceExtensionContext.stopServiceExtensionAbilityWithAccount 1286e41f4b71Sopenharmony_ci 1287e41f4b71Sopenharmony_cistopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<void>): void; 1288e41f4b71Sopenharmony_ci 1289e41f4b71Sopenharmony_ciStops a ServiceExtensionAbility in the same application with the account ID specified. This API uses an asynchronous callback to return the result. 1290e41f4b71Sopenharmony_ci 1291e41f4b71Sopenharmony_ci> **NOTE** 1292e41f4b71Sopenharmony_ci> 1293e41f4b71Sopenharmony_ci> Permission verification is not required when **accountId** specifies the current user. 1294e41f4b71Sopenharmony_ci 1295e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 1296e41f4b71Sopenharmony_ci 1297e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1298e41f4b71Sopenharmony_ci 1299e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 1300e41f4b71Sopenharmony_ci 1301e41f4b71Sopenharmony_ci**Parameters** 1302e41f4b71Sopenharmony_ci 1303e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1304e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1305e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 1306e41f4b71Sopenharmony_ci| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getcreatedosaccountscountdeprecated).| 1307e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.| 1308e41f4b71Sopenharmony_ci 1309e41f4b71Sopenharmony_ci**Error codes** 1310e41f4b71Sopenharmony_ci 1311e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1312e41f4b71Sopenharmony_ci 1313e41f4b71Sopenharmony_ci| ID| Error Message| 1314e41f4b71Sopenharmony_ci| ------- | -------- | 1315e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 1316e41f4b71Sopenharmony_ci| 202 | The application is not system-app, can not use system-api. | 1317e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1318e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 1319e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 1320e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 1321e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 1322e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 1323e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 1324e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1325e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. | 1326e41f4b71Sopenharmony_ci 1327e41f4b71Sopenharmony_ci**Example** 1328e41f4b71Sopenharmony_ci 1329e41f4b71Sopenharmony_ci```ts 1330e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want } from '@kit.AbilityKit'; 1331e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1332e41f4b71Sopenharmony_ci 1333e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 1334e41f4b71Sopenharmony_ci onCreate() { 1335e41f4b71Sopenharmony_ci let want: Want = { 1336e41f4b71Sopenharmony_ci deviceId: '', 1337e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 1338e41f4b71Sopenharmony_ci abilityName: 'EntryAbility' 1339e41f4b71Sopenharmony_ci }; 1340e41f4b71Sopenharmony_ci let accountId = 100; 1341e41f4b71Sopenharmony_ci 1342e41f4b71Sopenharmony_ci try { 1343e41f4b71Sopenharmony_ci this.context.stopServiceExtensionAbilityWithAccount(want, accountId, (error: BusinessError) => { 1344e41f4b71Sopenharmony_ci if (error.code) { 1345e41f4b71Sopenharmony_ci // Process service logic errors. 1346e41f4b71Sopenharmony_ci console.error(`stopServiceExtensionAbilityWithAccount failed, error.code: ${error.code}, error.message: ${error.message}`); 1347e41f4b71Sopenharmony_ci return; 1348e41f4b71Sopenharmony_ci } 1349e41f4b71Sopenharmony_ci // Carry out normal service processing. 1350e41f4b71Sopenharmony_ci console.log('stopServiceExtensionAbilityWithAccount succeed'); 1351e41f4b71Sopenharmony_ci }); 1352e41f4b71Sopenharmony_ci } catch (paramError) { 1353e41f4b71Sopenharmony_ci // Process input parameter errors. 1354e41f4b71Sopenharmony_ci console.error(`error.code: ${(paramError as BusinessError).code}, error.message: ${(paramError as BusinessError).message}`); 1355e41f4b71Sopenharmony_ci } 1356e41f4b71Sopenharmony_ci } 1357e41f4b71Sopenharmony_ci} 1358e41f4b71Sopenharmony_ci``` 1359e41f4b71Sopenharmony_ci 1360e41f4b71Sopenharmony_ci## ServiceExtensionContext.stopServiceExtensionAbilityWithAccount 1361e41f4b71Sopenharmony_ci 1362e41f4b71Sopenharmony_cistopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<void>; 1363e41f4b71Sopenharmony_ci 1364e41f4b71Sopenharmony_ciStops a ServiceExtensionAbility in the same application with the account ID specified. This API uses a promise to return the result. 1365e41f4b71Sopenharmony_ci 1366e41f4b71Sopenharmony_ci> **NOTE** 1367e41f4b71Sopenharmony_ci> 1368e41f4b71Sopenharmony_ci> Permission verification is not required when **accountId** specifies the current user. 1369e41f4b71Sopenharmony_ci 1370e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 1371e41f4b71Sopenharmony_ci 1372e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1373e41f4b71Sopenharmony_ci 1374e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 1375e41f4b71Sopenharmony_ci 1376e41f4b71Sopenharmony_ci**Parameters** 1377e41f4b71Sopenharmony_ci 1378e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1379e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1380e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 1381e41f4b71Sopenharmony_ci| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getcreatedosaccountscountdeprecated-1).| 1382e41f4b71Sopenharmony_ci 1383e41f4b71Sopenharmony_ci**Return value** 1384e41f4b71Sopenharmony_ci 1385e41f4b71Sopenharmony_ci| Type| Description| 1386e41f4b71Sopenharmony_ci| -------- | -------- | 1387e41f4b71Sopenharmony_ci| Promise<void> | Promise used to return the result.| 1388e41f4b71Sopenharmony_ci 1389e41f4b71Sopenharmony_ci**Error codes** 1390e41f4b71Sopenharmony_ci 1391e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1392e41f4b71Sopenharmony_ci 1393e41f4b71Sopenharmony_ci| ID| Error Message| 1394e41f4b71Sopenharmony_ci| ------- | -------- | 1395e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 1396e41f4b71Sopenharmony_ci| 202 | The application is not system-app, can not use system-api. | 1397e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1398e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 1399e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 1400e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 1401e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 1402e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 1403e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 1404e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1405e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. | 1406e41f4b71Sopenharmony_ci 1407e41f4b71Sopenharmony_ci**Example** 1408e41f4b71Sopenharmony_ci 1409e41f4b71Sopenharmony_ci```ts 1410e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want } from '@kit.AbilityKit'; 1411e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1412e41f4b71Sopenharmony_ci 1413e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 1414e41f4b71Sopenharmony_ci onCreate() { 1415e41f4b71Sopenharmony_ci let want: Want = { 1416e41f4b71Sopenharmony_ci deviceId: '', 1417e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 1418e41f4b71Sopenharmony_ci abilityName: 'EntryAbility' 1419e41f4b71Sopenharmony_ci }; 1420e41f4b71Sopenharmony_ci let accountId = 100; 1421e41f4b71Sopenharmony_ci 1422e41f4b71Sopenharmony_ci try { 1423e41f4b71Sopenharmony_ci this.context.stopServiceExtensionAbilityWithAccount(want, accountId) 1424e41f4b71Sopenharmony_ci .then(() => { 1425e41f4b71Sopenharmony_ci // Carry out normal service processing. 1426e41f4b71Sopenharmony_ci console.log('stopServiceExtensionAbilityWithAccount succeed'); 1427e41f4b71Sopenharmony_ci }) 1428e41f4b71Sopenharmony_ci .catch((error: BusinessError) => { 1429e41f4b71Sopenharmony_ci // Process service logic errors. 1430e41f4b71Sopenharmony_ci console.error(`stopServiceExtensionAbilityWithAccount failed, error.code: ${error.code}, error.message: ${error.message}`); 1431e41f4b71Sopenharmony_ci }); 1432e41f4b71Sopenharmony_ci } catch (paramError) { 1433e41f4b71Sopenharmony_ci // Process input parameter errors. 1434e41f4b71Sopenharmony_ci console.error(`error.code: ${(paramError as BusinessError).code}, error.message: ${(paramError as BusinessError).message}`); 1435e41f4b71Sopenharmony_ci } 1436e41f4b71Sopenharmony_ci } 1437e41f4b71Sopenharmony_ci} 1438e41f4b71Sopenharmony_ci``` 1439e41f4b71Sopenharmony_ci 1440e41f4b71Sopenharmony_ci## ServiceExtensionContext.terminateSelf 1441e41f4b71Sopenharmony_ci 1442e41f4b71Sopenharmony_citerminateSelf(callback: AsyncCallback<void>): void; 1443e41f4b71Sopenharmony_ci 1444e41f4b71Sopenharmony_ciTerminates this ability. This API uses an asynchronous callback to return the result. 1445e41f4b71Sopenharmony_ci 1446e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1447e41f4b71Sopenharmony_ci 1448e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 1449e41f4b71Sopenharmony_ci 1450e41f4b71Sopenharmony_ci**Parameters** 1451e41f4b71Sopenharmony_ci 1452e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1453e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1454e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1455e41f4b71Sopenharmony_ci 1456e41f4b71Sopenharmony_ci**Error codes** 1457e41f4b71Sopenharmony_ci 1458e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1459e41f4b71Sopenharmony_ci 1460e41f4b71Sopenharmony_ci| ID| Error Message| 1461e41f4b71Sopenharmony_ci| ------- | -------- | 1462e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1463e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 1464e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 1465e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 1466e41f4b71Sopenharmony_ci| 16000009 | An ability cannot be started or stopped in Wukong mode. | 1467e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 1468e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1469e41f4b71Sopenharmony_ci 1470e41f4b71Sopenharmony_ci**Example** 1471e41f4b71Sopenharmony_ci 1472e41f4b71Sopenharmony_ci```ts 1473e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility } from '@kit.AbilityKit'; 1474e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1475e41f4b71Sopenharmony_ci 1476e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 1477e41f4b71Sopenharmony_ci onCreate() { 1478e41f4b71Sopenharmony_ci this.context.terminateSelf((error: BusinessError) => { 1479e41f4b71Sopenharmony_ci if (error.code) { 1480e41f4b71Sopenharmony_ci // Process service logic errors. 1481e41f4b71Sopenharmony_ci console.error(`terminateSelf failed, error.code: ${error.code}, error.message: ${error.message}`); 1482e41f4b71Sopenharmony_ci return; 1483e41f4b71Sopenharmony_ci } 1484e41f4b71Sopenharmony_ci // Carry out normal service processing. 1485e41f4b71Sopenharmony_ci console.log('terminateSelf succeed'); 1486e41f4b71Sopenharmony_ci }); 1487e41f4b71Sopenharmony_ci } 1488e41f4b71Sopenharmony_ci} 1489e41f4b71Sopenharmony_ci``` 1490e41f4b71Sopenharmony_ci 1491e41f4b71Sopenharmony_ci## ServiceExtensionContext.terminateSelf 1492e41f4b71Sopenharmony_ci 1493e41f4b71Sopenharmony_citerminateSelf(): Promise<void>; 1494e41f4b71Sopenharmony_ci 1495e41f4b71Sopenharmony_ciTerminates this ability. This API uses a promise to return the result. 1496e41f4b71Sopenharmony_ci 1497e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1498e41f4b71Sopenharmony_ci 1499e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 1500e41f4b71Sopenharmony_ci 1501e41f4b71Sopenharmony_ci**Return value** 1502e41f4b71Sopenharmony_ci 1503e41f4b71Sopenharmony_ci| Type| Description| 1504e41f4b71Sopenharmony_ci| -------- | -------- | 1505e41f4b71Sopenharmony_ci| Promise<void> | Promise used to return the result.| 1506e41f4b71Sopenharmony_ci 1507e41f4b71Sopenharmony_ci**Error codes** 1508e41f4b71Sopenharmony_ci 1509e41f4b71Sopenharmony_ciFor details about the error codes, see [Ability Error Codes](errorcode-ability.md). 1510e41f4b71Sopenharmony_ci 1511e41f4b71Sopenharmony_ci| ID| Error Message| 1512e41f4b71Sopenharmony_ci| ------- | -------------------------------- | 1513e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 1514e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 1515e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 1516e41f4b71Sopenharmony_ci| 16000009 | An ability cannot be started or stopped in Wukong mode. | 1517e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 1518e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1519e41f4b71Sopenharmony_ci 1520e41f4b71Sopenharmony_ci**Example** 1521e41f4b71Sopenharmony_ci 1522e41f4b71Sopenharmony_ci```ts 1523e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility } from '@kit.AbilityKit'; 1524e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1525e41f4b71Sopenharmony_ci 1526e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 1527e41f4b71Sopenharmony_ci onCreate() { 1528e41f4b71Sopenharmony_ci this.context.terminateSelf().then(() => { 1529e41f4b71Sopenharmony_ci // Carry out normal service processing. 1530e41f4b71Sopenharmony_ci console.log('terminateSelf succeed'); 1531e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 1532e41f4b71Sopenharmony_ci // Process service logic errors. 1533e41f4b71Sopenharmony_ci console.error(`terminateSelf failed, error.code: ${error.code}, error.message: ${error.message}`); 1534e41f4b71Sopenharmony_ci }); 1535e41f4b71Sopenharmony_ci } 1536e41f4b71Sopenharmony_ci} 1537e41f4b71Sopenharmony_ci``` 1538e41f4b71Sopenharmony_ci 1539e41f4b71Sopenharmony_ci## ServiceExtensionContext.connectServiceExtensionAbility 1540e41f4b71Sopenharmony_ci 1541e41f4b71Sopenharmony_ciconnectServiceExtensionAbility(want: Want, options: ConnectOptions): number; 1542e41f4b71Sopenharmony_ci 1543e41f4b71Sopenharmony_ciConnects this ability to a ServiceExtensionAbility. 1544e41f4b71Sopenharmony_ci 1545e41f4b71Sopenharmony_ci> **NOTE** 1546e41f4b71Sopenharmony_ci> 1547e41f4b71Sopenharmony_ci> For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 1548e41f4b71Sopenharmony_ci 1549e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1550e41f4b71Sopenharmony_ci 1551e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 1552e41f4b71Sopenharmony_ci 1553e41f4b71Sopenharmony_ci**Parameters** 1554e41f4b71Sopenharmony_ci 1555e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1556e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1557e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability, such as the ability name and bundle name.| 1558e41f4b71Sopenharmony_ci| options | [ConnectOptions](js-apis-inner-ability-connectOptions.md) | Yes| Callback used to return the information indicating that the connection is successful, interrupted, or failed.| 1559e41f4b71Sopenharmony_ci 1560e41f4b71Sopenharmony_ci**Return value** 1561e41f4b71Sopenharmony_ci 1562e41f4b71Sopenharmony_ci| Type| Description| 1563e41f4b71Sopenharmony_ci| -------- | -------- | 1564e41f4b71Sopenharmony_ci| number | A number, based on which the connection will be interrupted.| 1565e41f4b71Sopenharmony_ci 1566e41f4b71Sopenharmony_ci**Error codes** 1567e41f4b71Sopenharmony_ci 1568e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1569e41f4b71Sopenharmony_ci 1570e41f4b71Sopenharmony_ci| ID| Error Message| 1571e41f4b71Sopenharmony_ci| ------- | -------- | 1572e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 1573e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1574e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 1575e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 1576e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 1577e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 1578e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 1579e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. | 1580e41f4b71Sopenharmony_ci| 16000053 | The ability is not on the top of the UI. | 1581e41f4b71Sopenharmony_ci| 16000055 | Installation-free timed out. | 1582e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 1583e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1584e41f4b71Sopenharmony_ci 1585e41f4b71Sopenharmony_ci**Example** 1586e41f4b71Sopenharmony_ci 1587e41f4b71Sopenharmony_ci```ts 1588e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want, common } from '@kit.AbilityKit'; 1589e41f4b71Sopenharmony_ciimport { rpc } from '@kit.IPCKit'; 1590e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1591e41f4b71Sopenharmony_ci 1592e41f4b71Sopenharmony_cilet commRemote: rpc.IRemoteObject; // Release the instance when the connection is disconnected. 1593e41f4b71Sopenharmony_ci 1594e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 1595e41f4b71Sopenharmony_ci onCreate() { 1596e41f4b71Sopenharmony_ci let want: Want = { 1597e41f4b71Sopenharmony_ci bundleName: 'com.example.myapp', 1598e41f4b71Sopenharmony_ci abilityName: 'MyAbility' 1599e41f4b71Sopenharmony_ci }; 1600e41f4b71Sopenharmony_ci let options: common.ConnectOptions = { 1601e41f4b71Sopenharmony_ci onConnect(elementName, remote) { 1602e41f4b71Sopenharmony_ci commRemote = remote; 1603e41f4b71Sopenharmony_ci console.log('----------- onConnect -----------'); 1604e41f4b71Sopenharmony_ci }, 1605e41f4b71Sopenharmony_ci onDisconnect(elementName) { 1606e41f4b71Sopenharmony_ci console.log('----------- onDisconnect -----------'); 1607e41f4b71Sopenharmony_ci }, 1608e41f4b71Sopenharmony_ci onFailed(code) { 1609e41f4b71Sopenharmony_ci console.error('----------- onFailed -----------'); 1610e41f4b71Sopenharmony_ci } 1611e41f4b71Sopenharmony_ci }; 1612e41f4b71Sopenharmony_ci let connection: number; 1613e41f4b71Sopenharmony_ci 1614e41f4b71Sopenharmony_ci try { 1615e41f4b71Sopenharmony_ci connection = this.context.connectServiceExtensionAbility(want, options); 1616e41f4b71Sopenharmony_ci } catch (paramError) { 1617e41f4b71Sopenharmony_ci // Process input parameter errors. 1618e41f4b71Sopenharmony_ci console.error(`error.code: ${(paramError as BusinessError).code}, error.message: ${(paramError as BusinessError).message}`); 1619e41f4b71Sopenharmony_ci } 1620e41f4b71Sopenharmony_ci } 1621e41f4b71Sopenharmony_ci} 1622e41f4b71Sopenharmony_ci``` 1623e41f4b71Sopenharmony_ci 1624e41f4b71Sopenharmony_ci## ServiceExtensionContext.connectServiceExtensionAbilityWithAccount 1625e41f4b71Sopenharmony_ci 1626e41f4b71Sopenharmony_ciconnectServiceExtensionAbilityWithAccount(want: Want, accountId: number, options: ConnectOptions): number; 1627e41f4b71Sopenharmony_ci 1628e41f4b71Sopenharmony_ciConnects this ability to a ServiceExtensionAbility of a given account. 1629e41f4b71Sopenharmony_ci 1630e41f4b71Sopenharmony_ci> **NOTE** 1631e41f4b71Sopenharmony_ci> 1632e41f4b71Sopenharmony_ci> For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 1633e41f4b71Sopenharmony_ci> Permission verification is not required when **accountId** specifies the current user. 1634e41f4b71Sopenharmony_ci 1635e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 1636e41f4b71Sopenharmony_ci 1637e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1638e41f4b71Sopenharmony_ci 1639e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 1640e41f4b71Sopenharmony_ci 1641e41f4b71Sopenharmony_ci**Parameters** 1642e41f4b71Sopenharmony_ci 1643e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1644e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1645e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 1646e41f4b71Sopenharmony_ci| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getcreatedosaccountscountdeprecated).| 1647e41f4b71Sopenharmony_ci| options | ConnectOptions | Yes| Remote object instance.| 1648e41f4b71Sopenharmony_ci 1649e41f4b71Sopenharmony_ci**Return value** 1650e41f4b71Sopenharmony_ci 1651e41f4b71Sopenharmony_ci| Type| Description| 1652e41f4b71Sopenharmony_ci| -------- | -------- | 1653e41f4b71Sopenharmony_ci| number | Result code of the connection.| 1654e41f4b71Sopenharmony_ci 1655e41f4b71Sopenharmony_ci**Error codes** 1656e41f4b71Sopenharmony_ci 1657e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1658e41f4b71Sopenharmony_ci 1659e41f4b71Sopenharmony_ci| ID| Error Message| 1660e41f4b71Sopenharmony_ci| ------- | -------- | 1661e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 1662e41f4b71Sopenharmony_ci| 202 | The application is not system-app, can not use system-api. | 1663e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1664e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 1665e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 1666e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 1667e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 1668e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 1669e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. | 1670e41f4b71Sopenharmony_ci| 16000053 | The ability is not on the top of the UI. | 1671e41f4b71Sopenharmony_ci| 16000055 | Installation-free timed out. | 1672e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 1673e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1674e41f4b71Sopenharmony_ci 1675e41f4b71Sopenharmony_ci**Example** 1676e41f4b71Sopenharmony_ci 1677e41f4b71Sopenharmony_ci```ts 1678e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want, common } from '@kit.AbilityKit'; 1679e41f4b71Sopenharmony_ciimport { rpc } from '@kit.IPCKit'; 1680e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1681e41f4b71Sopenharmony_ci 1682e41f4b71Sopenharmony_cilet commRemote: rpc.IRemoteObject; // Release the instance when the connection is disconnected. 1683e41f4b71Sopenharmony_ci 1684e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 1685e41f4b71Sopenharmony_ci onCreate() { 1686e41f4b71Sopenharmony_ci let want: Want = { 1687e41f4b71Sopenharmony_ci deviceId: '', 1688e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 1689e41f4b71Sopenharmony_ci abilityName: 'EntryAbility' 1690e41f4b71Sopenharmony_ci }; 1691e41f4b71Sopenharmony_ci let accountId = 100; 1692e41f4b71Sopenharmony_ci let options: common.ConnectOptions = { 1693e41f4b71Sopenharmony_ci onConnect(elementName, remote) { 1694e41f4b71Sopenharmony_ci commRemote = remote; 1695e41f4b71Sopenharmony_ci console.log('----------- onConnect -----------'); 1696e41f4b71Sopenharmony_ci }, 1697e41f4b71Sopenharmony_ci onDisconnect(elementName) { 1698e41f4b71Sopenharmony_ci console.log('----------- onDisconnect -----------'); 1699e41f4b71Sopenharmony_ci }, 1700e41f4b71Sopenharmony_ci onFailed(code) { 1701e41f4b71Sopenharmony_ci console.log('----------- onFailed -----------'); 1702e41f4b71Sopenharmony_ci } 1703e41f4b71Sopenharmony_ci }; 1704e41f4b71Sopenharmony_ci let connection: number; 1705e41f4b71Sopenharmony_ci 1706e41f4b71Sopenharmony_ci try { 1707e41f4b71Sopenharmony_ci connection = this.context.connectServiceExtensionAbilityWithAccount(want, accountId, options); 1708e41f4b71Sopenharmony_ci } catch (paramError) { 1709e41f4b71Sopenharmony_ci // Process input parameter errors. 1710e41f4b71Sopenharmony_ci console.error(`error.code: ${(paramError as BusinessError).code}, error.message: ${(paramError as BusinessError).message}`); 1711e41f4b71Sopenharmony_ci } 1712e41f4b71Sopenharmony_ci } 1713e41f4b71Sopenharmony_ci} 1714e41f4b71Sopenharmony_ci``` 1715e41f4b71Sopenharmony_ci 1716e41f4b71Sopenharmony_ci## ServiceExtensionContext.disconnectServiceExtensionAbility 1717e41f4b71Sopenharmony_ci 1718e41f4b71Sopenharmony_cidisconnectServiceExtensionAbility(connection: number, callback:AsyncCallback<void>): void; 1719e41f4b71Sopenharmony_ci 1720e41f4b71Sopenharmony_ciDisconnects this ability from a ServiceExtensionAbility and after the successful disconnection, sets the remote object returned upon the connection to void. This API uses an asynchronous callback to return the result. 1721e41f4b71Sopenharmony_ci 1722e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1723e41f4b71Sopenharmony_ci 1724e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 1725e41f4b71Sopenharmony_ci 1726e41f4b71Sopenharmony_ci**Parameters** 1727e41f4b71Sopenharmony_ci 1728e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1729e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1730e41f4b71Sopenharmony_ci| connection | number | Yes| Number returned after **connectServiceExtensionAbility** is called.| 1731e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1732e41f4b71Sopenharmony_ci 1733e41f4b71Sopenharmony_ci**Error codes** 1734e41f4b71Sopenharmony_ci 1735e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1736e41f4b71Sopenharmony_ci 1737e41f4b71Sopenharmony_ci| ID| Error Message| 1738e41f4b71Sopenharmony_ci| ------- | -------- | 1739e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1740e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 1741e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1742e41f4b71Sopenharmony_ci 1743e41f4b71Sopenharmony_ci**Example** 1744e41f4b71Sopenharmony_ci 1745e41f4b71Sopenharmony_ci```ts 1746e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility } from '@kit.AbilityKit'; 1747e41f4b71Sopenharmony_ciimport { rpc } from '@kit.IPCKit'; 1748e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1749e41f4b71Sopenharmony_ci 1750e41f4b71Sopenharmony_cilet commRemote: rpc.IRemoteObject | null; // Release the instance when the connection is disconnected. 1751e41f4b71Sopenharmony_ci 1752e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 1753e41f4b71Sopenharmony_ci onCreate() { 1754e41f4b71Sopenharmony_ci // connection is the return value of connectServiceExtensionAbility. 1755e41f4b71Sopenharmony_ci let connection = 1; 1756e41f4b71Sopenharmony_ci try { 1757e41f4b71Sopenharmony_ci this.context.disconnectServiceExtensionAbility(connection, (error: BusinessError) => { 1758e41f4b71Sopenharmony_ci commRemote = null; 1759e41f4b71Sopenharmony_ci if (error.code) { 1760e41f4b71Sopenharmony_ci // Process service logic errors. 1761e41f4b71Sopenharmony_ci console.error(`disconnectServiceExtensionAbility failed, error.code: ${error.code}, error.message: ${error.message}`); 1762e41f4b71Sopenharmony_ci return; 1763e41f4b71Sopenharmony_ci } 1764e41f4b71Sopenharmony_ci // Carry out normal service processing. 1765e41f4b71Sopenharmony_ci console.log('disconnectServiceExtensionAbility succeed'); 1766e41f4b71Sopenharmony_ci }); 1767e41f4b71Sopenharmony_ci } catch (paramError) { 1768e41f4b71Sopenharmony_ci commRemote = null; 1769e41f4b71Sopenharmony_ci // Process input parameter errors. 1770e41f4b71Sopenharmony_ci console.error(`error.code: ${(paramError as BusinessError).code}, error.message: ${(paramError as BusinessError).message}`); 1771e41f4b71Sopenharmony_ci } 1772e41f4b71Sopenharmony_ci } 1773e41f4b71Sopenharmony_ci} 1774e41f4b71Sopenharmony_ci``` 1775e41f4b71Sopenharmony_ci 1776e41f4b71Sopenharmony_ci## ServiceExtensionContext.disconnectServiceExtensionAbility 1777e41f4b71Sopenharmony_ci 1778e41f4b71Sopenharmony_cidisconnectServiceExtensionAbility(connection: number): Promise<void>; 1779e41f4b71Sopenharmony_ci 1780e41f4b71Sopenharmony_ciDisconnects this ability from a ServiceExtensionAbility and after the successful disconnection, sets the remote object returned upon the connection to void. This API uses a promise to return the result. 1781e41f4b71Sopenharmony_ci 1782e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1783e41f4b71Sopenharmony_ci 1784e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 1785e41f4b71Sopenharmony_ci 1786e41f4b71Sopenharmony_ci**Parameters** 1787e41f4b71Sopenharmony_ci 1788e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1789e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1790e41f4b71Sopenharmony_ci| connection | number | Yes| Number returned after **connectServiceExtensionAbility** is called.| 1791e41f4b71Sopenharmony_ci 1792e41f4b71Sopenharmony_ci**Return value** 1793e41f4b71Sopenharmony_ci 1794e41f4b71Sopenharmony_ci| Type| Description| 1795e41f4b71Sopenharmony_ci| -------- | -------- | 1796e41f4b71Sopenharmony_ci| Promise<void> | Promise used to return the result.| 1797e41f4b71Sopenharmony_ci 1798e41f4b71Sopenharmony_ci**Error codes** 1799e41f4b71Sopenharmony_ci 1800e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1801e41f4b71Sopenharmony_ci 1802e41f4b71Sopenharmony_ci| ID| Error Message| 1803e41f4b71Sopenharmony_ci| ------- | -------- | 1804e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1805e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 1806e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1807e41f4b71Sopenharmony_ci 1808e41f4b71Sopenharmony_ci**Example** 1809e41f4b71Sopenharmony_ci 1810e41f4b71Sopenharmony_ci```ts 1811e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility } from '@kit.AbilityKit'; 1812e41f4b71Sopenharmony_ciimport { rpc } from '@kit.IPCKit'; 1813e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1814e41f4b71Sopenharmony_ci 1815e41f4b71Sopenharmony_cilet commRemote: rpc.IRemoteObject | null; // Release the instance when the connection is disconnected. 1816e41f4b71Sopenharmony_ci 1817e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 1818e41f4b71Sopenharmony_ci onCreate() { 1819e41f4b71Sopenharmony_ci // connection is the return value of connectServiceExtensionAbility. 1820e41f4b71Sopenharmony_ci let connection = 1; 1821e41f4b71Sopenharmony_ci try { 1822e41f4b71Sopenharmony_ci this.context.disconnectServiceExtensionAbility(connection) 1823e41f4b71Sopenharmony_ci .then(() => { 1824e41f4b71Sopenharmony_ci commRemote = null; 1825e41f4b71Sopenharmony_ci // Carry out normal service processing. 1826e41f4b71Sopenharmony_ci console.log('disconnectServiceExtensionAbility succeed'); 1827e41f4b71Sopenharmony_ci }) 1828e41f4b71Sopenharmony_ci .catch((error: BusinessError) => { 1829e41f4b71Sopenharmony_ci commRemote = null; 1830e41f4b71Sopenharmony_ci // Process service logic errors. 1831e41f4b71Sopenharmony_ci console.error(`disconnectServiceExtensionAbility failed, error.code: ${error.code}, error.message: ${error.message}`); 1832e41f4b71Sopenharmony_ci }); 1833e41f4b71Sopenharmony_ci } catch (paramError) { 1834e41f4b71Sopenharmony_ci commRemote = null; 1835e41f4b71Sopenharmony_ci // Process input parameter errors. 1836e41f4b71Sopenharmony_ci console.error(`error.code: ${(paramError as BusinessError).code}, error.message: ${(paramError as BusinessError).message}`); 1837e41f4b71Sopenharmony_ci } 1838e41f4b71Sopenharmony_ci } 1839e41f4b71Sopenharmony_ci} 1840e41f4b71Sopenharmony_ci``` 1841e41f4b71Sopenharmony_ci 1842e41f4b71Sopenharmony_ci## ServiceExtensionContext.startAbilityByCall 1843e41f4b71Sopenharmony_ci 1844e41f4b71Sopenharmony_cistartAbilityByCall(want: Want): Promise<Caller>; 1845e41f4b71Sopenharmony_ci 1846e41f4b71Sopenharmony_ciStarts an ability in the foreground or background and obtains the caller object for communicating with the ability. 1847e41f4b71Sopenharmony_ci 1848e41f4b71Sopenharmony_ciObserve the following when using this API: 1849e41f4b71Sopenharmony_ci - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission. 1850e41f4b71Sopenharmony_ci - If **exported** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. 1851e41f4b71Sopenharmony_ci - The rules for using this API in the same-device and cross-device scenarios are different. For details, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 1852e41f4b71Sopenharmony_ci 1853e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ABILITY_BACKGROUND_COMMUNICATION 1854e41f4b71Sopenharmony_ci 1855e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1856e41f4b71Sopenharmony_ci 1857e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 1858e41f4b71Sopenharmony_ci 1859e41f4b71Sopenharmony_ci**Parameters** 1860e41f4b71Sopenharmony_ci 1861e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1862e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1863e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Information about the ability to start, including **abilityName**, **moduleName**, **bundleName**, **deviceId**, and **parameters** (optional). If **parameters** is left blank or null, the ability is started in the background.| 1864e41f4b71Sopenharmony_ci 1865e41f4b71Sopenharmony_ci**Return value** 1866e41f4b71Sopenharmony_ci 1867e41f4b71Sopenharmony_ci| Type| Description| 1868e41f4b71Sopenharmony_ci| -------- | -------- | 1869e41f4b71Sopenharmony_ci| Promise<Caller> | Promise used to return the caller object to communicate with.| 1870e41f4b71Sopenharmony_ci 1871e41f4b71Sopenharmony_ci**Error codes** 1872e41f4b71Sopenharmony_ci 1873e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1874e41f4b71Sopenharmony_ci 1875e41f4b71Sopenharmony_ci| ID| Error Message| 1876e41f4b71Sopenharmony_ci| ------- | -------- | 1877e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 1878e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1879e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 1880e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 1881e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 1882e41f4b71Sopenharmony_ci| 16000005 | Static permission denied. The specified process does not have the permission. | 1883e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 1884e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. | 1885e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 1886e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1887e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. | 1888e41f4b71Sopenharmony_ci 1889e41f4b71Sopenharmony_ci**Example** 1890e41f4b71Sopenharmony_ci 1891e41f4b71Sopenharmony_ciStart an ability in the background. 1892e41f4b71Sopenharmony_ci 1893e41f4b71Sopenharmony_ci```ts 1894e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Caller, Want } from '@kit.AbilityKit'; 1895e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1896e41f4b71Sopenharmony_ci 1897e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 1898e41f4b71Sopenharmony_ci onCreate() { 1899e41f4b71Sopenharmony_ci let caller: Caller; 1900e41f4b71Sopenharmony_ci // Start an ability in the background by not passing parameters. 1901e41f4b71Sopenharmony_ci let wantBackground: Want = { 1902e41f4b71Sopenharmony_ci bundleName: 'com.example.myservice', 1903e41f4b71Sopenharmony_ci moduleName: 'entry', 1904e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 1905e41f4b71Sopenharmony_ci deviceId: '' 1906e41f4b71Sopenharmony_ci }; 1907e41f4b71Sopenharmony_ci 1908e41f4b71Sopenharmony_ci try { 1909e41f4b71Sopenharmony_ci this.context.startAbilityByCall(wantBackground) 1910e41f4b71Sopenharmony_ci .then((obj: Caller) => { 1911e41f4b71Sopenharmony_ci // Carry out normal service processing. 1912e41f4b71Sopenharmony_ci caller = obj; 1913e41f4b71Sopenharmony_ci console.log('startAbilityByCall succeed'); 1914e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 1915e41f4b71Sopenharmony_ci // Process service logic errors. 1916e41f4b71Sopenharmony_ci console.error(`startAbilityByCall failed, error.code: ${error.code}, error.message: ${error.message}`); 1917e41f4b71Sopenharmony_ci }); 1918e41f4b71Sopenharmony_ci } catch (paramError) { 1919e41f4b71Sopenharmony_ci // Process input parameter errors. 1920e41f4b71Sopenharmony_ci console.error(`error.code: ${(paramError as BusinessError).code}, error.message: ${(paramError as BusinessError).message}`); 1921e41f4b71Sopenharmony_ci } 1922e41f4b71Sopenharmony_ci } 1923e41f4b71Sopenharmony_ci} 1924e41f4b71Sopenharmony_ci``` 1925e41f4b71Sopenharmony_ci 1926e41f4b71Sopenharmony_ciStart an ability in the foreground. 1927e41f4b71Sopenharmony_ci 1928e41f4b71Sopenharmony_ci```ts 1929e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Caller, Want } from '@kit.AbilityKit'; 1930e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1931e41f4b71Sopenharmony_ci 1932e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 1933e41f4b71Sopenharmony_ci onCreate() { 1934e41f4b71Sopenharmony_ci let caller: Caller; 1935e41f4b71Sopenharmony_ci // Start an ability in the foreground with 'ohos.aafwk.param.callAbilityToForeground' in parameters set to true. 1936e41f4b71Sopenharmony_ci let wantForeground: Want = { 1937e41f4b71Sopenharmony_ci bundleName: 'com.example.myservice', 1938e41f4b71Sopenharmony_ci moduleName: 'entry', 1939e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 1940e41f4b71Sopenharmony_ci deviceId: '', 1941e41f4b71Sopenharmony_ci parameters: { 1942e41f4b71Sopenharmony_ci 'ohos.aafwk.param.callAbilityToForeground': true 1943e41f4b71Sopenharmony_ci } 1944e41f4b71Sopenharmony_ci }; 1945e41f4b71Sopenharmony_ci 1946e41f4b71Sopenharmony_ci try { 1947e41f4b71Sopenharmony_ci this.context.startAbilityByCall(wantForeground) 1948e41f4b71Sopenharmony_ci .then((obj: Caller) => { 1949e41f4b71Sopenharmony_ci // Carry out normal service processing. 1950e41f4b71Sopenharmony_ci caller = obj; 1951e41f4b71Sopenharmony_ci console.log('startAbilityByCall succeed'); 1952e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 1953e41f4b71Sopenharmony_ci // Process service logic errors. 1954e41f4b71Sopenharmony_ci console.error(`startAbilityByCall failed, error.code: ${error.code}, error.message: ${error.message}`); 1955e41f4b71Sopenharmony_ci }); 1956e41f4b71Sopenharmony_ci } catch (paramError) { 1957e41f4b71Sopenharmony_ci // Process input parameter errors. 1958e41f4b71Sopenharmony_ci console.error(`error.code: ${(paramError as BusinessError).code}, error.message: ${(paramError as BusinessError).message}`); 1959e41f4b71Sopenharmony_ci } 1960e41f4b71Sopenharmony_ci } 1961e41f4b71Sopenharmony_ci} 1962e41f4b71Sopenharmony_ci``` 1963e41f4b71Sopenharmony_ci## ServiceExtensionContext.startRecentAbility 1964e41f4b71Sopenharmony_ci 1965e41f4b71Sopenharmony_cistartRecentAbility(want: Want, callback: AsyncCallback\<void>): void; 1966e41f4b71Sopenharmony_ci 1967e41f4b71Sopenharmony_ciStarts an ability. If the ability has multiple instances, the latest instance is started. This API uses an asynchronous callback to return the result. 1968e41f4b71Sopenharmony_ci 1969e41f4b71Sopenharmony_ci> **NOTE** 1970e41f4b71Sopenharmony_ci> 1971e41f4b71Sopenharmony_ci> For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 1972e41f4b71Sopenharmony_ci 1973e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1974e41f4b71Sopenharmony_ci 1975e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 1976e41f4b71Sopenharmony_ci 1977e41f4b71Sopenharmony_ci**Parameters** 1978e41f4b71Sopenharmony_ci 1979e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1980e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1981e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 1982e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes| Callback used to return the result.| 1983e41f4b71Sopenharmony_ci 1984e41f4b71Sopenharmony_ci**Error codes** 1985e41f4b71Sopenharmony_ci 1986e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1987e41f4b71Sopenharmony_ci 1988e41f4b71Sopenharmony_ci| ID| Error Message| 1989e41f4b71Sopenharmony_ci| ------- | -------- | 1990e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 1991e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1992e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 1993e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 1994e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 1995e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 1996e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 1997e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. | 1998e41f4b71Sopenharmony_ci| 16000009 | An ability cannot be started or stopped in Wukong mode. | 1999e41f4b71Sopenharmony_ci| 16000010 | The call with the continuation flag is forbidden. | 2000e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 2001e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 2002e41f4b71Sopenharmony_ci| 16000053 | The ability is not on the top of the UI. | 2003e41f4b71Sopenharmony_ci| 16000055 | Installation-free timed out. | 2004e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. | 2005e41f4b71Sopenharmony_ci 2006e41f4b71Sopenharmony_ci**Example** 2007e41f4b71Sopenharmony_ci 2008e41f4b71Sopenharmony_ci```ts 2009e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want } from '@kit.AbilityKit'; 2010e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2011e41f4b71Sopenharmony_ci 2012e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 2013e41f4b71Sopenharmony_ci onCreate() { 2014e41f4b71Sopenharmony_ci let want: Want = { 2015e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 2016e41f4b71Sopenharmony_ci abilityName: 'EntryAbility' 2017e41f4b71Sopenharmony_ci }; 2018e41f4b71Sopenharmony_ci 2019e41f4b71Sopenharmony_ci try { 2020e41f4b71Sopenharmony_ci this.context.startRecentAbility(want, (err: BusinessError) => { 2021e41f4b71Sopenharmony_ci if (err.code) { 2022e41f4b71Sopenharmony_ci // Process service logic errors. 2023e41f4b71Sopenharmony_ci console.error(`startRecentAbility failed, code is ${err.code}, message is ${err.message}`); 2024e41f4b71Sopenharmony_ci return; 2025e41f4b71Sopenharmony_ci } 2026e41f4b71Sopenharmony_ci // Carry out normal service processing. 2027e41f4b71Sopenharmony_ci console.info('startRecentAbility succeed'); 2028e41f4b71Sopenharmony_ci }); 2029e41f4b71Sopenharmony_ci } catch (err) { 2030e41f4b71Sopenharmony_ci // Process input parameter errors. 2031e41f4b71Sopenharmony_ci let code = (err as BusinessError).code; 2032e41f4b71Sopenharmony_ci let message = (err as BusinessError).message; 2033e41f4b71Sopenharmony_ci console.error(`startRecentAbility failed, code is ${code}, message is ${message}`); 2034e41f4b71Sopenharmony_ci } 2035e41f4b71Sopenharmony_ci } 2036e41f4b71Sopenharmony_ci} 2037e41f4b71Sopenharmony_ci``` 2038e41f4b71Sopenharmony_ci## ServiceExtensionContext.startRecentAbility 2039e41f4b71Sopenharmony_ci 2040e41f4b71Sopenharmony_cistartRecentAbility(want: Want, options: StartOptions, callback: AsyncCallback\<void>): void; 2041e41f4b71Sopenharmony_ci 2042e41f4b71Sopenharmony_ciStarts an ability with the start options specified. If the ability has multiple instances, the latest instance is started. This API uses an asynchronous callback to return the result. 2043e41f4b71Sopenharmony_ciYou can use this API to carry start options. 2044e41f4b71Sopenharmony_ci 2045e41f4b71Sopenharmony_ci> **NOTE** 2046e41f4b71Sopenharmony_ci> 2047e41f4b71Sopenharmony_ci> For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 2048e41f4b71Sopenharmony_ci 2049e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 2050e41f4b71Sopenharmony_ci 2051e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 2052e41f4b71Sopenharmony_ci 2053e41f4b71Sopenharmony_ci**Parameters** 2054e41f4b71Sopenharmony_ci 2055e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 2056e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2057e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 2058e41f4b71Sopenharmony_ci| options | [StartOptions](js-apis-app-ability-startOptions.md) | Yes| Parameters used for starting the ability.| 2059e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes| Callback used to return the result.| 2060e41f4b71Sopenharmony_ci 2061e41f4b71Sopenharmony_ci**Error codes** 2062e41f4b71Sopenharmony_ci 2063e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 2064e41f4b71Sopenharmony_ci 2065e41f4b71Sopenharmony_ci| ID| Error Message| 2066e41f4b71Sopenharmony_ci| ------- | -------- | 2067e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 2068e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2069e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 2070e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 2071e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 2072e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 2073e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 2074e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. | 2075e41f4b71Sopenharmony_ci| 16000009 | An ability cannot be started or stopped in Wukong mode. | 2076e41f4b71Sopenharmony_ci| 16000010 | The call with the continuation flag is forbidden. | 2077e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 2078e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 2079e41f4b71Sopenharmony_ci| 16000053 | The ability is not on the top of the UI. | 2080e41f4b71Sopenharmony_ci| 16000055 | Installation-free timed out. | 2081e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. | 2082e41f4b71Sopenharmony_ci 2083e41f4b71Sopenharmony_ci**Example** 2084e41f4b71Sopenharmony_ci 2085e41f4b71Sopenharmony_ci```ts 2086e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want, StartOptions } from '@kit.AbilityKit'; 2087e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2088e41f4b71Sopenharmony_ci 2089e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 2090e41f4b71Sopenharmony_ci onCreate() { 2091e41f4b71Sopenharmony_ci let want: Want = { 2092e41f4b71Sopenharmony_ci deviceId: '', 2093e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 2094e41f4b71Sopenharmony_ci abilityName: 'EntryAbility' 2095e41f4b71Sopenharmony_ci }; 2096e41f4b71Sopenharmony_ci let options: StartOptions = { 2097e41f4b71Sopenharmony_ci windowMode: 0 2098e41f4b71Sopenharmony_ci }; 2099e41f4b71Sopenharmony_ci 2100e41f4b71Sopenharmony_ci try { 2101e41f4b71Sopenharmony_ci this.context.startRecentAbility(want, options, (err: BusinessError) => { 2102e41f4b71Sopenharmony_ci if (err.code) { 2103e41f4b71Sopenharmony_ci // Process service logic errors. 2104e41f4b71Sopenharmony_ci console.error(`startRecentAbility failed, code is ${err.code}, message is ${err.message}`); 2105e41f4b71Sopenharmony_ci return; 2106e41f4b71Sopenharmony_ci } 2107e41f4b71Sopenharmony_ci // Carry out normal service processing. 2108e41f4b71Sopenharmony_ci console.info('startRecentAbility succeed'); 2109e41f4b71Sopenharmony_ci }); 2110e41f4b71Sopenharmony_ci } catch (err) { 2111e41f4b71Sopenharmony_ci // Process input parameter errors. 2112e41f4b71Sopenharmony_ci let code = (err as BusinessError).code; 2113e41f4b71Sopenharmony_ci let message = (err as BusinessError).message; 2114e41f4b71Sopenharmony_ci console.error(`startRecentAbility failed, code is ${code}, message is ${message}`); 2115e41f4b71Sopenharmony_ci } 2116e41f4b71Sopenharmony_ci } 2117e41f4b71Sopenharmony_ci} 2118e41f4b71Sopenharmony_ci``` 2119e41f4b71Sopenharmony_ci## ServiceExtensionContext.startRecentAbility 2120e41f4b71Sopenharmony_ci 2121e41f4b71Sopenharmony_cistartRecentAbility(want: Want, options?: StartOptions): Promise\<void>; 2122e41f4b71Sopenharmony_ci 2123e41f4b71Sopenharmony_ciStarts an ability. If the ability has multiple instances, the latest instance is started. 2124e41f4b71Sopenharmony_ciThis API uses a promise to return the result. 2125e41f4b71Sopenharmony_ci 2126e41f4b71Sopenharmony_ci> **NOTE** 2127e41f4b71Sopenharmony_ci> 2128e41f4b71Sopenharmony_ci> For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 2129e41f4b71Sopenharmony_ci 2130e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 2131e41f4b71Sopenharmony_ci 2132e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 2133e41f4b71Sopenharmony_ci 2134e41f4b71Sopenharmony_ci**Parameters** 2135e41f4b71Sopenharmony_ci 2136e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 2137e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2138e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Want information about the target ability.| 2139e41f4b71Sopenharmony_ci| options | [StartOptions](js-apis-app-ability-startOptions.md) | No| Parameters used for starting the ability.| 2140e41f4b71Sopenharmony_ci 2141e41f4b71Sopenharmony_ci**Error codes** 2142e41f4b71Sopenharmony_ci 2143e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 2144e41f4b71Sopenharmony_ci 2145e41f4b71Sopenharmony_ci| ID| Error Message| 2146e41f4b71Sopenharmony_ci| ------- | -------- | 2147e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 2148e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2149e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 2150e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 2151e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 2152e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 2153e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 2154e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. | 2155e41f4b71Sopenharmony_ci| 16000009 | An ability cannot be started or stopped in Wukong mode. | 2156e41f4b71Sopenharmony_ci| 16000010 | The call with the continuation flag is forbidden. | 2157e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 2158e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 2159e41f4b71Sopenharmony_ci| 16000053 | The ability is not on the top of the UI. | 2160e41f4b71Sopenharmony_ci| 16000055 | Installation-free timed out. | 2161e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. | 2162e41f4b71Sopenharmony_ci 2163e41f4b71Sopenharmony_ci**Example** 2164e41f4b71Sopenharmony_ci 2165e41f4b71Sopenharmony_ci```ts 2166e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want, StartOptions } from '@kit.AbilityKit'; 2167e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2168e41f4b71Sopenharmony_ci 2169e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 2170e41f4b71Sopenharmony_ci onCreate() { 2171e41f4b71Sopenharmony_ci let want: Want = { 2172e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 2173e41f4b71Sopenharmony_ci abilityName: 'EntryAbility' 2174e41f4b71Sopenharmony_ci }; 2175e41f4b71Sopenharmony_ci let options: StartOptions = { 2176e41f4b71Sopenharmony_ci windowMode: 0, 2177e41f4b71Sopenharmony_ci }; 2178e41f4b71Sopenharmony_ci 2179e41f4b71Sopenharmony_ci try { 2180e41f4b71Sopenharmony_ci this.context.startRecentAbility(want, options) 2181e41f4b71Sopenharmony_ci .then(() => { 2182e41f4b71Sopenharmony_ci // Carry out normal service processing. 2183e41f4b71Sopenharmony_ci console.info('startRecentAbility succeed'); 2184e41f4b71Sopenharmony_ci }) 2185e41f4b71Sopenharmony_ci .catch((err: BusinessError) => { 2186e41f4b71Sopenharmony_ci // Process service logic errors. 2187e41f4b71Sopenharmony_ci console.error(`startRecentAbility failed, code is ${err.code}, message is ${err.message}`); 2188e41f4b71Sopenharmony_ci }); 2189e41f4b71Sopenharmony_ci } catch (err) { 2190e41f4b71Sopenharmony_ci // Process input parameter errors. 2191e41f4b71Sopenharmony_ci let code = (err as BusinessError).code; 2192e41f4b71Sopenharmony_ci let message = (err as BusinessError).message; 2193e41f4b71Sopenharmony_ci console.error(`startRecentAbility failed, code is ${code}, message is ${message}`); 2194e41f4b71Sopenharmony_ci } 2195e41f4b71Sopenharmony_ci } 2196e41f4b71Sopenharmony_ci} 2197e41f4b71Sopenharmony_ci``` 2198e41f4b71Sopenharmony_ci 2199e41f4b71Sopenharmony_ci## ServiceExtensionContext.startAbilityByCallWithAccount<sup>10+</sup> 2200e41f4b71Sopenharmony_ci 2201e41f4b71Sopenharmony_cistartAbilityByCallWithAccount(want: Want, accountId: number): Promise<Caller>; 2202e41f4b71Sopenharmony_ci 2203e41f4b71Sopenharmony_ciStarts an ability with the account ID specified and obtains the caller object for communicating with the ability. 2204e41f4b71Sopenharmony_ci 2205e41f4b71Sopenharmony_ciObserve the following when using this API: 2206e41f4b71Sopenharmony_ci - If an application needs to call this API to start an ability that belongs to another user, it must have the **ohos.permission.ABILITY_BACKGROUND_COMMUNICATION** and **ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS** permissions. 2207e41f4b71Sopenharmony_ci - If an application running in the background needs to call this API to start an ability, it must have the **ohos.permission.START_ABILITIES_FROM_BACKGROUND** permission. 2208e41f4b71Sopenharmony_ci - If **exported** of the target ability is **false** in cross-application scenarios, the caller must have the **ohos.permission.START_INVISIBLE_ABILITY** permission. 2209e41f4b71Sopenharmony_ci - The rules for using this API in the same-device and cross-device scenarios are different. For details, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 2210e41f4b71Sopenharmony_ci 2211e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ABILITY_BACKGROUND_COMMUNICATION and ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS 2212e41f4b71Sopenharmony_ci 2213e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 2214e41f4b71Sopenharmony_ci 2215e41f4b71Sopenharmony_ci**System API**: This is a system API and cannot be called by third-party applications. 2216e41f4b71Sopenharmony_ci 2217e41f4b71Sopenharmony_ci**Parameters** 2218e41f4b71Sopenharmony_ci 2219e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 2220e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2221e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes| Information about the ability to start, including **abilityName**, **moduleName**, **bundleName**, **deviceId** (optional), and **parameters** (optional). If **deviceId** is left blank or null, the local ability is started. If **parameters** is left blank or null, the ability is started in the background.| 2222e41f4b71Sopenharmony_ci| accountId | number | Yes| ID of a system account. The value **-1** indicates the current user. For details, see [getCreatedOsAccountsCount](../apis-basic-services-kit/js-apis-osAccount.md#getcreatedosaccountscountdeprecated-1).| 2223e41f4b71Sopenharmony_ci 2224e41f4b71Sopenharmony_ci**Return value** 2225e41f4b71Sopenharmony_ci 2226e41f4b71Sopenharmony_ci| Type| Description| 2227e41f4b71Sopenharmony_ci| -------- | -------- | 2228e41f4b71Sopenharmony_ci| Promise<Caller> | Promise used to return the caller object to communicate with.| 2229e41f4b71Sopenharmony_ci 2230e41f4b71Sopenharmony_ci**Error codes** 2231e41f4b71Sopenharmony_ci 2232e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 2233e41f4b71Sopenharmony_ci 2234e41f4b71Sopenharmony_ci| ID| Error Message| 2235e41f4b71Sopenharmony_ci| ------- | -------- | 2236e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 2237e41f4b71Sopenharmony_ci| 202 | The application is not system-app, can not use system-api. | 2238e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2239e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 2240e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 2241e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 2242e41f4b71Sopenharmony_ci| 16000005 | Static permission denied. The specified process does not have the permission. | 2243e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 2244e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. | 2245e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 2246e41f4b71Sopenharmony_ci| 16000012 | The application is controlled. | 2247e41f4b71Sopenharmony_ci| 16000013 | The application is controlled by EDM. | 2248e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 2249e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. | 2250e41f4b71Sopenharmony_ci 2251e41f4b71Sopenharmony_ci**Example** 2252e41f4b71Sopenharmony_ci 2253e41f4b71Sopenharmony_ci```ts 2254e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want, Caller } from '@kit.AbilityKit'; 2255e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2256e41f4b71Sopenharmony_ci 2257e41f4b71Sopenharmony_ciclass EntryAbility extends ServiceExtensionAbility { 2258e41f4b71Sopenharmony_ci onCreate() { 2259e41f4b71Sopenharmony_ci let caller: Caller; 2260e41f4b71Sopenharmony_ci // ID of a system account. The value -1 indicates the current user. 2261e41f4b71Sopenharmony_ci let accountId = -1; 2262e41f4b71Sopenharmony_ci // Specify the ability to start. 2263e41f4b71Sopenharmony_ci let want: Want = { 2264e41f4b71Sopenharmony_ci bundleName: 'com.acts.actscalleeabilityrely', 2265e41f4b71Sopenharmony_ci moduleName: 'entry', 2266e41f4b71Sopenharmony_ci abilityName: 'EntryAbility', 2267e41f4b71Sopenharmony_ci deviceId: '', 2268e41f4b71Sopenharmony_ci parameters: { 2269e41f4b71Sopenharmony_ci // If the value of 'ohos.aafwk.param.callAbilityToForeground' is true, the ability is started in the foreground. If the value is false or not set, the ability is started in the background. 2270e41f4b71Sopenharmony_ci 'ohos.aafwk.param.callAbilityToForeground': true 2271e41f4b71Sopenharmony_ci } 2272e41f4b71Sopenharmony_ci }; 2273e41f4b71Sopenharmony_ci 2274e41f4b71Sopenharmony_ci try { 2275e41f4b71Sopenharmony_ci this.context.startAbilityByCallWithAccount(want, accountId) 2276e41f4b71Sopenharmony_ci .then((obj: Caller) => { 2277e41f4b71Sopenharmony_ci // Carry out normal service processing. 2278e41f4b71Sopenharmony_ci caller = obj; 2279e41f4b71Sopenharmony_ci console.log('startAbilityByCallWithAccount succeed'); 2280e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 2281e41f4b71Sopenharmony_ci // Process service logic errors. 2282e41f4b71Sopenharmony_ci console.error(`startAbilityByCallWithAccount failed, error.code: ${error.code}, error.message: ${error.message}`); 2283e41f4b71Sopenharmony_ci }); 2284e41f4b71Sopenharmony_ci } catch (paramError) { 2285e41f4b71Sopenharmony_ci // Process input parameter errors. 2286e41f4b71Sopenharmony_ci console.error(`error.code: ${(paramError as BusinessError).code}, error.message: ${(paramError as BusinessError).message}`); 2287e41f4b71Sopenharmony_ci } 2288e41f4b71Sopenharmony_ci } 2289e41f4b71Sopenharmony_ci} 2290e41f4b71Sopenharmony_ci``` 2291e41f4b71Sopenharmony_ci 2292e41f4b71Sopenharmony_ci## ServiceExtensionContext.requestModalUIExtension<sup>11+<sup> 2293e41f4b71Sopenharmony_ci 2294e41f4b71Sopenharmony_cirequestModalUIExtension(pickerWant: Want): Promise\<void> 2295e41f4b71Sopenharmony_ci 2296e41f4b71Sopenharmony_ciRequests the specified foreground application to start the UIExtensionAbility of the corresponding type. The foreground application is specified by **bundleName** in **want.parameters**. If **bundleName** is left unspecified, or if the application specified by **bundleName** is not running in the foreground or does not exist, the UIExtensionAbility is directly started on the system UI. The UIExtensionAbility to start is determined by the combination of the **bundleName**, **abilityName**, and **moduleName** fields in **want**, and its type is determined by the **ability.want.params.uiExtensionType** field in **want.parameters**. This API uses a promise to return the result. 2297e41f4b71Sopenharmony_ci 2298e41f4b71Sopenharmony_ciBefore starting the UIExtensionAbility, ensure that the foreground application has finished page initialization. Otherwise, the UIExtensionAbility fails to start and the error message "uiContent is nullptr" is displayed. The application can determine the time to start the UIExtensionAbility by listening for the page loading status. After the page initialization is successful, the key log information "UIContentImpl: focus again" is recorded. 2299e41f4b71Sopenharmony_ci 2300e41f4b71Sopenharmony_ci> **NOTE** 2301e41f4b71Sopenharmony_ci> 2302e41f4b71Sopenharmony_ci> For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 2303e41f4b71Sopenharmony_ci 2304e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 2305e41f4b71Sopenharmony_ci 2306e41f4b71Sopenharmony_ci**System API**: This is a system API. 2307e41f4b71Sopenharmony_ci 2308e41f4b71Sopenharmony_ci**Parameters** 2309e41f4b71Sopenharmony_ci 2310e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 2311e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2312e41f4b71Sopenharmony_ci| pickerWant | [Want](js-apis-app-ability-want.md) | Yes| Want information used to start the UIExtensionAbility.| 2313e41f4b71Sopenharmony_ci 2314e41f4b71Sopenharmony_ci**Return value** 2315e41f4b71Sopenharmony_ci 2316e41f4b71Sopenharmony_ci| Type| Description| 2317e41f4b71Sopenharmony_ci| -------- | -------- | 2318e41f4b71Sopenharmony_ci| Promise<void> | Promise that returns no value.| 2319e41f4b71Sopenharmony_ci 2320e41f4b71Sopenharmony_ci**Error codes** 2321e41f4b71Sopenharmony_ci 2322e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 2323e41f4b71Sopenharmony_ci 2324e41f4b71Sopenharmony_ci| ID| Error Message| 2325e41f4b71Sopenharmony_ci| ------- | -------- | 2326e41f4b71Sopenharmony_ci| 202 | The application is not system-app, can not use system-api. | 2327e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2328e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 2329e41f4b71Sopenharmony_ci 2330e41f4b71Sopenharmony_ci**Example** 2331e41f4b71Sopenharmony_ci 2332e41f4b71Sopenharmony_ci```ts 2333e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want } from '@kit.AbilityKit'; 2334e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2335e41f4b71Sopenharmony_ci 2336e41f4b71Sopenharmony_ciclass ServiceExtension extends ServiceExtensionAbility { 2337e41f4b71Sopenharmony_ci onCreate() { 2338e41f4b71Sopenharmony_ci let pickerWant: Want = { 2339e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 2340e41f4b71Sopenharmony_ci abilityName: 'UIExtAbility', 2341e41f4b71Sopenharmony_ci moduleName: 'entry_test', 2342e41f4b71Sopenharmony_ci parameters: { 2343e41f4b71Sopenharmony_ci 'bundleName': 'com.example.myapplication', 2344e41f4b71Sopenharmony_ci // The value is the same as the value of type configured for com.example.myapplication.UIExtAbility. 2345e41f4b71Sopenharmony_ci 'ability.want.params.uiExtensionType': 'sys/commonUI' 2346e41f4b71Sopenharmony_ci } 2347e41f4b71Sopenharmony_ci }; 2348e41f4b71Sopenharmony_ci 2349e41f4b71Sopenharmony_ci try { 2350e41f4b71Sopenharmony_ci this.context.requestModalUIExtension(pickerWant) 2351e41f4b71Sopenharmony_ci .then(() => { 2352e41f4b71Sopenharmony_ci // Carry out normal service processing. 2353e41f4b71Sopenharmony_ci console.info('requestModalUIExtension succeed'); 2354e41f4b71Sopenharmony_ci }) 2355e41f4b71Sopenharmony_ci .catch((err: BusinessError) => { 2356e41f4b71Sopenharmony_ci // Process service logic errors. 2357e41f4b71Sopenharmony_ci console.error(`requestModalUIExtension failed, code is ${err.code}, message is ${err.message}`); 2358e41f4b71Sopenharmony_ci }); 2359e41f4b71Sopenharmony_ci } catch (err) { 2360e41f4b71Sopenharmony_ci // Process input parameter errors. 2361e41f4b71Sopenharmony_ci let code = (err as BusinessError).code; 2362e41f4b71Sopenharmony_ci let message = (err as BusinessError).message; 2363e41f4b71Sopenharmony_ci console.error(`requestModalUIExtension failed, code is ${code}, message is ${message}`); 2364e41f4b71Sopenharmony_ci } 2365e41f4b71Sopenharmony_ci } 2366e41f4b71Sopenharmony_ci} 2367e41f4b71Sopenharmony_ci``` 2368e41f4b71Sopenharmony_ci 2369e41f4b71Sopenharmony_ci## ServiceExtensionContext.requestModalUIExtension<sup>11+<sup> 2370e41f4b71Sopenharmony_ci 2371e41f4b71Sopenharmony_cirequestModalUIExtension(pickerWant: Want, callback: AsyncCallback\<void>): void 2372e41f4b71Sopenharmony_ci 2373e41f4b71Sopenharmony_ciRequests the specified foreground application to start the UIExtensionAbility of the corresponding type. The foreground application is specified by **bundleName** in **want.parameters**. If **bundleName** is left unspecified, or if the application specified by **bundleName** is not running in the foreground or does not exist, the UIExtensionAbility is directly started on the system UI. The UIExtensionAbility to start is determined by the combination of the **bundleName**, **abilityName**, and **moduleName** fields in **want**, and its type is determined by the **ability.want.params.uiExtensionType** field in **want.parameters**. This API uses an asynchronous callback to return the result. 2374e41f4b71Sopenharmony_ci 2375e41f4b71Sopenharmony_ciBefore starting the UIExtensionAbility, ensure that the foreground application has finished page initialization. Otherwise, the UIExtensionAbility fails to start and the error message "uiContent is nullptr" is displayed. The application can determine the time to start the UIExtensionAbility by listening for the page loading status. After the page initialization is successful, the key log information "UIContentImpl: focus again" is recorded. 2376e41f4b71Sopenharmony_ci 2377e41f4b71Sopenharmony_ci> **NOTE** 2378e41f4b71Sopenharmony_ci> 2379e41f4b71Sopenharmony_ci> For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 2380e41f4b71Sopenharmony_ci 2381e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 2382e41f4b71Sopenharmony_ci 2383e41f4b71Sopenharmony_ci**System API**: This is a system API. 2384e41f4b71Sopenharmony_ci 2385e41f4b71Sopenharmony_ci**Parameters** 2386e41f4b71Sopenharmony_ci 2387e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 2388e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2389e41f4b71Sopenharmony_ci| pickerWant | [Want](js-apis-app-ability-want.md) | Yes| Want information used to start the UIExtensionAbility.| 2390e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the UIExtensionAbility is started, **err** is **undefined**; otherwise, **err** is an error object.| 2391e41f4b71Sopenharmony_ci 2392e41f4b71Sopenharmony_ci**Error codes** 2393e41f4b71Sopenharmony_ci 2394e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 2395e41f4b71Sopenharmony_ci 2396e41f4b71Sopenharmony_ci| ID| Error Message| 2397e41f4b71Sopenharmony_ci| ------- | -------- | 2398e41f4b71Sopenharmony_ci| 202 | The application is not system-app, can not use system-api. | 2399e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2400e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 2401e41f4b71Sopenharmony_ci 2402e41f4b71Sopenharmony_ci**Example** 2403e41f4b71Sopenharmony_ci 2404e41f4b71Sopenharmony_ci```ts 2405e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want } from '@kit.AbilityKit'; 2406e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2407e41f4b71Sopenharmony_ci 2408e41f4b71Sopenharmony_ciclass ServiceExtension extends ServiceExtensionAbility { 2409e41f4b71Sopenharmony_ci onCreate() { 2410e41f4b71Sopenharmony_ci let pickerWant: Want = { 2411e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 2412e41f4b71Sopenharmony_ci abilityName: 'com.example.myapplication.UIExtAbility', 2413e41f4b71Sopenharmony_ci moduleName: 'entry_test', 2414e41f4b71Sopenharmony_ci parameters: { 2415e41f4b71Sopenharmony_ci 'bundleName': 'com.example.myapplication', 2416e41f4b71Sopenharmony_ci // The value is the same as the value of type configured for com.example.myapplication.UIExtAbility. 2417e41f4b71Sopenharmony_ci 'ability.want.params.uiExtensionType': 'sys/commonUI' 2418e41f4b71Sopenharmony_ci } 2419e41f4b71Sopenharmony_ci }; 2420e41f4b71Sopenharmony_ci 2421e41f4b71Sopenharmony_ci try { 2422e41f4b71Sopenharmony_ci this.context.requestModalUIExtension(pickerWant, (err: BusinessError) => { 2423e41f4b71Sopenharmony_ci if (err.code) { 2424e41f4b71Sopenharmony_ci // Process service logic errors. 2425e41f4b71Sopenharmony_ci console.error(`requestModalUIExtension failed, code is ${err.code}, message is ${err.message}`); 2426e41f4b71Sopenharmony_ci return; 2427e41f4b71Sopenharmony_ci } 2428e41f4b71Sopenharmony_ci // Carry out normal service processing. 2429e41f4b71Sopenharmony_ci console.info('requestModalUIExtension succeed'); 2430e41f4b71Sopenharmony_ci }); 2431e41f4b71Sopenharmony_ci } catch (err) { 2432e41f4b71Sopenharmony_ci // Process input parameter errors. 2433e41f4b71Sopenharmony_ci let code = (err as BusinessError).code; 2434e41f4b71Sopenharmony_ci let message = (err as BusinessError).message; 2435e41f4b71Sopenharmony_ci console.error(`requestModalUIExtension failed, code is ${code}, message is ${message}`); 2436e41f4b71Sopenharmony_ci } 2437e41f4b71Sopenharmony_ci } 2438e41f4b71Sopenharmony_ci} 2439e41f4b71Sopenharmony_ci``` 2440e41f4b71Sopenharmony_ci 2441e41f4b71Sopenharmony_ci## ServiceExtensionContext.openLink<sup>12+<sup> 2442e41f4b71Sopenharmony_ciopenLink(link:string, options?: OpenLinkOptions): Promise<void> 2443e41f4b71Sopenharmony_ci 2444e41f4b71Sopenharmony_ciStarts a UIAbility through App Linking. This API uses a promise to return the result. 2445e41f4b71Sopenharmony_ci 2446e41f4b71Sopenharmony_ciA URL in the standard format is passed in to the **link** field to start the target UIAbility based on the implicit Want matching rules. The target UIAbility must have the following filter characteristics to process links of App Linking: 2447e41f4b71Sopenharmony_ci- The **actions** field contains **ohos.want.action.viewData**. 2448e41f4b71Sopenharmony_ci- The **entities** field contains **entity.system.browsable**. 2449e41f4b71Sopenharmony_ci- The **uris** field contains elements whose **scheme** is **https** and **domainVerify** is **true**. 2450e41f4b71Sopenharmony_ci 2451e41f4b71Sopenharmony_ciIf an input parameter is invalid, for example, a mandatory parameter is not set or the URL set in **link** is not in the standard format, an exception is thrown. If the parameter verification is successful but an error occurs when starting the target UIAbility, the error information is returned through promise. 2452e41f4b71Sopenharmony_ci 2453e41f4b71Sopenharmony_ci> **NOTE** 2454e41f4b71Sopenharmony_ci> 2455e41f4b71Sopenharmony_ci> For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 2456e41f4b71Sopenharmony_ci 2457e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 2458e41f4b71Sopenharmony_ci 2459e41f4b71Sopenharmony_ci**System API**: This is a system API. 2460e41f4b71Sopenharmony_ci 2461e41f4b71Sopenharmony_ci**Parameters** 2462e41f4b71Sopenharmony_ci 2463e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 2464e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2465e41f4b71Sopenharmony_ci| link | string | Yes| URL to open, which must be in the standard format.| 2466e41f4b71Sopenharmony_ci| options | [OpenLinkOptions](js-apis-app-ability-openLinkOptions.md) | No| Options of the URL.| 2467e41f4b71Sopenharmony_ci 2468e41f4b71Sopenharmony_ci**Return value** 2469e41f4b71Sopenharmony_ci 2470e41f4b71Sopenharmony_ci| Type| Description| 2471e41f4b71Sopenharmony_ci| -------- | -------- | 2472e41f4b71Sopenharmony_ci| Promise<void> | Promise that returns no value.| 2473e41f4b71Sopenharmony_ci 2474e41f4b71Sopenharmony_ci**Error codes** 2475e41f4b71Sopenharmony_ci 2476e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 2477e41f4b71Sopenharmony_ci 2478e41f4b71Sopenharmony_ci| ID| Error Message| 2479e41f4b71Sopenharmony_ci| ------- | -------- | 2480e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 2481e41f4b71Sopenharmony_ci| 202 | The application is not system-app, can not use system-api. | 2482e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2483e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 2484e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 2485e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 2486e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 2487e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 2488e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. | 2489e41f4b71Sopenharmony_ci| 16000009 | An ability cannot be started or stopped in Wukong mode. | 2490e41f4b71Sopenharmony_ci| 16000010 | The call with the continuation flag is forbidden. | 2491e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 2492e41f4b71Sopenharmony_ci| 16000012 | The application is controlled. | 2493e41f4b71Sopenharmony_ci| 16000013 | The application is controlled by EDM. | 2494e41f4b71Sopenharmony_ci| 16000019 | No matching ability is found. | 2495e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. | 2496e41f4b71Sopenharmony_ci 2497e41f4b71Sopenharmony_ci**Example** 2498e41f4b71Sopenharmony_ci 2499e41f4b71Sopenharmony_ci```ts 2500e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want, OpenLinkOptions } from '@kit.AbilityKit'; 2501e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2502e41f4b71Sopenharmony_ci 2503e41f4b71Sopenharmony_cifunction log(info: string) { 2504e41f4b71Sopenharmony_ci console.error(`[ServiceExtApp]:: ${JSON.stringify(info)}`); 2505e41f4b71Sopenharmony_ci} 2506e41f4b71Sopenharmony_ci 2507e41f4b71Sopenharmony_ciexport default class ServiceExtAbility extends ServiceExtensionAbility { 2508e41f4b71Sopenharmony_ci onCreate(want: Want) { 2509e41f4b71Sopenharmony_ci log(`ServiceExtAbility OnCreate`); 2510e41f4b71Sopenharmony_ci } 2511e41f4b71Sopenharmony_ci 2512e41f4b71Sopenharmony_ci onRequest(want: Want, startId: number) { 2513e41f4b71Sopenharmony_ci log(`ServiceExtAbility onRequest`); 2514e41f4b71Sopenharmony_ci let link: string = 'https://www.example.com'; 2515e41f4b71Sopenharmony_ci let openLinkOptions: OpenLinkOptions = { 2516e41f4b71Sopenharmony_ci appLinkingOnly: false 2517e41f4b71Sopenharmony_ci }; 2518e41f4b71Sopenharmony_ci try { 2519e41f4b71Sopenharmony_ci this.context.openLink( 2520e41f4b71Sopenharmony_ci link, 2521e41f4b71Sopenharmony_ci openLinkOptions 2522e41f4b71Sopenharmony_ci ).then(() => { 2523e41f4b71Sopenharmony_ci log(`open link success.`); 2524e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 2525e41f4b71Sopenharmony_ci log(`open link failed, errCode ${JSON.stringify(err.code)}`); 2526e41f4b71Sopenharmony_ci }); 2527e41f4b71Sopenharmony_ci } 2528e41f4b71Sopenharmony_ci catch (e) { 2529e41f4b71Sopenharmony_ci log(`exception occured, errCode ${JSON.stringify(e.code)}`); 2530e41f4b71Sopenharmony_ci } 2531e41f4b71Sopenharmony_ci } 2532e41f4b71Sopenharmony_ci 2533e41f4b71Sopenharmony_ci onDestroy() { 2534e41f4b71Sopenharmony_ci log(`ServiceExtAbility onDestroy`); 2535e41f4b71Sopenharmony_ci } 2536e41f4b71Sopenharmony_ci} 2537e41f4b71Sopenharmony_ci``` 2538e41f4b71Sopenharmony_ci 2539e41f4b71Sopenharmony_ci## ServiceExtensionContext.preStartMission<sup>12+<sup> 2540e41f4b71Sopenharmony_cipreStartMission(bundleName:string, moduleName: string, abilitName: string, startTime: string): Promise<void> 2541e41f4b71Sopenharmony_ci 2542e41f4b71Sopenharmony_ciStarts an atomic service and pre-opens the window, with the loading box skipped. This API uses a promise to return the result. 2543e41f4b71Sopenharmony_ci 2544e41f4b71Sopenharmony_ciIf parameter verification is successful but the atomic service fails to start, you need to implement an exception mechanism to capture the error. 2545e41f4b71Sopenharmony_ci 2546e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PRE_START_ATOMIC_SERVICE 2547e41f4b71Sopenharmony_ci 2548e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 2549e41f4b71Sopenharmony_ci 2550e41f4b71Sopenharmony_ci**System API**: This is a system API. 2551e41f4b71Sopenharmony_ci 2552e41f4b71Sopenharmony_ci**Parameters** 2553e41f4b71Sopenharmony_ci 2554e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 2555e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2556e41f4b71Sopenharmony_ci| bundleName | string | Yes| Bundle name of the atomic service.| 2557e41f4b71Sopenharmony_ci| moduleName | string | Yes| Module name of the atomic service.| 2558e41f4b71Sopenharmony_ci| abilityName | string | Yes| Ability name of the atomic service.| 2559e41f4b71Sopenharmony_ci| startTime | string | Yes| Start time to open the atomic service, in milliseconds.| 2560e41f4b71Sopenharmony_ci 2561e41f4b71Sopenharmony_ci 2562e41f4b71Sopenharmony_ci**Return value** 2563e41f4b71Sopenharmony_ci 2564e41f4b71Sopenharmony_ci| Type| Description| 2565e41f4b71Sopenharmony_ci| -------- | -------- | 2566e41f4b71Sopenharmony_ci| Promise<void> | Promise that returns no value.| 2567e41f4b71Sopenharmony_ci 2568e41f4b71Sopenharmony_ci**Error codes** 2569e41f4b71Sopenharmony_ci 2570e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 2571e41f4b71Sopenharmony_ci 2572e41f4b71Sopenharmony_ci| ID| Error Message| 2573e41f4b71Sopenharmony_ci| ------- | -------- | 2574e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 2575e41f4b71Sopenharmony_ci| 202 | The application is not system-app, can not use system-api. | 2576e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2577e41f4b71Sopenharmony_ci| 16300007 | The target free install task does not exist. | 2578e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 2579e41f4b71Sopenharmony_ci 2580e41f4b71Sopenharmony_ci**Example** 2581e41f4b71Sopenharmony_ci 2582e41f4b71Sopenharmony_ci```ts 2583e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want } from '@kit.AbilityKit'; 2584e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2585e41f4b71Sopenharmony_ci 2586e41f4b71Sopenharmony_cifunction log(info: string) { 2587e41f4b71Sopenharmony_ci console.error(`[ServiceExtApp]:: ${JSON.stringify(info)}`); 2588e41f4b71Sopenharmony_ci} 2589e41f4b71Sopenharmony_ci 2590e41f4b71Sopenharmony_ciexport default class ServiceExtAbility extends ServiceExtensionAbility { 2591e41f4b71Sopenharmony_ci onCreate(want: Want) { 2592e41f4b71Sopenharmony_ci log(`ServiceExtAbility OnCreate`); 2593e41f4b71Sopenharmony_ci } 2594e41f4b71Sopenharmony_ci 2595e41f4b71Sopenharmony_ci onRequest(want: Want, startId: number) { 2596e41f4b71Sopenharmony_ci log(`ServiceExtAbility onRequest`); 2597e41f4b71Sopenharmony_ci try { 2598e41f4b71Sopenharmony_ci this.context.preStartMission( 2599e41f4b71Sopenharmony_ci want.bundleName, 2600e41f4b71Sopenharmony_ci want.moduleName, 2601e41f4b71Sopenharmony_ci want.abilityName, 2602e41f4b71Sopenharmony_ci want.parameters["ohos.aafwk.param.startTime"] 2603e41f4b71Sopenharmony_ci ).then(() => { 2604e41f4b71Sopenharmony_ci log(`pre-start mission success.`); 2605e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 2606e41f4b71Sopenharmony_ci log(`pre-start mission failed, errCode ${JSON.stringify(err.code)}`); 2607e41f4b71Sopenharmony_ci }); 2608e41f4b71Sopenharmony_ci } 2609e41f4b71Sopenharmony_ci catch (e) { 2610e41f4b71Sopenharmony_ci log(`exception occured, errCode ${JSON.stringify(e.code)}`); 2611e41f4b71Sopenharmony_ci } 2612e41f4b71Sopenharmony_ci } 2613e41f4b71Sopenharmony_ci 2614e41f4b71Sopenharmony_ci onDestroy() { 2615e41f4b71Sopenharmony_ci log(`ServiceExtAbility onDestroy`); 2616e41f4b71Sopenharmony_ci } 2617e41f4b71Sopenharmony_ci} 2618e41f4b71Sopenharmony_ci``` 2619e41f4b71Sopenharmony_ci 2620e41f4b71Sopenharmony_ci## ServiceExtensionContext.startUIServiceExtensionAbility<sup>13+<sup> 2621e41f4b71Sopenharmony_cistartUIServiceExtensionAbility(want: Want): Promise<void> 2622e41f4b71Sopenharmony_ci 2623e41f4b71Sopenharmony_ciStarts a new [UIServiceExtensionAbility](js-apis-app-ability-uiServiceExtensionAbility-sys.md). This API uses a promise to return the result. 2624e41f4b71Sopenharmony_ci 2625e41f4b71Sopenharmony_ci 2626e41f4b71Sopenharmony_ci> **NOTE** 2627e41f4b71Sopenharmony_ci> 2628e41f4b71Sopenharmony_ci> For details about the startup rules for the components in the stage model, see [Component Startup Rules (Stage Model)](../../application-models/component-startup-rules.md). 2629e41f4b71Sopenharmony_ci> 2630e41f4b71Sopenharmony_ci 2631e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 2632e41f4b71Sopenharmony_ci 2633e41f4b71Sopenharmony_ci**System API**: This is a system API. 2634e41f4b71Sopenharmony_ci 2635e41f4b71Sopenharmony_ci**Parameters** 2636e41f4b71Sopenharmony_ci| Name| Type| Read Only| Optional| Description | 2637e41f4b71Sopenharmony_ci| ------ | ---- | ---- | -------------------- | -------------------- | 2638e41f4b71Sopenharmony_ci| want | [Want](js-apis-app-ability-want.md) | Yes | No| [Want](js-apis-app-ability-want.md) used to pass the information about the ability to start, such as the ability name and bundle name.| 2639e41f4b71Sopenharmony_ci 2640e41f4b71Sopenharmony_ci**Return value** 2641e41f4b71Sopenharmony_ci 2642e41f4b71Sopenharmony_ci| Type | Description | 2643e41f4b71Sopenharmony_ci| ------------------- | -------------------------------------- | 2644e41f4b71Sopenharmony_ci| Promise<void> | Promise that returns no value.| 2645e41f4b71Sopenharmony_ci 2646e41f4b71Sopenharmony_ci**Error codes** 2647e41f4b71Sopenharmony_ci 2648e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 2649e41f4b71Sopenharmony_ci| ID| Error Message | 2650e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------------------------------| 2651e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 2652e41f4b71Sopenharmony_ci| 202 | The application is not system-app, can not use system-api. | 2653e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2654e41f4b71Sopenharmony_ci| 801 | The Ability is not supported. | 2655e41f4b71Sopenharmony_ci| 16000001 | The specified ability does not exist. | 2656e41f4b71Sopenharmony_ci| 16000002 | Incorrect ability type. | 2657e41f4b71Sopenharmony_ci| 16000004 | Failed to start the invisible ability. | 2658e41f4b71Sopenharmony_ci| 16000005 | The specified process does not have the permission. | 2659e41f4b71Sopenharmony_ci| 16000006 | Cross-user operations are not allowed. | 2660e41f4b71Sopenharmony_ci| 16000008 | The crowdtesting application expires. | 2661e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 2662e41f4b71Sopenharmony_ci| 16000012 | The application is controlled. | 2663e41f4b71Sopenharmony_ci| 16000013 | The application is controlled by EDM. | 2664e41f4b71Sopenharmony_ci| 16000019 | No matching ability is found. | 2665e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 2666e41f4b71Sopenharmony_ci| 16200001 | The caller has been released. | 2667e41f4b71Sopenharmony_ci 2668e41f4b71Sopenharmony_ci**Example** 2669e41f4b71Sopenharmony_ci 2670e41f4b71Sopenharmony_ci```ts 2671e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 2672e41f4b71Sopenharmony_ciimport { ServiceExtensionAbility, Want } from '@kit.AbilityKit'; 2673e41f4b71Sopenharmony_ci 2674e41f4b71Sopenharmony_ciexport default class MyServiceExtensionAbility extends ServiceExtensionAbility { 2675e41f4b71Sopenharmony_ci onRequest(want: Want, startId: number) { 2676e41f4b71Sopenharmony_ci const startWant: Want = { 2677e41f4b71Sopenharmony_ci bundleName: 'com.example.myapplication', 2678e41f4b71Sopenharmony_ci abilityName: 'UIServiceExtensionAbility' 2679e41f4b71Sopenharmony_ci } 2680e41f4b71Sopenharmony_ci // Start a UIServiceExtensionAbility. 2681e41f4b71Sopenharmony_ci this.context.startUIServiceExtensionAbility(startWant).then(() => { 2682e41f4b71Sopenharmony_ci console.info('succeeded'); 2683e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 2684e41f4b71Sopenharmony_ci console.error(`error code: ${error.code}, error essage : ${error.message}`); 2685e41f4b71Sopenharmony_ci }) 2686e41f4b71Sopenharmony_ci } 2687e41f4b71Sopenharmony_ci} 2688e41f4b71Sopenharmony_ci``` 2689