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