• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.application.formHost (formHost)
2
3formHost模块提供了卡片使用方相关接口的能力,包括对使用方同一用户下安装的卡片进行删除、释放、请求更新,获取信息、状态等操作。
4
5> **说明:**
6>
7> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8> 从API version 9 开始不再维护,建议使用[formHost](js-apis-app-form-formHost.md)替代。
9> 本模块接口均为系统接口。
10
11## 导入模块
12
13```ts
14import formHost from '@ohos.application.formHost';
15```
16
17## deleteForm
18
19deleteForm(formId: string, callback: AsyncCallback<void>): void
20
21删除指定的卡片。调用此方法后,应用程序将无法使用该卡片,卡片管理器服务不再保留有关该卡片的信息。使用callback异步回调。
22
23**需要权限**:ohos.permission.REQUIRE_FORM
24
25**系统能力**:SystemCapability.Ability.Form
26
27**参数:**
28
29| 参数名 | 类型    | 必填 | 说明    |
30| ------ | ------ | ---- | ------- |
31| formId | string | 是   | 卡片标识。 |
32| callback | AsyncCallback<void> | 是 | 回调函数。当删除指定的卡片成功,error为undefined,否则为错误对象 |
33
34**示例:**
35
36```ts
37import Base from '@ohos.base';
38import formHost from '@ohos.application.formHost';
39
40let formId: string = '12400633174999288';
41formHost.deleteForm(formId, (error: Base.BusinessError) => {
42  if (error.code) {
43    console.error(`formHost deleteForm, error: ${JSON.stringify(error)}`);
44  }
45});
46```
47
48## deleteForm
49
50deleteForm(formId: string): Promise<void>
51
52删除指定的卡片。调用此方法后,应用程序将无法使用该卡片,卡片管理器服务不再保留有关该卡片的信息。使用Promise异步回调。
53
54**需要权限**:ohos.permission.REQUIRE_FORM
55
56**系统能力**:SystemCapability.Ability.Form
57
58**参数:**
59
60| 参数名 | 类型    | 必填 | 说明    |
61| ------ | ------ | ---- | ------- |
62| formId | string | 是   | 卡片标识。 |
63
64**返回值:**
65
66| 类型 | 说明 |
67| -------- | -------- |
68| Promise<void> | 无返回结果的Promise对象。 |
69
70**示例:**
71
72```ts
73import Base from '@ohos.base';
74import formHost from '@ohos.application.formHost';
75
76let formId: string = '12400633174999288';
77formHost.deleteForm(formId).then(() => {
78  console.log('formHost deleteForm success');
79}).catch((error: Base.BusinessError) => {
80  console.error(`formHost deleteForm, error: ${JSON.stringify(error)}`);
81});
82```
83
84## releaseForm
85
86releaseForm(formId: string, callback: AsyncCallback<void>): void
87
88释放指定的卡片。调用此方法后,应用程序将无法使用该卡片,但卡片管理器服务仍然保留有关该卡片的缓存信息和存储信息。使用callback异步回调。
89
90**需要权限**:ohos.permission.REQUIRE_FORM
91
92**系统能力**:SystemCapability.Ability.Form
93
94**参数:**
95
96| 参数名 | 类型    | 必填 | 说明    |
97| ------ | ------ | ---- | ------- |
98| formId | string | 是   | 卡片标识。 |
99| callback | AsyncCallback<void> | 是 | 回调函数。当释放指定的卡片成功,error为undefined;否则为错误对象。|
100
101**示例:**
102
103```ts
104import Base from '@ohos.base';
105import formHost from '@ohos.application.formHost';
106
107let formId: string = '12400633174999288';
108formHost.releaseForm(formId, (error: Base.BusinessError) => {
109  if (error.code) {
110    console.error(`formHost releaseForm, error: ${JSON.stringify(error)}`);
111  } else {
112    console.log('formHost releaseForm success');
113  }
114});
115```
116
117## releaseForm
118
119releaseForm(formId: string, isReleaseCache: boolean, callback: AsyncCallback<void>): void
120
121释放指定的卡片。调用此方法后,应用程序将无法使用该卡片,卡片管理器服务保留有关该卡片的存储信息,可以选择是否保留缓存信息。使用callback异步回调。
122
123**需要权限**:ohos.permission.REQUIRE_FORM
124
125**系统能力**:SystemCapability.Ability.Form
126
127**参数:**
128
129| 参数名         | 类型     | 必填 | 说明        |
130| -------------- | ------  | ---- | ----------- |
131| formId         | string  | 是   | 卡片标识。     |
132| isReleaseCache | boolean | 是   | 是否释放缓存。 |
133| callback | AsyncCallback<void> | 是 | 回调函数。当释放指定的卡片成功,error为undefined;否则为错误对象。 |
134
135**示例:**
136
137```ts
138import Base from '@ohos.base';
139import formHost from '@ohos.application.formHost';
140
141let formId: string = '12400633174999288';
142formHost.releaseForm(formId, true, (error: Base.BusinessError) => {
143  if (error.code) {
144    console.error(`formHost releaseForm, error: ${JSON.stringify(error)}`);
145  } else {
146    console.log('formHost releaseForm success');
147  }
148});
149```
150
151## releaseForm
152
153releaseForm(formId: string, isReleaseCache?: boolean): Promise<void>
154
155释放指定的卡片。调用此方法后,应用程序将无法使用该卡片,卡片管理器服务保留有关该卡片的存储信息,可以选择是否保留缓存信息。使用Promise异步回调。
156
157**需要权限**:ohos.permission.REQUIRE_FORM
158
159**系统能力**:SystemCapability.Ability.Form
160
161**参数:**
162
163| 参数名         | 类型     | 必填 | 说明        |
164| -------------- | ------  | ---- | ----------- |
165| formId         | string  | 是   | 卡片标识。     |
166| isReleaseCache | boolean | 否   | 是否释放缓存,默认为false。 |
167
168**返回值:**
169
170| 类型 | 说明 |
171| -------- | -------- |
172| Promise<void> | 无返回结果的Promise对象。 |
173
174**示例:**
175
176```ts
177import Base from '@ohos.base';
178import formHost from '@ohos.application.formHost';
179
180let formId: string = '12400633174999288';
181formHost.releaseForm(formId, true).then(() => {
182  console.log('formHost releaseForm success');
183}).catch((error: Base.BusinessError) => {
184  console.error(`formHost releaseForm, error: ${JSON.stringify(error)}`);
185});
186```
187
188## requestForm
189
190requestForm(formId: string, callback: AsyncCallback<void>): void
191
192请求卡片更新。使用callback异步回调。
193
194**需要权限**:ohos.permission.REQUIRE_FORM
195
196**系统能力**:SystemCapability.Ability.Form
197
198**参数:**
199
200| 参数名 | 类型    | 必填 | 说明    |
201| ------ | ------ | ---- | ------- |
202| formId | string | 是   | 卡片标识。 |
203| callback | AsyncCallback<void> | 是 | 回调函数。当请求卡片更新成功,error为undefined;否则为错误对象。 |
204
205**示例:**
206
207```ts
208import Base from '@ohos.base';
209import formHost from '@ohos.application.formHost';
210
211let formId: string = '12400633174999288';
212formHost.requestForm(formId, (error: Base.BusinessError) => {
213  if (error.code) {
214    console.error(`formHost requestForm, error: ${JSON.stringify(error)}`);
215  }
216});
217```
218
219## requestForm
220
221requestForm(formId: string): Promise<void>
222
223请求卡片更新。使用Promise异步回调。
224
225**需要权限**:ohos.permission.REQUIRE_FORM
226
227**系统能力**:SystemCapability.Ability.Form
228
229**参数:**
230
231| 参数名 | 类型    | 必填 | 说明    |
232| ------ | ------ | ---- | ------- |
233| formId | string | 是   | 卡片标识。 |
234
235**返回值:**
236
237| 类型 | 说明 |
238| -------- | -------- |
239| Promise<void> | 无返回结果的Promise对象。 |
240
241**示例:**
242
243```ts
244import Base from '@ohos.base';
245import formHost from '@ohos.application.formHost';
246
247let formId: string = '12400633174999288';
248formHost.requestForm(formId).then(() => {
249  console.log('formHost requestForm success');
250}).catch((error: Base.BusinessError) => {
251  console.error(`formHost requestForm, error: ${JSON.stringify(error)}`);
252});
253```
254
255## castTempForm
256
257castTempForm(formId: string, callback: AsyncCallback<void>): void
258
259将指定的临时卡片转换为普通卡片。使用callback异步回调。
260
261**需要权限**:ohos.permission.REQUIRE_FORM
262
263**系统能力**:SystemCapability.Ability.Form
264
265**参数:**
266
267| 参数名 | 类型    | 必填 | 说明    |
268| ------ | ------ | ---- | ------- |
269| formId | string | 是   | 卡片标识。 |
270| callback | AsyncCallback<void> | 是 | 回调函数。当将指定的临时卡片转换为普通卡片成功,error为undefined,否则为错误对象。 |
271
272**示例:**
273
274```ts
275import Base from '@ohos.base';
276import formHost from '@ohos.application.formHost';
277
278let formId: string = '12400633174999288';
279formHost.castTempForm(formId, (error: Base.BusinessError) => {
280  if (error.code) {
281    console.error(`formHost castTempForm, error: ${JSON.stringify(error)}`);
282  }
283});
284```
285
286## castTempForm
287
288castTempForm(formId: string): Promise<void>
289
290将指定的临时卡片转换为普通卡片。使用Promise异步回调。
291
292**需要权限**:ohos.permission.REQUIRE_FORM
293
294**系统能力**:SystemCapability.Ability.Form
295
296**参数:**
297
298| 参数名 | 类型    | 必填 | 说明    |
299| ------ | ------ | ---- | ------- |
300| formId | string | 是   | 卡片标识。 |
301
302**返回值:**
303
304| 类型 | 说明 |
305| -------- | -------- |
306| Promise<void> | 无返回结果的Promise对象。|
307
308**示例:**
309
310```ts
311import Base from '@ohos.base';
312import formHost from '@ohos.application.formHost';
313
314let formId: string = '12400633174999288';
315formHost.castTempForm(formId).then(() => {
316  console.log('formHost castTempForm success');
317}).catch((error: Base.BusinessError) => {
318  console.error(`formHost castTempForm, error: ${JSON.stringify(error)}`);
319});
320```
321
322## notifyVisibleForms
323
324notifyVisibleForms(formIds: Array<string>, callback: AsyncCallback<void>): void
325
326向卡片框架发送通知以使指定的卡片可见。该方法调用成功后,会调用onVisibilityChange通知卡片提供方。使用callback异步回调。
327
328**需要权限**:ohos.permission.REQUIRE_FORM
329
330**系统能力**:SystemCapability.Ability.Form
331
332**参数:**
333
334| 参数名 | 类型    | 必填 | 说明    |
335| ------ | ------ | ---- | ------- |
336| formIds  | Array<string>       | 是   | 卡片标识列表。         |
337| callback | AsyncCallback<void> | 是 | 回调函数。当向卡片框架发送通知以使指定的卡片可见成功,error为undefined,否则为错误对象。 |
338
339**示例:**
340
341```ts
342import Base from '@ohos.base';
343import formHost from '@ohos.application.formHost';
344
345let formId: string[] = ['12400633174999288'];
346formHost.notifyVisibleForms(formId, (error: Base.BusinessError) => {
347  if (error.code) {
348    console.error(`formHost notifyVisibleForms, error: ${JSON.stringify(error)}`);
349  }
350});
351```
352
353## notifyVisibleForms
354
355notifyVisibleForms(formIds: Array<string>): Promise<void>
356
357向卡片框架发送通知以使指定的卡片可见。该方法调用成功后,会调用onVisibilityChange通知卡片提供方。使用Promise异步回调。
358
359**需要权限**:ohos.permission.REQUIRE_FORM
360
361**系统能力**:SystemCapability.Ability.Form
362
363**参数:**
364
365| 参数名 | 类型    | 必填 | 说明    |
366| ------ | ------ | ---- | ------- |
367| formIds | Array<string> | 是   | 卡片标识列表。 |
368
369**返回值:**
370
371| 类型 | 说明 |
372| -------- | -------- |
373| Promise<void> | 无返回结果的Promise对象。 |
374
375**示例:**
376
377```ts
378import Base from '@ohos.base';
379import formHost from '@ohos.application.formHost';
380
381let formId: string[] = ['12400633174999288'];
382formHost.notifyVisibleForms(formId).then(() => {
383  console.log('formHost notifyVisibleForms success');
384}).catch((error: Base.BusinessError) => {
385  console.error(`formHost notifyVisibleForms, error: ${JSON.stringify(error)}`);
386});
387```
388
389## notifyInvisibleForms
390
391notifyInvisibleForms(formIds: Array<string>, callback: AsyncCallback<void>): void
392
393向卡片框架发送通知以使指定的卡片不可见。该方法调用成功后,会调用onVisibilityChange通知卡片提供方。使用callback异步回调。
394
395**需要权限**:ohos.permission.REQUIRE_FORM
396
397**系统能力**:SystemCapability.Ability.Form
398
399**参数:**
400
401| 参数名 | 类型    | 必填 | 说明    |
402| ------ | ------ | ---- | ------- |
403| formIds  | Array<string>       | 是   | 卡片标识列表。|
404| callback | AsyncCallback<void> | 是 | 回调函数。当向卡片框架发送通知以使指定的卡片不可见成功,error为undefined,否则为错误对象。 |
405
406**示例:**
407
408```ts
409import Base from '@ohos.base';
410import formHost from '@ohos.application.formHost';
411
412let formId: string[] = ['12400633174999288'];
413formHost.notifyInvisibleForms(formId, (error: Base.BusinessError) => {
414  if (error.code) {
415    console.error(`formHost notifyInvisibleForms, error: ${JSON.stringify(error)}`);
416  }
417});
418```
419
420## notifyInvisibleForms
421
422notifyInvisibleForms(formIds: Array<string>): Promise<void>
423
424向卡片框架发送通知以使指定的卡片不可见。该方法调用成功后,会调用onVisibilityChange通知卡片提供方。使用Promise异步回调。
425
426**需要权限**:ohos.permission.REQUIRE_FORM
427
428**系统能力**:SystemCapability.Ability.Form
429
430**参数:**
431
432| 参数名 | 类型    | 必填 | 说明    |
433| ------ | ------ | ---- | ------- |
434| formIds | Array<string> | 是   | 卡片标识列表。 |
435
436**返回值:**
437
438| 类型 | 说明 |
439| -------- | -------- |
440| Promise<void> | 无返回结果的Promise对象。|
441
442**示例:**
443
444```ts
445import Base from '@ohos.base';
446import formHost from '@ohos.application.formHost';
447
448let formId: string[] = ['12400633174999288'];
449formHost.notifyInvisibleForms(formId).then(() => {
450  console.log('formHost notifyInvisibleForms success');
451}).catch((error: Base.BusinessError) => {
452  console.error(`formHost notifyInvisibleForms, error: ${JSON.stringify(error)}`);
453});
454```
455
456## enableFormsUpdate
457
458enableFormsUpdate(formIds: Array<string>, callback: AsyncCallback<void>): void
459
460向卡片框架发送通知以使指定的卡片可以更新。该方法调用成功后,卡片刷新状态设置为使能,卡片可以接收来自卡片提供方的更新。使用callback异步回调。
461
462**需要权限**:ohos.permission.REQUIRE_FORM
463
464**系统能力**:SystemCapability.Ability.Form
465
466**参数:**
467
468| 参数名 | 类型    | 必填 | 说明    |
469| ------ | ------ | ---- | ------- |
470| formIds  | Array<string>       | 是   | 卡片标识列表。         |
471| callback | AsyncCallback<void> | 是 | 回调函数。当向卡片框架发送通知以使指定的卡片可以更新成功,error为undefined,否则为错误对象。 |
472
473**示例:**
474
475```ts
476import Base from '@ohos.base';
477import formHost from '@ohos.application.formHost';
478
479let formId: string[] = ['12400633174999288'];
480formHost.enableFormsUpdate(formId, (error: Base.BusinessError) => {
481  if (error.code) {
482    console.error(`formHost enableFormsUpdate, error: ${JSON.stringify(error)}`);
483  }
484});
485```
486
487## enableFormsUpdate
488
489enableFormsUpdate(formIds: Array<string>): Promise<void>
490
491向卡片框架发送通知以使指定的卡片可以更新。该方法调用成功后,卡片刷新状态设置为使能,卡片可以接收来自卡片提供方的更新。使用Promise异步回调。
492
493**需要权限**:ohos.permission.REQUIRE_FORM
494
495**系统能力**:SystemCapability.Ability.Form
496
497**参数:**
498
499| 参数名 | 类型    | 必填 | 说明    |
500| ------ | ------ | ---- | ------- |
501| formIds | Array<string> | 是   | 卡片标识列表。 |
502
503**返回值:**
504
505| 类型 | 说明 |
506| -------- | -------- |
507| Promise<void> | 无返回结果的Promise对象。 |
508
509**示例:**
510
511```ts
512import Base from '@ohos.base';
513import formHost from '@ohos.application.formHost';
514
515let formId: string[] = ['12400633174999288'];
516formHost.enableFormsUpdate(formId).then(() => {
517  console.log('formHost enableFormsUpdate success');
518}).catch((error: Base.BusinessError) => {
519  console.error(`formHost enableFormsUpdate, error: ${JSON.stringify(error)}`);
520});
521```
522
523## disableFormsUpdate
524
525disableFormsUpdate(formIds: Array<string>, callback: AsyncCallback<void>): void
526
527向卡片框架发送通知以使指定的卡片不可以更新。该方法调用成功后,卡片刷新状态设置为去使能,卡片不可以接收来自卡片提供方的更新。使用callback异步回调。
528
529**需要权限**:ohos.permission.REQUIRE_FORM
530
531**系统能力**:SystemCapability.Ability.Form
532
533**参数:**
534
535| 参数名 | 类型    | 必填 | 说明    |
536| ------ | ------ | ---- | ------- |
537| formIds  | Array<string>       | 是   | 卡片标识列表。         |
538| callback | AsyncCallback<void> | 是 | 回调函数。当向卡片框架发送通知以使指定的卡片不可以更新成功,error为undefined,否则为错误对象。 |
539
540**示例:**
541
542```ts
543import Base from '@ohos.base';
544import formHost from '@ohos.application.formHost';
545
546let formId: string[] = ['12400633174999288'];
547formHost.disableFormsUpdate(formId, (error: Base.BusinessError) => {
548  if (error.code) {
549    console.error(`formHost disableFormsUpdate, error: ${JSON.stringify(error)}`);
550  }
551});
552```
553
554## disableFormsUpdate
555
556disableFormsUpdate(formIds: Array<string>): Promise<void>
557
558向卡片框架发送通知以使指定的卡片不可以更新。该方法调用成功后,卡片刷新状态设置为去使能,卡片不可以接收来自卡片提供方的更新。使用Promise异步回调。
559
560**需要权限**:ohos.permission.REQUIRE_FORM
561
562**系统能力**:SystemCapability.Ability.Form
563
564**参数:**
565
566| 参数名 | 类型    | 必填 | 说明    |
567| ------ | ------ | ---- | ------- |
568| formIds | Array<string> | 是   | 卡片标识列表。 |
569
570**返回值:**
571
572| 类型 | 说明 |
573| -------- | -------- |
574| Promise<void> | 无返回结果的Promise对象。 |
575
576**示例:**
577
578```ts
579import Base from '@ohos.base';
580import formHost from '@ohos.application.formHost';
581
582let formId: string[] = ['12400633174999288'];
583formHost.disableFormsUpdate(formId).then(() => {
584  console.log('formHost disableFormsUpdate success');
585}).catch((error: Base.BusinessError) => {
586  console.error(`formHost disableFormsUpdate, error: ${JSON.stringify(error)}`);
587});
588```
589
590## isSystemReady
591
592isSystemReady(callback: AsyncCallback<void>): void
593
594检查系统是否准备好。使用callback异步回调。
595
596**系统能力**:SystemCapability.Ability.Form
597
598**参数:**
599
600| 参数名 | 类型    | 必填 | 说明    |
601| ------ | ------ | ---- | ------- |
602| callback | AsyncCallback<void> | 是 | 回调函数。当检查系统是否准备好成功,error为undefined,否则为错误对象。 |
603
604**示例:**
605
606```ts
607import Base from '@ohos.base';
608import formHost from '@ohos.application.formHost';
609
610let formId: string = '12400633174999288';
611formHost.isSystemReady((error: Base.BusinessError) => {
612  if (error.code) {
613    console.error(`formHost isSystemReady, error: ${JSON.stringify(error)}`);
614  }
615});
616```
617
618## isSystemReady
619
620isSystemReady(): Promise<void>
621
622检查系统是否准备好。使用Promise异步回调。
623
624**系统能力**:SystemCapability.Ability.Form
625
626**返回值:**
627
628| 类型 | 说明 |
629| -------- | -------- |
630| Promise<void> | 无返回结果的Promise对象。 |
631
632**示例:**
633
634```ts
635import Base from '@ohos.base';
636import formHost from '@ohos.application.formHost';
637
638let formId: string = '12400633174999288';
639formHost.isSystemReady().then(() => {
640  console.log('formHost isSystemReady success');
641}).catch((error: Base.BusinessError) => {
642  console.error(`formHost isSystemReady, error: ${JSON.stringify(error)}`);
643});
644```
645
646## getAllFormsInfo
647
648getAllFormsInfo(callback: AsyncCallback<Array<formInfo.FormInfo>>): void
649
650获取设备上所有应用提供的卡片信息。使用callback异步回调。
651
652**需要权限**:ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
653
654**系统能力**:SystemCapability.Ability.Form
655
656**参数:**
657
658| 参数名 | 类型    | 必填 | 说明    |
659| ------ | ------ | ---- | ------- |
660| callback | AsyncCallback<Array<[formInfo.FormInfo](js-apis-application-formInfo.md)>> | 是 | 回调函数。当获取设备上所有应用提供的卡片信息成功,error为undefined,data为查询到的卡片信息;否则为错误对象。 |
661
662**示例:**
663
664```ts
665import Base from '@ohos.base';
666import formHost from '@ohos.application.formHost';
667import formInfo from '@ohos.app.form.formInfo';
668
669formHost.getAllFormsInfo((error: Base.BusinessError, data: formInfo.FormInfo[]) => {
670  if (error.code) {
671    console.error(`formHost getAllFormsInfo, error: ${JSON.stringify(error)}`);
672  } else {
673    console.log(`formHost getAllFormsInfo, data: ${JSON.stringify(data)}`);
674  }
675});
676```
677
678## getAllFormsInfo
679
680getAllFormsInfo(): Promise<Array<formInfo.FormInfo>>
681
682获取设备上所有应用提供的卡片信息。使用Promise异步回调。
683
684**需要权限**:ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
685
686**系统能力**:SystemCapability.Ability.Form
687
688**返回值:**
689
690| 类型          | 说明                                |
691| :------------ | :---------------------------------- |
692| Promise<Array<[formInfo.FormInfo](js-apis-application-formInfo.md)>> | Promise对象,返回查询到的卡片信息。 |
693
694**示例:**
695
696  ```ts
697  import Base from '@ohos.base';
698  import formHost from '@ohos.application.formHost';
699  import formInfo from '@ohos.app.form.formInfo';
700
701  formHost.getAllFormsInfo().then((data: formInfo.FormInfo[]) => {
702    console.log(`formHost getAllFormsInfo data: ${JSON.stringify(data)}`);
703  }).catch((error: Base.BusinessError) => {
704    console.error(`formHost getAllFormsInfo, error: ${JSON.stringify(error)}`);
705  });
706  ```
707
708## getFormsInfo
709
710getFormsInfo(bundleName: string, callback: AsyncCallback<Array<formInfo.FormInfo>>): void
711
712获取设备上指定应用程序提供的卡片信息。使用callback异步回调。
713
714**需要权限**:ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
715
716**系统能力**:SystemCapability.Ability.Form
717
718**参数:**
719
720| 参数名 | 类型    | 必填 | 说明    |
721| ------ | ------ | ---- | ------- |
722| bundleName | string | 是 | 要查询的应用Bundle名称。 |
723| callback | AsyncCallback<Array<[formInfo.FormInfo](js-apis-application-formInfo.md)>> | 是 | 回调函数。当获取设备上指定应用程序提供的卡片信息成功,error为undefined,data为查询到的卡片信息;否则为错误对象。 |
724
725**示例:**
726
727```ts
728import Base from '@ohos.base';
729import formHost from '@ohos.application.formHost';
730import formInfo from '@ohos.app.form.formInfo';
731
732formHost.getFormsInfo('com.example.ohos.formjsdemo', (error: Base.BusinessError, data: formInfo.FormInfo[]) => {
733  if (error.code) {
734    console.error(`formHost getFormsInfo, error: ${JSON.stringify(error)}`);
735  } else {
736    console.log(`formHost getFormsInfo, data: ${JSON.stringify(data)}`);
737  }
738});
739```
740
741## getFormsInfo
742
743getFormsInfo(bundleName: string, moduleName: string, callback: AsyncCallback<Array<formInfo.FormInfo>>): void
744
745获取设备上指定应用程序提供的卡片信息。使用callback异步回调。
746
747**需要权限**:ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
748
749**系统能力**:SystemCapability.Ability.Form
750
751**参数:**
752
753| 参数名 | 类型    | 必填 | 说明    |
754| ------ | ------ | ---- | ------- |
755| bundleName | string | 是 | 要查询的应用程序Bundle名称。 |
756| moduleName | string | 是 |  要查询的模块名称。 |
757| callback | AsyncCallback<Array<[formInfo.FormInfo](js-apis-application-formInfo.md)>> | 是 | 回调函数。当获取设备上指定应用程序提供的卡片信息成功,error为undefined,data为查询到的卡片信息;否则为错误对象。 |
758
759**示例:**
760
761```ts
762import Base from '@ohos.base';
763import formHost from '@ohos.application.formHost';
764import formInfo from '@ohos.app.form.formInfo';
765
766formHost.getFormsInfo('com.example.ohos.formjsdemo', 'entry', (error: Base.BusinessError, data: formInfo.FormInfo[]) => {
767  if (error.code) {
768    console.error(`formHost getFormsInfo, error: ${JSON.stringify(error)}`);
769  } else {
770    console.log(`formHost getFormsInfo, data: ${JSON.stringify(data)}`);
771  }
772});
773```
774
775## getFormsInfo
776
777getFormsInfo(bundleName: string, moduleName?: string): Promise<Array<formInfo.FormInfo>>
778
779获取设备上指定应用程序提供的卡片信息。使用Promise异步回调。
780
781**需要权限**:ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
782
783**系统能力**:SystemCapability.Ability.Form
784
785**参数:**
786
787| 参数名 | 类型    | 必填 | 说明    |
788| ------ | ------ | ---- | ------- |
789| bundleName | string | 是 | 要查询的应用程序Bundle名称。 |
790| moduleName | string | 否 |  要查询的模块名称。 |
791
792**返回值:**
793
794| 类型          | 说明                                |
795| :------------ | :---------------------------------- |
796| Promise<Array<[formInfo.FormInfo](js-apis-application-formInfo.md)>> | Promise对象,返回查询到的卡片信息。 |
797
798**示例:**
799
800  ```ts
801  import Base from '@ohos.base';
802  import formHost from '@ohos.application.formHost';
803
804  formHost.getFormsInfo('com.example.ohos.formjsdemo', 'entry').then((data: formInfo.FormInfo[]) => {
805    console.log(`formHost getFormsInfo, data: ${JSON.stringify(data)}`);
806  }).catch((error: Base.BusinessError) => {
807    console.error(`formHost getFormsInfo, error: ${JSON.stringify(error)}`);
808  });
809  ```
810
811## deleteInvalidForms
812
813deleteInvalidForms(formIds: Array<string>, callback: AsyncCallback<number>): void
814
815根据列表删除应用程序的无效卡片。使用callback异步回调。
816
817**需要权限**:ohos.permission.REQUIRE_FORM
818
819**系统能力**:SystemCapability.Ability.Form
820
821**参数:**
822
823| 参数名 | 类型    | 必填 | 说明    |
824| ------ | ------ | ---- | ------- |
825| formIds | Array<string> | 是   | 有效卡片标识列表。 |
826| callback | AsyncCallback<number> | 是 | 回调函数。当根据列表删除应用程序的无效卡片成功,error为undefined,data为删除的卡片个数;否则为错误对象。 |
827
828**示例:**
829
830```ts
831import Base from '@ohos.base';
832import formHost from '@ohos.application.formHost';
833
834let formIds: string[] = new Array('12400633174999288', '12400633174999289');
835formHost.deleteInvalidForms(formIds, (error: Base.BusinessError, data: number) => {
836  if (error.code) {
837    console.error(`formHost deleteInvalidForms, error: ${JSON.stringify(error)}`);
838  } else {
839    console.log(`formHost deleteInvalidForms, data: ${JSON.stringify(data)}`);
840  }
841});
842```
843
844## deleteInvalidForms
845
846deleteInvalidForms(formIds: Array<string>): Promise<number>
847
848根据列表删除应用程序的无效卡片。使用Promise异步回调。
849
850**需要权限**:ohos.permission.REQUIRE_FORM
851
852**系统能力**:SystemCapability.Ability.Form
853
854**参数:**
855
856| 参数名 | 类型    | 必填 | 说明    |
857| ------ | ------ | ---- | ------- |
858| formIds | Array<string> | 是   | 有效卡片标识列表。 |
859
860**返回值:**
861
862| 类型          | 说明                                |
863| :------------ | :---------------------------------- |
864| Promise<number> | Promise对象,返回删除的卡片个数。 |
865
866**示例:**
867
868```ts
869import Base from '@ohos.base';
870import formHost from '@ohos.application.formHost';
871
872let formIds: string[] = new Array('12400633174999288', '12400633174999289');
873formHost.deleteInvalidForms(formIds).then((data: number) => {
874  console.log(`formHost deleteInvalidForms, data: ${JSON.stringify(data)}`);
875}).catch((error: Base.BusinessError) => {
876  console.error(`formHost deleteInvalidForms, error: ${JSON.stringify(error)}`);
877});
878```
879
880## acquireFormState
881
882acquireFormState(want: Want, callback: AsyncCallback<formInfo.FormStateInfo>): void
883
884获取卡片状态。使用callback异步回调。
885
886**需要权限**:ohos.permission.REQUIRE_FORMohos.permission.GET_BUNDLE_INFO_PRIVILEGED
887
888**系统能力**:SystemCapability.Ability.Form
889
890**参数:**
891
892| 参数名 | 类型    | 必填 | 说明    |
893| ------ | ------ | ---- | ------- |
894| want | [Want](js-apis-application-want.md) | 是   | 查询卡片状态时携带的want信息。需要包含bundle名、ability名、module名、卡片名、卡片规格等。 |
895| callback | AsyncCallback<[formInfo.FormStateInfo](js-apis-application-formInfo.md#formstateinfo)> | 是 | 回调函数。当获取卡片状态成功,error为undefined,data为获取到的卡片状态;否则为错误对象。 |
896
897**示例:**
898
899```ts
900import Base from '@ohos.base';
901import formHost from '@ohos.application.formHost';
902import Want from '@ohos.app.ability.Want';
903import formInfo from '@ohos.app.form.formInfo';
904
905let want: Want = {
906  'deviceId': '',
907  'bundleName': 'ohos.samples.FormApplication',
908  'abilityName': 'FormAbility',
909  'parameters': {
910    'ohos.extra.param.key.module_name': 'entry',
911    'ohos.extra.param.key.form_name': 'widget',
912    'ohos.extra.param.key.form_dimension': 2
913  }
914};
915formHost.acquireFormState(want, (error:Base.BusinessError, data: formInfo.FormStateInfo) => {
916  if (error.code) {
917    console.error(`formHost acquireFormState, error: ${JSON.stringify(error)}`);
918  } else {
919    console.log(`formHost acquireFormState, data: ${JSON.stringify(data)}`);
920  }
921});
922```
923
924## acquireFormState
925
926acquireFormState(want: Want): Promise<formInfo.FormStateInfo>
927
928获取卡片状态。使用Promise异步回调。
929
930**需要权限**:ohos.permission.REQUIRE_FORMohos.permission.GET_BUNDLE_INFO_PRIVILEGED
931
932**系统能力**:SystemCapability.Ability.Form
933
934**参数:**
935
936| 参数名 | 类型    | 必填 | 说明    |
937| ------ | ------ | ---- | ------- |
938| want   | [Want](js-apis-application-want.md) | 是   | 查询卡片状态时携带的want信息。 |
939
940**返回值:**
941
942| 类型          | 说明                                |
943| :------------ | :---------------------------------- |
944| Promise<[FormStateInfo](js-apis-application-formInfo.md#formstateinfo)> | Promise对象,返回卡片状态。 |
945
946**示例:**
947
948```ts
949import Base from '@ohos.base';
950import formHost from '@ohos.application.formHost';
951import Want from '@ohos.app.ability.Want';
952import formInfo from '@ohos.app.form.formInfo';
953
954let want: Want = {
955  'deviceId': '',
956  'bundleName': 'ohos.samples.FormApplication',
957  'abilityName': 'FormAbility',
958  'parameters': {
959    'ohos.extra.param.key.module_name': 'entry',
960    'ohos.extra.param.key.form_name': 'widget',
961    'ohos.extra.param.key.form_dimension': 2
962  }
963};
964formHost.acquireFormState(want).then((data: formInfo.FormStateInfo) => {
965  console.log(`formHost acquireFormState, data: ${JSON.stringify(data)}`);
966}).catch((error: Base.BusinessError) => {
967  console.error(`formHost acquireFormState, error: ${JSON.stringify(error)}`);
968});
969```
970
971## on('formUninstall')
972
973on(type: 'formUninstall', callback: Callback<string>): void
974
975订阅卡片卸载事件。使用callback异步回调。
976
977**系统能力**:SystemCapability.Ability.Form
978
979**参数:**
980
981| 参数名 | 类型    | 必填 | 说明    |
982| ------ | ------ | ---- | ------- |
983| type | string | 是   | 填写'formUninstall',表示卡片卸载事件。 |
984| callback | Callback<string> | 是 | 回调函数。返回卡片标识。 |
985
986**示例:**
987
988```ts
989import Base from '@ohos.base';
990import formHost from '@ohos.application.formHost';
991
992formHost.on('formUninstall', (formId: string) => {
993  console.log(`formHost on formUninstall, formId: ${formId}`);
994});
995```
996
997## off('formUninstall')
998
999off(type: 'formUninstall', callback?: Callback<string>): void
1000
1001取消订阅卡片卸载事件。使用callback异步回调。
1002
1003**系统能力**:SystemCapability.Ability.Form
1004
1005**参数:**
1006
1007| 参数名 | 类型    | 必填 | 说明    |
1008| ------ | ------ | ---- | ------- |
1009| type | string | 是   | 填写'formUninstall',表示卡片卸载事件。 |
1010| callback | Callback&lt;string&gt; | 否 | 回调函数。返回卡片标识。缺省时,表示注销所有已注册事件回调。<br> 需与对应on('formUninstall')的callback一致。|
1011
1012**示例:**
1013
1014```ts
1015import Base from '@ohos.base';
1016import formHost from '@ohos.application.formHost';
1017
1018formHost.off('formUninstall', (formId: string) => {
1019  console.log(`formHost on formUninstall, formId: ${formId}`);
1020});
1021```
1022
1023## notifyFormsVisible
1024
1025notifyFormsVisible(formIds: Array&lt;string&gt;, isVisible: boolean, callback: AsyncCallback&lt;void&gt;): void
1026
1027通知卡片是否可见。使用callback异步回调。
1028
1029**需要权限**:ohos.permission.REQUIRE_FORM
1030
1031**系统能力**:SystemCapability.Ability.Form
1032
1033**参数:**
1034
1035| 参数名 | 类型    | 必填 | 说明    |
1036| ------ | ------ | ---- | ------- |
1037| formIds | Array&lt;string&gt; | 是   | 卡片标识列表。 |
1038| isVisible | boolean | 是   | 是否可见。 |
1039| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当通知卡片是否可见成功,error为undefined,否则为错误对象。 |
1040
1041**示例:**
1042
1043```ts
1044import Base from '@ohos.base';
1045import formHost from '@ohos.application.formHost';
1046
1047let formIds: string[]= new Array('12400633174999288', '12400633174999289');
1048formHost.notifyFormsVisible(formIds, true, (error: Base.BusinessError) => {
1049  if (error.code) {
1050    console.error(`formHost notifyFormsVisible, error: ${JSON.stringify(error)}`);
1051  }
1052});
1053```
1054
1055## notifyFormsVisible
1056
1057notifyFormsVisible(formIds: Array&lt;string&gt;, isVisible: boolean): Promise&lt;void&gt;
1058
1059通知卡片是否可见。使用Promise异步回调。
1060
1061**需要权限**:ohos.permission.REQUIRE_FORM
1062
1063**系统能力**:SystemCapability.Ability.Form
1064
1065**参数:**
1066
1067| 参数名 | 类型    | 必填 | 说明    |
1068| ------ | ------ | ---- | ------- |
1069| formIds | Array&lt;string&gt; | 是   | 卡片标识列表。 |
1070| isVisible | boolean | 是   | 是否可见。 |
1071
1072**返回值:**
1073
1074| 类型 | 说明 |
1075| -------- | -------- |
1076| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1077
1078**示例:**
1079
1080```ts
1081import Base from '@ohos.base';
1082import formHost from '@ohos.application.formHost';
1083
1084let formIds: string[] = new Array('12400633174999288', '12400633174999289');
1085formHost.notifyFormsVisible(formIds, true).then(() => {
1086  console.log('formHost notifyFormsVisible success');
1087}).catch((error: Base.BusinessError) => {
1088  console.error(`formHost notifyFormsVisible, error: ${JSON.stringify(error)}`);
1089});
1090```
1091
1092## notifyFormsEnableUpdate
1093
1094notifyFormsEnableUpdate(formIds: Array&lt;string&gt;, isEnableUpdate: boolean, callback: AsyncCallback&lt;void&gt;): void
1095
1096通知卡片是否启用更新状态。使用callback异步回调。
1097
1098**需要权限**:ohos.permission.REQUIRE_FORM
1099
1100**系统能力**:SystemCapability.Ability.Form
1101
1102**参数:**
1103
1104| 参数名 | 类型    | 必填 | 说明    |
1105| ------ | ------ | ---- | ------- |
1106| formIds | Array&lt;string&gt; | 是   | 卡片标识列表。 |
1107| isEnableUpdate | boolean | 是   | 是否使能更新。 |
1108| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当通知卡片是否启用更新状态成功,error为undefined,否则为错误对象。 |
1109
1110**示例:**
1111
1112```ts
1113import Base from '@ohos.base';
1114import formHost from '@ohos.application.formHost';
1115
1116let formIds: string[] = new Array('12400633174999288', '12400633174999289');
1117formHost.notifyFormsEnableUpdate(formIds, true, (error: Base.BusinessError) => {
1118  if (error.code) {
1119    console.error(`formHost notifyFormsEnableUpdate, error: ${JSON.stringify(error)}`);
1120  }
1121});
1122```
1123
1124## notifyFormsEnableUpdate
1125
1126notifyFormsEnableUpdate(formIds: Array&lt;string&gt;, isEnableUpdate: boolean): Promise&lt;void&gt;
1127
1128通知卡片是否启用更新状态。使用Promise异步回调。
1129
1130**需要权限**:ohos.permission.REQUIRE_FORM
1131
1132**系统能力**:SystemCapability.Ability.Form
1133
1134**参数:**
1135
1136  | 参数名 | 类型    | 必填 | 说明    |
1137  | ------ | ------ | ---- | ------- |
1138  | formIds | Array&lt;string&gt; | 是   | 卡片标识列表。 |
1139  | isEnableUpdate | boolean | 是   | 是否使能更新。 |
1140
1141**返回值:**
1142
1143  | 类型 | 说明 |
1144  | -------- | -------- |
1145  | Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1146
1147**示例:**
1148
1149```ts
1150import Base from '@ohos.base';
1151import formHost from '@ohos.application.formHost';
1152
1153let formIds: string[] = new Array('12400633174999288', '12400633174999289');
1154formHost.notifyFormsEnableUpdate(formIds, true).then(() => {
1155  console.log('formHost notifyFormsEnableUpdate success');
1156}).catch((error: Base.BusinessError) => {
1157  console.error(`formHost notifyFormsEnableUpdate, error: ${JSON.stringify(error)}`);
1158});
1159```
1160