js-apis-formhost.md 29.9 KB
Newer Older
Z
zengyawen 已提交
1 2
# FormHost

3
> **NOTE**<br/>
Z
zengyawen 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Provides APIs related to the widget host.

## Modules to Import

```
import formHost from '@ohos.application.formHost';
```

## Required Permissions

ohos.permission.REQUIRE_FORM

ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

## deleteForm

deleteForm(formId: string, callback: AsyncCallback&lt;void&gt;): void;

Deletes a widget. This API uses an asynchronous callback to return the result. After this API is called, the application can no longer use the widget, and the Widget Manager will not retain the widget information.

W
wusongqing 已提交
26
**System capability**
Z
zengyawen 已提交
27 28 29 30 31

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
32 33 34 35
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formId | string | Yes  | ID of a widget.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
Z
zengyawen 已提交
36 37 38 39 40 41

**Example**

  ```js
  var formId = "12400633174999288";
  formHost.deleteForm(formId, (error, data) => {
W
wusongqing 已提交
42 43
      if (error.code) {
          console.log('formHost deleteForm, error:' + JSON.stringify(error));
Z
zengyawen 已提交
44 45 46 47 48 49 50 51 52 53
      }
  });
  ```

## deleteForm

deleteForm(formId: string): Promise&lt;void&gt;;

Deletes a widget. This API uses a promise to return the result. After this API is called, the application can no longer use the widget, and the Widget Manager will not retain the widget information.

W
wusongqing 已提交
54
**System capability**
Z
zengyawen 已提交
55 56 57 58 59

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
60 61 62
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formId | string | Yes  | ID of a widget.|
Z
zengyawen 已提交
63 64 65

**Return value**

W
wusongqing 已提交
66 67 68
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
Z
zengyawen 已提交
69 70 71 72 73

**Parameters**

  ```js
  var formId = "12400633174999288";
W
wusongqing 已提交
74 75 76 77
  formHost.deleteForm(formId).then(() => {
      console.log('formHost deleteForm success');
  }).catch((error) => {
      console.log('formHost deleteForm, error:' + JSON.stringify(error));
Z
zengyawen 已提交
78 79 80 81 82 83 84 85 86
  });
  ```

## releaseForm

releaseForm(formId: string, callback: AsyncCallback&lt;void&gt;): void;

Releases a widget. This API uses an asynchronous callback to return the result. After this API is called, the application can no longer use the widget, but the Widget Manager still retains the widget cache and storage information.

W
wusongqing 已提交
87
**System capability**
Z
zengyawen 已提交
88 89 90 91 92

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
93 94 95 96
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formId | string | Yes  | ID of a widget.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
Z
zengyawen 已提交
97 98 99 100 101 102

**Example**

  ```js
  var formId = "12400633174999288";
  formHost.releaseForm(formId, (error, data) => {
W
wusongqing 已提交
103 104
      if (error.code) {
          console.log('formHost releaseForm, error:' + JSON.stringify(error));
Z
zengyawen 已提交
105 106 107 108 109 110 111 112
      }
  });
  ```

## releaseForm

releaseForm(formId: string, isReleaseCache: boolean, callback: AsyncCallback&lt;void&gt;): void;

W
wusongqing 已提交
113
Releases a widget. This API uses an asynchronous callback to return the result. After this API is called, the application can no longer use the widget, but the Widget Manager retains the storage information about the widget and retains or releases the cache information based on the setting.
Z
zengyawen 已提交
114

W
wusongqing 已提交
115
**System capability**
Z
zengyawen 已提交
116 117 118 119 120

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
121 122 123 124 125
| Name        | Type    | Mandatory| Description       |
| -------------- | ------  | ---- | ----------- |
| formId         | string  | Yes  | ID of a widget.    |
| isReleaseCache | boolean | Yes  | Whether to release the cache.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
Z
zengyawen 已提交
126 127 128 129 130 131

**Example**

  ```js
  var formId = "12400633174999288";
  formHost.releaseForm(formId, true, (error, data) => {
W
wusongqing 已提交
132 133
      if (error.code) {
          console.log('formHost releaseForm, error:' + JSON.stringify(error));
Z
zengyawen 已提交
134 135 136 137 138 139 140 141
      }
  });
  ```

## releaseForm

releaseForm(formId: string, isReleaseCache?: boolean): Promise&lt;void&gt;;

W
wusongqing 已提交
142
Releases a widget. This API uses a promise to return the result. After this API is called, the application can no longer use the widget, but the Widget Manager retains the storage information about the widget and retains or releases the cache information based on the setting.
Z
zengyawen 已提交
143

W
wusongqing 已提交
144
**System capability**
Z
zengyawen 已提交
145 146 147 148 149

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
150 151 152 153
| Name        | Type    | Mandatory| Description       |
| -------------- | ------  | ---- | ----------- |
| formId         | string  | Yes  | ID of a widget.    |
| isReleaseCache | boolean | No  | Whether to release the cache.|
Z
zengyawen 已提交
154 155 156

**Return value**

W
wusongqing 已提交
157 158 159
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
Z
zengyawen 已提交
160 161 162 163 164

**Example**

  ```js
  var formId = "12400633174999288";
W
wusongqing 已提交
165 166 167 168
  formHost.releaseForm(formId, true).then(() => {
      console.log('formHost releaseForm success');
  }).catch((error) => {
      console.log('formHost releaseForm, error:' + JSON.stringify(error));
Z
zengyawen 已提交
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
  });
  ```

## requestForm

requestForm(formId: string, callback: AsyncCallback&lt;void&gt;): void;

Requests a widget update. This API uses an asynchronous callback to return the result.

**System capability**

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
184 185 186 187
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formId | string | Yes  | ID of a widget.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
Z
zengyawen 已提交
188 189 190 191 192 193

**Example**

  ```js
  var formId = "12400633174999288";
  formHost.requestForm(formId, (error, data) => {
W
wusongqing 已提交
194 195
      if (error.code) {
          console.log('formHost requestForm, error:' + JSON.stringify(error));
Z
zengyawen 已提交
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
      }
  });
  ```

## requestForm

requestForm(formId: string): Promise&lt;void&gt;;

Requests a widget update. This API uses a promise to return the result.

**System capability**

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
212 213 214
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formId | string | Yes  | ID of a widget.|
Z
zengyawen 已提交
215 216 217

**Return value**

W
wusongqing 已提交
218 219 220
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
Z
zengyawen 已提交
221 222 223 224 225

**Example**

  ```js
  var formId = "12400633174999288";
W
wusongqing 已提交
226 227 228 229
  formHost.requestForm(formId).then(() => {
      console.log('formHost requestForm success');
  }).catch((error) => {
      console.log('formHost requestForm, error:' + JSON.stringify(error));
Z
zengyawen 已提交
230 231 232 233 234 235 236 237 238
  });
  ```

## castTempForm

castTempForm(formId: string, callback: AsyncCallback&lt;void&gt;): void;

Converts a temporary widget to a normal one. This API uses an asynchronous callback to return the result.

W
wusongqing 已提交
239
**System capability**
Z
zengyawen 已提交
240 241 242 243 244

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
245 246 247 248
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formId | string | Yes  | ID of a widget.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
Z
zengyawen 已提交
249 250 251 252 253 254

**Example**

  ```js
  var formId = "12400633174999288";
  formHost.castTempForm(formId, (error, data) => {
W
wusongqing 已提交
255 256
      if (error.code) {
          console.log('formHost castTempForm, error:' + JSON.stringify(error));
Z
zengyawen 已提交
257 258 259 260 261 262 263 264 265 266
      }
  });
  ```

## castTempForm

castTempForm(formId: string): Promise&lt;void&gt;;

Converts a temporary widget to a normal one. This API uses a promise to return the result.

W
wusongqing 已提交
267
**System capability**
Z
zengyawen 已提交
268 269 270 271 272

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
273 274 275
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formId | string | Yes  | ID of a widget.|
Z
zengyawen 已提交
276 277 278

**Return value**

W
wusongqing 已提交
279 280 281
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
Z
zengyawen 已提交
282 283 284 285 286

**Example**

  ```js
  var formId = "12400633174999288";
W
wusongqing 已提交
287 288 289 290
  formHost.castTempForm(formId).then(() => {
      console.log('formHost castTempForm success');
  }).catch((error) => {
      console.log('formHost castTempForm, error:' + JSON.stringify(error));
Z
zengyawen 已提交
291 292 293 294 295
  });
  ```

## notifyVisibleForms

W
wusongqing 已提交
296
notifyVisibleForms(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void;
Z
zengyawen 已提交
297 298 299

Instructs the widget framework to make a widget visible. This API uses an asynchronous callback to return the result. After this API is called, **onVisibilityChange** is invoked to notify the widget provider.

W
wusongqing 已提交
300
**System capability**
Z
zengyawen 已提交
301 302 303 304 305

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
306 307 308 309
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds  | Array&lt;string&gt;       | Yes  | List of widget IDs.        |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
Z
zengyawen 已提交
310 311 312 313 314 315

**Example**

  ```js
  var formId = "12400633174999288";
  formHost.notifyVisibleForms(formId, (error, data) => {
W
wusongqing 已提交
316 317
      if (error.code) {
          console.log('formHost notifyVisibleForms, error:' + JSON.stringify(error));
Z
zengyawen 已提交
318 319 320 321 322 323
      }
  });
  ```

## notifyVisibleForms

W
wusongqing 已提交
324
notifyVisibleForms(formIds: Array&lt;string&gt;): Promise&lt;void&gt;;
Z
zengyawen 已提交
325 326 327

Instructs the widget framework to make a widget visible. This API uses a promise to return the result. After this API is called, **onVisibilityChange** is invoked to notify the widget provider.

W
wusongqing 已提交
328
**System capability**
Z
zengyawen 已提交
329 330 331 332 333

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
334 335 336
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array&lt;string&gt; | Yes  | List of widget IDs.|
Z
zengyawen 已提交
337 338 339

**Return value**

W
wusongqing 已提交
340 341 342
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
Z
zengyawen 已提交
343 344 345 346 347

**Example**

  ```js
  var formId = "12400633174999288";
W
wusongqing 已提交
348 349 350 351
  formHost.notifyVisibleForms(formId).then(() => {
      console.log('formHost notifyVisibleForms success');
  }).catch((error) => {
      console.log('formHost notifyVisibleForms, error:' + JSON.stringify(error));
Z
zengyawen 已提交
352 353 354 355 356
  });
  ```

## notifyInvisibleForms

W
wusongqing 已提交
357
notifyInvisibleForms(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void;
Z
zengyawen 已提交
358 359 360

Instructs the widget framework to make a widget invisible. This API uses an asynchronous callback to return the result. After this API is called, **onVisibilityChange** is invoked to notify the widget provider.

W
wusongqing 已提交
361
**System capability**
Z
zengyawen 已提交
362 363 364 365 366

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
367 368 369 370
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds  | Array&lt;string&gt;       | Yes  | List of widget IDs.        |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
Z
zengyawen 已提交
371 372 373 374 375 376

**Example**

  ```js
  var formId = "12400633174999288";
  formHost.notifyInvisibleForms(formId, (error, data) => {
W
wusongqing 已提交
377 378
      if (error.code) {
          console.log('formHost notifyInvisibleForms, error:' + JSON.stringify(error));
Z
zengyawen 已提交
379 380 381 382 383 384
      }
  });
  ```

## notifyInvisibleForms

W
wusongqing 已提交
385
notifyInvisibleForms(formIds: Array&lt;string&gt;): Promise&lt;void&gt;;
Z
zengyawen 已提交
386 387 388

Instructs the widget framework to make a widget invisible. This API uses a promise to return the result. After this API is called, **onVisibilityChange** is invoked to notify the widget provider.

W
wusongqing 已提交
389
**System capability**
Z
zengyawen 已提交
390 391 392 393 394

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
395 396 397
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array&lt;string&gt; | Yes  | List of widget IDs.|
Z
zengyawen 已提交
398 399 400

**Return value**

W
wusongqing 已提交
401 402 403
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
Z
zengyawen 已提交
404 405 406 407 408

**Example**

  ```js
  var formId = "12400633174999288";
W
wusongqing 已提交
409 410 411 412
  formHost.notifyInvisibleForms(formId).then(() => {
      console.log('formHost notifyInvisibleForms success');
  }).catch((error) => {
      console.log('formHost notifyInvisibleForms, error:' + JSON.stringify(error));
Z
zengyawen 已提交
413 414 415 416 417
  });
  ```

## enableFormsUpdate

W
wusongqing 已提交
418
enableFormsUpdate(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void;
Z
zengyawen 已提交
419

W
wusongqing 已提交
420
Instructs the widget framework to make a widget updatable. This API uses an asynchronous callback to return the result. After this API is called, the widget is in the enabled state and can receive updates from the widget provider.
Z
zengyawen 已提交
421

W
wusongqing 已提交
422
**System capability**
Z
zengyawen 已提交
423 424 425 426 427

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
428 429 430 431
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds  | Array&lt;string&gt;       | Yes  | List of widget IDs.        |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
Z
zengyawen 已提交
432 433 434 435 436 437

**Example**

  ```js
  var formId = "12400633174999288";
  formHost.enableFormsUpdate(formId, (error, data) => {
W
wusongqing 已提交
438 439
      if (error.code) {
          console.log('formHost enableFormsUpdate, error:' + JSON.stringify(error));
Z
zengyawen 已提交
440 441 442 443 444 445
      }
  });
  ```

## enableFormsUpdate

W
wusongqing 已提交
446
enableFormsUpdate(formIds: Array&lt;string&gt;): Promise&lt;void&gt;;
Z
zengyawen 已提交
447

W
wusongqing 已提交
448
Instructs the widget framework to make a widget updatable. This API uses a promise to return the result. After this API is called, the widget is in the enabled state and can receive updates from the widget provider.
Z
zengyawen 已提交
449

W
wusongqing 已提交
450
**System capability**
Z
zengyawen 已提交
451 452 453 454 455

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
456 457 458
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array&lt;string&gt; | Yes  | List of widget IDs.|
Z
zengyawen 已提交
459 460 461

**Return value**

W
wusongqing 已提交
462 463 464
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
Z
zengyawen 已提交
465 466 467 468 469

**Example**

  ```js
  var formId = "12400633174999288";
W
wusongqing 已提交
470 471 472 473
  formHost.enableFormsUpdate(formId).then(() => {
      console.log('formHost enableFormsUpdate success');
  }).catch((error) => {
      console.log('formHost enableFormsUpdate, error:' + JSON.stringify(error));
Z
zengyawen 已提交
474 475 476 477 478
  });
  ```

## disableFormsUpdate

W
wusongqing 已提交
479
disableFormsUpdate(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void;
Z
zengyawen 已提交
480

W
wusongqing 已提交
481
Instructs the widget framework to make a widget not updatable. This API uses an asynchronous callback to return the result. After this API is called, the widget cannot receive updates from the widget provider.
Z
zengyawen 已提交
482

W
wusongqing 已提交
483
**System capability**
Z
zengyawen 已提交
484 485 486 487 488

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
489 490 491 492
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds  | Array&lt;string&gt;       | Yes  | List of widget IDs.        |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
Z
zengyawen 已提交
493 494 495 496 497 498

**Example**

  ```js
  var formId = "12400633174999288";
  formHost.disableFormsUpdate(formId, (error, data) => {
W
wusongqing 已提交
499 500
      if (error.code) {
          console.log('formHost disableFormsUpdate, error:' + JSON.stringify(error));
Z
zengyawen 已提交
501 502 503 504 505 506
      }
  });
  ```

## disableFormsUpdate

W
wusongqing 已提交
507
disableFormsUpdate(formIds: Array&lt;string&gt;): Promise&lt;void&gt;;
Z
zengyawen 已提交
508

W
wusongqing 已提交
509
Instructs the widget framework to make a widget not updatable. This API uses a promise to return the result. After this API is called, the widget cannot receive updates from the widget provider.
Z
zengyawen 已提交
510

W
wusongqing 已提交
511
**System capability**
Z
zengyawen 已提交
512 513 514 515 516

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
517 518 519
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array&lt;string&gt; | Yes  | List of widget IDs.|
Z
zengyawen 已提交
520 521 522

**Return value**

W
wusongqing 已提交
523 524 525
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
Z
zengyawen 已提交
526 527 528 529 530

**Example**

  ```js
  var formId = "12400633174999288";
W
wusongqing 已提交
531 532 533 534
  formHost.disableFormsUpdate(formId).then(() => {
      console.log('formHost disableFormsUpdate success');
  }).catch((error) => {
      console.log('formHost disableFormsUpdate, error:' + JSON.stringify(error));
Z
zengyawen 已提交
535 536 537 538 539 540 541 542 543
  });
  ```

## isSystemReady

isSystemReady(callback: AsyncCallback&lt;void&gt;): void;

Checks whether the system is ready. This API uses an asynchronous callback to return the result.

W
wusongqing 已提交
544
**System capability**
Z
zengyawen 已提交
545 546 547 548 549

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
550 551 552
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
Z
zengyawen 已提交
553 554 555 556 557 558

**Example**

  ```js
  var formId = "12400633174999288";
  formHost.isSystemReady((error, data) => {
W
wusongqing 已提交
559 560
      if (error.code) {
          console.log('formHost isSystemReady, error:' + JSON.stringify(error));
Z
zengyawen 已提交
561 562 563 564 565 566 567 568 569 570
      }
  });
  ```

## isSystemReady

isSystemReady(): Promise&lt;void&gt;;

Checks whether the system is ready. This API uses a promise to return the result.

W
wusongqing 已提交
571
**System capability**
Z
zengyawen 已提交
572 573 574 575 576

SystemCapability.Ability.Form

**Return value**

W
wusongqing 已提交
577 578 579
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
Z
zengyawen 已提交
580 581 582 583 584

**Example**

  ```js
  var formId = "12400633174999288";
W
wusongqing 已提交
585 586 587 588
  formHost.isSystemReady().then(() => {
      console.log('formHost isSystemReady success');
  }).catch((error) => {
      console.log('formHost isSystemReady, error:' + JSON.stringify(error));
Z
zengyawen 已提交
589 590 591 592 593 594 595 596 597
  });
  ```

## getAllFormsInfo

getAllFormsInfo(callback: AsyncCallback&lt;Array&lt;FormInfo&gt;&gt;): void;

Obtains the widget information provided by all applications on the device. This API uses an asynchronous callback to return the result.

W
wusongqing 已提交
598
**System capability**
Z
zengyawen 已提交
599 600 601 602 603

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
604 605 606
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| callback | AsyncCallback&lt;Array&lt;[FormInfo](./js-apis-formInfo.md#forminfo-1)&gt;&gt; | Yes| Callback used to return the widget information.|
Z
zengyawen 已提交
607 608 609 610 611

**Example**

  ```js
  formHost.getAllFormsInfo((error, data) => {
W
wusongqing 已提交
612 613 614 615
      if (error.code) {
          console.log('formHost getAllFormsInfo, error:' + JSON.stringify(error));
      } else {
          console.log('formHost getAllFormsInfo, data:' + JSON.stringify(data));
Z
zengyawen 已提交
616 617 618 619 620 621 622 623 624 625
      }
  });
  ```

## getAllFormsInfo

getAllFormsInfo(): Promise&lt;Array&lt;FormInfo&gt;&gt;;

Obtains the widget information provided by all applications on the device. This API uses a promise to return the result.

W
wusongqing 已提交
626
**System capability**
Z
zengyawen 已提交
627 628 629 630 631 632 633 634 635 636 637 638

SystemCapability.Ability.Form

**Return value**

| Type         | Description                               |
| :------------ | :---------------------------------- |
| Promise&lt;Array&lt;[FormInfo](./js-apis-formInfo.md#forminfo-1)&gt;&gt; | Promise used to return the widget information.|

**Example**

  ```js
W
wusongqing 已提交
639 640 641 642
  formHost.getAllFormsInfo().then((data) => {
      console.log('formHost getAllFormsInfo data:' + JSON.stringify(data));
  }).catch((error) => {
      console.log('formHost getAllFormsInfo, error:' + JSON.stringify(error));
Z
zengyawen 已提交
643 644 645 646 647 648 649 650 651
  });
  ```

## getFormsInfo

getFormsInfo(bundleName: string, callback: AsyncCallback&lt;Array&lt;FormInfo&gt;&gt;): void;

Obtains the widget information provided by a given application on the device. This API uses an asynchronous callback to return the result.

W
wusongqing 已提交
652
**System capability**
Z
zengyawen 已提交
653 654 655 656 657

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
658 659 660 661
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| bundleName | string | Yes|  Bundle name of the target application.|
| callback | AsyncCallback&lt;Array&lt;[FormInfo](./js-apis-formInfo.md#forminfo-1)&gt;&gt; | Yes| Callback used to return the widget information.|
Z
zengyawen 已提交
662 663 664 665

**Example**

  ```js
W
wusongqing 已提交
666 667 668 669 670
  formHost.getFormsInfo("com.example.ohos.formjsdemo", (error, data) => {
      if (error.code) {
          console.log('formHost getFormsInfo, error:' + JSON.stringify(error));
      } else {
          console.log('formHost getFormsInfo, data:' + JSON.stringify(data));
Z
zengyawen 已提交
671 672 673 674 675 676 677 678 679 680
      }
  });
  ```

## getFormsInfo

getFormsInfo(bundleName: string, moduleName: string, callback: AsyncCallback&lt;Array&lt;FormInfo&gt;&gt;): void;

Obtains the widget information provided by a given application on the device. This API uses an asynchronous callback to return the result.

W
wusongqing 已提交
681
**System capability**
Z
zengyawen 已提交
682 683 684 685 686

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
687 688 689 690 691
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| bundleName | string | Yes|  Bundle name of the target application.|
| moduleName | string | Yes|  Module name.|
| callback | AsyncCallback&lt;Array&lt;[FormInfo](./js-apis-formInfo.md#forminfo-1)&gt;&gt; | Yes| Callback used to return the widget information.|
Z
zengyawen 已提交
692 693 694 695

**Example**

  ```js
W
wusongqing 已提交
696 697 698 699 700
  formHost.getFormsInfo("com.example.ohos.formjsdemo", "entry", (error, data) => {
      if (error.code) {
          console.log('formHost getFormsInfo, error:' + JSON.stringify(error));
      } else {
          console.log('formHost getFormsInfo, data:' + JSON.stringify(data));
Z
zengyawen 已提交
701 702 703 704 705 706 707 708 709 710
      }
  });
  ```

## getFormsInfo

getFormsInfo(bundleName: string, moduleName?: string): Promise&lt;Array&lt;FormInfo&gt;&gt;;

Obtains the widget information provided by a given application on the device. This API uses a promise to return the result.

W
wusongqing 已提交
711
**System capability**
Z
zengyawen 已提交
712 713 714 715 716

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
717 718 719 720
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| bundleName | string | Yes|  Bundle name of the target application.|
| moduleName | string | No|  Module name.|
Z
zengyawen 已提交
721 722 723 724 725 726 727 728 729 730

**Return value**

| Type         | Description                               |
| :------------ | :---------------------------------- |
| Promise&lt;Array&lt;[FormInfo](./js-apis-formInfo.md#forminfo-1)&gt;&gt; | Promise used to return the widget information.|

**Example**

  ```js
W
wusongqing 已提交
731 732 733 734
  formHost.getFormsInfo("com.example.ohos.formjsdemo", "entry").then((data) => {
      console.log('formHost getFormsInfo, data:' + JSON.stringify(data));
  }).catch((error) => {
      console.log('formHost getFormsInfo, error:' + JSON.stringify(error));
Z
zengyawen 已提交
735 736 737 738 739 740 741 742 743
  });
  ```

## deleteInvalidForms

deleteInvalidForms(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;number&gt;): void;

Deletes invalid widgets from the list. This API uses an asynchronous callback to return the result.

W
wusongqing 已提交
744
**System capability**
Z
zengyawen 已提交
745 746 747 748 749

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
750 751 752 753
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array&lt;string&gt; | Yes  | List of valid widget IDs.|
| callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the number of widgets deleted.|
Z
zengyawen 已提交
754 755 756 757 758 759

**Example**

  ```js
  var formIds = new Array("12400633174999288", "12400633174999289");
  formHost.deleteInvalidForms(formIds, (error, data) => {
W
wusongqing 已提交
760 761 762 763
      if (error.code) {
          console.log('formHost deleteInvalidForms, error:' + JSON.stringify(error));
      } else {
          console.log('formHost deleteInvalidForms, data:' + JSON.stringify(data));
Z
zengyawen 已提交
764 765 766 767 768 769
      }
  });
  ```

## deleteInvalidForms

W
wusongqing 已提交
770
function deleteInvalidForms(formIds: Array&lt;string&gt;): Promise&lt;number&gt;;
Z
zengyawen 已提交
771 772 773

Deletes invalid widgets from the list. This API uses a promise to return the result.

W
wusongqing 已提交
774
**System capability**
Z
zengyawen 已提交
775 776 777 778 779

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
780 781 782
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array&lt;string&gt; | Yes  | List of valid widget IDs.|
Z
zengyawen 已提交
783 784 785 786 787 788 789 790 791 792 793

**Return value**

| Type         | Description                               |
| :------------ | :---------------------------------- |
| Promise&lt;number&gt; | Promise used to return the number of widgets deleted.|

**Example**

  ```js
  var formIds = new Array("12400633174999288", "12400633174999289");
W
wusongqing 已提交
794 795 796 797
  formHost.deleteInvalidForms(formIds).then((data) => {
      console.log('formHost deleteInvalidForms, data:' + JSON.stringify(data));
  }).catch((error) => {
      console.log('formHost deleteInvalidForms, error:' + JSON.stringify(error));
Z
zengyawen 已提交
798 799 800 801 802 803 804 805 806
  });
  ```

## acquireFormState

acquireFormState(want: Want, callback: AsyncCallback&lt;FormStateInfo&gt;): void;

Obtains the widget state. This API uses an asynchronous callback to return the result.

W
wusongqing 已提交
807
**System capability**
Z
zengyawen 已提交
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826

SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| want | [Want](js-apis-featureAbility.md#want) | Yes  | **Want** information carried to query the widget state.|
| callback | AsyncCallback&lt;[FormStateInfo](js-apis-formInfo.md#formstateinfo)&gt; | Yes| Callback used to return the widget state.|

**Example**

  ```js
  var want = {
  	"deviceId": "",
  	"bundleName": "com.extreme.test",
  	"abilityName": "com.extreme.test.MainAbility"
  };
  formHost.acquireFormState(want, (error, data) => {
W
wusongqing 已提交
827 828 829 830
      if (error.code) {
          console.log('formHost acquireFormState, error:' + JSON.stringify(error));
      } else {
          console.log('formHost acquireFormState, data:' + JSON.stringify(data));
Z
zengyawen 已提交
831 832 833 834 835 836 837 838 839 840 841 842
      }
  });
  ```

## acquireFormState

function acquireFormState(want: Want): Promise&lt;FormStateInfo&gt;;

Obtains the widget state. This API uses a promise to return the result.

**Parameters**

W
wusongqing 已提交
843 844 845
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| want   | [Want](js-apis-featureAbility.md#want) | Yes  | **Want** information carried to query the widget state.|
Z
zengyawen 已提交
846 847 848 849 850 851 852

**Return value**

| Type         | Description                               |
| :------------ | :---------------------------------- |
| Promise&lt;[FormStateInfo](js-apis-formInfo.md#formstateinfo)&gt; | Promise used to return the widget state.|

W
wusongqing 已提交
853
**System capability**
Z
zengyawen 已提交
854 855 856 857 858 859 860 861 862 863 864

SystemCapability.Ability.Form

**Example**

  ```js
  var want = {
  	"deviceId": "",
  	"bundleName": "com.extreme.test",
  	"abilityName": "com.extreme.test.MainAbility"
  };
W
wusongqing 已提交
865 866 867 868
  formHost.acquireFormState(want).then((data) => {
      console.log('formHost acquireFormState, data:' + JSON.stringify(data));
  }).catch((error) => {
      console.log('formHost acquireFormState, error:' + JSON.stringify(error));
Z
zengyawen 已提交
869 870 871 872 873 874 875 876 877
  });
  ```

## on("formUninstall")

on(type: "formUninstall", callback: Callback&lt;string&gt;): void;

Subscribes to widget uninstall events.

W
wusongqing 已提交
878
**System capability**
Z
zengyawen 已提交
879 880 881 882 883

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
884 885 886 887
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| type | string | Yes  | Type of event to subscribe to. The value **formUninstall** indicates a widget uninstallation event.|
| callback | Callback&lt;string&gt; | Yes| Callback used for event subscription.|
Z
zengyawen 已提交
888 889 890 891

**Example**

  ```js
W
wusongqing 已提交
892 893 894 895
  let callback = function(formId) {
      console.log('formHost on formUninstall, formId:' + formId);
  }
  formHost.on("formUninstall", callback);
Z
zengyawen 已提交
896 897 898 899
  ```

## off("formUninstall")

W
wusongqing 已提交
900
off(type: "formUninstall", callback?: Callback&lt;string&gt;): void;
Z
zengyawen 已提交
901 902 903

Unsubscribes from widget uninstall events.

W
wusongqing 已提交
904
**System capability**
Z
zengyawen 已提交
905 906 907 908 909

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
910 911 912 913
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| type | string | Yes  | Type of event to subscribe to. The value **formUninstall** indicates a widget uninstallation event.|
| callback | Callback&lt;string&gt; | No| Callback used for event unsubscription. If it is left unspecified, it indicates the callback for all the events that have been subscribed.|
Z
zengyawen 已提交
914 915 916 917

**Example**

  ```js
W
wusongqing 已提交
918 919 920 921
  let callback = function(formId) {
      console.log('formHost on formUninstall, formId:' + formId);
  }
  formHost.off("formUninstall", callback);
Z
zengyawen 已提交
922 923 924 925 926 927 928 929
  ```

## notifyFormsVisible

notifyFormsVisible(formIds: Array&lt;string&gt;, isVisible: boolean, callback: AsyncCallback&lt;void&gt;): void;

Instructs the widgets to make themselves visible. This API uses an asynchronous callback to return the result.

W
wusongqing 已提交
930
**System capability**
Z
zengyawen 已提交
931 932 933 934 935

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
936 937 938 939 940
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array&lt;string&gt; | Yes  | List of widget IDs.|
| isVisible | boolean | Yes  | Whether to be visible.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
Z
zengyawen 已提交
941 942 943 944 945 946

**Example**

  ```js
  var formIds = new Array("12400633174999288", "12400633174999289");
  formHost.notifyFormsVisible(formIds, true, (error, data) => {
W
wusongqing 已提交
947 948
      if (error.code) {
          console.log('formHost notifyFormsVisible, error:' + JSON.stringify(error));
Z
zengyawen 已提交
949 950 951 952 953 954 955 956 957 958
      }
  });
  ```

## notifyFormsVisible

notifyFormsVisible(formIds: Array&lt;string&gt;, isVisible: boolean): Promise&lt;void&gt;;

Instructs the widgets to make themselves visible. This API uses a promise to return the result.

W
wusongqing 已提交
959
**System capability**
Z
zengyawen 已提交
960 961 962 963 964

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
965 966 967 968
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array&lt;string&gt; | Yes  | List of widget IDs.|
| isVisible | boolean | Yes  | Whether to be visible.|
Z
zengyawen 已提交
969 970 971

**Return value**

W
wusongqing 已提交
972 973 974
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
Z
zengyawen 已提交
975 976 977 978 979

**Example**

  ```js
  var formIds = new Array("12400633174999288", "12400633174999289");
W
wusongqing 已提交
980 981 982 983
  formHost.notifyFormsVisible(formIds, true).then(() => {
      console.log('formHost notifyFormsVisible success');
  }).catch((error) => {
      console.log('formHost notifyFormsVisible, error:' + JSON.stringify(error));
Z
zengyawen 已提交
984 985 986 987 988 989 990
  });
  ```

## notifyFormsEnableUpdate

notifyFormsEnableUpdate(formIds: Array&lt;string&gt;, isEnableUpdate: boolean, callback: AsyncCallback&lt;void&gt;): void;

W
wusongqing 已提交
991
Instructs the widgets to enable or disable updates. This API uses an asynchronous callback to return the result.
Z
zengyawen 已提交
992

W
wusongqing 已提交
993
**System capability**
Z
zengyawen 已提交
994 995 996 997 998

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
999 1000 1001 1002 1003
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array&lt;string&gt; | Yes  | List of widget IDs.|
| isEnableUpdate | boolean | Yes  | Whether to enable update.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
Z
zengyawen 已提交
1004 1005 1006 1007 1008 1009

**Example**

  ```js
  var formIds = new Array("12400633174999288", "12400633174999289");
  formHost.notifyFormsEnableUpdate(formIds, true, (error, data) => {
W
wusongqing 已提交
1010 1011
      if (error.code) {
          console.log('formHost notifyFormsEnableUpdate, error:' + JSON.stringify(error));
Z
zengyawen 已提交
1012 1013 1014 1015 1016 1017 1018 1019
      }
  });
  ```

## notifyFormsEnableUpdate

notifyFormsEnableUpdate(formIds: Array&lt;string&gt;, isEnableUpdate: boolean): Promise&lt;void&gt;;

W
wusongqing 已提交
1020
Instructs the widgets to enable or disable updates. This API uses a promise to return the result.
Z
zengyawen 已提交
1021

W
wusongqing 已提交
1022
**System capability**
Z
zengyawen 已提交
1023 1024 1025 1026 1027

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
1028 1029 1030 1031
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array&lt;string&gt; | Yes  | List of widget IDs.|
| isEnableUpdate | boolean | Yes  | Whether to enable update.|
Z
zengyawen 已提交
1032 1033 1034

**Return value**

W
wusongqing 已提交
1035 1036 1037
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
Z
zengyawen 已提交
1038 1039 1040 1041 1042

**Example**

  ```js
  var formIds = new Array("12400633174999288", "12400633174999289");
W
wusongqing 已提交
1043 1044 1045 1046
  formHost.notifyFormsEnableUpdate(formIds, true).then(() => {
      console.log('formHost notifyFormsEnableUpdate success');
  }).catch((error) => {
      console.log('formHost notifyFormsEnableUpdate, error:' + JSON.stringify(error));
Z
zengyawen 已提交
1047 1048
  });
  ```