js-apis-app-form-formHost.md 60.5 KB
Newer Older
G
Gloria 已提交
1
# @ohos.app.form.formHost (formHost)
2

G
Gloria 已提交
3
The **formHost** module provides APIs related to the widget host, which is an application that displays the widget content and controls the position where the widget is displayed. You can use the APIs to delete, release, and update widgets installed by the same user, and obtain widget information and status.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs provided by this module are system APIs.

## Modules to Import

```ts
import formHost from '@ohos.app.form.formHost';
```

## deleteForm

deleteForm(formId: string, callback: AsyncCallback<void>): void

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

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formId | string | Yes  | Widget ID.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is deleted, **error** is undefined; otherwise, **error** is an error object.|

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
37
| 201 | Permissions denied. |
38
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
39 40 41 42 43 44 45
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 202 | The application is not a system application. |
| 16501000 | An internal functional error occurred. |
| 16501001 | The ID of the form to be operated does not exist. |
| 16501003 | The form can not be operated by the current application. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
46 47 48 49 50

**Example**

```ts
try {
51 52
  var formId = '12400633174999288';
  formHost.deleteForm(formId, (error, data) => {
53
  if (error) {
54
    console.log('formHost deleteForm, error:' + JSON.stringify(error));
55 56 57 58 59
  } else {
    console.log('formHost deleteForm success');
  }
  });
} catch (error) {
60
  console.log(`catch err->${JSON.stringify(error)}`);
61
}
62

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
```

## deleteForm

deleteForm(formId: string): Promise<void>

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

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formId | string | Yes  | Widget ID.|

**Return value**

| Type| Description|
| -------- | -------- |
| Promise<void> | Promise that returns no value.|


**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
92 93
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
94
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
95 96 97 98 99 100
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16501000 | An internal functional error occurred. |
| 16501001 | The ID of the form to be operated does not exist. |
| 16501003 | The form can not be operated by the current application. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
101

G
Gloria 已提交
102
**Example**
103 104 105

```ts
try {
106
  var formId = '12400633174999288';
107 108 109
  formHost.deleteForm(formId).then(() => {
    console.log('formHost deleteForm success');
  }).catch((error) => {
110
    console.log('formHost deleteForm, error:' + JSON.stringify(error));
111 112
  });
} catch(error) {
113
  console.log(`catch err->${JSON.stringify(error)}`);
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
}
```

## releaseForm

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

Releases a widget. 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. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formId | string | Yes  | Widget ID.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is released, **error** is undefined; otherwise, **error** is an error object.|

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
138 139
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
140
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
141 142 143 144 145 146
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16501000 | An internal functional error occurred. |
| 16501001 | The ID of the form to be operated does not exist. |
| 16501003 | The form can not be operated by the current application. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
147 148 149 150 151

**Example**

```ts
try {
152 153
  var formId = '12400633174999288';
  formHost.releaseForm(formId, (error, data) => {
154
    if (error) {
155
      console.log('formHost releaseForm, error:' + JSON.stringify(error));
156 157 158
    }
  });
} catch(error) {
159
    console.log(`catch err->${JSON.stringify(error)}`);
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
}
```

## releaseForm

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

Releases a widget. 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. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name        | Type    | Mandatory| Description       |
| -------------- | ------  | ---- | ----------- |
| formId         | string  | Yes  | Widget ID.    |
| isReleaseCache | boolean | Yes  | Whether to release the cache.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is released, **error** is undefined; otherwise, **error** is an error object.|

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
185 186
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
187
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
188 189 190 191 192 193
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16501000 | An internal functional error occurred. |
| 16501001 | The ID of the form to be operated does not exist. |
| 16501003 | The form can not be operated by the current application. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
194 195 196 197 198

**Example**

```ts
try {
199 200
  var formId = '12400633174999288';
  formHost.releaseForm(formId, true, (error, data) => {
201
    if (error) {
202
      console.log('formHost releaseForm, error:' + JSON.stringify(error));
203 204 205
    }
  });
} catch(error) {
206
    console.log(`catch err->${JSON.stringify(error)}`);
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
}
```

## releaseForm

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

Releases a widget. 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. This API uses a promise to return the result.

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name        | Type    | Mandatory| Description       |
| -------------- | ------  | ---- | ----------- |
| formId         | string  | Yes  | Widget ID.    |
G
Gloria 已提交
225
| isReleaseCache | boolean | No  | Whether to release the cache. The default value is **false**. |
226 227 228 229 230 231 232 233 234 235 236

**Return value**

| Type| Description|
| -------- | -------- |
| Promise<void> | Promise that returns no value.|

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
237 238
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
239
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
240 241 242 243 244 245
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16501000 | An internal functional error occurred. |
| 16501001 | The ID of the form to be operated does not exist. |
| 16501003 | The form can not be operated by the current application. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
246 247 248 249 250

**Example**

```ts
try {
251
  var formId = '12400633174999288';
252 253 254
  formHost.releaseForm(formId, true).then(() => {
    console.log('formHost releaseForm success');
  }).catch((error) => {
255
    console.log('formHost releaseForm, error:' + JSON.stringify(error));
256 257
  });
} catch(error) {
258
    console.log(`catch err->${JSON.stringify(error)}`);
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
}
```

## requestForm

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

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

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formId | string | Yes  | Widget ID.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is updated, **error** is undefined; otherwise, **error** is an error object.|

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
283 284
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
285
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
286 287 288 289 290 291
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16501000 | An internal functional error occurred. |
| 16501001 | The ID of the form to be operated does not exist. |
| 16501003 | The form can not be operated by the current application. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
292 293 294 295 296

**Example**

```ts
try {
297 298
  var formId = '12400633174999288';
  formHost.requestForm(formId, (error, data) => {
299
    if (error) {
300
      console.log('formHost requestForm, error:' + JSON.stringify(error));
301 302 303
    }
  });
} catch(error) {
304
    console.log(`catch err->${JSON.stringify(error)}`);
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
}
```

## requestForm

requestForm(formId: string): Promise<void>

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

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formId | string | Yes  | Widget ID.|

**Return value**

| Type| Description|
| -------- | -------- |
| Promise<void> | Promise that returns no value.|

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
334 335
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
336
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
337 338 339 340 341 342
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16501000 | An internal functional error occurred. |
| 16501001 | The ID of the form to be operated does not exist. |
| 16501003 | The form can not be operated by the current application. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
343 344 345 346 347

**Example**

```ts
try {
348
  var formId = '12400633174999288';
349 350 351
  formHost.requestForm(formId).then(() => {
    console.log('formHost requestForm success');
  }).catch((error) => {
352
    console.log('formHost requestForm, error:' + JSON.stringify(error));
353 354
  });
} catch(error) {
355
    console.log(`catch err->${JSON.stringify(error)}`);
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
}

```

## castToNormalForm

castToNormalForm(formId: string, callback: AsyncCallback<void>): void

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

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formId | string | Yes  | Widget ID.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is converted to a normal one, **error** is undefined; otherwise, **error** is an error object.|

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
381 382
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
383
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
384 385 386 387 388 389
| 16500050 | An IPC connection error happened. |
| 16501000 | An internal functional error occurred. |
| 16501001 | The ID of the form to be operated does not exist. |
| 16501002 | The number of forms exceeds upper bound. |
| 16501003 | The form can not be operated by the current application. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
390 391 392 393 394

**Example**

```ts
try {
395 396
  var formId = '12400633174999288';
  formHost.castToNormalForm(formId, (error, data) => {
397
    if (error) {
398
      console.log('formHost castTempForm, error:' + JSON.stringify(error));
399 400 401
    }
  });
} catch(error) {
402
    console.log(`catch err->${JSON.stringify(error)}`);
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
}
```

## castToNormalForm

castToNormalForm(formId: string): Promise<void>

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

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formId | string | Yes  | Widget ID.|

**Return value**

| Type| Description|
| -------- | -------- |
| Promise<void> | Promise that returns no value.|

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
432 433
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
434
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
435 436 437 438 439 440
| 16500050 | An IPC connection error happened. |
| 16501000 | An internal functional error occurred. |
| 16501001 | The ID of the form to be operated does not exist. |
| 16501002 | The number of forms exceeds upper bound. |
| 16501003 | The form can not be operated by the current application. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
441 442 443 444 445

**Example**

```ts
try {
446
  var formId = '12400633174999288';
447 448 449
  formHost.castToNormalForm(formId).then(() => {
    console.log('formHost castTempForm success');
  }).catch((error) => {
450
    console.log('formHost castTempForm, error:' + JSON.stringify(error));
451 452
  });
} catch(error) {
453
    console.log(`catch err->${JSON.stringify(error)}`);
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
}
```

## notifyVisibleForms

notifyVisibleForms(formIds: Array<string>, callback: AsyncCallback<void>): void

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

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds  | Array<string>       | Yes  | List of widget IDs.        |
| callback | AsyncCallback<void> | Yes| Callback used to return the result. If a notification is sent to the widget framework to make the widget visible, **error** is undefined; otherwise, **error** is an error object.|

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
478 479
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
480
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
481 482 483 484
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16501000 | An internal functional error occurred. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
485 486 487 488 489

**Example**

```ts
try {
490 491
  var formId = ['12400633174999288'];
  formHost.notifyVisibleForms(formId, (error, data) => {
492
    if (error) {
493
      console.log('formHost notifyVisibleForms, error:' + JSON.stringify(error));
494 495 496
    }
  });
} catch(error) {
497
    console.log(`catch err->${JSON.stringify(error)}`);
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526
}
```

## notifyVisibleForms

notifyVisibleForms(formIds: Array<string>): Promise<void>

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

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes  | List of widget IDs.|

**Return value**

| Type| Description|
| -------- | -------- |
| Promise<void> | Promise that returns no value.|

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
527 528
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
529
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
530 531 532 533
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16501000 | An internal functional error occurred. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
534 535 536 537 538

**Example**

```ts
try {
539
  var formId = ['12400633174999288'];
540 541 542
  formHost.notifyVisibleForms(formId).then(() => {
    console.log('formHost notifyVisibleForms success');
  }).catch((error) => {
543
    console.log('formHost notifyVisibleForms, error:' + JSON.stringify(error));
544 545
  });
} catch(error) {
546
    console.log(`catch err->${JSON.stringify(error)}`);
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
}
```

## notifyInvisibleForms

notifyInvisibleForms(formIds: Array<string>, callback: AsyncCallback<void>): void

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

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds  | Array<string>       | Yes  | List of widget IDs.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result. If a notification is sent to the widget framework to make the widget invisible, **error** is undefined; otherwise, **error** is an error object.|

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
571 572
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
573
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
574 575 576 577
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16501000 | An internal functional error occurred. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
578 579 580 581 582

**Example**

```ts
try {
583 584
  var formId = ['12400633174999288'];
  formHost.notifyInvisibleForms(formId, (error, data) => {
585
    if (error) {
586
      console.log('formHost notifyInvisibleForms, error:' + JSON.stringify(error));
587 588 589
    }
  });
} catch(error) {
590
    console.log(`catch err->${JSON.stringify(error)}`);
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
}
```

## notifyInvisibleForms

notifyInvisibleForms(formIds: Array<string>): Promise<void>

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

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes  | List of widget IDs.|

**Return value**

| Type| Description|
| -------- | -------- |
| Promise<void> | Promise that returns no value.|

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
620 621
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
622
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
623 624 625 626
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16501000 | An internal functional error occurred. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
627 628 629 630 631

**Example**

```ts
try {
632
  var formId = ['12400633174999288'];
633 634 635
  formHost.notifyInvisibleForms(formId).then(() => {
    console.log('formHost notifyInvisibleForms success');
  }).catch((error) => {
636
    console.log('formHost notifyInvisibleForms, error:' + JSON.stringify(error));
637 638
  });
} catch(error) {
639
    console.log(`catch err->${JSON.stringify(error)}`);
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
}
```

## enableFormsUpdate

enableFormsUpdate(formIds: Array<string>, callback: AsyncCallback<void>): void

Instructs the widget framework to make a widget updatable. After this API is called, the widget is in the enabled state and can receive updates from the widget provider. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds  | Array<string>       | Yes  | List of widget IDs.        |
| callback | AsyncCallback<void> | Yes| Callback used to return the result. If a notification is sent to the widget framework to make the widget updatable, **error** is undefined; otherwise, **error** is an error object.|

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
664 665
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
666
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
667 668 669 670 671
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16501000 | An internal functional error occurred. |
| 16501003 | The form can not be operated by the current application. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
672 673 674 675 676

**Example**

```ts
try {
677 678
  var formId = ['12400633174999288'];
  formHost.enableFormsUpdate(formId, (error, data) => {
679
    if (error) {
680
      console.log('formHost enableFormsUpdate, error:' + JSON.stringify(error));
681 682 683
    }
  });
} catch(error) {
684
    console.log(`catch err->${JSON.stringify(error)}`);
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713
}
```

## enableFormsUpdate

enableFormsUpdate(formIds: Array<string>): Promise<void>

Instructs the widget framework to make a widget updatable. After this API is called, the widget is in the enabled state and can receive updates from the widget provider. This API uses a promise to return the result.

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes  | List of widget IDs.|

**Return value**

| Type| Description|
| -------- | -------- |
| Promise<void> | Promise that returns no value.|

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
714 715
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
716
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
717 718 719 720 721
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16501000 | An internal functional error occurred. |
| 16501003 | The form can not be operated by the current application. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
722 723 724 725 726

**Example**

```ts
try {
727
  var formId = ['12400633174999288'];
728 729 730
  formHost.enableFormsUpdate(formId).then(() => {
    console.log('formHost enableFormsUpdate success');
  }).catch((error) => {
731
    console.log('formHost enableFormsUpdate, error:' + JSON.stringify(error));
732 733
  });
} catch(error) {
734
    console.log(`catch err->${JSON.stringify(error)}`);
735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758
}
```

## disableFormsUpdate

disableFormsUpdate(formIds: Array<string>, callback: AsyncCallback<void>): void

Instructs the widget framework to make a widget not updatable. After this API is called, the widget cannot receive updates from the widget provider. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds  | Array<string>       | Yes  | List of widget IDs.        |
| callback | AsyncCallback<void> | Yes| Callback used to return the result. If a notification is sent to the widget framework to make the widget not updatable, **error** is undefined; otherwise, **error** is an error object.|

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
759 760
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
761
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
762 763 764 765 766 767
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16501000 | An internal functional error occurred. |
| 16501001 | The ID of the form to be operated does not exist. |
| 16501003 | The form can not be operated by the current application. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
768 769 770 771 772

**Example**

```ts
try {
773 774
  var formId = ['12400633174999288'];
  formHost.disableFormsUpdate(formId, (error, data) => {
775
    if (error) {
776
      console.log('formHost disableFormsUpdate, error:' + JSON.stringify(error));
777 778 779
    }
  });
} catch(error) {
780
    console.log(`catch err->${JSON.stringify(error)}`);
781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809
}
```

## disableFormsUpdate

disableFormsUpdate(formIds: Array<string>): Promise<void>

Instructs the widget framework to make a widget not updatable. After this API is called, the widget cannot receive updates from the widget provider. This API uses a promise to return the result.

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes  | List of widget IDs.|

**Return value**

| Type| Description|
| -------- | -------- |
| Promise<void> | Promise that returns no value.|

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
810 811
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
812
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
813 814 815 816 817 818
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16501000 | An internal functional error occurred. |
| 16501001 | The ID of the form to be operated does not exist. |
| 16501003 | The form can not be operated by the current application. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
819 820 821 822 823

**Example**

```ts
try {
824
  var formId = ['12400633174999288'];
825 826 827
  formHost.disableFormsUpdate(formId).then(() => {
    console.log('formHost disableFormsUpdate success');
  }).catch((error) => {
828
    console.log('formHost disableFormsUpdate, error:' + JSON.stringify(error));
829 830
  });
} catch(error) {
831
    console.log(`catch err->${JSON.stringify(error)}`);
832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848
}
```

## isSystemReady

isSystemReady(callback: AsyncCallback<void>): void

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

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the check is successful, **error** is undefined; otherwise, **error** is an error object.|

G
Gloria 已提交
849 850 851 852 853 854 855 856
**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
| 202 | The application is not a system application.   |
| 401 | If the input parameter is not valid parameter. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||

857 858 859 860
**Example**

```ts
try {
861
  var formId = '12400633174999288';
862 863
  formHost.isSystemReady((error, data) => {
    if (error) {
864
      console.log('formHost isSystemReady, error:' + JSON.stringify(error));
865 866 867
    }
  });
} catch(error) {
868
    console.log(`catch err->${JSON.stringify(error)}`);
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885
}
```

## isSystemReady

isSystemReady(): Promise<void>

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

**System capability**: SystemCapability.Ability.Form

**Return value**

| Type| Description|
| -------- | -------- |
| Promise<void> | Promise that returns no value.|

G
Gloria 已提交
886 887 888 889 890 891 892
**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
| 202 | The application is not a system application.   |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||

893 894 895 896
**Example**

```ts
try {
897
  var formId = '12400633174999288';
898 899 900
  formHost.isSystemReady().then(() => {
    console.log('formHost isSystemReady success');
  }).catch((error) => {
901
    console.log('formHost isSystemReady, error:' + JSON.stringify(error));
902 903
  });
} catch(error) {
904
    console.log(`catch err->${JSON.stringify(error)}`);
905 906 907 908 909 910 911 912 913 914 915 916 917
}
```

## getAllFormsInfo

getAllFormsInfo(callback: AsyncCallback<Array<formInfo.FormInfo>>): void

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

**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**System capability**: SystemCapability.Ability.Form

G
Gloria 已提交
918 919 920 921 922 923 924 925 926 927 928 929
**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
| 401 | If the input parameter is not valid parameter. |
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16501000 | An internal functional error occurred. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||

930 931 932 933
**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
934
| callback | AsyncCallback<Array<[FormInfo](js-apis-app-form-formInfo.md)>> | Yes| Callback used to return the result. If the widget information is obtained, **error** is undefined and **data** is the information obtained; otherwise, **error** is an error object.|
935 936 937 938 939 940 941

**Example**

```ts
try {
  formHost.getAllFormsInfo((error, data) => {
    if (error) {
942
      console.log('formHost getAllFormsInfo, error:' + JSON.stringify(error));
943 944 945 946 947
    } else {
      console.log('formHost getAllFormsInfo, data:' + JSON.stringify(data));
    }
  });
} catch(error) {
948
    console.log(`catch err->${JSON.stringify(error)}`);
949 950 951 952 953 954 955 956 957 958 959 960 961
}
```

## getAllFormsInfo

getAllFormsInfo(): Promise<Array<formInfo.FormInfo>>

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

**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**System capability**: SystemCapability.Ability.Form

G
Gloria 已提交
962 963 964 965 966 967 968 969 970 971 972
**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16501000 | An internal functional error occurred. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||

973 974 975 976
**Return value**

| Type                                                        | Description                               |
| :----------------------------------------------------------- | :---------------------------------- |
977
| Promise<Array<[FormInfo](js-apis-app-form-formInfo.md)>> | Promise used to return the information obtained.|
978 979 980 981 982 983

**Example**

```ts
try {
  formHost.getAllFormsInfo().then((data) => {
984
      console.log('formHost getAllFormsInfo data:' + JSON.stringify(data));
985
  }).catch((error) => {
986
      console.log('formHost getAllFormsInfo, error:' + JSON.stringify(error));
987 988
  });
} catch(error) {
989
    console.log(`catch err->${JSON.stringify(error)}`);
990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007
}
```

## getFormsInfo

getFormsInfo(bundleName: string, callback: AsyncCallback<Array<formInfo.FormInfo>>): void

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

**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| bundleName | string | Yes| Bundle name of the application.|
G
Gloria 已提交
1008
| callback | AsyncCallback<Array<[FormInfo](js-apis-app-form-formInfo.md)>> | Yes| Callback used to return the result. If the widget information is obtained, **error** is undefined and **data** is the information obtained; otherwise, **error** is an error object.|
1009 1010 1011 1012 1013

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
1014 1015
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
1016
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
1017 1018 1019 1020 1021
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16500100 | Failed to obtain the configuration information. |
| 16501000 | An internal functional error occurred. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
1022 1023 1024 1025 1026

**Example**

```ts
try {
1027
  formHost.getFormsInfo('com.example.ohos.formjsdemo', (error, data) => {
1028
    if (error) {
1029
      console.log('formHost getFormsInfo, error:' + JSON.stringify(error));
1030 1031 1032 1033 1034
    } else {
      console.log('formHost getFormsInfo, data:' + JSON.stringify(data));
    }
  });
} catch(error) {
1035
    console.log(`catch err->${JSON.stringify(error)}`);
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054
}
```

## getFormsInfo

getFormsInfo(bundleName: string, moduleName: string, callback: AsyncCallback<Array<formInfo.FormInfo>>): void

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

**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| bundleName | string | Yes| Bundle name of the application.|
| moduleName | string | Yes|  Module name.|
G
Gloria 已提交
1055
| callback | AsyncCallback<Array<[FormInfo](js-apis-app-form-formInfo.md)>> | Yes| Callback used to return the result. If the widget information is obtained, **error** is undefined and **data** is the information obtained; otherwise, **error** is an error object.|
1056 1057 1058 1059 1060

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
1061 1062
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
1063
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
1064 1065 1066 1067 1068
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16500100 | Failed to obtain the configuration information. |
| 16501000 | An internal functional error occurred. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
1069 1070 1071 1072 1073

**Example**

```ts
try {
1074
  formHost.getFormsInfo('com.example.ohos.formjsdemo', 'entry', (error, data) => {
1075
    if (error) {
1076
        console.log('formHost getFormsInfo, error:' + JSON.stringify(error));
1077
    } else {
1078
        console.log('formHost getFormsInfo, data:' + JSON.stringify(data));
1079 1080 1081
    }
  });
} catch(error) {
1082
    console.log(`catch err->${JSON.stringify(error)}`);
1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100
}
```

## getFormsInfo

getFormsInfo(bundleName: string, moduleName?: string): Promise<Array<formInfo.FormInfo>>

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

**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| bundleName | string | Yes| Bundle name of the application.|
G
Gloria 已提交
1101
| moduleName | string | No|  Module name. By default, no value is passed.|
1102 1103 1104 1105 1106

**Return value**

| Type                                                        | Description                               |
| :----------------------------------------------------------- | :---------------------------------- |
1107
| Promise<Array<[FormInfo](js-apis-app-form-formInfo.md)>> | Promise used to return the information obtained.|
1108 1109 1110 1111 1112

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
1113 1114
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
1115
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
1116 1117 1118 1119 1120
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16500100 | Failed to obtain the configuration information. |
| 16501000 | An internal functional error occurred. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
1121 1122 1123 1124 1125

**Example**

```ts
try {
1126
  formHost.getFormsInfo('com.example.ohos.formjsdemo', 'entry').then((data) => {
1127 1128
    console.log('formHost getFormsInfo, data:' + JSON.stringify(data));
  }).catch((error) => {
1129
    console.log('formHost getFormsInfo, error:' + JSON.stringify(error));
1130 1131
  });
} catch(error) {
1132
    console.log(`catch err->${JSON.stringify(error)}`);
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152
}
```

## 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.

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes  | List of valid widget IDs.|
| callback | AsyncCallback<number> | Yes| Callback used to return the result. If the invalid widgets are deleted, **error** is undefined and **data** is the number of widgets deleted; otherwise, **error** is an error object.|

G
Gloria 已提交
1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164
**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
| 401 | If the input parameter is not valid parameter. |
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16501000 | An internal functional error occurred. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||

1165 1166 1167 1168
**Example**

```ts
try {
1169
  var formIds = new Array('12400633174999288', '12400633174999289');
1170 1171
  formHost.deleteInvalidForms(formIds, (error, data) => {
    if (error) {
1172
      console.log('formHost deleteInvalidForms, error:' + JSON.stringify(error));
1173 1174 1175 1176 1177
    } else {
      console.log('formHost deleteInvalidForms, data:' + JSON.stringify(data));
    }
  });
} catch(error) {
1178
    console.log(`catch err->${JSON.stringify(error)}`);
1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203
}
```

## deleteInvalidForms

deleteInvalidForms(formIds: Array<string>): Promise<number>

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

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array<string> | Yes  | List of valid widget IDs.|

**Return value**

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

G
Gloria 已提交
1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215
**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
| 401 | If the input parameter is not valid parameter. |
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16501000 | An internal functional error occurred. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||

1216 1217 1218 1219
**Example**

```ts
try {
1220
  var formIds = new Array('12400633174999288', '12400633174999289');
1221 1222 1223
  formHost.deleteInvalidForms(formIds).then((data) => {
    console.log('formHost deleteInvalidForms, data:' + JSON.stringify(data));
  }).catch((error) => {
1224
    console.log('formHost deleteInvalidForms, error:' + JSON.stringify(error));
1225 1226
  });
} catch(error) {
1227
    console.log(`catch err->${JSON.stringify(error)}`);
1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245
}
```

## acquireFormState

acquireFormState(want: Want, callback: AsyncCallback<formInfo.FormStateInfo>): void

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

**Required permissions**: ohos.permission.REQUIRE_FORM and ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| want | [Want](js-apis-application-want.md) | Yes  | **Want** information carried to query the widget state. The information must contain the bundle name, ability name, module name, widget name, and widget dimensions.|
G
Gloria 已提交
1246
| callback | AsyncCallback<[FormStateInfo](js-apis-app-form-formInfo.md#formstateinfo)> | Yes| Callback used to return the result. If the widget state is obtained, **error** is undefined and **data** is the widget state obtained; otherwise, **error** is an error object.|
1247 1248 1249 1250 1251

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
1252 1253
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
1254
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
1255 1256 1257 1258 1259
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16500100 | Failed to obtain the configuration information. |
| 16501000 | An internal functional error occurred. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
1260 1261 1262 1263

**Example**

```ts
1264 1265 1266 1267 1268 1269 1270 1271
var want = {
  '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
1272 1273 1274 1275 1276
  }
};
try {
  formHost.acquireFormState(want, (error, data) => {
    if (error) {
1277
      console.log('formHost acquireFormState, error:' + JSON.stringify(error));
1278 1279 1280 1281 1282
    } else {
      console.log('formHost acquireFormState, data:' + JSON.stringify(data));
    }
  });
} catch(error) {
1283
    console.log(`catch err->${JSON.stringify(error)}`);
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306
}
```

## acquireFormState

acquireFormState(want: Want): Promise<formInfo.FormStateInfo>

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

**Required permissions**: ohos.permission.REQUIRE_FORM and ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| want   | [Want](js-apis-application-want.md) | Yes  | **Want** information carried to query the widget state. The information must contain the bundle name, ability name, module name, widget name, and widget dimensions.|

**Return value**

| Type         | Description                               |
| :------------ | :---------------------------------- |
1307
| Promise<[FormStateInfo](js-apis-app-form-formInfo.md#formstateinfo)> | Promise used to return the widget state obtained.|
1308 1309 1310 1311 1312

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
1313 1314
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
1315
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
1316 1317 1318 1319 1320
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16500100 | Failed to obtain the configuration information. |
| 16501000 | An internal functional error occurred. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
1321 1322 1323 1324

**Example**

```ts
1325 1326 1327 1328 1329 1330 1331 1332
var want = {
  '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
1333 1334 1335 1336 1337 1338
  }
};
try {
  formHost.acquireFormState(want).then((data) => {
    console.log('formHost acquireFormState, data:' + JSON.stringify(data));
  }).catch((error) => {
1339
    console.log('formHost acquireFormState, error:' + JSON.stringify(error));
1340 1341
  });
} catch(error) {
1342
    console.log(`catch err->${JSON.stringify(error)}`);
1343 1344 1345
}
```

1346
## on('formUninstall')
1347

1348
on(type: 'formUninstall', callback: Callback<string>): void
1349 1350 1351 1352 1353 1354 1355 1356 1357

Subscribes to widget uninstall events. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
1358
| type | string | Yes  | Event type. The value **'formUninstall'** indicates a widget uninstallation event.|
1359 1360
| callback | Callback<string> | Yes| Callback used to return the widget ID.|

G
Gloria 已提交
1361 1362 1363 1364 1365 1366 1367 1368
**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
| 202 | The application is not a system application. |
| 401 | If the input parameter is not valid parameter. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||

1369 1370 1371 1372 1373 1374
**Example**

```ts
let callback = function(formId) {
  console.log('formHost on formUninstall, formId:' + formId);
}
1375
formHost.on('formUninstall', callback);
1376 1377
```

1378
## off('formUninstall')
1379

1380
off(type: 'formUninstall', callback?: Callback<string>): void
1381 1382 1383 1384 1385 1386 1387 1388 1389

Unsubscribes from widget uninstall events. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
1390 1391
| type | string | Yes  | Event type. The value **'formUninstall'** indicates a widget uninstallation event.|
| callback | Callback&lt;string&gt; | No| Callback used to return the widget ID. If it is left unspecified, it indicates the callback for all the events that have been subscribed.<br> The value must be the same as that in **on('formUninstall')**.|
1392

G
Gloria 已提交
1393 1394 1395 1396 1397 1398 1399 1400
**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
| 202 | The application is not a system application. |
| 401 | If the input parameter is not valid parameter. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||

1401 1402 1403 1404 1405 1406
**Example**

```ts
let callback = function(formId) {
  console.log('formHost on formUninstall, formId:' + formId);
}
1407
formHost.off('formUninstall', callback);
1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431
```

## 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.

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array&lt;string&gt; | Yes  | List of widget IDs.|
| isVisible | boolean | Yes  | Whether to make the widgets visible.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the notification is sent, **error** is undefined; otherwise, **error** is an error object.|

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
1432 1433
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
1434
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
1435 1436 1437 1438 1439
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16501000 | An internal functional error occurred. |
| 16501003 | The form can not be operated by the current application. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
1440 1441 1442 1443

**Example**

```ts
1444
var formIds = new Array('12400633174999288', '12400633174999289');
1445
try {
1446
  formHost.notifyFormsVisible(formIds, true, (error, data) => {
1447
    if (error) {
1448
      console.log('formHost notifyFormsVisible, error:' + JSON.stringify(error));
1449 1450 1451
    }
  });
} catch(error) {
1452
    console.log(`catch err->${JSON.stringify(error)}`);
1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482
}
```

## 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.

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array&lt;string&gt; | Yes  | List of widget IDs.|
| isVisible | boolean | Yes  | Whether to make the widgets visible.|

**Return value**

| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
1483 1484
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
1485
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
1486 1487 1488 1489 1490
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16501000 | An internal functional error occurred. |
| 16501003 | The form can not be operated by the current application. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
1491 1492 1493 1494

**Example**

```ts
1495
var formIds = new Array('12400633174999288', '12400633174999289');
1496 1497 1498 1499
try {
  formHost.notifyFormsVisible(formIds, true).then(() => {
    console.log('formHost notifyFormsVisible success');
  }).catch((error) => {
1500
    console.log('formHost notifyFormsVisible, error:' + JSON.stringify(error));
1501 1502
  });
} catch(error) {
1503
    console.log(`catch err->${JSON.stringify(error)}`);
1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528
}
```

## notifyFormsEnableUpdate

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

Instructs the widgets to enable or disable updates. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array&lt;string&gt; | Yes  | List of widget IDs.|
| isEnableUpdate | boolean | Yes  | Whether to make the widgets updatable.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the notification is sent, **error** is undefined; otherwise, **error** is an error object.|

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
1529 1530
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
1531
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
1532 1533 1534 1535 1536
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16501000 | An internal functional error occurred. |
| 16501003 | The form can not be operated by the current application. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
1537 1538 1539 1540

**Example**

```ts
1541
var formIds = new Array('12400633174999288', '12400633174999289');
1542
try {
1543
  formHost.notifyFormsEnableUpdate(formIds, true, (error, data) => {
1544
    if (error) {
1545
      console.log('formHost notifyFormsEnableUpdate, error:' + JSON.stringify(error));
1546 1547 1548
    }
  });
} catch(error) {
1549
    console.log(`catch err->${JSON.stringify(error)}`);
1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579
}
```

## notifyFormsEnableUpdate

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

Instructs the widgets to enable or disable updates. This API uses a promise to return the result.

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formIds | Array&lt;string&gt; | Yes  | List of widget IDs.|
| isEnableUpdate | boolean | Yes  | Whether to make the widgets updatable.|

**Return value**

| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
1580 1581
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
1582
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
1583 1584 1585 1586 1587
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16501000 | An internal functional error occurred. |
| 16501003 | The form can not be operated by the current application. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
1588 1589 1590 1591

**Example**

```ts
1592
var formIds = new Array('12400633174999288', '12400633174999289');
1593 1594 1595 1596
try {
  formHost.notifyFormsEnableUpdate(formIds, true).then(() => {
    console.log('formHost notifyFormsEnableUpdate success');
  }).catch((error) => {
1597
    console.log('formHost notifyFormsEnableUpdate, error:' + JSON.stringify(error));
1598 1599
  });
} catch(error) {
1600
    console.log(`catch err->${JSON.stringify(error)}`);
1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624
}
```
## shareForm

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

Shares a specified widget with a remote device. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.REQUIRE_FORM and ohos.permission.DISTRIBUTED_DATASYNC

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formId | string | Yes  | Widget ID.|
| deviceId | string | Yes  | Remote device ID.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the widget is shared, **error** is undefined; otherwise, **error** is an error object.|

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
1625 1626
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
1627
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
1628 1629 1630 1631 1632
| 16500050 | An IPC connection error happened. |
| 16501000 | An internal functional error occurred. |
| 16501001 | The ID of the form to be operated does not exist. |
| 16501003 | The form can not be operated by the current application. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
1633

1634 1635 1636
**Example**

```ts
1637 1638
var formId = '12400633174999288';
var deviceId = 'EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2';
1639
try {
1640
  formHost.shareForm(formId, deviceId, (error, data) => {
1641
    if (error) {
1642
      console.log('formHost shareForm, error:' + JSON.stringify(error));
1643 1644 1645
    }
  });
} catch(error) {
1646
    console.log(`catch err->${JSON.stringify(error)}`);
1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676
}
```

## shareForm

shareForm(formId: string, deviceId: string): Promise&lt;void&gt;

Shares a specified widget with a remote device. This API uses a promise to return the result.

**Required permissions**: ohos.permission.REQUIRE_FORM and ohos.permission.DISTRIBUTED_DATASYNC

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
| formId | string | Yes  | Widget ID.|
| deviceId | string | Yes  | Remote device ID.|

**Return value**

| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
G
Gloria 已提交
1677 1678
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
1679
| 401 | If the input parameter is not valid parameter. |
G
Gloria 已提交
1680 1681 1682 1683 1684
| 16500050 | An IPC connection error happened. |
| 16501000 | An internal functional error occurred. |
| 16501001 | The ID of the form to be operated does not exist. |
| 16501003 | The form can not be operated by the current application. |
|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).||
1685 1686 1687 1688

**Example**

```ts
1689 1690
var formId = '12400633174999288';
var deviceId = 'EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2';
1691 1692 1693 1694
try {
  formHost.shareForm(formId, deviceId).then(() => {
    console.log('formHost shareForm success');
  }).catch((error) => {
1695
    console.log('formHost shareForm, error:' + JSON.stringify(error));
1696 1697
  });
} catch(error) {
1698
    console.log(`catch err->${JSON.stringify(error)}`);
1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715
}
```

## notifyFormsPrivacyProtected

notifyFormsPrivacyProtected(formIds: Array\<string>, isProtected: boolean, callback: AsyncCallback\<void>): void

Notifies that the privacy protection status of the specified widgets changes. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name| Type   | Mandatory| Description   |
| ------ | ------ | ---- | ------- |
G
Gloria 已提交
1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732
| formIds | Array\<string\> | Yes  | ID of the widgets.|
| isProtected | boolean | Yes  | Whether privacy protection is enabled.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result. If privacy protection is set successfully, **error** is undefined; otherwise, **error** is an error object.|

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
| 401 | If the input parameter is not valid parameter. |
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16501000 | An internal functional error occurred. |
| For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|                    |

**Example**
1733 1734

```ts
G
Gloria 已提交
1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787
import formHost from '@ohos.app.form.formHost';

let formIds = new Array('12400633174999288', '12400633174999289');
try {
  formHost.notifyFormsPrivacyProtected(formIds, true, (error) => {
    if (error) {
      console.error(`error, code: ${error.code}, message: ${error.message}`);
    }
  });
} catch(error) {
  console.error(`catch error, code: ${error.code}, message: ${error.message}`);
}
```

## notifyFormsPrivacyProtected

function notifyFormsPrivacyProtected(formIds: Array\<string\>, isProtected: boolean): Promise\<void\>;

Notifies that the privacy protection status of the specified widgets changes. This API uses a promise to return the result.

**Required permissions**: ohos.permission.REQUIRE_FORM

**System capability**: SystemCapability.Ability.Form

**Parameters**

| Name     | Type           | Mandatory| Description                            |
| ----------- | --------------- | ---- | -------------------------------- |
| formIds     | Array\<string\> | Yes  | ID of the widgets.|
| isProtected | boolean         | Yes  | Whether privacy protection is enabled.              |

**Return value**

| Type               | Description                     |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

| Error Code ID| Error Message|
| -------- | -------- |
| 201 | Permissions denied. |
| 202 | The application is not a system application. |
| 401 | If the input parameter is not valid parameter. |
| 16500050 | An IPC connection error happened. |
| 16500060 | A service connection error happened, please try again later. |
| 16501000 | An internal functional error occurred. |
| For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|                    |

```ts
import formHost from '@ohos.app.form.formHost';

let formIds = new Array('12400633174999288', '12400633174999289');
1788 1789
try {
  formHost.notifyFormsPrivacyProtected(formIds, true).then(() => {
1790
    console.log('formHost shareForm success');
1791
  }).catch((error) => {
1792
    console.log('formHost shareForm, error:' + JSON.stringify(error));
1793 1794
  });
} catch(error) {
1795
    console.log(`catch err->${JSON.stringify(error)}`);
1796 1797
}
```