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

W
wusongqing 已提交
3 4
> **NOTE**
>
Z
zengyawen 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
> 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<void>): 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 已提交
27
**System capability**
Z
zengyawen 已提交
28 29 30 31 32

SystemCapability.Ability.Form

**Parameters**

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

**Example**

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

## deleteForm

deleteForm(formId: string): Promise<void>;

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 已提交
55
**System capability**
Z
zengyawen 已提交
56 57 58 59 60

SystemCapability.Ability.Form

**Parameters**

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

**Return value**

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

**Parameters**

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

## releaseForm

releaseForm(formId: string, callback: AsyncCallback<void>): 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 已提交
88
**System capability**
Z
zengyawen 已提交
89 90 91 92 93

SystemCapability.Ability.Form

**Parameters**

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

**Example**

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

## releaseForm

releaseForm(formId: string, isReleaseCache: boolean, callback: AsyncCallback<void>): void;

W
wusongqing 已提交
114
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 已提交
115

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

SystemCapability.Ability.Form

**Parameters**

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

**Example**

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

## releaseForm

releaseForm(formId: string, isReleaseCache?: boolean): Promise<void>;

W
wusongqing 已提交
143
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 已提交
144

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

SystemCapability.Ability.Form

**Parameters**

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

**Return value**

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

**Example**

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

## requestForm

requestForm(formId: string, callback: AsyncCallback<void>): void;

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

**System capability**

SystemCapability.Ability.Form

**Parameters**

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

**Example**

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

## requestForm

requestForm(formId: string): Promise<void>;

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

**System capability**

SystemCapability.Ability.Form

**Parameters**

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

**Return value**

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

**Example**

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

## castTempForm

castTempForm(formId: string, callback: AsyncCallback<void>): void;

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

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

SystemCapability.Ability.Form

**Parameters**

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

**Example**

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

## castTempForm

castTempForm(formId: string): Promise<void>;

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

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

SystemCapability.Ability.Form

**Parameters**

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

**Return value**

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

**Example**

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

## notifyVisibleForms

W
wusongqing 已提交
297
notifyVisibleForms(formIds: Array<string>, callback: AsyncCallback<void>): void;
Z
zengyawen 已提交
298 299 300

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 已提交
301
**System capability**
Z
zengyawen 已提交
302 303 304 305 306

SystemCapability.Ability.Form

**Parameters**

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

**Example**

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

## notifyVisibleForms

W
wusongqing 已提交
325
notifyVisibleForms(formIds: Array<string>): Promise<void>;
Z
zengyawen 已提交
326 327 328

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 已提交
329
**System capability**
Z
zengyawen 已提交
330 331 332 333 334

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
335 336 337
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes  | List of widget IDs.|
Z
zengyawen 已提交
338 339 340

**Return value**

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

**Example**

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

## notifyInvisibleForms

W
wusongqing 已提交
358
notifyInvisibleForms(formIds: Array<string>, callback: AsyncCallback<void>): void;
Z
zengyawen 已提交
359 360 361

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 已提交
362
**System capability**
Z
zengyawen 已提交
363 364 365 366 367

SystemCapability.Ability.Form

**Parameters**

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

**Example**

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

## notifyInvisibleForms

W
wusongqing 已提交
386
notifyInvisibleForms(formIds: Array<string>): Promise<void>;
Z
zengyawen 已提交
387 388 389

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 已提交
390
**System capability**
Z
zengyawen 已提交
391 392 393 394 395

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
396 397 398
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes  | List of widget IDs.|
Z
zengyawen 已提交
399 400 401

**Return value**

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

**Example**

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

## enableFormsUpdate

W
wusongqing 已提交
419
enableFormsUpdate(formIds: Array<string>, callback: AsyncCallback<void>): void;
Z
zengyawen 已提交
420

W
wusongqing 已提交
421
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 已提交
422

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

SystemCapability.Ability.Form

**Parameters**

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

**Example**

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

## enableFormsUpdate

W
wusongqing 已提交
447
enableFormsUpdate(formIds: Array<string>): Promise<void>;
Z
zengyawen 已提交
448

W
wusongqing 已提交
449
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 已提交
450

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

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
457 458 459
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes  | List of widget IDs.|
Z
zengyawen 已提交
460 461 462

**Return value**

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

**Example**

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

## disableFormsUpdate

W
wusongqing 已提交
480
disableFormsUpdate(formIds: Array<string>, callback: AsyncCallback<void>): void;
Z
zengyawen 已提交
481

W
wusongqing 已提交
482
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 已提交
483

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

SystemCapability.Ability.Form

**Parameters**

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

**Example**

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

## disableFormsUpdate

W
wusongqing 已提交
508
disableFormsUpdate(formIds: Array<string>): Promise<void>;
Z
zengyawen 已提交
509

W
wusongqing 已提交
510
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 已提交
511

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

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
518 519 520
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes  | List of widget IDs.|
Z
zengyawen 已提交
521 522 523

**Return value**

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

**Example**

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

## isSystemReady

isSystemReady(callback: AsyncCallback<void>): void;

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

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

SystemCapability.Ability.Form

**Parameters**

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

**Example**

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

## isSystemReady

isSystemReady(): Promise<void>;

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

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

SystemCapability.Ability.Form

**Return value**

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

**Example**

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

## getAllFormsInfo

W
wusongqing 已提交
595
getAllFormsInfo(callback: AsyncCallback<Array<formInfo.FormInfo>>): void;
Z
zengyawen 已提交
596 597 598

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

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

SystemCapability.Ability.Form

**Parameters**

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

**Example**

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

## getAllFormsInfo

W
wusongqing 已提交
623
getAllFormsInfo(): Promise<Array<formInfo.FormInfo>>;
Z
zengyawen 已提交
624 625 626

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

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

SystemCapability.Ability.Form

**Return value**

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

**Example**

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

## getFormsInfo

W
wusongqing 已提交
649
getFormsInfo(bundleName: string, callback: AsyncCallback<Array<formInfo.FormInfo>>): void;
Z
zengyawen 已提交
650 651 652

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

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

SystemCapability.Ability.Form

**Parameters**

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

**Example**

  ```js
W
wusongqing 已提交
667 668 669 670 671
  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 已提交
672 673 674 675 676 677
      }
  });
  ```

## getFormsInfo

W
wusongqing 已提交
678
getFormsInfo(bundleName: string, moduleName: string, callback: AsyncCallback<Array<formInfo.FormInfo>>): void;
Z
zengyawen 已提交
679 680 681

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

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

SystemCapability.Ability.Form

**Parameters**

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

**Example**

  ```js
W
wusongqing 已提交
697 698 699 700 701
  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 已提交
702 703 704 705 706 707
      }
  });
  ```

## getFormsInfo

W
wusongqing 已提交
708
getFormsInfo(bundleName: string, moduleName?: string): Promise<Array<formInfo.FormInfo>>;
Z
zengyawen 已提交
709 710 711

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

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

SystemCapability.Ability.Form

**Parameters**

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

**Return value**

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

**Example**

  ```js
W
wusongqing 已提交
732 733 734 735
  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 已提交
736 737 738 739 740 741 742 743 744
  });
  ```

## deleteInvalidForms

deleteInvalidForms(formIds: Array<string>, callback: AsyncCallback<number>): void;

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

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

SystemCapability.Ability.Form

**Parameters**

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

**Example**

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

## deleteInvalidForms

W
wusongqing 已提交
771
deleteInvalidForms(formIds: Array<string>): Promise<number>;
Z
zengyawen 已提交
772 773 774

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

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

SystemCapability.Ability.Form

**Parameters**

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

**Return value**

| Type         | Description                               |
| :------------ | :---------------------------------- |
| Promise<number> | Promise used to return the number of widgets deleted.|

**Example**

  ```js
  var formIds = new Array("12400633174999288", "12400633174999289");
W
wusongqing 已提交
795 796 797 798
  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 已提交
799 800 801 802 803
  });
  ```

## acquireFormState

W
wusongqing 已提交
804
acquireFormState(want: Want, callback: AsyncCallback<formInfo.FormStateInfo>): void;
Z
zengyawen 已提交
805 806 807

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

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

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<[FormStateInfo](js-apis-formInfo.md#formstateinfo)> | Yes| Callback used to return the widget state.|

**Example**

  ```js
  var want = {
W
wusongqing 已提交
823 824 825 826 827 828 829 830
      "deviceId": "",
      "bundleName": "ohos.samples.FormApplication",
      "abilityName": "FormAbility",
      "parameters": {
          "ohos.extra.param.key.module_name": "entry",
          "ohos.extra.param.key.form_name": "widget",
          "ohos.extra.param.key.form_dimension": 2
      }
Z
zengyawen 已提交
831 832
  };
  formHost.acquireFormState(want, (error, data) => {
W
wusongqing 已提交
833 834 835 836
      if (error.code) {
          console.log('formHost acquireFormState, error:' + JSON.stringify(error));
      } else {
          console.log('formHost acquireFormState, data:' + JSON.stringify(data));
Z
zengyawen 已提交
837 838 839 840 841 842
      }
  });
  ```

## acquireFormState

W
wusongqing 已提交
843
acquireFormState(want: Want): Promise<formInfo.FormStateInfo>;
Z
zengyawen 已提交
844 845 846 847 848

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

**Parameters**

W
wusongqing 已提交
849 850 851
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| want   | [Want](js-apis-featureAbility.md#want) | Yes  | **Want** information carried to query the widget state.|
Z
zengyawen 已提交
852 853 854 855 856 857 858

**Return value**

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

W
wusongqing 已提交
859
**System capability**
Z
zengyawen 已提交
860 861 862 863 864 865 866

SystemCapability.Ability.Form

**Example**

  ```js
  var want = {
W
wusongqing 已提交
867 868 869 870 871 872 873 874
      "deviceId": "",
      "bundleName": "ohos.samples.FormApplication",
      "abilityName": "FormAbility",
      "parameters": {
          "ohos.extra.param.key.module_name": "entry",
          "ohos.extra.param.key.form_name": "widget",
          "ohos.extra.param.key.form_dimension": 2
      }
Z
zengyawen 已提交
875
  };
W
wusongqing 已提交
876 877 878 879
  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 已提交
880 881 882 883 884 885 886 887 888
  });
  ```

## on("formUninstall")

on(type: "formUninstall", callback: Callback<string>): void;

Subscribes to widget uninstall events.

W
wusongqing 已提交
889
**System capability**
Z
zengyawen 已提交
890 891 892 893 894

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
895 896 897 898
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| type | string | Yes  | Type of event to subscribe to. The value **formUninstall** indicates a widget uninstallation event.|
| callback | Callback<string> | Yes| Callback used for event subscription.|
Z
zengyawen 已提交
899 900 901 902

**Example**

  ```js
W
wusongqing 已提交
903 904 905 906
  let callback = function(formId) {
      console.log('formHost on formUninstall, formId:' + formId);
  }
  formHost.on("formUninstall", callback);
Z
zengyawen 已提交
907 908 909 910
  ```

## off("formUninstall")

W
wusongqing 已提交
911
off(type: "formUninstall", callback?: Callback<string>): void;
Z
zengyawen 已提交
912 913 914

Unsubscribes from widget uninstall events.

W
wusongqing 已提交
915
**System capability**
Z
zengyawen 已提交
916 917 918 919 920

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
921 922 923 924
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| type | string | Yes  | Type of event to subscribe to. The value **formUninstall** indicates a widget uninstallation event.|
| callback | Callback<string> | 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 已提交
925 926 927 928

**Example**

  ```js
W
wusongqing 已提交
929 930 931 932
  let callback = function(formId) {
      console.log('formHost on formUninstall, formId:' + formId);
  }
  formHost.off("formUninstall", callback);
Z
zengyawen 已提交
933 934 935 936 937 938 939 940
  ```

## notifyFormsVisible

notifyFormsVisible(formIds: Array<string>, isVisible: boolean, callback: AsyncCallback<void>): void;

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

W
wusongqing 已提交
941
**System capability**
Z
zengyawen 已提交
942 943 944 945 946

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
947 948 949 950 951
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes  | List of widget IDs.|
| isVisible | boolean | Yes  | Whether to be visible.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
Z
zengyawen 已提交
952 953 954 955 956 957

**Example**

  ```js
  var formIds = new Array("12400633174999288", "12400633174999289");
  formHost.notifyFormsVisible(formIds, true, (error, data) => {
W
wusongqing 已提交
958 959
      if (error.code) {
          console.log('formHost notifyFormsVisible, error:' + JSON.stringify(error));
Z
zengyawen 已提交
960 961 962 963 964 965 966 967 968 969
      }
  });
  ```

## notifyFormsVisible

notifyFormsVisible(formIds: Array<string>, isVisible: boolean): Promise<void>;

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

W
wusongqing 已提交
970
**System capability**
Z
zengyawen 已提交
971 972 973 974 975

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
976 977 978 979
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes  | List of widget IDs.|
| isVisible | boolean | Yes  | Whether to be visible.|
Z
zengyawen 已提交
980 981 982

**Return value**

W
wusongqing 已提交
983 984 985
| Type| Description|
| -------- | -------- |
| Promise<void> | Promise used to return the result indicating whether the API is successfully called.|
Z
zengyawen 已提交
986 987 988 989 990

**Example**

  ```js
  var formIds = new Array("12400633174999288", "12400633174999289");
W
wusongqing 已提交
991 992 993 994
  formHost.notifyFormsVisible(formIds, true).then(() => {
      console.log('formHost notifyFormsVisible success');
  }).catch((error) => {
      console.log('formHost notifyFormsVisible, error:' + JSON.stringify(error));
Z
zengyawen 已提交
995 996 997 998 999 1000 1001
  });
  ```

## notifyFormsEnableUpdate

notifyFormsEnableUpdate(formIds: Array<string>, isEnableUpdate: boolean, callback: AsyncCallback<void>): void;

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

W
wusongqing 已提交
1004
**System capability**
Z
zengyawen 已提交
1005 1006 1007 1008 1009

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
1010 1011 1012 1013 1014
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes  | List of widget IDs.|
| isEnableUpdate | boolean | Yes  | Whether to enable update.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
Z
zengyawen 已提交
1015 1016 1017 1018 1019 1020

**Example**

  ```js
  var formIds = new Array("12400633174999288", "12400633174999289");
  formHost.notifyFormsEnableUpdate(formIds, true, (error, data) => {
W
wusongqing 已提交
1021 1022
      if (error.code) {
          console.log('formHost notifyFormsEnableUpdate, error:' + JSON.stringify(error));
Z
zengyawen 已提交
1023 1024 1025 1026 1027 1028 1029 1030
      }
  });
  ```

## notifyFormsEnableUpdate

notifyFormsEnableUpdate(formIds: Array<string>, isEnableUpdate: boolean): Promise<void>;

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

W
wusongqing 已提交
1033
**System capability**
Z
zengyawen 已提交
1034 1035 1036 1037 1038

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
1039 1040 1041 1042
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes  | List of widget IDs.|
| isEnableUpdate | boolean | Yes  | Whether to enable update.|
Z
zengyawen 已提交
1043 1044 1045

**Return value**

W
wusongqing 已提交
1046 1047 1048
| Type| Description|
| -------- | -------- |
| Promise<void> | Promise used to return the result indicating whether the API is successfully called.|
Z
zengyawen 已提交
1049 1050 1051 1052 1053

**Example**

  ```js
  var formIds = new Array("12400633174999288", "12400633174999289");
W
wusongqing 已提交
1054 1055 1056 1057
  formHost.notifyFormsEnableUpdate(formIds, true).then(() => {
      console.log('formHost notifyFormsEnableUpdate success');
  }).catch((error) => {
      console.log('formHost notifyFormsEnableUpdate, error:' + JSON.stringify(error));
Z
zengyawen 已提交
1058 1059
  });
  ```