js-apis-formhost.md 30.5 KB
Newer Older
1 2
# FormHost

W
wusongqing 已提交
3 4
> **NOTE**
> 
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**
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.|
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));
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**
W
wusongqing 已提交
56 57 58

SystemCapability.Ability.Form

59 60
**Parameters**

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

W
wusongqing 已提交
65
**Return value**
66

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

W
wusongqing 已提交
71
**Parameters**
72 73 74

  ```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));
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**
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.|
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));
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.
115

W
wusongqing 已提交
116
**System capability**
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.|
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));
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.
144

W
wusongqing 已提交
145
**System capability**
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.|
155

W
wusongqing 已提交
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.|
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));
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.|
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));
197 198 199 200 201 202 203 204 205 206
      }
  });
  ```

## requestForm

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

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

W
wusongqing 已提交
207 208 209 210
**System capability**

SystemCapability.Ability.Form

211 212
**Parameters**

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

W
wusongqing 已提交
217
**Return value**
218

W
wusongqing 已提交
219 220 221
  | Type| Description|
  | -------- | -------- |
  | Promise<void> | Promise used to return the result indicating whether the API is successfully called.|
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));
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**
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.|
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));
258 259 260 261 262 263 264 265
      }
  });
  ```

## castTempForm

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

W
wusongqing 已提交
266 267
Converts a temporary widget to a normal one. This API uses a promise to return the result.

W
wusongqing 已提交
268
**System capability**
W
wusongqing 已提交
269 270

SystemCapability.Ability.Form
271 272 273

**Parameters**

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

W
wusongqing 已提交
278
**Return value**
279

W
wusongqing 已提交
280 281 282
  | Type| Description|
  | -------- | -------- |
  | Promise<void> | Promise used to return the result indicating whether the API is successfully called.|
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));
292 293 294 295 296
  });
  ```

## notifyVisibleForms

W
wusongqing 已提交
297
notifyVisibleForms(formIds: Array<string>, callback: AsyncCallback<void>): void;
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**
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.|
311 312 313 314

**Example**

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

## notifyVisibleForms

W
wusongqing 已提交
325
notifyVisibleForms(formIds: Array<string>): Promise<void>;
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**
W
wusongqing 已提交
330 331 332

SystemCapability.Ability.Form

333 334
**Parameters**

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

W
wusongqing 已提交
339
**Return value**
340

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

**Example**

  ```js
W
wusongqing 已提交
348
  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));
353 354 355 356 357
  });
  ```

## notifyInvisibleForms

W
wusongqing 已提交
358
notifyInvisibleForms(formIds: Array<string>, callback: AsyncCallback<void>): void;
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**
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.|
372 373 374 375

**Example**

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

## notifyInvisibleForms

W
wusongqing 已提交
386
notifyInvisibleForms(formIds: Array<string>): Promise<void>;
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**
W
wusongqing 已提交
391 392 393

SystemCapability.Ability.Form

394 395
**Parameters**

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

W
wusongqing 已提交
400
**Return value**
401

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

**Example**

  ```js
W
wusongqing 已提交
409
  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));
414 415 416 417 418
  });
  ```

## enableFormsUpdate

W
wusongqing 已提交
419
enableFormsUpdate(formIds: Array<string>, callback: AsyncCallback<void>): void;
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.
422

W
wusongqing 已提交
423
**System capability**
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.|
433 434 435 436

**Example**

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

## enableFormsUpdate

W
wusongqing 已提交
447
enableFormsUpdate(formIds: Array<string>): Promise<void>;
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.
450

W
wusongqing 已提交
451
**System capability**
W
wusongqing 已提交
452 453 454

SystemCapability.Ability.Form

455 456
**Parameters**

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

W
wusongqing 已提交
461
**Return value**
462

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

**Example**

  ```js
W
wusongqing 已提交
470
  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));
475 476 477 478 479
  });
  ```

## disableFormsUpdate

W
wusongqing 已提交
480
disableFormsUpdate(formIds: Array<string>, callback: AsyncCallback<void>): void;
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.
483

W
wusongqing 已提交
484
**System capability**
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.|
494 495 496 497

**Example**

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

## disableFormsUpdate

W
wusongqing 已提交
508
disableFormsUpdate(formIds: Array<string>): Promise<void>;
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.
511

W
wusongqing 已提交
512
**System capability**
W
wusongqing 已提交
513 514 515

SystemCapability.Ability.Form

516 517
**Parameters**

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

W
wusongqing 已提交
522
**Return value**
523

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

**Example**

  ```js
W
wusongqing 已提交
531
  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));
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**
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.|
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));
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**
573 574 575

SystemCapability.Ability.Form

W
wusongqing 已提交
576 577
**Return value**

W
wusongqing 已提交
578 579 580
  | Type| Description|
  | -------- | -------- |
  | Promise<void> | Promise used to return the result indicating whether the API is successfully called.|
W
wusongqing 已提交
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));
590 591 592 593 594
  });
  ```

## getAllFormsInfo

W
wusongqing 已提交
595
getAllFormsInfo(callback: AsyncCallback<Array<formInfo.FormInfo>>): void;
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**
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.|
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));
617 618 619 620 621 622
      }
  });
  ```

## getAllFormsInfo

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

625 626 627

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

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

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 已提交
641 642 643 644
  formHost.getAllFormsInfo().then((data) => {
      console.log('formHost getAllFormsInfo data:' + JSON.stringify(data));
  }).catch((error) => {
      console.log('formHost getAllFormsInfo, error:' + JSON.stringify(error));
645 646 647 648 649
  });
  ```

## getFormsInfo

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

652 653 654

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

W
wusongqing 已提交
655
**System capability**
656 657 658 659 660

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
661 662 663 664
  | 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.|
665 666 667 668

**Example**

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

## getFormsInfo

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

682 683 684

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

W
wusongqing 已提交
685
**System capability**
686 687 688 689 690

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
691 692 693 694 695
  | 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.|
696 697 698 699

**Example**

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

## getFormsInfo

W
wusongqing 已提交
711 712
getFormsInfo(bundleName: string, moduleName?: string): Promise<Array<formInfo.FormInfo>>;

713 714 715

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

W
wusongqing 已提交
716
**System capability**
717 718 719 720 721

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
722 723 724 725
  | Name| Type   | Mandatory| Description   |
  | ------ | ------ | ---- | ------- |
  | bundleName | string | Yes|  Bundle name of the target application.|
  | moduleName | string | No|  Module name.|
726 727 728 729 730 731 732 733 734 735

**Return value**

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

**Example**

  ```js
W
wusongqing 已提交
736 737 738 739
  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));
740 741 742 743 744 745 746 747 748
  });
  ```

## 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 已提交
749
**System capability**
750 751 752 753 754

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
755 756 757 758
| 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.|
759 760 761 762 763 764

**Example**

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

## deleteInvalidForms

W
wusongqing 已提交
775
deleteInvalidForms(formIds: Array<string>): Promise<number>;
776

W
wusongqing 已提交
777 778
Deletes invalid widgets from the list. This API uses a promise to return the result.

W
wusongqing 已提交
779
**System capability**
W
wusongqing 已提交
780 781

SystemCapability.Ability.Form
782 783 784

**Parameters**

W
wusongqing 已提交
785 786 787
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes  | List of valid widget IDs.|
788 789 790 791 792 793 794 795 796 797 798

**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 已提交
799 800 801 802
  formHost.deleteInvalidForms(formIds).then((data) => {
      console.log('formHost deleteInvalidForms, data:' + JSON.stringify(data));
  }).catch((error) => {
      console.log('formHost deleteInvalidForms, error:' + JSON.stringify(error));
803 804 805 806 807
  });
  ```

## acquireFormState

W
wusongqing 已提交
808
acquireFormState(want: Want, callback: AsyncCallback<formInfo.FormStateInfo>): void;
809 810 811

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

W
wusongqing 已提交
812
**System capability**
813 814 815 816 817 818 819

SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
W
wusongqing 已提交
820
| want | [Want](js-apis-application-Want.md) | Yes  | **Want** information carried to query the widget state.|
821 822 823 824 825 826
| callback | AsyncCallback<[FormStateInfo](js-apis-formInfo.md#formstateinfo)> | Yes| Callback used to return the widget state.|

**Example**

  ```js
  var want = {
W
wusongqing 已提交
827 828 829 830 831 832 833 834
      "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
      }
835 836
  };
  formHost.acquireFormState(want, (error, data) => {
W
wusongqing 已提交
837 838 839 840
      if (error.code) {
          console.log('formHost acquireFormState, error:' + JSON.stringify(error));
      } else {
          console.log('formHost acquireFormState, data:' + JSON.stringify(data));
841 842 843 844 845 846
      }
  });
  ```

## acquireFormState

W
wusongqing 已提交
847
acquireFormState(want: Want): Promise<formInfo.FormStateInfo>;
848 849 850 851 852

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

**Parameters**

W
wusongqing 已提交
853 854 855
| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| want   | [Want](js-apis-application-Want.md) | Yes  | **Want** information carried to query the widget state.|
856 857 858 859 860 861 862

**Return value**

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

W
wusongqing 已提交
863
**System capability**
864 865 866 867 868 869 870

SystemCapability.Ability.Form

**Example**

  ```js
  var want = {
W
wusongqing 已提交
871 872 873 874 875 876 877 878
      "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
      }
879
  };
W
wusongqing 已提交
880 881 882 883
  formHost.acquireFormState(want).then((data) => {
      console.log('formHost acquireFormState, data:' + JSON.stringify(data));
  }).catch((error) => {
      console.log('formHost acquireFormState, error:' + JSON.stringify(error));
884 885 886 887 888 889 890
  });
  ```

## on("formUninstall")

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

W
wusongqing 已提交
891
Subscribes to widget uninstall events.
892

W
wusongqing 已提交
893
**System capability**
894 895 896 897 898

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
899 900 901 902
| 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.|
903 904 905 906

**Example**

  ```js
W
wusongqing 已提交
907 908 909 910
  let callback = function(formId) {
      console.log('formHost on formUninstall, formId:' + formId);
  }
  formHost.on("formUninstall", callback);
911 912 913 914
  ```

## off("formUninstall")

W
wusongqing 已提交
915
off(type: "formUninstall", callback?: Callback<string>): void;
916

W
wusongqing 已提交
917
Unsubscribes from widget uninstall events.
918

W
wusongqing 已提交
919
**System capability**
920 921 922 923 924

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
925 926 927 928
| 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.|
929 930 931 932

**Example**

  ```js
W
wusongqing 已提交
933 934 935 936
  let callback = function(formId) {
      console.log('formHost on formUninstall, formId:' + formId);
  }
  formHost.off("formUninstall", callback);
937 938 939 940 941 942 943 944
  ```

## 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 已提交
945
**System capability**
946 947 948 949 950

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
951 952 953 954 955
| 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.|
956 957 958 959 960 961

**Example**

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

## 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 已提交
974
**System capability**
975 976 977 978 979

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
980 981 982 983
  | Name| Type   | Mandatory| Description   |
  | ------ | ------ | ---- | ------- |
  | formIds | Array<string> | Yes  | List of widget IDs.|
  | isVisible | boolean | Yes  | Whether to be visible.|
984

W
wusongqing 已提交
985 986
**Return value**

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

991 992 993 994
**Example**

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

## notifyFormsEnableUpdate

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

W
wusongqing 已提交
1006
Instructs the widgets to enable or disable updates. This API uses an asynchronous callback to return the result.
1007

W
wusongqing 已提交
1008
**System capability**
1009 1010 1011 1012 1013

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
1014 1015 1016 1017 1018
| 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.|
1019 1020 1021 1022 1023 1024

**Example**

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

## notifyFormsEnableUpdate

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

W
wusongqing 已提交
1035
Instructs the widgets to enable or disable updates. This API uses a promise to return the result.
1036

W
wusongqing 已提交
1037
**System capability**
1038 1039 1040 1041 1042

SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
1043 1044 1045 1046
  | Name| Type   | Mandatory| Description   |
  | ------ | ------ | ---- | ------- |
  | formIds | Array<string> | Yes  | List of widget IDs.|
  | isEnableUpdate | boolean | Yes  | Whether to enable update.|
1047

W
wusongqing 已提交
1048 1049
**Return value**

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

1054 1055 1056 1057
**Example**

  ```js
  var formIds = new Array("12400633174999288", "12400633174999289");
W
wusongqing 已提交
1058 1059 1060 1061
  formHost.notifyFormsEnableUpdate(formIds, true).then(() => {
      console.log('formHost notifyFormsEnableUpdate success');
  }).catch((error) => {
      console.log('formHost notifyFormsEnableUpdate, error:' + JSON.stringify(error));
1062 1063
  });
  ```