• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# UIExtensionContext
2
3UIExtensionContext是[UIExtensionAbility](js-apis-app-ability-uiExtensionAbility.md)的上下文环境,继承自[ExtensionContext](js-apis-inner-application-extensionContext.md),提供UIExtensionAbility的相关配置信息以及操作UIAbility的方法,如启动UIAbility等。
4
5> **说明:**
6>
7>  - 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8>  - 本模块接口仅可在Stage模型下使用。
9>  - 本模块接口需要在主线程中使用,不要在Worker、TaskPool等子线程中使用。
10
11## 导入模块
12
13```ts
14import { common } from '@kit.AbilityKit';
15```
16
17## UIExtensionContext.startAbility
18
19startAbility(want: Want, callback: AsyncCallback<void>): void
20
21启动Ability。使用callback异步回调。
22
23> **说明:**
24>
25> 组件启动规则详见:[组件启动规则(Stage模型)](../../application-models/component-startup-rules.md)。
26
27**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
28
29**参数:**
30
31| 参数名 | 类型 | 必填 | 说明 |
32| -------- | -------- | -------- | -------- |
33| want | [Want](js-apis-app-ability-want.md) | 是 | 启动Ability的want信息。 |
34| callback | AsyncCallback<void> | 是 | 回调函数。当启动Ability成功,err为undefined,否则为错误对象。 |
35
36**错误码:**
37
38以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
39
40| 错误码ID | 错误信息 |
41| ------- | -------------------------------- |
42| 201 | The application does not have permission to call the interface. |
43| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
44| 16000001 | The specified ability does not exist. |
45| 16000002 | Incorrect ability type. |
46| 16000004 | Can not start invisible component. |
47| 16000005 | The specified process does not have the permission. |
48| 16000006 | Cross-user operations are not allowed. |
49| 16000008 | The crowdtesting application expires. |
50| 16000009 | An ability cannot be started or stopped in Wukong mode. |
51| 16000010 | The call with the continuation flag is forbidden.        |
52| 16000011 | The context does not exist.        |
53| 16000012 | The application is controlled.        |
54| 16000013 | The application is controlled by EDM.       |
55| 16000018 | The application is not allow jumping to other applications. |
56| 16000019 | Can not match any component. |
57| 16000050 | Internal error. |
58| 16000053 | The ability is not on the top of the UI. |
59| 16000055 | Installation-free timed out. |
60| 16000069 | The extension cannot start the third party application. |
61| 16000070 | The extension cannot start the service. |
62| 16200001 | The caller has been released. |
63| 16000073 | The app clone index is invalid. |
64
65**示例:**
66
67```ts
68import { UIExtensionAbility, Want } from '@kit.AbilityKit';
69import { BusinessError } from '@kit.BasicServicesKit';
70
71export default class EntryAbility extends UIExtensionAbility {
72
73  onForeground() {
74    let want: Want = {
75      bundleName: 'com.example.myapplication',
76      abilityName: 'EntryAbility'
77    };
78
79    try {
80      this.context.startAbility(want, (err: BusinessError) => {
81        if (err.code) {
82          // 处理业务逻辑错误
83          console.error(`startAbility failed, code is ${err.code}, message is ${err.message}`);
84          return;
85        }
86        // 执行正常业务
87        console.info('startAbility succeed');
88      });
89    } catch (err) {
90      // 处理入参错误异常
91      let code = (err as BusinessError).code;
92      let message = (err as BusinessError).message;
93      console.error(`startAbility failed, code is ${code}, message is ${message}`);
94    }
95  }
96}
97```
98
99## UIExtensionContext.startAbility
100
101startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void>): void
102
103启动Ability。使用callback异步回调。
104
105> **说明:**
106>
107> 组件启动规则详见:[组件启动规则(Stage模型)](../../application-models/component-startup-rules.md)。
108
109**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
110
111**参数:**
112
113| 参数名 | 类型 | 必填 | 说明 |
114| -------- | -------- | -------- | -------- |
115| want | [Want](js-apis-app-ability-want.md)  | 是 | 启动Ability的want信息。 |
116| options | [StartOptions](js-apis-app-ability-startOptions.md) | 是 | 启动Ability所携带的参数。 |
117| callback | AsyncCallback<void> | 是 | 回调函数。当启动Ability成功,err为undefined,否则为错误对象。 |
118
119**错误码:**
120
121以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
122
123| 错误码ID | 错误信息 |
124| ------- | -------------------------------- |
125| 201 | The application does not have permission to call the interface. |
126| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
127| 16000001 | The specified ability does not exist. |
128| 16000004 | Can not start invisible component. |
129| 16000005 | The specified process does not have the permission. |
130| 16000006 | Cross-user operations are not allowed. |
131| 16000008 | The crowdtesting application expires. |
132| 16000009 | An ability cannot be started or stopped in Wukong mode. |
133| 16000011 | The context does not exist.        |
134| 16000012 | The application is controlled.        |
135| 16000013 | The application is controlled by EDM.       |
136| 16000018 | The application is not allow jumping to other applications. |
137| 16000019 | Can not match any component. |
138| 16000050 | Internal error. |
139| 16000053 | The ability is not on the top of the UI. |
140| 16000055 | Installation-free timed out. |
141| 16000069 | The extension cannot start the third party application. |
142| 16000070 | The extension cannot start the service. |
143| 16200001 | The caller has been released. |
144| 16000073 | The app clone index is invalid. |
145
146**示例:**
147
148```ts
149import { UIExtensionAbility, Want, StartOptions } from '@kit.AbilityKit';
150import { BusinessError } from '@kit.BasicServicesKit';
151
152export default class EntryAbility extends UIExtensionAbility {
153  onForeground() {
154    let want: Want = {
155      deviceId: '',
156      bundleName: 'com.example.myapplication',
157      abilityName: 'EntryAbility'
158    };
159    let options: StartOptions = {
160      displayId: 0
161    };
162
163    try {
164      this.context.startAbility(want, options, (err: BusinessError) => {
165        if (err.code) {
166          // 处理业务逻辑错误
167          console.error(`startAbility failed, code is ${err.code}, message is ${err.message}`);
168          return;
169        }
170        // 执行正常业务
171        console.info('startAbility succeed');
172      });
173    } catch (err) {
174      // 处理入参错误异常
175      let code = (err as BusinessError).code;
176      let message = (err as BusinessError).message;
177      console.error(`startAbility failed, code is ${code}, message is ${message}`);
178    }
179  }
180}
181```
182
183## UIExtensionContext.startAbility
184
185startAbility(want: Want, options?: StartOptions): Promise<void>
186
187启动Ability。使用Promise异步回调。
188
189> **说明:**
190>
191> 组件启动规则详见:[组件启动规则(Stage模型)](../../application-models/component-startup-rules.md)。
192
193**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
194
195**参数:**
196
197| 参数名 | 类型 | 必填 | 说明 |
198| -------- | -------- | -------- | -------- |
199| want | [Want](js-apis-app-ability-want.md) | 是 | 启动Ability的want信息。 |
200| options | [StartOptions](js-apis-app-ability-startOptions.md) | 否 | 启动Ability所携带的参数。 |
201
202**返回值:**
203
204| 类型 | 说明 |
205| -------- | -------- |
206| Promise<void> | Promise对象。无返回结果的Promise对象。 |
207
208**错误码:**
209
210以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
211
212| 错误码ID | 错误信息 |
213| ------- | -------------------------------- |
214| 201 | The application does not have permission to call the interface. |
215| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
216| 16000001 | The specified ability does not exist. |
217| 16000002 | Incorrect ability type. |
218| 16000004 | Can not start invisible component. |
219| 16000005 | The specified process does not have the permission. |
220| 16000006 | Cross-user operations are not allowed. |
221| 16000008 | The crowdtesting application expires. |
222| 16000009 | An ability cannot be started or stopped in Wukong mode. |
223| 16000010 | The call with the continuation flag is forbidden.        |
224| 16000011 | The context does not exist.        |
225| 16000012 | The application is controlled.        |
226| 16000013 | The application is controlled by EDM.       |
227| 16000018 | The application is not allow jumping to other applications. |
228| 16000019 | Can not match any component. |
229| 16000050 | Internal error. |
230| 16000053 | The ability is not on the top of the UI. |
231| 16000055 | Installation-free timed out. |
232| 16000069 | The extension cannot start the third party application. |
233| 16000070 | The extension cannot start the service. |
234| 16200001 | The caller has been released. |
235| 16000073 | The app clone index is invalid. |
236
237**示例:**
238
239```ts
240import { UIExtensionAbility, Want, StartOptions } from '@kit.AbilityKit';
241import { BusinessError } from '@kit.BasicServicesKit';
242
243export default class EntryAbility extends UIExtensionAbility {
244  onForeground() {
245    let want: Want = {
246      bundleName: 'com.example.myapplication',
247      abilityName: 'EntryAbility'
248    };
249    let options: StartOptions = {
250      displayId: 0,
251    };
252
253    try {
254      this.context.startAbility(want, options)
255        .then(() => {
256          // 执行正常业务
257          console.info('startAbility succeed');
258        })
259        .catch((err: BusinessError) => {
260          // 处理业务逻辑错误
261          console.error(`startAbility failed, code is ${err.code}, message is ${err.message}`);
262        });
263    } catch (err) {
264      // 处理入参错误异常
265      let code = (err as BusinessError).code;
266      let message = (err as BusinessError).message;
267      console.error(`startAbility failed, code is ${code}, message is ${message}`);
268    }
269  }
270}
271```
272
273## UIExtensionContext.startAbilityForResult
274
275startAbilityForResult(want: Want, callback: AsyncCallback<AbilityResult>): void
276
277启动一个Ability。使用callback异步回调。Ability被启动后,有如下情况:
278 - 正常情况下可通过调用[terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult)接口使之终止并且返回结果给调用方。
279 - 异常情况下比如杀死Ability会返回异常信息给调用方, 异常信息中resultCode为-1。
280 - 如果被启动的Ability模式是单实例模式, 不同应用多次调用该接口启动这个Ability,当这个Ability调用[terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult)接口使之终止时,只将正常结果返回给最后一个调用方, 其它调用方返回异常信息, 异常信息中resultCode为-1。
281
282> **说明:**
283>
284> 组件启动规则详见:[组件启动规则(Stage模型)](../../application-models/component-startup-rules.md)。
285
286**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
287
288**参数:**
289
290| 参数名 | 类型 | 必填 | 说明 |
291| -------- | -------- | -------- | -------- |
292| want |[Want](js-apis-app-ability-want.md) | 是 | 启动Ability的want信息。 |
293| callback | AsyncCallback<[AbilityResult](js-apis-inner-ability-abilityResult.md)> | 是 | 回调函数,返回启动Ability的结果。 |
294
295**错误码:**
296
297以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
298
299| 错误码ID | 错误信息 |
300| ------- | -------------------------------- |
301| 201 | The application does not have permission to call the interface. |
302| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
303| 16000001 | The specified ability does not exist. |
304| 16000002 | Incorrect ability type. |
305| 16000004 | Can not start invisible component. |
306| 16000005 | The specified process does not have the permission. |
307| 16000006 | Cross-user operations are not allowed. |
308| 16000008 | The crowdtesting application expires. |
309| 16000009 | An ability cannot be started or stopped in Wukong mode. |
310| 16000010 | The call with the continuation flag is forbidden. |
311| 16000011 | The context does not exist. |
312| 16000012 | The application is controlled.        |
313| 16000013 | The application is controlled by EDM.       |
314| 16000018 | The application is not allow jumping to other applications. |
315| 16000019 | Can not match any component. |
316| 16000050 | Internal error. |
317| 16000053 | The ability is not on the top of the UI. |
318| 16000055 | Installation-free timed out. |
319| 16000069 | The extension cannot start the third party application. |
320| 16000070 | The extension cannot start the service. |
321| 16200001 | The caller has been released. |
322| 16000073 | The app clone index is invalid. |
323
324**示例:**
325
326```ts
327import { UIExtensionAbility, Want, common } from '@kit.AbilityKit';
328import { BusinessError } from '@kit.BasicServicesKit';
329
330export default class EntryAbility extends UIExtensionAbility {
331  onForeground() {
332    let want: Want = {
333      deviceId: '',
334      bundleName: 'com.example.myapplication',
335    };
336
337    try {
338      this.context.startAbilityForResult(want, (err: BusinessError, result: common.AbilityResult) => {
339        if (err.code) {
340          // 处理业务逻辑错误
341          console.error(`startAbilityForResult failed, code is ${err.code}, message is ${err.message}`);
342          return;
343        }
344        // 执行正常业务
345        console.info('startAbilityForResult succeed');
346      });
347    } catch (err) {
348      // 处理入参错误异常
349      let code = (err as BusinessError).code;
350      let message = (err as BusinessError).message;
351      console.error(`startAbilityForResult failed, code is ${code}, message is ${message}`);
352    }
353  }
354}
355```
356
357## UIExtensionContext.startAbilityForResult
358
359startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback<AbilityResult>): void
360
361启动一个Ability。使用callback异步回调。Ability被启动后,有如下情况:
362 - 正常情况下可通过调用[terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult)接口使之终止并且返回结果给调用方。
363 - 异常情况下比如杀死Ability会返回异常信息给调用方,异常信息中resultCode为-1。
364 - 如果被启动的Ability模式是单实例模式, 不同应用多次调用该接口启动这个Ability,当这个Ability调用[terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult)接口使之终止时,只将正常结果返回给最后一个调用方,其它调用方返回异常信息, 异常信息中resultCode为-1。
365
366> **说明:**
367>
368> 组件启动规则详见:[组件启动规则(Stage模型)](../../application-models/component-startup-rules.md)。
369
370**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
371
372**参数:**
373
374| 参数名 | 类型 | 必填 | 说明 |
375| -------- | -------- | -------- | -------- |
376| want |[Want](js-apis-app-ability-want.md) | 是 | 启动Ability的want信息。 |
377| options | [StartOptions](js-apis-app-ability-startOptions.md) | 是 | 启动Ability所携带的参数。 |
378| callback | AsyncCallback<[AbilityResult](js-apis-inner-ability-abilityResult.md)> | 是 | 回调函数,返回启动Ability的结果。 |
379
380**错误码:**
381
382以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
383
384| 错误码ID | 错误信息 |
385| ------- | -------------------------------- |
386| 201 | The application does not have permission to call the interface. |
387| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
388| 16000001 | The specified ability does not exist. |
389| 16000004 | Can not start invisible component. |
390| 16000005 | The specified process does not have the permission. |
391| 16000006 | Cross-user operations are not allowed. |
392| 16000008 | The crowdtesting application expires. |
393| 16000009 | An ability cannot be started or stopped in Wukong mode. |
394| 16000011 | The context does not exist. |
395| 16000012 | The application is controlled.        |
396| 16000013 | The application is controlled by EDM.       |
397| 16000018 | The application is not allow jumping to other applications. |
398| 16000019 | Can not match any component. |
399| 16000050 | Internal error. |
400| 16000053 | The ability is not on the top of the UI. |
401| 16000055 | Installation-free timed out. |
402| 16000069 | The extension cannot start the third party application. |
403| 16000070 | The extension cannot start the service. |
404| 16200001 | The caller has been released. |
405| 16000073 | The app clone index is invalid. |
406
407**示例:**
408
409```ts
410import { UIExtensionAbility, Want, common, StartOptions } from '@kit.AbilityKit';
411import { BusinessError } from '@kit.BasicServicesKit';
412
413export default class EntryAbility extends UIExtensionAbility {
414  onForeground() {
415    let want: Want = {
416      deviceId: '',
417      bundleName: 'com.example.myapplication',
418      abilityName: 'EntryAbility'
419    };
420    let options: StartOptions = {
421      displayId: 0,
422    };
423
424    try {
425      this.context.startAbilityForResult(want, options, (err: BusinessError, result: common.AbilityResult) => {
426        if (err.code) {
427          // 处理业务逻辑错误
428          console.error(`startAbilityForResult failed, code is ${err.code}, message is ${err.message}`);
429          return;
430        }
431        // 执行正常业务
432        console.info('startAbilityForResult succeed');
433      });
434    } catch (err) {
435      // 处理入参错误异常
436      let code = (err as BusinessError).code;
437      let message = (err as BusinessError).message;
438      console.error(`startAbilityForResult failed, code is ${code}, message is ${message}`);
439    }
440  }
441}
442```
443
444## UIExtensionContext.startAbilityForResult
445
446startAbilityForResult(want: Want, options?: StartOptions): Promise<AbilityResult>
447
448启动一个Ability。使用Promise异步回调。Ability被启动后,有如下情况:
449 - 正常情况下可通过调用[terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult)接口使之终止并且返回结果给调用方。
450 - 异常情况下比如杀死Ability会返回异常信息给调用方, 异常信息中resultCode为-1。
451 - 如果被启动的Ability模式是单实例模式, 不同应用多次调用该接口启动这个Ability,当这个Ability调用[terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult)接口使之终止时,只将正常结果返回给最后一个调用方, 其它调用方返回异常信息, 异常信息中resultCode为-1。
452
453> **说明:**
454>
455> 组件启动规则详见:[组件启动规则(Stage模型)](../../application-models/component-startup-rules.md)。
456
457**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
458
459**参数:**
460
461| 参数名 | 类型 | 必填 | 说明 |
462| -------- | -------- | -------- | -------- |
463| want | [Want](js-apis-app-ability-want.md) | 是 | 启动Ability的want信息。 |
464| options | [StartOptions](js-apis-app-ability-startOptions.md) | 否 | 启动Ability所携带的参数。 |
465
466
467**返回值:**
468
469| 类型 | 说明 |
470| -------- | -------- |
471| Promise<[AbilityResult](js-apis-inner-ability-abilityResult.md)> | Promise对象,返回启动Ability的结果。 |
472
473**错误码:**
474
475以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
476
477| 错误码ID | 错误信息 |
478| ------- | -------------------------------- |
479| 201 | The application does not have permission to call the interface. |
480| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
481| 16000001 | The specified ability does not exist. |
482| 16000002 | Incorrect ability type. |
483| 16000004 | Can not start invisible component. |
484| 16000005 | The specified process does not have the permission. |
485| 16000006 | Cross-user operations are not allowed. |
486| 16000008 | The crowdtesting application expires. |
487| 16000009 | An ability cannot be started or stopped in Wukong mode. |
488| 16000010 | The call with the continuation flag is forbidden. |
489| 16000011 | The context does not exist. |
490| 16000012 | The application is controlled.        |
491| 16000013 | The application is controlled by EDM.       |
492| 16000018 | The application is not allow jumping to other applications. |
493| 16000019 | Can not match any component. |
494| 16000050 | Internal error. |
495| 16000053 | The ability is not on the top of the UI. |
496| 16000055 | Installation-free timed out. |
497| 16000069 | The extension cannot start the third party application. |
498| 16000070 | The extension cannot start the service. |
499| 16200001 | The caller has been released. |
500| 16000073 | The app clone index is invalid. |
501
502**示例:**
503
504```ts
505import { UIExtensionAbility, Want, common, StartOptions } from '@kit.AbilityKit';
506import { BusinessError } from '@kit.BasicServicesKit';
507
508export default class EntryAbility extends UIExtensionAbility {
509  onForeground() {
510    let want: Want = {
511      bundleName: 'com.example.myapplication',
512      abilityName: 'EntryAbility'
513    };
514    let options: StartOptions = {
515      displayId: 0,
516    };
517
518    try {
519      this.context.startAbilityForResult(want, options)
520        .then((result: common.AbilityResult) => {
521          // 执行正常业务
522          console.info('startAbilityForResult succeed');
523        })
524        .catch((err: BusinessError) => {
525          // 处理业务逻辑错误
526          console.error(`startAbilityForResult failed, code is ${err.code}, message is ${err.message}`);
527        });
528    } catch (err) {
529      // 处理入参错误异常
530      let code = (err as BusinessError).code;
531      let message = (err as BusinessError).message;
532      console.error(`startAbilityForResult failed, code is ${code}, message is ${message}`);
533    }
534  }
535}
536```
537
538
539## UIExtensionContext.connectServiceExtensionAbility
540
541connectServiceExtensionAbility(want: Want, options: ConnectOptions): number
542
543将当前Ability连接到一个ServiceExtensionAbility。
544
545> **说明:**
546>
547> 组件启动规则详见:[组件启动规则(Stage模型)](../../application-models/component-startup-rules.md)。
548
549**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
550
551**参数:**
552
553| 参数名 | 类型 | 必填 | 说明 |
554| -------- | -------- | -------- | -------- |
555| want | [Want](js-apis-app-ability-want.md) | 是 | 连接ServiceExtensionAbility的want信息。 |
556| options | [ConnectOptions](js-apis-inner-ability-connectOptions.md) | 是 | 与ServiceExtensionAbility建立连接后回调函数的实例。 |
557
558**返回值:**
559
560| 类型 | 说明 |
561| -------- | -------- |
562| number | 返回Ability连接的结果code。 |
563
564**错误码:**
565
566以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
567
568| 错误码ID | 错误信息 |
569| ------- | -------------------------------- |
570| 201 | The application does not have permission to call the interface. |
571| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
572| 16000001 | The specified ability does not exist. |
573| 16000002 | Incorrect ability type. |
574| 16000004 | Can not start invisible component. |
575| 16000005 | The specified process does not have the permission. |
576| 16000006 | Cross-user operations are not allowed. |
577| 16000008 | The crowdtesting application expires. |
578| 16000011 | The context does not exist.        |
579| 16000050 | Internal error. |
580| 16000053 | The ability is not on the top of the UI. |
581| 16000055 | Installation-free timed out. |
582| 16000070 | The extension cannot start the service. |
583
584**示例:**
585
586```ts
587import { UIExtensionAbility, Want, common } from '@kit.AbilityKit';
588import { rpc } from '@kit.IPCKit';
589import { BusinessError } from '@kit.BasicServicesKit';
590
591export default class EntryAbility extends UIExtensionAbility {
592  onForeground() {
593    let want: Want = {
594      deviceId: '',
595      bundleName: 'com.example.myapplication',
596      abilityName: 'ServiceExtensionAbility'
597    };
598    let commRemote: rpc.IRemoteObject;
599    let options: common.ConnectOptions = {
600      onConnect(elementName, remote) {
601        commRemote = remote;
602        console.info('onConnect...')
603      },
604      onDisconnect(elementName) {
605        console.info('onDisconnect...')
606      },
607      onFailed(code) {
608        console.info('onFailed...')
609      }
610    };
611    let connection: number;
612    try {
613      connection = this.context.connectServiceExtensionAbility(want, options);
614    } catch (err) {
615      // 处理入参错误异常
616      let code = (err as BusinessError).code;
617      let message = (err as BusinessError).message;
618      console.error(`connectServiceExtensionAbility failed, code is ${code}, message is ${message}`);
619    }
620  }
621}
622```
623
624## UIExtensionContext.disconnectServiceExtensionAbility
625
626disconnectServiceExtensionAbility(connection: number): Promise\<void>
627
628断开与ServiceExtensionAbility的连接,断开连接之后需要将连接成功时返回的remote对象置空。使用Promise异步回调。
629
630**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
631
632**参数:**
633
634| 参数名 | 类型 | 必填 | 说明 |
635| -------- | -------- | -------- | -------- |
636| connection | number | 是 | 连接的ServiceExtensionAbility的数字代码,即connectServiceExtensionAbility返回的connectionId。 |
637
638**返回值:**
639
640| 类型 | 说明 |
641| -------- | -------- |
642| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
643
644**错误码:**
645
646以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
647
648| 错误码ID | 错误信息 |
649| ------- | -------------------------------- |
650| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
651| 16000011 | The context does not exist. |
652| 16000050 | Internal error. |
653
654**示例:**
655
656```ts
657import { UIExtensionAbility } from '@kit.AbilityKit';
658import { rpc } from '@kit.IPCKit';
659import { BusinessError } from '@kit.BasicServicesKit';
660
661export default class EntryAbility extends UIExtensionAbility {
662  onForeground() {
663    // connection为connectServiceExtensionAbility中的返回值
664    let connection = 1;
665    let commRemote: rpc.IRemoteObject | null;
666
667    try {
668      this.context.disconnectServiceExtensionAbility(connection).then(() => {
669        commRemote = null;
670        // 执行正常业务
671        console.info('disconnectServiceExtensionAbility succeed');
672      }).catch((err: BusinessError) => {
673        // 处理业务逻辑错误
674        console.error(`disconnectServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
675      })
676    } catch (err) {
677      commRemote = null;
678      // 处理入参错误异常
679      let code = (err as BusinessError).code;
680      let message = (err as BusinessError).message;
681      console.error(`disconnectServiceExtensionAbility failed, code is ${code}, message is ${message}`);
682    }
683  }
684}
685```
686
687## UIExtensionContext.disconnectServiceExtensionAbility
688
689disconnectServiceExtensionAbility(connection: number, callback: AsyncCallback\<void>): void
690
691断开与ServiceExtensionAbility的连接,断开连接之后需要将连接成功时返回的remote对象置空。使用callback异步回调。
692
693**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
694
695**参数:**
696
697| 参数名 | 类型 | 必填 | 说明 |
698| -------- | -------- | -------- | -------- |
699| connection | number | 是 | 连接的ServiceExtensionAbility的数字代码,即connectServiceExtensionAbility返回的connectionId。 |
700| callback | AsyncCallback\<void> | 是 | 回调函数。当断开与ServiceExtensionAbility的连接成功,err为undefined,否则为错误对象。 |
701
702**错误码:**
703
704以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
705
706| 错误码ID | 错误信息 |
707| ------- | -------------------------------- |
708| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
709| 16000011 | The context does not exist. |
710| 16000050 | Internal error. |
711
712**示例:**
713
714```ts
715import { UIExtensionAbility } from '@kit.AbilityKit';
716import { rpc } from '@kit.IPCKit';
717import { BusinessError } from '@kit.BasicServicesKit';
718
719export default class EntryAbility extends UIExtensionAbility {
720  onForeground() {
721    // connection为connectServiceExtensionAbility中的返回值
722    let connection = 1;
723    let commRemote: rpc.IRemoteObject | null;
724
725    try {
726      this.context.disconnectServiceExtensionAbility(connection, (err: BusinessError) => {
727        commRemote = null;
728        if (err.code) {
729          // 处理业务逻辑错误
730          console.error(`disconnectServiceExtensionAbility failed, code is ${err.code}, message is ${err.message}`);
731          return;
732        }
733        // 执行正常业务
734        console.info('disconnectServiceExtensionAbility succeed');
735      });
736    } catch (err) {
737      commRemote = null;
738      // 处理入参错误异常
739      let code = (err as BusinessError).code;
740      let message = (err as BusinessError).message;
741      console.error(`disconnectServiceExtensionAbility failed, code is ${code}, message is ${message}`);
742    }
743  }
744}
745```
746
747## UIExtensionContext.terminateSelf<sup>12+</sup>
748
749terminateSelf(callback: AsyncCallback&lt;void&gt;): void
750
751停止UIExtensionContext对应的窗口界面对象。使用callback异步回调。
752
753**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
754
755**参数:**
756
757| 参数名   | 类型                      | 必填 | 说明                                                         |
758| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
759| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。当停止UIExtensionContext对应的窗口界面对象成功,err为undefined,否则为错误对象。 |
760
761**错误码**:
762
763以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)。
764
765| 错误码ID | 错误信息 |
766| ------- | -------- |
767| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
768
769**示例:**
770
771```ts
772import { UIExtensionAbility } from '@kit.AbilityKit';
773import { BusinessError } from '@kit.BasicServicesKit';
774
775export default class EntryAbility extends UIExtensionAbility {
776  onForeground() {
777    try {
778      this.context.terminateSelf((err: BusinessError) => {
779        if (err.code) {
780          // 处理业务逻辑错误
781          console.error(`terminateSelf failed, code is ${err.code}, message is ${err.message}`);
782          return;
783        }
784        // 执行正常业务
785        console.info('terminateSelf succeed');
786      });
787    } catch (err) {
788      // 捕获同步的参数错误
789      let code = (err as BusinessError).code;
790      let message = (err as BusinessError).message;
791      console.error(`terminateSelf failed, code is ${code}, message is ${message}`);
792    }
793  }
794}
795```
796
797## UIExtensionContext.terminateSelf<sup>12+</sup>
798
799terminateSelf(): Promise&lt;void&gt;
800
801停止UIExtensionContext对应的窗口界面对象。使用Promise异步回调。
802
803**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
804
805**返回值:**
806
807| 类型                | 说明                                   |
808| ------------------- | -------------------------------------- |
809| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。 |
810
811**示例:**
812
813```ts
814import { UIExtensionAbility } from '@kit.AbilityKit';
815import { BusinessError } from '@kit.BasicServicesKit';
816
817export default class EntryAbility extends UIExtensionAbility {
818  onForeground() {
819    try {
820      this.context.terminateSelf()
821        .then(() => {
822          // 执行正常业务
823          console.info('terminateSelf succeed');
824        })
825        .catch((err: BusinessError) => {
826          // 处理业务逻辑错误
827          console.error(`terminateSelf failed, code is ${err.code}, message is ${err.message}`);
828        });
829    } catch (err) {
830      // 捕获同步的参数错误
831      let code = (err as BusinessError).code;
832      let message = (err as BusinessError).message;
833      console.error(`terminateSelf failed, code is ${code}, message is ${message}`);
834    }
835  }
836}
837```
838
839## UIExtensionContext.terminateSelfWithResult<sup>12+</sup>
840
841terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback&lt;void&gt;): void
842
843停止UIExtensionContext对应的窗口界面对象,并将结果返回给UIExtensionComponent控件。使用callback异步回调。
844
845**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
846
847**参数:**
848
849| 参数名    | 类型                                                    | 必填 | 说明                                                   |
850| --------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ |
851| parameter | [AbilityResult](js-apis-inner-ability-abilityResult.md) | 是   | 返回给UIExtensionComponent控件的信息。                 |
852| callback  | AsyncCallback&lt;void&gt;                               | 是   | 回调函数。当停止成功,err为undefined,否则为错误对象。 |
853
854**错误码**:
855
856以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)。
857
858| 错误码ID | 错误信息 |
859| ------- | -------- |
860| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
861
862**示例:**
863
864```ts
865import { UIExtensionAbility, Want, common } from '@kit.AbilityKit';
866import { BusinessError } from '@kit.BasicServicesKit';
867
868export default class EntryAbility extends UIExtensionAbility {
869  onForeground() {
870    let want: Want = {
871      bundleName: 'com.example.myapplication',
872      abilityName: 'EntryAbility'
873    };
874    let resultCode = 100;
875    // 返回给接口调用方AbilityResult信息
876    let abilityResult: common.AbilityResult = {
877      want,
878      resultCode
879    };
880
881    try {
882      this.context.terminateSelfWithResult(abilityResult, (err: BusinessError) => {
883        if (err.code) {
884          // 处理业务逻辑错误
885          console.error(`terminateSelfWithResult failed, code is ${err.code}, message is ${err.message}`);
886          return;
887        }
888        // 执行正常业务
889        console.info('terminateSelfWithResult succeed');
890      });
891    } catch (err) {
892      // 处理入参错误异常
893      let code = (err as BusinessError).code;
894      let message = (err as BusinessError).message;
895      console.error(`terminateSelfWithResult failed, code is ${code}, message is ${message}`);
896    }
897  }
898}
899```
900
901## UIExtensionContext.terminateSelfWithResult<sup>12+</sup>
902
903terminateSelfWithResult(parameter: AbilityResult): Promise&lt;void&gt;
904
905停止UIExtensionContext对应的窗口界面对象,并将结果返回给UIExtensionComponent控件。使用Promise异步回调。
906
907**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
908
909**参数:**
910
911| 参数名    | 类型                                                    | 必填 | 说明                                   |
912| --------- | ------------------------------------------------------- | ---- | -------------------------------------- |
913| parameter | [AbilityResult](js-apis-inner-ability-abilityResult.md) | 是   | 返回给UIExtensionComponent控件的信息。 |
914
915**返回值:**
916
917| 类型                | 说明                                   |
918| ------------------- | -------------------------------------- |
919| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。 |
920
921**错误码**:
922
923以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)。
924
925| 错误码ID | 错误信息 |
926| ------- | -------- |
927| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
928
929```ts
930import { UIExtensionAbility, Want, common } from '@kit.AbilityKit';
931import { BusinessError } from '@kit.BasicServicesKit';
932
933export default class EntryAbility extends UIExtensionAbility {
934  onForeground() {
935    let want: Want = {
936      bundleName: 'com.example.myapplication',
937      abilityName: 'EntryAbility'
938    };
939    let resultCode = 100;
940    // 返回给接口调用方AbilityResult信息
941    let abilityResult: common.AbilityResult = {
942      want,
943      resultCode
944    };
945
946    try {
947      this.context.terminateSelfWithResult(abilityResult)
948        .then(() => {
949          // 执行正常业务
950          console.info('terminateSelfWithResult succeed');
951        })
952        .catch((err: BusinessError) => {
953          // 处理业务逻辑错误
954          console.error(`terminateSelfWithResult failed, code is ${err.code}, message is ${err.message}`);
955        });
956    } catch (err) {
957      // 处理入参错误异常
958      let code = (err as BusinessError).code;
959      let message = (err as BusinessError).message;
960      console.error(`terminateSelfWithResult failed, code is ${code}, message is ${message}`);
961    }
962  }
963}
964```
965
966## UIExtensionContext.reportDrawnCompleted<sup>12+<sup>
967
968reportDrawnCompleted(callback: AsyncCallback\<void>): void
969
970当页面加载完成(onSessionCreate成功)时,为开发者提供打点功能。使用callback异步回调。
971
972**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
973
974**参数:**
975
976| 参数名 | 类型 | 必填 | 说明 |
977| -------- | -------- | -------- | -------- |
978| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当打点成功,err为undefined,否则为错误对象。|
979
980**错误码:**
981
982以下错误码详细介绍请参考[元能力子系统错误码](errorcode-ability.md)。
983
984| 错误码ID | 错误信息 |
985| ------- | -------------------------------- |
986| 16000011 | The context does not exist. |
987| 16000050 | Internal error. |
988
989**示例:**
990
991```ts
992import { UIExtensionAbility, Want, UIExtensionContentSession } from '@kit.AbilityKit';
993import { BusinessError } from '@kit.BasicServicesKit';
994
995const TAG: string = '[testTag] UIExtAbility';
996
997export default class UIExtAbility extends UIExtensionAbility {
998  onSessionCreate(want: Want, session: UIExtensionContentSession) {
999    console.info(TAG, `onSessionCreate, want: ${JSON.stringify(want)}`);
1000    let data: Record<string, UIExtensionContentSession> = {
1001      'session': session
1002    };
1003    let storage: LocalStorage = new LocalStorage(data);
1004    session.loadContent('pages/extension', storage);
1005    try {
1006      this.context.reportDrawnCompleted((err) => {
1007        if (err.code) {
1008          // 处理业务逻辑错误
1009          console.error(`reportDrawnCompleted failed, code is ${err.code}, message is ${err.message}`);
1010          return;
1011        }
1012        // 执行正常业务
1013        console.info('reportDrawnCompleted succeed');
1014      });
1015    } catch (err) {
1016      // 捕获同步的参数错误
1017      let code = (err as BusinessError).code;
1018      let message = (err as BusinessError).message;
1019      console.error(`reportDrawnCompleted failed, code is ${code}, message is ${message}`);
1020    }
1021  }
1022}
1023```
1024
1025## UIExtensionContext.openAtomicService<sup>12+<sup>
1026openAtomicService(appId: string, options?: AtomicServiceOptions): Promise&lt;AbilityResult&gt;
1027
1028跳出式启动[EmbeddableUIAbility](js-apis-app-ability-embeddableUIAbility.md),并返回结果。使用Promise异步回调。
1029分为以下几种情况:
1030 - 正常情况下可通过调用[terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult)接口使之终止并且返回结果给调用方。
1031 - 异常情况下比如杀死EmbeddableUIAbility会返回异常信息给调用方,异常信息中resultCode为-1。
1032 - 如果不同应用多次调用该接口启动同一个EmbeddableUIAbility,当这个EmbeddableUIAbility调用[terminateSelfWithResult](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult)接口使之终止时,只将正常结果返回给最后一个调用方, 其它调用方返回异常信息,异常信息中resultCode为-1。
1033
1034> **说明:**
1035>
1036> 组件启动规则详见:[组件启动规则(Stage模型)](../../application-models/component-startup-rules.md)。
1037
1038**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1039
1040**参数:**
1041
1042| 参数名 | 类型 | 必填 | 说明 |
1043| -------- | -------- | -------- | -------- |
1044| appId | string | 是 | 应用的唯一标识,由云端统一分配。 |
1045| options | [AtomicServiceOptions](js-apis-app-ability-atomicServiceOptions.md) | 否 | 跳出式启动原子化服务所携带的参数。 |
1046
1047
1048**返回值:**
1049
1050| 类型 | 说明 |
1051| -------- | -------- |
1052| Promise&lt;[AbilityResult](js-apis-inner-ability-abilityResult.md)&gt; | Promise对象。返回[AbilityResult](js-apis-inner-ability-abilityResult.md)对象。 |
1053
1054**错误码:**
1055
1056以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
1057
1058| 错误码ID | 错误信息 |
1059| ------- | -------------------------------- |
1060| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1061| 16000002 | Incorrect ability type. |
1062| 16000003 | The appId does not exist. |
1063| 16000004 | Can not start invisible component. |
1064| 16000011 | The context does not exist. |
1065| 16000012 | The application is controlled.        |
1066| 16000050 | Internal error. |
1067| 16000069 | The extension cannot start the third party application. |
1068| 16200001 | The caller has been released. |
1069
1070
1071**示例:**
1072
1073```ts
1074import { UIExtensionAbility, common, AtomicServiceOptions } from '@kit.AbilityKit';
1075import { BusinessError } from '@kit.BasicServicesKit';
1076
1077export default class EntryAbility extends UIExtensionAbility {
1078  onForeground() {
1079    let appId: string = '6918661953712445909';
1080    let options: AtomicServiceOptions = {
1081      displayId: 0,
1082    };
1083
1084    try {
1085      this.context.openAtomicService(appId, options)
1086        .then((result: common.AbilityResult) => {
1087          // 执行正常业务
1088          console.info('openAtomicService succeed');
1089        })
1090        .catch((err: BusinessError) => {
1091          // 处理业务逻辑错误
1092          console.error(`openAtomicService failed, code is ${err.code}, message is ${err.message}`);
1093        });
1094    } catch (err) {
1095      // 处理入参错误异常
1096      let code = (err as BusinessError).code;
1097      let message = (err as BusinessError).message;
1098      console.error(`openAtomicService failed, code is ${code}, message is ${message}`);
1099    }
1100  }
1101}
1102```
1103
1104## UIExtensionContext.openLink<sup>12+<sup>
1105openLink(link:string, options?: OpenLinkOptions, callback?: AsyncCallback&lt;AbilityResult&gt;): Promise&lt;void&gt;
1106
1107通过AppLinking启动UIAbility,使用Promise异步回调。
1108
1109通过在link字段中传入标准格式的URL,基于隐式want匹配规则拉起目标UIAbility。目标方必须具备以下过滤器特征,才能处理AppLinking链接:
1110- "actions"列表中包含"ohos.want.action.viewData"。
1111- "entities"列表中包含"entity.system.browsable"。
1112- "uris"列表中包含"scheme"为"https"且"domainVerify"为true的元素。
1113
1114如果希望获取被拉起方终止后的结果,可以设置callback参数,此参数的使用可参照[startAbilityForResult](#uiextensioncontextstartabilityforresult)接口。
1115传入的参数不合法时,如未设置必选参数或link字符串不是标准格式的URL,接口会直接抛出异常。参数校验通过,拉起目标方时出现的错误通过promise返回错误信息。
1116
1117> **说明:**
1118>
1119> 组件启动规则详见:[组件启动规则(Stage模型)](../../application-models/component-startup-rules.md)。
1120
1121**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1122
1123**参数:**
1124
1125| 参数名 | 类型 | 必填 | 说明 |
1126| -------- | -------- | -------- | -------- |
1127| link | string | 是 | 指示要打开的标准格式URL。 |
1128| options | [OpenLinkOptions](js-apis-app-ability-openLinkOptions.md) | 否 | 打开URL的选项参数。 |
1129| callback | AsyncCallback&lt;[AbilityResult](js-apis-inner-ability-abilityResult.md)&gt; | 否 | 执行结果回调函数。 |
1130
1131**返回值:**
1132
1133| 类型 | 说明 |
1134| -------- | -------- |
1135| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。 |
1136
1137**错误码:**
1138
1139以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
1140
1141| 错误码ID | 错误信息 |
1142| ------- | -------------------------------- |
1143| 201 | The application does not have permission to call the interface. |
1144| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1145| 16000001 | The specified ability does not exist. |
1146| 16000002 | Incorrect ability type. |
1147| 16000004 | Can not start invisible component. |
1148| 16000005 | The specified process does not have the permission. |
1149| 16000006 | Cross-user operations are not allowed. |
1150| 16000008 | The crowdtesting application expires. |
1151| 16000009 | An ability cannot be started or stopped in Wukong mode. |
1152| 16000010 | The call with the continuation flag is forbidden.        |
1153| 16000011 | The context does not exist.        |
1154| 16000012 | The application is controlled.        |
1155| 16000013 | The application is controlled by EDM.       |
1156| 16000019 | Can not match any component. |
1157| 16000069 | The extension cannot start the third party application. |
1158| 16200001 | The caller has been released. |
1159| 16000053 | The ability is not on the top of the UI. |
1160
1161**示例:**
1162
1163```ts
1164import { UIExtensionAbility, Want, UIExtensionContentSession, OpenLinkOptions } from '@kit.AbilityKit';
1165import { BusinessError } from '@kit.BasicServicesKit';
1166
1167function log(info: string) {
1168  console.error(`MyUIExtension:: ${JSON.stringify(info)}`);
1169}
1170
1171export default class UIExtAbility extends UIExtensionAbility {
1172  onCreate() {
1173    log(`UIExtAbility onCreate`);
1174  }
1175
1176  onForeground() {
1177    log(`UIExtAbility onForeground`);
1178  }
1179
1180  onBackground() {
1181    log(`UIExtAbility onBackground`);
1182  }
1183
1184  onDestroy() {
1185    log(`UIExtAbility onDestroy`);
1186  }
1187
1188  onSessionCreate(want: Want, session: UIExtensionContentSession) {
1189    log(`UIExtAbility onSessionCreate`);
1190    log(`UIExtAbility onSessionCreate, want: ${JSON.stringify(want)}`);
1191    let record: Record<string, UIExtensionContentSession> = {
1192      'session': session
1193    };
1194    let storage: LocalStorage = new LocalStorage(record);
1195    session.loadContent('pages/UIExtensionIndex', storage);
1196
1197    let link: string = 'https://www.example.com';
1198    let openLinkOptions: OpenLinkOptions = {
1199      appLinkingOnly: true
1200    };
1201    try {
1202      this.context.openLink(
1203        link,
1204        openLinkOptions,
1205        (err, result) => {
1206          log(`openLink callback error.code: ${JSON.stringify(err)}`);
1207          log(`openLink callback result: ${JSON.stringify(result.resultCode)}`);
1208          log(`openLink callback result data: ${JSON.stringify(result.want)}`);
1209        }
1210      ).then(() => {
1211        log(`open link success.`);
1212      }).catch((err: BusinessError) => {
1213        log(`open link failed, errCode ${JSON.stringify(err.code)}`);
1214      });
1215    }
1216    catch (e) {
1217      log(`exception occured, errCode ${JSON.stringify(e.code)}`);
1218    }
1219
1220  }
1221
1222  onSessionDestroy(session: UIExtensionContentSession) {
1223    log(`UIExtAbility onSessionDestroy`);
1224  }
1225}
1226```
1227