1# @ohos.app.form.formHost (formHost) 2 3The **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> **NOTE** 6> 7> 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. 8> 9> The APIs provided by this module are system APIs. 10 11## Modules to Import 12 13```ts 14import formHost from '@ohos.app.form.formHost'; 15``` 16 17## deleteForm 18 19deleteForm(formId: string, callback: AsyncCallback<void>): void 20 21Deletes 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. 22 23**Required permissions**: ohos.permission.REQUIRE_FORM 24 25**System capability**: SystemCapability.Ability.Form 26 27**Parameters** 28 29| Name| Type | Mandatory| Description | 30| ------ | ------ | ---- | ------- | 31| formId | string | Yes | Widget ID.| 32| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is deleted, **error** is undefined; otherwise, **error** is an error object.| 33 34**Error codes** 35 36| Error Code ID| Error Message| 37| -------- | -------- | 38| 201 | Permissions denied. | 39| 202 | The application is not a system application. | 40| 401 | If the input parameter is not valid parameter. | 41| 16500050 | An IPC connection error happened. | 42| 16500060 | A service connection error happened, please try again later. | 43| 16501000 | An internal functional error occurred. | 44| 16501001 | The ID of the form to be operated does not exist. | 45| 16501003 | The form can not be operated by the current application. | 46 47For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 48 49**Example** 50 51```ts 52import Base from '@ohos.base'; 53 54try { 55 let formId: string = '12400633174999288'; 56 formHost.deleteForm(formId, (error: Base.BusinessError) => { 57 if (error) { 58 console.error(`error, code: ${error.code}, message: ${error.message}`); 59 } else { 60 console.log('formHost deleteForm success'); 61 } 62 }); 63} catch (error) { 64 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 65} 66``` 67 68## deleteForm 69 70deleteForm(formId: string): Promise<void> 71 72Deletes 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. 73 74**Required permissions**: ohos.permission.REQUIRE_FORM 75 76**System capability**: SystemCapability.Ability.Form 77 78**Parameters** 79 80| Name| Type | Mandatory| Description | 81| ------ | ------ | ---- | ------- | 82| formId | string | Yes | Widget ID.| 83 84**Return value** 85 86| Type| Description| 87| -------- | -------- | 88| Promise<void> | Promise that returns no value.| 89 90 91**Error codes** 92 93| Error Code ID| Error Message| 94| -------- | -------- | 95| 201 | Permissions denied. | 96| 202 | The application is not a system application. | 97| 401 | If the input parameter is not valid parameter. | 98| 16500050 | An IPC connection error happened. | 99| 16500060 | A service connection error happened, please try again later. | 100| 16501000 | An internal functional error occurred. | 101| 16501001 | The ID of the form to be operated does not exist. | 102| 16501003 | The form can not be operated by the current application. | 103 104For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 105 106**Parameters** 107 108```ts 109import Base from '@ohos.base'; 110 111try { 112 let formId: string = '12400633174999288'; 113 formHost.deleteForm(formId).then(() => { 114 console.log('formHost deleteForm success'); 115 }).catch((error: Base.BusinessError) => { 116 console.error(`formHost deleteForm, error: ${JSON.stringify(error)}`); 117 }); 118} catch(error) { 119 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 120} 121``` 122 123## releaseForm 124 125releaseForm(formId: string, callback: AsyncCallback<void>): void 126 127Releases 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. 128 129**Required permissions**: ohos.permission.REQUIRE_FORM 130 131**System capability**: SystemCapability.Ability.Form 132 133**Parameters** 134 135| Name| Type | Mandatory| Description | 136| ------ | ------ | ---- | ------- | 137| formId | string | Yes | Widget ID.| 138| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is released, **error** is undefined; otherwise, **error** is an error object.| 139 140**Error codes** 141 142| Error Code ID| Error Message| 143| -------- | -------- | 144| 201 | Permissions denied. | 145| 202 | The application is not a system application. | 146| 401 | If the input parameter is not valid parameter. | 147| 16500050 | An IPC connection error happened. | 148| 16500060 | A service connection error happened, please try again later. | 149| 16501000 | An internal functional error occurred. | 150| 16501001 | The ID of the form to be operated does not exist. | 151| 16501003 | The form can not be operated by the current application. | 152 153For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 154 155**Example** 156 157```ts 158import Base from '@ohos.base'; 159 160try { 161 let formId: string = '12400633174999288'; 162 formHost.releaseForm(formId, (error: Base.BusinessError) => { 163 if (error) { 164 console.error(`error, code: ${error.code}, message: ${error.message}`); 165 } 166 }); 167} catch(error) { 168 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 169} 170``` 171 172## releaseForm 173 174releaseForm(formId: string, isReleaseCache: boolean, callback: AsyncCallback<void>): void 175 176Releases 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. 177 178**Required permissions**: ohos.permission.REQUIRE_FORM 179 180**System capability**: SystemCapability.Ability.Form 181 182**Parameters** 183 184| Name | Type | Mandatory| Description | 185| -------------- | ------ | ---- | ----------- | 186| formId | string | Yes | Widget ID. | 187| isReleaseCache | boolean | Yes | Whether to release the cache.| 188| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is released, **error** is undefined; otherwise, **error** is an error object.| 189 190**Error codes** 191 192| Error Code ID| Error Message| 193| -------- | -------- | 194| 201 | Permissions denied. | 195| 202 | The application is not a system application. | 196| 401 | If the input parameter is not valid parameter. | 197| 16500050 | An IPC connection error happened. | 198| 16500060 | A service connection error happened, please try again later. | 199| 16501000 | An internal functional error occurred. | 200| 16501001 | The ID of the form to be operated does not exist. | 201| 16501003 | The form can not be operated by the current application. | 202 203For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 204 205**Example** 206 207```ts 208import Base from '@ohos.base'; 209 210try { 211 let formId: string = '12400633174999288'; 212 formHost.releaseForm(formId, true, (error: Base.BusinessError) => { 213 if (error) { 214 console.error(`error, code: ${error.code}, message: ${error.message}`); 215 } 216 }); 217} catch(error) { 218 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 219} 220``` 221 222## releaseForm 223 224releaseForm(formId: string, isReleaseCache?: boolean): Promise<void> 225 226Releases 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. 227 228**Required permissions**: ohos.permission.REQUIRE_FORM 229 230**System capability**: SystemCapability.Ability.Form 231 232**Parameters** 233 234| Name | Type | Mandatory| Description | 235| -------------- | ------ | ---- | ----------- | 236| formId | string | Yes | Widget ID. | 237| isReleaseCache | boolean | No | Whether to release the cache. The default value is **false**. | 238 239**Return value** 240 241| Type| Description| 242| -------- | -------- | 243| Promise<void> | Promise that returns no value.| 244 245**Error codes** 246 247| Error Code ID| Error Message| 248| -------- | -------- | 249| 201 | Permissions denied. | 250| 202 | The application is not a system application. | 251| 401 | If the input parameter is not valid parameter. | 252| 16500050 | An IPC connection error happened. | 253| 16500060 | A service connection error happened, please try again later. | 254| 16501000 | An internal functional error occurred. | 255| 16501001 | The ID of the form to be operated does not exist. | 256| 16501003 | The form can not be operated by the current application. | 257 258For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 259 260**Example** 261 262```ts 263import Base from '@ohos.base'; 264 265try { 266 let formId: string = '12400633174999288'; 267 formHost.releaseForm(formId, true).then(() => { 268 console.log('formHost releaseForm success'); 269 }).catch((error: Base.BusinessError) => { 270 console.error(`error, code: ${error.code}, message: ${error.message}`); 271 }); 272} catch(error) { 273 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 274} 275``` 276 277## requestForm 278 279requestForm(formId: string, callback: AsyncCallback<void>): void 280 281Requests a widget update. This API uses an asynchronous callback to return the result. 282 283**Required permissions**: ohos.permission.REQUIRE_FORM 284 285**System capability**: SystemCapability.Ability.Form 286 287**Parameters** 288 289| Name| Type | Mandatory| Description | 290| ------ | ------ | ---- | ------- | 291| formId | string | Yes | Widget ID.| 292| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is updated, **error** is undefined; otherwise, **error** is an error object.| 293 294**Error codes** 295 296| Error Code ID| Error Message| 297| -------- | -------- | 298| 201 | Permissions denied. | 299| 202 | The application is not a system application. | 300| 401 | If the input parameter is not valid parameter. | 301| 16500050 | An IPC connection error happened. | 302| 16500060 | A service connection error happened, please try again later. | 303| 16501000 | An internal functional error occurred. | 304| 16501001 | The ID of the form to be operated does not exist. | 305| 16501003 | The form can not be operated by the current application. | 306 307For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 308 309**Example** 310 311```ts 312import Base from '@ohos.base'; 313 314try { 315 let formId: string = '12400633174999288'; 316 formHost.requestForm(formId, (error: Base.BusinessError) => { 317 if (error) { 318 console.error(`error, code: ${error.code}, message: ${error.message}`); 319 } 320 }); 321} catch(error) { 322 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 323} 324``` 325 326## requestForm 327 328requestForm(formId: string): Promise<void> 329 330Requests a widget update. This API uses a promise to return the result. 331 332**Required permissions**: ohos.permission.REQUIRE_FORM 333 334**System capability**: SystemCapability.Ability.Form 335 336**Parameters** 337 338| Name| Type | Mandatory| Description | 339| ------ | ------ | ---- | ------- | 340| formId | string | Yes | Widget ID.| 341 342**Return value** 343 344| Type| Description| 345| -------- | -------- | 346| Promise<void> | Promise that returns no value.| 347 348**Error codes** 349 350| Error Code ID| Error Message| 351| -------- | -------- | 352| 201 | Permissions denied. | 353| 202 | The application is not a system application. | 354| 401 | If the input parameter is not valid parameter. | 355| 16500050 | An IPC connection error happened. | 356| 16500060 | A service connection error happened, please try again later. | 357| 16501000 | An internal functional error occurred. | 358| 16501001 | The ID of the form to be operated does not exist. | 359| 16501003 | The form can not be operated by the current application. | 360 361For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 362 363**Example** 364 365```ts 366import Base from '@ohos.base'; 367 368try { 369 let formId: string = '12400633174999288'; 370 formHost.requestForm(formId).then(() => { 371 console.log('formHost requestForm success'); 372 }).catch((error: Base.BusinessError) => { 373 console.error(`error, code: ${error.code}, message: ${error.message}`); 374 }); 375} catch(error) { 376 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 377} 378 379``` 380 381## castToNormalForm 382 383castToNormalForm(formId: string, callback: AsyncCallback<void>): void 384 385Converts a temporary widget to a normal one. This API uses an asynchronous callback to return the result. 386 387**Required permissions**: ohos.permission.REQUIRE_FORM 388 389**System capability**: SystemCapability.Ability.Form 390 391**Parameters** 392 393| Name| Type | Mandatory| Description | 394| ------ | ------ | ---- | ------- | 395| formId | string | Yes | Widget ID.| 396| 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.| 397 398**Error codes** 399 400| Error Code ID| Error Message| 401| -------- | -------- | 402| 201 | Permissions denied. | 403| 202 | The application is not a system application. | 404| 401 | If the input parameter is not valid parameter. | 405| 16500050 | An IPC connection error happened. | 406| 16501000 | An internal functional error occurred. | 407| 16501001 | The ID of the form to be operated does not exist. | 408| 16501002 | The number of forms exceeds upper bound. | 409| 16501003 | The form can not be operated by the current application. | 410 411For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 412 413**Example** 414 415```ts 416import Base from '@ohos.base'; 417 418try { 419 let formId: string = '12400633174999288'; 420 formHost.castToNormalForm(formId, (error: Base.BusinessError) => { 421 if (error) { 422 console.error(`error, code: ${error.code}, message: ${error.message}`); 423 } 424 }); 425} catch(error) { 426 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 427} 428``` 429 430## castToNormalForm 431 432castToNormalForm(formId: string): Promise<void> 433 434Converts a temporary widget to a normal one. This API uses a promise to return the result. 435 436**Required permissions**: ohos.permission.REQUIRE_FORM 437 438**System capability**: SystemCapability.Ability.Form 439 440**Parameters** 441 442| Name| Type | Mandatory| Description | 443| ------ | ------ | ---- | ------- | 444| formId | string | Yes | Widget ID.| 445 446**Return value** 447 448| Type| Description| 449| -------- | -------- | 450| Promise<void> | Promise that returns no value.| 451 452**Error codes** 453 454| Error Code ID| Error Message| 455| -------- | -------- | 456| 201 | Permissions denied. | 457| 202 | The application is not a system application. | 458| 401 | If the input parameter is not valid parameter. | 459| 16500050 | An IPC connection error happened. | 460| 16501000 | An internal functional error occurred. | 461| 16501001 | The ID of the form to be operated does not exist. | 462| 16501002 | The number of forms exceeds upper bound. | 463| 16501003 | The form can not be operated by the current application. | 464 465For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 466 467**Example** 468 469```ts 470import Base from '@ohos.base'; 471 472try { 473 let formId: string = '12400633174999288'; 474 formHost.castToNormalForm(formId).then(() => { 475 console.log('formHost castTempForm success'); 476 }).catch((error: Base.BusinessError) => { 477 console.error(`error, code: ${error.code}, message: ${error.message}`); 478 }); 479} catch(error) { 480 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 481} 482``` 483 484## notifyVisibleForms 485 486notifyVisibleForms(formIds: Array<string>, callback: AsyncCallback<void>): void 487 488Instructs 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. 489 490**Required permissions**: ohos.permission.REQUIRE_FORM 491 492**System capability**: SystemCapability.Ability.Form 493 494**Parameters** 495 496| Name| Type | Mandatory| Description | 497| ------ | ------ | ---- | ------- | 498| formIds | Array<string> | Yes | List of widget IDs. | 499| 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.| 500 501**Error codes** 502 503| Error Code ID| Error Message| 504| -------- | -------- | 505| 201 | Permissions denied. | 506| 202 | The application is not a system application. | 507| 401 | If the input parameter is not valid parameter. | 508| 16500050 | An IPC connection error happened. | 509| 16500060 | A service connection error happened, please try again later. | 510| 16501000 | An internal functional error occurred. | 511 512For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 513 514**Example** 515 516```ts 517import Base from '@ohos.base'; 518 519try { 520 let formId: string[] = ['12400633174999288']; 521 formHost.notifyVisibleForms(formId, (error: Base.BusinessError) => { 522 if (error) { 523 console.error(`error, code: ${error.code}, message: ${error.message}`); 524 } 525 }); 526} catch(error) { 527 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 528} 529``` 530 531## notifyVisibleForms 532 533notifyVisibleForms(formIds: Array<string>): Promise<void> 534 535Instructs 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. 536 537**Required permissions**: ohos.permission.REQUIRE_FORM 538 539**System capability**: SystemCapability.Ability.Form 540 541**Parameters** 542 543| Name| Type | Mandatory| Description | 544| ------ | ------ | ---- | ------- | 545| formIds | Array<string> | Yes | List of widget IDs.| 546 547**Return value** 548 549| Type| Description| 550| -------- | -------- | 551| Promise<void> | Promise that returns no value.| 552 553**Error codes** 554 555| Error Code ID| Error Message| 556| -------- | -------- | 557| 201 | Permissions denied. | 558| 202 | The application is not a system application. | 559| 401 | If the input parameter is not valid parameter. | 560| 16500050 | An IPC connection error happened. | 561| 16500060 | A service connection error happened, please try again later. | 562| 16501000 | An internal functional error occurred. | 563 564For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 565 566**Example** 567 568```ts 569import Base from '@ohos.base'; 570 571try { 572 let formId: string[] = ['12400633174999288']; 573 formHost.notifyVisibleForms(formId).then(() => { 574 console.log('formHost notifyVisibleForms success'); 575 }).catch((error: Base.BusinessError) => { 576 console.error(`error, code: ${error.code}, message: ${error.message}`); 577 }); 578} catch(error) { 579 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 580} 581``` 582 583## notifyInvisibleForms 584 585notifyInvisibleForms(formIds: Array<string>, callback: AsyncCallback<void>): void 586 587Instructs 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. 588 589**Required permissions**: ohos.permission.REQUIRE_FORM 590 591**System capability**: SystemCapability.Ability.Form 592 593**Parameters** 594 595| Name| Type | Mandatory| Description | 596| ------ | ------ | ---- | ------- | 597| formIds | Array<string> | Yes | List of widget IDs.| 598| 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.| 599 600**Error codes** 601 602| Error Code ID| Error Message| 603| -------- | -------- | 604| 201 | Permissions denied. | 605| 202 | The application is not a system application. | 606| 401 | If the input parameter is not valid parameter. | 607| 16500050 | An IPC connection error happened. | 608| 16500060 | A service connection error happened, please try again later. | 609| 16501000 | An internal functional error occurred. | 610 611For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 612 613**Example** 614 615```ts 616import Base from '@ohos.base'; 617 618try { 619 let formId: string[] = ['12400633174999288']; 620 formHost.notifyInvisibleForms(formId, (error: Base.BusinessError) => { 621 if (error) { 622 console.error(`error, code: ${error.code}, message: ${error.message}`); 623 } 624 }); 625} catch(error) { 626 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 627} 628``` 629 630## notifyInvisibleForms 631 632notifyInvisibleForms(formIds: Array<string>): Promise<void> 633 634Instructs 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. 635 636**Required permissions**: ohos.permission.REQUIRE_FORM 637 638**System capability**: SystemCapability.Ability.Form 639 640**Parameters** 641 642| Name| Type | Mandatory| Description | 643| ------ | ------ | ---- | ------- | 644| formIds | Array<string> | Yes | List of widget IDs.| 645 646**Return value** 647 648| Type| Description| 649| -------- | -------- | 650| Promise<void> | Promise that returns no value.| 651 652**Error codes** 653 654| Error Code ID| Error Message| 655| -------- | -------- | 656| 201 | Permissions denied. | 657| 202 | The application is not a system application. | 658| 401 | If the input parameter is not valid parameter. | 659| 16500050 | An IPC connection error happened. | 660| 16500060 | A service connection error happened, please try again later. | 661| 16501000 | An internal functional error occurred. | 662 663For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 664 665**Example** 666 667```ts 668import Base from '@ohos.base'; 669 670try { 671 let formId: string[] = ['12400633174999288']; 672 formHost.notifyInvisibleForms(formId).then(() => { 673 console.log('formHost notifyInvisibleForms success'); 674 }).catch((error: Base.BusinessError) => { 675 console.error(`error, code: ${error.code}, message: ${error.message}`); 676 }); 677} catch(error) { 678 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 679} 680``` 681 682## enableFormsUpdate 683 684enableFormsUpdate(formIds: Array<string>, callback: AsyncCallback<void>): void 685 686Instructs 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. 687 688**Required permissions**: ohos.permission.REQUIRE_FORM 689 690**System capability**: SystemCapability.Ability.Form 691 692**Parameters** 693 694| Name| Type | Mandatory| Description | 695| ------ | ------ | ---- | ------- | 696| formIds | Array<string> | Yes | List of widget IDs. | 697| 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.| 698 699**Error codes** 700 701| Error Code ID| Error Message| 702| -------- | -------- | 703| 201 | Permissions denied. | 704| 202 | The application is not a system application. | 705| 401 | If the input parameter is not valid parameter. | 706| 16500050 | An IPC connection error happened. | 707| 16500060 | A service connection error happened, please try again later. | 708| 16501000 | An internal functional error occurred. | 709| 16501003 | The form can not be operated by the current application. | 710 711For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 712 713**Example** 714 715```ts 716import Base from '@ohos.base'; 717 718try { 719 let formId: string[] = ['12400633174999288']; 720 formHost.enableFormsUpdate(formId, (error: Base.BusinessError) => { 721 if (error) { 722 console.error(`error, code: ${error.code}, message: ${error.message}`); 723 } 724 }); 725} catch(error) { 726 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 727} 728``` 729 730## enableFormsUpdate 731 732enableFormsUpdate(formIds: Array<string>): Promise<void> 733 734Instructs 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. 735 736**Required permissions**: ohos.permission.REQUIRE_FORM 737 738**System capability**: SystemCapability.Ability.Form 739 740**Parameters** 741 742| Name| Type | Mandatory| Description | 743| ------ | ------ | ---- | ------- | 744| formIds | Array<string> | Yes | List of widget IDs.| 745 746**Return value** 747 748| Type| Description| 749| -------- | -------- | 750| Promise<void> | Promise that returns no value.| 751 752**Error codes** 753 754| Error Code ID| Error Message| 755| -------- | -------- | 756| 201 | Permissions denied. | 757| 202 | The application is not a system application. | 758| 401 | If the input parameter is not valid parameter. | 759| 16500050 | An IPC connection error happened. | 760| 16500060 | A service connection error happened, please try again later. | 761| 16501000 | An internal functional error occurred. | 762| 16501003 | The form can not be operated by the current application. | 763 764For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 765 766**Example** 767 768```ts 769import Base from '@ohos.base'; 770 771try { 772 let formId: string[] = ['12400633174999288']; 773 formHost.enableFormsUpdate(formId).then(() => { 774 console.log('formHost enableFormsUpdate success'); 775 }).catch((error: Base.BusinessError) => { 776 console.error(`error, code: ${error.code}, message: ${error.message}`); 777 }); 778} catch(error) { 779 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 780} 781``` 782 783## disableFormsUpdate 784 785disableFormsUpdate(formIds: Array<string>, callback: AsyncCallback<void>): void 786 787Instructs 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. 788 789**Required permissions**: ohos.permission.REQUIRE_FORM 790 791**System capability**: SystemCapability.Ability.Form 792 793**Parameters** 794 795| Name| Type | Mandatory| Description | 796| ------ | ------ | ---- | ------- | 797| formIds | Array<string> | Yes | List of widget IDs. | 798| 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.| 799 800**Error codes** 801 802| Error Code ID| Error Message| 803| -------- | -------- | 804| 201 | Permissions denied. | 805| 202 | The application is not a system application. | 806| 401 | If the input parameter is not valid parameter. | 807| 16500050 | An IPC connection error happened. | 808| 16500060 | A service connection error happened, please try again later. | 809| 16501000 | An internal functional error occurred. | 810| 16501001 | The ID of the form to be operated does not exist. | 811| 16501003 | The form can not be operated by the current application. | 812 813For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 814 815**Example** 816 817```ts 818import Base from '@ohos.base'; 819 820try { 821 let formId: string[] = ['12400633174999288']; 822 formHost.disableFormsUpdate(formId, (error: Base.BusinessError) => { 823 if (error) { 824 console.error(`error, code: ${error.code}, message: ${error.message}`); 825 } 826 }); 827} catch(error) { 828 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 829} 830``` 831 832## disableFormsUpdate 833 834disableFormsUpdate(formIds: Array<string>): Promise<void> 835 836Instructs 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. 837 838**Required permissions**: ohos.permission.REQUIRE_FORM 839 840**System capability**: SystemCapability.Ability.Form 841 842**Parameters** 843 844| Name| Type | Mandatory| Description | 845| ------ | ------ | ---- | ------- | 846| formIds | Array<string> | Yes | List of widget IDs.| 847 848**Return value** 849 850| Type| Description| 851| -------- | -------- | 852| Promise<void> | Promise that returns no value.| 853 854**Error codes** 855 856| Error Code ID| Error Message| 857| -------- | -------- | 858| 201 | Permissions denied. | 859| 202 | The application is not a system application. | 860| 401 | If the input parameter is not valid parameter. | 861| 16500050 | An IPC connection error happened. | 862| 16500060 | A service connection error happened, please try again later. | 863| 16501000 | An internal functional error occurred. | 864| 16501001 | The ID of the form to be operated does not exist. | 865| 16501003 | The form can not be operated by the current application. | 866 867For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 868 869**Example** 870 871```ts 872import Base from '@ohos.base'; 873 874try { 875 let formId: string[] = ['12400633174999288']; 876 formHost.disableFormsUpdate(formId).then(() => { 877 console.log('formHost disableFormsUpdate success'); 878 }).catch((error: Base.BusinessError) => { 879 console.error(`error, code: ${error.code}, message: ${error.message}`); 880 }); 881} catch(error) { 882 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 883} 884``` 885 886## isSystemReady 887 888isSystemReady(callback: AsyncCallback<void>): void 889 890Checks whether the system is ready. This API uses an asynchronous callback to return the result. 891 892**System capability**: SystemCapability.Ability.Form 893 894**Parameters** 895 896| Name| Type | Mandatory| Description | 897| ------ | ------ | ---- | ------- | 898| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the check is successful, **error** is undefined; otherwise, **error** is an error object.| 899 900**Error codes** 901 902| Error Code ID| Error Message| 903| -------- | -------- | 904| 202 | The application is not a system application. | 905| 401 | If the input parameter is not valid parameter. | 906 907For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 908 909**Example** 910 911```ts 912import Base from '@ohos.base'; 913 914try { 915 formHost.isSystemReady((error: Base.BusinessError) => { 916 if (error) { 917 console.error(`error, code: ${error.code}, message: ${error.message}`); 918 } 919 }); 920} catch(error) { 921 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 922} 923``` 924 925## isSystemReady 926 927isSystemReady(): Promise<void> 928 929Checks whether the system is ready. This API uses a promise to return the result. 930 931**System capability**: SystemCapability.Ability.Form 932 933**Return value** 934 935| Type| Description| 936| -------- | -------- | 937| Promise<void> | Promise that returns no value.| 938 939**Error codes** 940 941| Error Code ID| Error Message| 942| -------- | -------- | 943| 202 | The application is not a system application. | 944 945For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 946 947**Example** 948 949```ts 950import Base from '@ohos.base'; 951 952try { 953 formHost.isSystemReady().then(() => { 954 console.log('formHost isSystemReady success'); 955 }).catch((error: Base.BusinessError) => { 956 console.error(`error, code: ${error.code}, message: ${error.message}`); 957 }); 958} catch(error) { 959 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 960} 961``` 962 963## getAllFormsInfo 964 965getAllFormsInfo(callback: AsyncCallback<Array<formInfo.FormInfo>>): void 966 967Obtains the widget information provided by all applications on the device. This API uses an asynchronous callback to return the result. 968 969**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 970 971**System capability**: SystemCapability.Ability.Form 972 973**Parameters** 974 975| Name| Type | Mandatory| Description | 976| ------ |----------------------------------------------------------------------------------------------| ---- | ------- | 977| callback | AsyncCallback<Array<[formInfo.FormInfo](js-apis-app-form-formInfo.md#forminfo)>> | 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.| 978 979**Error codes** 980 981| Error Code ID| Error Message| 982| -------- | -------- | 983| 201 | Permissions denied. | 984| 202 | The application is not a system application. | 985| 401 | If the input parameter is not valid parameter. | 986| 16500050 | An IPC connection error happened. | 987| 16500060 | A service connection error happened, please try again later. | 988| 16501000 | An internal functional error occurred. | 989 990For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 991 992 993**Example** 994 995```ts 996import formInfo from '@ohos.app.form.formInfo'; 997import Base from '@ohos.base'; 998 999try { 1000 formHost.getAllFormsInfo((error: Base.BusinessError, data: formInfo.FormInfo[]) => { 1001 if (error) { 1002 console.error(`error, code: ${error.code}, message: ${error.message}`); 1003 } else { 1004 console.log(`formHost getAllFormsInfo, data: ${JSON.stringify(data)}`); 1005 } 1006 }); 1007} catch(error) { 1008 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1009} 1010``` 1011 1012## getAllFormsInfo 1013 1014getAllFormsInfo(): Promise<Array<formInfo.FormInfo>> 1015 1016Obtains the widget information provided by all applications on the device. This API uses a promise to return the result. 1017 1018**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1019 1020**System capability**: SystemCapability.Ability.Form 1021 1022**Return value** 1023 1024| Type | Description | 1025|:---------------------------------------------------------------------------------------|:----------------------| 1026| Promise<Array<[formInfo.FormInfo](js-apis-app-form-formInfo.md#forminfo)>> | Promise used to return the information obtained.| 1027 1028**Error codes** 1029 1030| Error Code ID| Error Message| 1031| -------- | -------- | 1032| 201 | Permissions denied. | 1033| 202 | The application is not a system application. | 1034| 16500050 | An IPC connection error happened. | 1035| 16500060 | A service connection error happened, please try again later. | 1036| 16501000 | An internal functional error occurred. | 1037 1038For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 1039 1040**Example** 1041 1042```ts 1043import formInfo from '@ohos.app.form.formInfo'; 1044import Base from '@ohos.base'; 1045 1046try { 1047 formHost.getAllFormsInfo().then((data: formInfo.FormInfo[]) => { 1048 console.log(`formHost getAllFormsInfo data: ${JSON.stringify(data)}`); 1049 }).catch((error: Base.BusinessError) => { 1050 console.error(`error, code: ${error.code}, message: ${error.message}`); 1051 }); 1052} catch(error) { 1053 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1054} 1055``` 1056 1057## getFormsInfo 1058 1059getFormsInfo(bundleName: string, callback: AsyncCallback<Array<formInfo.FormInfo>>): void 1060 1061Obtains the widget information provided by a given application on the device. This API uses an asynchronous callback to return the result. 1062 1063**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1064 1065**System capability**: SystemCapability.Ability.Form 1066 1067**Parameters** 1068 1069| Name| Type | Mandatory| Description | 1070| ------ |----------------------------------------------------------------------------------------------| ---- | ------- | 1071| bundleName | string | Yes| Bundle name of the application.| 1072| callback | AsyncCallback<Array<[formInfo.FormInfo](js-apis-app-form-formInfo.md#forminfo)>> | 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.| 1073 1074**Error codes** 1075 1076| Error Code ID| Error Message| 1077| -------- | -------- | 1078| 201 | Permissions denied. | 1079| 202 | The application is not a system application. | 1080| 401 | If the input parameter is not valid parameter. | 1081| 16500050 | An IPC connection error happened. | 1082| 16500060 | A service connection error happened, please try again later. | 1083| 16500100 | Failed to obtain the configuration information. | 1084| 16501000 | An internal functional error occurred. | 1085 1086For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 1087 1088**Example** 1089 1090```ts 1091import formInfo from '@ohos.app.form.formInfo'; 1092import Base from '@ohos.base'; 1093 1094try { 1095 formHost.getFormsInfo('com.example.ohos.formjsdemo', (error: Base.BusinessError, data: formInfo.FormInfo[]) => { 1096 if (error) { 1097 console.error(`error, code: ${error.code}, message: ${error.message}`); 1098 } else { 1099 console.log(`formHost getFormsInfo, data: ${JSON.stringify(data)}`); 1100 } 1101 }); 1102} catch(error) { 1103 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1104} 1105``` 1106 1107## getFormsInfo 1108 1109getFormsInfo(bundleName: string, moduleName: string, callback: AsyncCallback<Array<formInfo.FormInfo>>): void 1110 1111Obtains the widget information provided by a given application on the device. This API uses an asynchronous callback to return the result. 1112 1113**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1114 1115**System capability**: SystemCapability.Ability.Form 1116 1117**Parameters** 1118 1119| Name| Type | Mandatory| Description | 1120| ------ |----------------------------------------------------------------------------------------------| ---- | ------- | 1121| bundleName | string | Yes| Bundle name of the application.| 1122| moduleName | string | Yes| Module name.| 1123| callback | AsyncCallback<Array<[formInfo.FormInfo](js-apis-app-form-formInfo.md#forminfo)>> | 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.| 1124 1125**Error codes** 1126 1127| Error Code ID| Error Message| 1128| -------- | -------- | 1129| 201 | Permissions denied. | 1130| 202 | The application is not a system application. | 1131| 401 | If the input parameter is not valid parameter. | 1132| 16500050 | An IPC connection error happened. | 1133| 16500060 | A service connection error happened, please try again later. | 1134| 16500100 | Failed to obtain the configuration information. | 1135| 16501000 | An internal functional error occurred. | 1136 1137For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 1138 1139**Example** 1140 1141```ts 1142import formInfo from '@ohos.app.form.formInfo'; 1143import Base from '@ohos.base'; 1144 1145try { 1146 formHost.getFormsInfo('com.example.ohos.formjsdemo', 'entry', (error: Base.BusinessError, data: formInfo.FormInfo[]) => { 1147 if (error) { 1148 console.error(`error, code: ${error.code}, message: ${error.message}`); 1149 } else { 1150 console.log('formHost getFormsInfo, data: ${JSON.stringify(data)}'); 1151 } 1152 }); 1153} catch(error) { 1154 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1155} 1156``` 1157 1158## getFormsInfo 1159 1160getFormsInfo(bundleName: string, moduleName?: string): Promise<Array<formInfo.FormInfo>> 1161 1162Obtains the widget information provided by a given application on the device. This API uses a promise to return the result. 1163 1164**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1165 1166**System capability**: SystemCapability.Ability.Form 1167 1168**Parameters** 1169 1170| Name| Type | Mandatory| Description | 1171| ------ | ------ | ---- | ------- | 1172| bundleName | string | Yes| Bundle name of the application.| 1173| moduleName | string | No| Module name. By default, no value is passed.| 1174 1175**Return value** 1176 1177| Type | Description | 1178|:---------------------------------------------------------------------------------------| :---------------------------------- | 1179| Promise<Array<[formInfo.FormInfo](js-apis-app-form-formInfo.md#forminfo)>> | Promise used to return the information obtained.| 1180 1181**Error codes** 1182 1183| Error Code ID| Error Message| 1184| -------- | -------- | 1185| 201 | Permissions denied. | 1186| 202 | The application is not a system application. | 1187| 401 | If the input parameter is not valid parameter. | 1188| 16500050 | An IPC connection error happened. | 1189| 16500060 | A service connection error happened, please try again later. | 1190| 16500100 | Failed to obtain the configuration information. | 1191| 16501000 | An internal functional error occurred. | 1192 1193For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 1194 1195**Example** 1196 1197```ts 1198import formInfo from '@ohos.app.form.formInfo'; 1199import Base from '@ohos.base'; 1200 1201try { 1202 formHost.getFormsInfo('com.example.ohos.formjsdemo', 'entry').then((data: formInfo.FormInfo[]) => { 1203 console.log(`formHost getFormsInfo, data: ${JSON.stringify(data)}`); 1204 }).catch((error: Base.BusinessError) => { 1205 console.error(`error, code: ${error.code}, message: ${error.message}`); 1206 }); 1207} catch(error) { 1208 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1209} 1210``` 1211 1212## deleteInvalidForms 1213 1214deleteInvalidForms(formIds: Array<string>, callback: AsyncCallback<number>): void 1215 1216Deletes invalid widgets from the list. This API uses an asynchronous callback to return the result. 1217 1218**Required permissions**: ohos.permission.REQUIRE_FORM 1219 1220**System capability**: SystemCapability.Ability.Form 1221 1222**Parameters** 1223 1224| Name| Type | Mandatory| Description | 1225| ------ | ------ | ---- | ------- | 1226| formIds | Array<string> | Yes | List of valid widget IDs.| 1227| 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.| 1228 1229**Error codes** 1230 1231| Error Code ID| Error Message| 1232| -------- | -------- | 1233| 201 | Permissions denied. | 1234| 202 | The application is not a system application. | 1235| 401 | If the input parameter is not valid parameter. | 1236| 16500050 | An IPC connection error happened. | 1237| 16500060 | A service connection error happened, please try again later. | 1238| 16501000 | An internal functional error occurred. | 1239 1240For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 1241 1242**Example** 1243 1244```ts 1245import Base from '@ohos.base'; 1246 1247try { 1248 let formIds: string[] = new Array('12400633174999288', '12400633174999289'); 1249 formHost.deleteInvalidForms(formIds, (error: Base.BusinessError, data: number) => { 1250 if (error) { 1251 console.error(`error, code: ${error.code}, message: ${error.message}`); 1252 } else { 1253 console.log(`formHost deleteInvalidForms, data: ${JSON.stringify(data)}`); 1254 } 1255 }); 1256} catch(error) { 1257 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1258} 1259``` 1260 1261## deleteInvalidForms 1262 1263deleteInvalidForms(formIds: Array<string>): Promise<number> 1264 1265Deletes invalid widgets from the list. This API uses a promise to return the result. 1266 1267**Required permissions**: ohos.permission.REQUIRE_FORM 1268 1269**System capability**: SystemCapability.Ability.Form 1270 1271**Parameters** 1272 1273| Name| Type | Mandatory| Description | 1274| ------ | ------ | ---- | ------- | 1275| formIds | Array<string> | Yes | List of valid widget IDs.| 1276 1277**Return value** 1278 1279| Type | Description | 1280| :------------ | :---------------------------------- | 1281| Promise<number> | Promise used to return the number of widgets deleted.| 1282 1283**Error codes** 1284 1285| Error Code ID| Error Message| 1286| -------- | -------- | 1287| 201 | Permissions denied. | 1288| 202 | The application is not a system application. | 1289| 401 | If the input parameter is not valid parameter. | 1290| 16500050 | An IPC connection error happened. | 1291| 16500060 | A service connection error happened, please try again later. | 1292| 16501000 | An internal functional error occurred. | 1293 1294For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 1295 1296**Example** 1297 1298```ts 1299import Base from '@ohos.base'; 1300 1301try { 1302 let formIds: string[] = new Array('12400633174999288', '12400633174999289'); 1303 formHost.deleteInvalidForms(formIds).then((data: number) => { 1304 console.log(`formHost deleteInvalidForms, data: ${JSON.stringify(data)}`); 1305 }).catch((error: Base.BusinessError) => { 1306 console.error(`error, code: ${error.code}, message: ${error.message}`); 1307 }); 1308} catch(error) { 1309 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1310} 1311``` 1312 1313## acquireFormState 1314 1315acquireFormState(want: Want, callback: AsyncCallback<formInfo.FormStateInfo>): void 1316 1317Obtains the widget state. This API uses an asynchronous callback to return the result. 1318 1319**Required permissions**: ohos.permission.REQUIRE_FORM and ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1320 1321**System capability**: SystemCapability.Ability.Form 1322 1323**Parameters** 1324 1325| Name| Type | Mandatory| Description | 1326| ------ | ------ | ---- | ------- | 1327| want | [Want](js-apis-app-ability-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.| 1328| callback | AsyncCallback<[formInfo.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.| 1329 1330**Error codes** 1331 1332| Error Code ID| Error Message| 1333| -------- | -------- | 1334| 201 | Permissions denied. | 1335| 202 | The application is not a system application. | 1336| 401 | If the input parameter is not valid parameter. | 1337| 16500050 | An IPC connection error happened. | 1338| 16500060 | A service connection error happened, please try again later. | 1339| 16500100 | Failed to obtain the configuration information. | 1340| 16501000 | An internal functional error occurred. | 1341 1342For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 1343 1344**Example** 1345 1346```ts 1347import Want from '@ohos.app.ability.Want'; 1348import formInfo from '@ohos.app.form.formInfo'; 1349import Base from '@ohos.base'; 1350 1351let want: Want = { 1352 'deviceId': '', 1353 'bundleName': 'ohos.samples.FormApplication', 1354 'abilityName': 'FormAbility', 1355 'parameters': { 1356 'ohos.extra.param.key.module_name': 'entry', 1357 'ohos.extra.param.key.form_name': 'widget', 1358 'ohos.extra.param.key.form_dimension': 2 1359 } 1360}; 1361try { 1362 formHost.acquireFormState(want, (error:Base.BusinessError, data: formInfo.FormStateInfo) => { 1363 if (error) { 1364 console.error(`error, code: ${error.code}, message: ${error.message}`); 1365 } else { 1366 console.log(`formHost acquireFormState, data: ${JSON.stringify(data)}`); 1367 } 1368 }); 1369} catch(error) { 1370 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1371} 1372``` 1373 1374## acquireFormState 1375 1376acquireFormState(want: Want): Promise<formInfo.FormStateInfo> 1377 1378Obtains the widget state. This API uses a promise to return the result. 1379 1380**Required permissions**: ohos.permission.REQUIRE_FORM and ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1381 1382**System capability**: SystemCapability.Ability.Form 1383 1384**Parameters** 1385 1386| Name| Type | Mandatory| Description | 1387| ------ | ------ | ---- | ------- | 1388| want | [Want](js-apis-app-ability-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.| 1389 1390**Return value** 1391 1392| Type | Description | 1393| :------------ | :---------------------------------- | 1394| Promise<[formInfo.FormStateInfo](js-apis-app-form-formInfo.md#formstateinfo)> | Promise used to return the widget state obtained.| 1395 1396**Error codes** 1397 1398| Error Code ID| Error Message| 1399| -------- | -------- | 1400| 201 | Permissions denied. | 1401| 202 | The application is not a system application. | 1402| 401 | If the input parameter is not valid parameter. | 1403| 16500050 | An IPC connection error happened. | 1404| 16500060 | A service connection error happened, please try again later. | 1405| 16500100 | Failed to obtain the configuration information. | 1406| 16501000 | An internal functional error occurred. | 1407 1408For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 1409 1410**Example** 1411 1412```ts 1413import Want from '@ohos.app.ability.Want'; 1414import formInfo from '@ohos.app.form.formInfo'; 1415import Base from '@ohos.base'; 1416 1417let want: Want = { 1418 'deviceId': '', 1419 'bundleName': 'ohos.samples.FormApplication', 1420 'abilityName': 'FormAbility', 1421 'parameters': { 1422 'ohos.extra.param.key.module_name': 'entry', 1423 'ohos.extra.param.key.form_name': 'widget', 1424 'ohos.extra.param.key.form_dimension': 2 1425 } 1426}; 1427try { 1428 formHost.acquireFormState(want).then((data: formInfo.FormStateInfo) => { 1429 console.log(`formHost acquireFormState, data: ${JSON.stringify(data)}`); 1430 }).catch((error: Base.BusinessError) => { 1431 console.error(`error, code: ${error.code}, message: ${error.message}`); 1432 }); 1433} catch(error) { 1434 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1435} 1436``` 1437 1438## on('formUninstall') 1439 1440on(type: 'formUninstall', callback: Callback<string>): void 1441 1442Subscribes to widget uninstall events. This API uses an asynchronous callback to return the result. 1443 1444> **NOTE** 1445> 1446> Widget uninstall is different from widget removal. When an application is uninstalled, the corresponding widget is automatically uninstalled. 1447 1448**System capability**: SystemCapability.Ability.Form 1449 1450**Parameters** 1451 1452| Name| Type | Mandatory| Description | 1453| ------ | ------ | ---- | ------- | 1454| type | string | Yes | Event type. The value **'formUninstall'** indicates a widget uninstall event.| 1455| callback | Callback<string> | Yes| Callback used to return the widget ID.| 1456 1457**Error codes** 1458 1459| Error Code ID| Error Message| 1460| -------- | -------- | 1461| 202 | The application is not a system application. | 1462| 401 | If the input parameter is not valid parameter. | 1463 1464For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 1465 1466**Example** 1467 1468```ts 1469formHost.on('formUninstall', (formId: string) => { 1470 console.log(`formHost on formUninstall, formId: ${formId}`); 1471}); 1472``` 1473 1474## off('formUninstall') 1475 1476off(type: 'formUninstall', callback?: Callback<string>): void 1477 1478Unsubscribes from widget uninstall events. This API uses an asynchronous callback to return the result. 1479 1480> **NOTE** 1481> 1482> Widget uninstall is different from widget removal. When an application is uninstalled, the corresponding widget is automatically uninstalled. 1483 1484**System capability**: SystemCapability.Ability.Form 1485 1486**Parameters** 1487 1488| Name| Type | Mandatory| Description | 1489| ------ | ------ | ---- | ------- | 1490| type | string | Yes | Event type. The value **'formUninstall'** indicates a widget uninstall event.| 1491| callback | Callback<string> | 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> To cancel the subscription with a given callback, this parameter must be set to the same value as **callback** in **on('formUninstall')**.| 1492 1493**Error codes** 1494 1495| Error Code ID| Error Message| 1496| -------- | -------- | 1497| 202 | The application is not a system application. | 1498| 401 | If the input parameter is not valid parameter. | 1499 1500For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 1501 1502**Example** 1503 1504```ts 1505formHost.off('formUninstall', (formId: string) => { 1506 console.log(`formHost on formUninstall, formId: ${formId}`); 1507}); 1508``` 1509 1510## notifyFormsVisible 1511 1512notifyFormsVisible(formIds: Array<string>, isVisible: boolean, callback: AsyncCallback<void>): void 1513 1514Instructs the widgets to make themselves visible. This API uses an asynchronous callback to return the result. 1515 1516**Required permissions**: ohos.permission.REQUIRE_FORM 1517 1518**System capability**: SystemCapability.Ability.Form 1519 1520**Parameters** 1521 1522| Name| Type | Mandatory| Description | 1523| ------ | ------ | ---- | ------- | 1524| formIds | Array<string> | Yes | List of widget IDs.| 1525| isVisible | boolean | Yes | Whether to make the widgets visible.| 1526| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the notification is sent, **error** is undefined; otherwise, **error** is an error object.| 1527 1528**Error codes** 1529 1530| Error Code ID| Error Message| 1531| -------- | -------- | 1532| 201 | Permissions denied. | 1533| 202 | The application is not a system application. | 1534| 401 | If the input parameter is not valid parameter. | 1535| 16500050 | An IPC connection error happened. | 1536| 16500060 | A service connection error happened, please try again later. | 1537| 16501000 | An internal functional error occurred. | 1538| 16501003 | The form can not be operated by the current application. | 1539 1540For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 1541 1542**Example** 1543 1544```ts 1545import Base from '@ohos.base'; 1546 1547let formIds: string[] = new Array('12400633174999288', '12400633174999289'); 1548try { 1549 formHost.notifyFormsVisible(formIds, true, (error: Base.BusinessError) => { 1550 if (error) { 1551 console.error(`error, code: ${error.code}, message: ${error.message}`); 1552 } 1553 }); 1554} catch(error) { 1555 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1556} 1557``` 1558 1559## notifyFormsVisible 1560 1561notifyFormsVisible(formIds: Array<string>, isVisible: boolean): Promise<void> 1562 1563Instructs the widgets to make themselves visible. This API uses a promise to return the result. 1564 1565**Required permissions**: ohos.permission.REQUIRE_FORM 1566 1567**System capability**: SystemCapability.Ability.Form 1568 1569**Parameters** 1570 1571| Name| Type | Mandatory| Description | 1572| ------ | ------ | ---- | ------- | 1573| formIds | Array<string> | Yes | List of widget IDs.| 1574| isVisible | boolean | Yes | Whether to make the widgets visible.| 1575 1576**Return value** 1577 1578| Type| Description| 1579| -------- | -------- | 1580| Promise<void> | Promise that returns no value.| 1581 1582**Error codes** 1583 1584| Error Code ID| Error Message| 1585| -------- | -------- | 1586| 201 | Permissions denied. | 1587| 202 | The application is not a system application. | 1588| 401 | If the input parameter is not valid parameter. | 1589| 16500050 | An IPC connection error happened. | 1590| 16500060 | A service connection error happened, please try again later. | 1591| 16501000 | An internal functional error occurred. | 1592| 16501003 | The form can not be operated by the current application. | 1593 1594For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 1595 1596**Example** 1597 1598```ts 1599import Base from '@ohos.base'; 1600 1601let formIds: string[] = new Array('12400633174999288', '12400633174999289'); 1602try { 1603 formHost.notifyFormsVisible(formIds, true).then(() => { 1604 console.log('formHost notifyFormsVisible success'); 1605 }).catch((error: Base.BusinessError) => { 1606 console.error(`error, code: ${error.code}, message: ${error.message}`); 1607 }); 1608} catch(error) { 1609 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1610} 1611``` 1612 1613## notifyFormsEnableUpdate 1614 1615notifyFormsEnableUpdate(formIds: Array<string>, isEnableUpdate: boolean, callback: AsyncCallback<void>): void 1616 1617Instructs the widgets to enable or disable updates. This API uses an asynchronous callback to return the result. 1618 1619**Required permissions**: ohos.permission.REQUIRE_FORM 1620 1621**System capability**: SystemCapability.Ability.Form 1622 1623**Parameters** 1624 1625| Name| Type | Mandatory| Description | 1626| ------ | ------ | ---- | ------- | 1627| formIds | Array<string> | Yes | List of widget IDs.| 1628| isEnableUpdate | boolean | Yes | Whether to make the widgets updatable.| 1629| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the notification is sent, **error** is undefined; otherwise, **error** is an error object.| 1630 1631**Error codes** 1632 1633| Error Code ID| Error Message| 1634| -------- | -------- | 1635| 201 | Permissions denied. | 1636| 202 | The application is not a system application. | 1637| 401 | If the input parameter is not valid parameter. | 1638| 16500050 | An IPC connection error happened. | 1639| 16500060 | A service connection error happened, please try again later. | 1640| 16501000 | An internal functional error occurred. | 1641| 16501003 | The form can not be operated by the current application. | 1642 1643For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 1644 1645**Example** 1646 1647```ts 1648import Base from '@ohos.base'; 1649 1650let formIds: string[] = new Array('12400633174999288', '12400633174999289'); 1651try { 1652 formHost.notifyFormsEnableUpdate(formIds, true, (error: Base.BusinessError) => { 1653 if (error) { 1654 console.error(`error, code: ${error.code}, message: ${error.message}`); 1655 } 1656 }); 1657} catch(error) { 1658 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1659} 1660``` 1661 1662## notifyFormsEnableUpdate 1663 1664notifyFormsEnableUpdate(formIds: Array<string>, isEnableUpdate: boolean): Promise<void> 1665 1666Instructs the widgets to enable or disable updates. This API uses a promise to return the result. 1667 1668**Required permissions**: ohos.permission.REQUIRE_FORM 1669 1670**System capability**: SystemCapability.Ability.Form 1671 1672**Parameters** 1673 1674| Name| Type | Mandatory| Description | 1675| ------ | ------ | ---- | ------- | 1676| formIds | Array<string> | Yes | List of widget IDs.| 1677| isEnableUpdate | boolean | Yes | Whether to make the widgets updatable.| 1678 1679**Return value** 1680 1681| Type| Description| 1682| -------- | -------- | 1683| Promise<void> | Promise that returns no value.| 1684 1685**Error codes** 1686 1687| Error Code ID| Error Message| 1688| -------- | -------- | 1689| 201 | Permissions denied. | 1690| 202 | The application is not a system application. | 1691| 401 | If the input parameter is not valid parameter. | 1692| 16500050 | An IPC connection error happened. | 1693| 16500060 | A service connection error happened, please try again later. | 1694| 16501000 | An internal functional error occurred. | 1695| 16501003 | The form can not be operated by the current application. | 1696 1697For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 1698 1699**Example** 1700 1701```ts 1702import Base from '@ohos.base'; 1703 1704let formIds: string[] = new Array('12400633174999288', '12400633174999289'); 1705try { 1706 formHost.notifyFormsEnableUpdate(formIds, true).then(() => { 1707 console.log('formHost notifyFormsEnableUpdate success'); 1708 }).catch((error: Base.BusinessError) => { 1709 console.error(`error, code: ${error.code}, message: ${error.message}`); 1710 }); 1711} catch(error) { 1712 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1713} 1714``` 1715## shareForm 1716 1717shareForm(formId: string, deviceId: string, callback: AsyncCallback<void>): void 1718 1719Shares a specified widget with a remote device. This API uses an asynchronous callback to return the result. 1720 1721**Required permissions**: ohos.permission.REQUIRE_FORM and ohos.permission.DISTRIBUTED_DATASYNC 1722 1723**System capability**: SystemCapability.Ability.Form 1724 1725**Parameters** 1726 1727| Name| Type | Mandatory| Description | 1728| ------ | ------ | ---- | ------- | 1729| formId | string | Yes | Widget ID.| 1730| deviceId | string | Yes | Remote device ID.| 1731| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is shared, **error** is undefined; otherwise, **error** is an error object.| 1732 1733**Error codes** 1734 1735| Error Code ID| Error Message| 1736| -------- | -------- | 1737| 201 | Permissions denied. | 1738| 202 | The application is not a system application. | 1739| 401 | If the input parameter is not valid parameter. | 1740| 16500050 | An IPC connection error happened. | 1741| 16501000 | An internal functional error occurred. | 1742| 16501001 | The ID of the form to be operated does not exist. | 1743| 16501003 | The form can not be operated by the current application. | 1744 1745For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 1746 1747**Example** 1748 1749```ts 1750import Base from '@ohos.base'; 1751 1752let formId: string = '12400633174999288'; 1753let deviceId: string = 'EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2'; 1754try { 1755 formHost.shareForm(formId, deviceId, (error: Base.BusinessError) => { 1756 if (error) { 1757 console.error(`error, code: ${error.code}, message: ${error.message}`); 1758 } 1759 }); 1760} catch(error) { 1761 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1762} 1763``` 1764 1765## shareForm 1766 1767shareForm(formId: string, deviceId: string): Promise<void> 1768 1769Shares a specified widget with a remote device. This API uses a promise to return the result. 1770 1771**Required permissions**: ohos.permission.REQUIRE_FORM and ohos.permission.DISTRIBUTED_DATASYNC 1772 1773**System capability**: SystemCapability.Ability.Form 1774 1775**Parameters** 1776 1777| Name| Type | Mandatory| Description | 1778| ------ | ------ | ---- | ------- | 1779| formId | string | Yes | Widget ID.| 1780| deviceId | string | Yes | Remote device ID.| 1781 1782**Return value** 1783 1784| Type| Description| 1785| -------- | -------- | 1786| Promise<void> | Promise that returns no value.| 1787 1788**Error codes** 1789 1790| Error Code ID| Error Message| 1791| -------- | -------- | 1792| 201 | Permissions denied. | 1793| 202 | The application is not a system application. | 1794| 401 | If the input parameter is not valid parameter. | 1795| 16500050 | An IPC connection error happened. | 1796| 16501000 | An internal functional error occurred. | 1797| 16501001 | The ID of the form to be operated does not exist. | 1798| 16501003 | The form can not be operated by the current application. | 1799 1800For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 1801 1802**Example** 1803 1804```ts 1805import Base from '@ohos.base'; 1806 1807let formId: string = '12400633174999288'; 1808let deviceId: string = 'EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2'; 1809try { 1810 formHost.shareForm(formId, deviceId).then(() => { 1811 console.log('formHost shareForm success'); 1812 }).catch((error: Base.BusinessError) => { 1813 console.error(`error, code: ${error.code}, message: ${error.message}`); 1814 }); 1815} catch(error) { 1816 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1817} 1818``` 1819 1820## notifyFormsPrivacyProtected 1821 1822notifyFormsPrivacyProtected(formIds: Array\<string>, isProtected: boolean, callback: AsyncCallback\<void>): void 1823 1824Notifies that the privacy protection status of the specified widgets changes. This API uses an asynchronous callback to return the result. 1825 1826**Required permissions**: ohos.permission.REQUIRE_FORM 1827 1828**System capability**: SystemCapability.Ability.Form 1829 1830**Parameters** 1831 1832| Name| Type | Mandatory| Description | 1833| ------ | ------ | ---- | ------- | 1834| formIds | Array\<string\> | Yes | ID of the widgets.| 1835| isProtected | boolean | Yes | Whether privacy protection is enabled.| 1836| 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.| 1837 1838**Error codes** 1839 1840| Error Code ID| Error Message| 1841| -------- | -------- | 1842| 201 | Permissions denied. | 1843| 202 | The application is not a system application. | 1844| 401 | If the input parameter is not valid parameter. | 1845| 16500050 | An IPC connection error happened. | 1846| 16500060 | A service connection error happened, please try again later. | 1847| 16501000 | An internal functional error occurred. | 1848 1849For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 1850 1851**Example** 1852 1853```ts 1854import Base from '@ohos.base'; 1855 1856let formIds: string[] = new Array('12400633174999288', '12400633174999289'); 1857try { 1858 formHost.notifyFormsPrivacyProtected(formIds, true, (error: Base.BusinessError) => { 1859 if (error) { 1860 console.error(`error, code: ${error.code}, message: ${error.message}`); 1861 } 1862 }); 1863} catch(error) { 1864 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1865} 1866``` 1867 1868## notifyFormsPrivacyProtected 1869 1870notifyFormsPrivacyProtected(formIds: Array\<string\>, isProtected: boolean): Promise\<void\> 1871 1872Notifies that the privacy protection status of the specified widgets changes. This API uses a promise to return the result. 1873 1874**Required permissions**: ohos.permission.REQUIRE_FORM 1875 1876**System capability**: SystemCapability.Ability.Form 1877 1878**Parameters** 1879 1880| Name | Type | Mandatory| Description | 1881| ----------- | --------------- | ---- | -------------------------------- | 1882| formIds | Array\<string\> | Yes | ID of the widgets.| 1883| isProtected | boolean | Yes | Whether privacy protection is enabled. | 1884 1885**Return value** 1886 1887| Type | Description | 1888| ------------------- | ------------------------- | 1889| Promise<void> | Promise that returns no value.| 1890 1891**Error codes** 1892 1893| Error Code ID| Error Message| 1894| -------- | -------- | 1895| 201 | Permissions denied. | 1896| 202 | The application is not a system application. | 1897| 401 | If the input parameter is not valid parameter. | 1898| 16500050 | An IPC connection error happened. | 1899| 16500060 | A service connection error happened, please try again later. | 1900| 16501000 | An internal functional error occurred. | 1901 1902For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 1903 1904```ts 1905import Base from '@ohos.base'; 1906 1907let formIds: string[] = new Array('12400633174999288', '12400633174999289'); 1908try { 1909 formHost.notifyFormsPrivacyProtected(formIds, true).then(() => { 1910 console.log('formHost notifyFormsPrivacyProtected success'); 1911 }).catch((error: Base.BusinessError) => { 1912 console.error(`error, code: ${error.code}, message: ${error.message}`); 1913 }); 1914} catch(error) { 1915 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1916} 1917``` 1918 1919## acquireFormData<sup>10+</sup> 1920 1921acquireFormData(formId: string, callback: AsyncCallback\<Record\<string, Object>>): void 1922 1923Requests data from the widget provider. This API uses an asynchronous callback to return the result. 1924 1925**Model restriction**: This API can be used only in the stage model. 1926 1927**Required permissions**: ohos.permission.REQUIRE_FORM 1928 1929**System capability**: SystemCapability.Ability.Form 1930 1931**Parameters** 1932 1933| Name| Type | Mandatory| Description | 1934| ------ | ------ | ---- | ------- | 1935| formId | string | Yes | Widget ID.| 1936| callback | AsyncCallback\<Record\<string, Object> | Yes | Callback used to return the API call result and the shared data.| 1937 1938**Error codes** 1939 1940| Error Code ID| Error Message| 1941| -------- | -------- | 1942| 201 | Permissions denied. | 1943| 401 | If the input parameter is not valid parameter. | 1944| 16500050 | An IPC connection error happened. | 1945| 16500060 | A service connection error happened, please try again later. | 1946| 16500100 | Failed to obtain the configuration information. | 1947| 16501000 | An internal functional error occurred. | 1948 1949For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 1950 1951**Example** 1952 1953```ts 1954import Base from '@ohos.base'; 1955 1956let formId: string = '12400633174999288'; 1957try { 1958 formHost.acquireFormData(formId, (error, data) => { 1959 if (error) { 1960 console.error(`error, code: ${error.code}, message: ${error.message}`); 1961 } else { 1962 console.log(`formHost acquireFormData, data: ${JSON.stringify(data)}`); 1963 } 1964 }); 1965} catch(error) { 1966 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1967} 1968``` 1969 1970## acquireFormData<sup>10+</sup> 1971 1972acquireFormData(formId: string): Promise\<Record\<string, Object>> 1973 1974Requests data from the widget provider. This API uses a promise to return the result. 1975 1976**Model restriction**: This API can be used only in the stage model. 1977 1978**Required permissions**: ohos.permission.REQUIRE_FORM 1979 1980**System capability**: SystemCapability.Ability.Form 1981 1982**Parameters** 1983 1984| Name | Type | Mandatory| Description | 1985| ----------- | --------------- | ---- | -------------------------------- | 1986| formId | string | Yes | Widget ID.| 1987 1988**Return value** 1989 1990| Type | Description | 1991| ------------------- | ------------------------- | 1992| Promise\<Record\<string, Object>>| Promise used to return the API call result and the shared data.| 1993 1994**Error codes** 1995 1996| Error Code ID| Error Message| 1997| -------- | -------- | 1998| 201 | Permissions denied. | 1999| 401 | If the input parameter is not valid parameter. | 2000| 16500050 | An IPC connection error happened. | 2001| 16500060 | A service connection error happened, please try again later. | 2002| 16500100 | Failed to obtain the configuration information. | 2003| 16501000 | An internal functional error occurred. | 2004 2005For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 2006 2007```ts 2008import Base from '@ohos.base'; 2009 2010let formId: string = '12400633174999288'; 2011try { 2012 formHost.acquireFormData(formId).then((data) => { 2013 console.log('formHost acquireFormData success' + data); 2014 }).catch((error: Base.BusinessError) => { 2015 console.error(`error, code: ${error.code}, message: ${error.message}`); 2016 }); 2017} catch(error) { 2018 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 2019} 2020``` 2021 2022## setRouterProxy<sup>11+</sup> 2023 2024setRouterProxy(formIds: Array<string>, proxy: Callback<Want>, callback: AsyncCallback<void>): void 2025 2026Sets a router proxy for widgets and obtains the Want information required for redirection. This API uses an asynchronous callback to return the result. 2027 2028> **NOTE** 2029> 2030>- Generally, for a widget added to the home screen, in the case of router-based redirection, the widget framework checks whether the destination is proper and whether the widget has the redirection permission, and then triggers redirection accordingly. For a widget that is added to a widget host and has a router proxy configured, in the case of router-based redirection, the widget framework does not trigger redirection for the widget. Instead, it returns the **want** parameter containing the destination to the widget host. Therefore, if the widget host wants to use the Want information for redirection, it must have the application redirection permission. For details, see [UIAbilityContext.startAbility()](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartability). 2031> 2032>- Only one router proxy can be set for a widget. If multiple proxies are set, only the last proxy takes effect. 2033 2034**Required permissions**: ohos.permission.REQUIRE_FORM 2035 2036**System capability**: SystemCapability.Ability.Form 2037 2038**Parameters** 2039 2040| Name | Type | Mandatory| Description | 2041| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 2042| formIds | Array<string> | Yes | Array of widget IDs. | 2043| proxy | Callback<Want> | Yes | Callback used to return the Want information required for redirection. | 2044| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the router proxy is set, **error** is **undefined**; otherwise, an exception is thrown.| 2045 2046**Error codes** 2047 2048| Error Code ID| Error Message | 2049| -------- | ------------------------------------------------------------ | 2050| 201 | Permissions denied. | 2051| 202 | The application is not a system application. | 2052| 401 | If the input parameter is not valid parameter. | 2053| 16500050 | An IPC connection error happened. | 2054| 16500060 | A service connection error happened, please try again later. | 2055| 16501000 | An internal functional error occurred. | 2056| 16501003 | The form can not be operated by the current application. | 2057 2058For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 2059 2060**Example** 2061 2062```ts 2063import common from '@ohos.app.ability.common'; 2064import formHost from '@ohos.app.form.formHost'; 2065import Base from '@ohos.base'; 2066import Want from '@ohos.app.ability.Want'; 2067 2068@Entry 2069@Component 2070struct CardExample { 2071 private context = getContext(this) as common.UIAbilityContext; 2072 @State formId:number = 0; 2073 @State fwidth:number = 420; 2074 @State fheight:number = 280; 2075 2076 build() { 2077 Column() { 2078 FormComponent({ 2079 id:this.formId, 2080 name:"widget", 2081 bundle:"com.example.cardprovider", 2082 ability:"EntryFormAbility", 2083 module:"entry", 2084 dimension:FormDimension.Dimension_2_2, 2085 temporary:false, 2086 }) 2087 .allowUpdate(true) 2088 .size({width:this.fwidth,height:this.fheight}) 2089 .visibility(Visibility.Visible) 2090 .onAcquired((form)=>{ 2091 console.log(`testTag form info : ${JSON.stringify(form)}`); 2092 this.formId = form.id; 2093 try { 2094 let formIds: string[] = [ this.formId.toString() ]; 2095 formHost.setRouterProxy(formIds, (want: Want) => { 2096 console.info(`formHost recv router event, want: ${JSON.stringify(want)}`); 2097 // The widget host processes the redirection. 2098 this.context.startAbility(want, (err: Base.BusinessError) => { 2099 console.info(`formHost startAbility error, code: ${err.code}, message: ${err.message}`); 2100 }); 2101 }, (err: Base.BusinessError) => { 2102 console.error(`set router proxy error, code: ${err.code}, message: ${err.message}`); 2103 }) 2104 } catch (e) { 2105 console.log('formHost setRouterProxy catch exception: ' + JSON.stringify(e)); 2106 } 2107 }) 2108 } 2109 .width('100%') 2110 .height('100%') 2111 } 2112} 2113``` 2114 2115## setRouterProxy<sup>11+</sup> 2116 2117setRouterProxy(formIds: Array<string>, proxy: Callback<Want>): Promise<void> 2118 2119Sets a router proxy for widgets and obtains the Want information required for redirection. This API uses a promise to return the result. 2120 2121> **NOTE** 2122> 2123>- Generally, for a widget added to the home screen, in the case of router-based redirection, the widget framework checks whether the destination is proper and whether the widget has the redirection permission, and then triggers redirection accordingly. For a widget that is added to a widget host and has a router proxy configured, in the case of router-based redirection, the widget framework does not trigger redirection for the widget. Instead, it returns the **want** parameter containing the destination to the widget host. Therefore, if the widget host wants to use the Want information for redirection, it must have the application redirection permission. For details, see [UIAbilityContext.startAbility()](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartability). 2124> 2125>- Only one router proxy can be set for a widget. If multiple proxies are set, only the last proxy takes effect. 2126 2127 2128 2129**Required permissions**: ohos.permission.REQUIRE_FORM 2130 2131**System capability**: SystemCapability.Ability.Form 2132 2133**Parameters** 2134 2135| Name | Type | Mandatory| Description | 2136| ------- | -------------------- | ---- | ------------------------------------ | 2137| formIds | Array<string> | Yes | Array of widget IDs. | 2138| proxy | Callback<Want> | Yes | Callback used to return the Want information required for redirection.| 2139 2140**Return value** 2141 2142| Type | Description | 2143| ------------------- | ------------------------- | 2144| Promise<void> | Promise that returns no value.| 2145 2146**Error codes** 2147 2148| Error Code ID| Error Message | 2149| -------- | ------------------------------------------------------------ | 2150| 201 | Permissions denied. | 2151| 202 | The application is not a system application. | 2152| 401 | If the input parameter is not valid parameter. | 2153| 16500050 | An IPC connection error happened. | 2154| 16500060 | A service connection error happened, please try again later. | 2155| 16501000 | An internal functional error occurred. | 2156| 16501003 | The form can not be operated by the current application. | 2157 2158For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 2159 2160**Example** 2161 2162```ts 2163import common from '@ohos.app.ability.common'; 2164import formHost from '@ohos.app.form.formHost'; 2165import Base from '@ohos.base'; 2166import Want from '@ohos.app.ability.Want'; 2167 2168@Entry 2169@Component 2170struct CardExample { 2171 private context = getContext(this) as common.UIAbilityContext; 2172 @State formId:number = 0; 2173 @State fwidth:number = 420; 2174 @State fheight:number = 280; 2175 2176 build() { 2177 Column() { 2178 FormComponent({ 2179 id:this.formId, 2180 name:"widget", 2181 bundle:"com.example.cardprovider", 2182 ability:"EntryFormAbility", 2183 module:"entry", 2184 dimension:FormDimension.Dimension_2_2, 2185 temporary:false, 2186 }) 2187 .allowUpdate(true) 2188 .size({width:this.fwidth,height:this.fheight}) 2189 .visibility(Visibility.Visible) 2190 .onAcquired((form)=>{ 2191 console.log(`testTag form info : ${JSON.stringify(form)}`); 2192 this.formId = form.id; 2193 try { 2194 let formIds: string[] = [ this.formId.toString() ]; 2195 formHost.setRouterProxy(formIds, (want: Want) => { 2196 console.info(`formHost recv router event, want: ${JSON.stringify(want)}`); 2197 // The widget host processes the redirection. 2198 this.context.startAbility(want, (err: Base.BusinessError) => { 2199 console.info(`formHost startAbility error, code: ${err.code}, message: ${err.message}`); 2200 }); 2201 }).then(() => { 2202 console.info('formHost set router proxy success'); 2203 }).catch((err: Base.BusinessError) => { 2204 console.error(`set router proxy error, code: ${err.code}, message: ${err.message}`); 2205 }) 2206 } catch (e) { 2207 console.log('formHost setRouterProxy catch exception: ' + JSON.stringify(e)); 2208 } 2209 }) 2210 } 2211 .width('100%') 2212 .height('100%') 2213 } 2214} 2215``` 2216 2217## clearRouterProxy<sup>11+</sup> 2218 2219clearRouterProxy(formIds:Array<string>, callback: AsyncCallback<void>): void 2220 2221Clears the router proxy set for widgets. This API uses an asynchronous callback to return the result. 2222 2223**Required permissions**: ohos.permission.REQUIRE_FORM 2224 2225**System capability**: SystemCapability.Ability.Form 2226 2227**Parameters** 2228 2229| Name | Type | Mandatory| Description | 2230| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 2231| formIds | Array<string>; | Yes | Array of widget IDs. | 2232| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the router proxy is cleared, **error** is **undefined**; otherwise, an exception is thrown.| 2233 2234**Error codes** 2235 2236| Error Code ID| Error Message | 2237| -------- | ------------------------------------------------------------ | 2238| 201 | Permissions denied. | 2239| 202 | The application is not a system application. | 2240| 401 | If the input parameter is not valid parameter. | 2241| 16500050 | An IPC connection error happened. | 2242| 16500060 | A service connection error happened, please try again later. | 2243| 16501000 | An internal functional error occurred. | 2244| 16501003 | The form can not be operated by the current application. | 2245 2246For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 2247 2248**Example** 2249 2250```ts 2251import formHost from '@ohos.app.form.formHost'; 2252import Base from '@ohos.base'; 2253import Want from '@ohos.app.ability.Want'; 2254 2255try { 2256 let formIds: string[] = [ '12400633174999288' ]; 2257 formHost.clearRouterProxy(formIds, (err: Base.BusinessError) => { 2258 if (err) { 2259 console.error(`formHost clear router proxy error, code: ${err.code}, message: ${err.message}`); 2260 } 2261 }); 2262} catch(error) { 2263 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 2264} 2265``` 2266 2267## clearRouterProxy<sup>11+</sup> 2268 2269clearRouterProxy(formIds:Array<string>): Promise<void> 2270 2271Clears the router proxy set for widgets. This API uses a promise to return the result. 2272 2273**Required permissions**: ohos.permission.REQUIRE_FORM 2274 2275**System capability**: SystemCapability.Ability.Form 2276 2277**Parameters** 2278 2279| Name | Type | Mandatory| Description | 2280| ------- | ------------------- | ---- | -------------- | 2281| formIds | Array<string> | Yes | Array of widget IDs.| 2282 2283**Return value** 2284 2285| Type | Description | 2286| ------------------- | ------------------------- | 2287| Promise<void> | Promise that returns no value.| 2288 2289**Error codes** 2290 2291| Error Code ID| Error Message | 2292| -------- | ------------------------------------------------------------ | 2293| 201 | Permissions denied. | 2294| 202 | The application is not a system application. | 2295| 401 | If the input parameter is not valid parameter. | 2296| 16500050 | An IPC connection error happened. | 2297| 16500060 | A service connection error happened, please try again later. | 2298| 16501000 | An internal functional error occurred. | 2299| 16501003 | The form can not be operated by the current application. | 2300 2301For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 2302 2303**Example** 2304 2305```ts 2306import formHost from '@ohos.app.form.formHost'; 2307import Base from '@ohos.base'; 2308import Want from '@ohos.app.ability.Want'; 2309 2310try { 2311 let formIds: string[] = [ '12400633174999288' ]; 2312 formHost.clearRouterProxy(formIds).then(() => { 2313 console.log('formHost clear rourter proxy success'); 2314 }).catch((err: Base.BusinessError) => { 2315 console.error(`formHost clear router proxy error, code: ${err.code}, message: ${err.message}`); 2316 }); 2317} catch(error) { 2318 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 2319} 2320``` 2321## setFormsRecyclable<sup>11+</sup> 2322 2323setFormsRecyclable(formIds:Array<string>, callback: AsyncCallback<void>): void 2324 2325Sets widgets to be recyclable. This API uses an asynchronous callback to return the result. 2326 2327**Required permissions**: ohos.permission.REQUIRE_FORM 2328 2329**System capability**: SystemCapability.Ability.Form 2330 2331**Parameters** 2332 2333| Name | Type | Mandatory| Description | 2334| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 2335| formIds | Array<string>; | Yes | Array of widget IDs. | 2336| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the widgets are set to be recyclable, **error** is **undefined**; otherwise, an exception is thrown.| 2337 2338**Error codes** 2339 2340| Error Code ID| Error Message | 2341| -------- | ------------------------------------------------------------ | 2342| 16500050 | An IPC connection error happened. | 2343| 16500060 | A service connection error happened, please try again later. | 2344| 16501000 | An internal functional error occurred. | 2345| 16501003 | The form can not be operated by the current application. | 2346 2347For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 2348 2349**Example** 2350 2351```ts 2352import formHost from '@ohos.app.form.formHost'; 2353import Base from '@ohos.base'; 2354import Want from '@ohos.app.ability.Want'; 2355 2356try { 2357 let formIds: string[] = [ '12400633174999288' ]; 2358 formHost.setFormsRecyclable(formIds, (err: Base.BusinessError) => { 2359 if (err) { 2360 console.error(`setFormsRecyclable error, code: ${err.code}, message: ${err.message}`); 2361 } 2362 }); 2363} catch(error) { 2364 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 2365} 2366``` 2367 2368## setFormsRecyclable<sup>11+</sup> 2369 2370setFormsRecyclable(formIds:Array<string>): Promise<void> 2371 2372Sets widgets to be recyclable. This API uses a promise to return the result. 2373 2374**Required permissions**: ohos.permission.REQUIRE_FORM 2375 2376**System capability**: SystemCapability.Ability.Form 2377 2378**Parameters** 2379 2380| Name | Type | Mandatory| Description | 2381| ------- | ------------------- | ---- | -------------- | 2382| formIds | Array<string> | Yes | Array of widget IDs.| 2383 2384**Return value** 2385 2386| Type | Description | 2387| ------------------- | ------------------------- | 2388| Promise<void> | Promise that returns no value.| 2389 2390**Error codes** 2391 2392| Error Code ID| Error Message | 2393| -------- | ------------------------------------------------------------ | 2394| 16500050 | An IPC connection error happened. | 2395| 16500060 | A service connection error happened, please try again later. | 2396| 16501000 | An internal functional error occurred. | 2397| 16501003 | The form can not be operated by the current application. | 2398 2399For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 2400 2401**Example** 2402 2403```ts 2404import formHost from '@ohos.app.form.formHost'; 2405import Base from '@ohos.base'; 2406import Want from '@ohos.app.ability.Want'; 2407 2408try { 2409 let formIds: string[] = [ '12400633174999288' ]; 2410 formHost.setFormsRecyclable(formIds).then(() => { 2411 console.log('setFormsRecyclable success'); 2412 }).catch((err: Base.BusinessError) => { 2413 console.error(`setFormsRecyclable error, code: ${err.code}, message: ${err.message}`); 2414 }); 2415} catch(error) { 2416 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 2417} 2418``` 2419## recoverForms<sup>11+</sup> 2420 2421recoverForms(formIds:Array<string>, callback: AsyncCallback<void>): void 2422 2423Recovers widgets. This API uses an asynchronous callback to return the result. 2424 2425**Required permissions**: ohos.permission.REQUIRE_FORM 2426 2427**System capability**: SystemCapability.Ability.Form 2428 2429**Parameters** 2430 2431| Name | Type | Mandatory| Description | 2432| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 2433| formIds | Array<string>; | Yes | Array of widget IDs. | 2434| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the widgets are recovered, **error** is **undefined**; otherwise, an exception is thrown.| 2435 2436**Error codes** 2437 2438| Error Code ID| Error Message | 2439| -------- | ------------------------------------------------------------ | 2440| 16500050 | An IPC connection error happened. | 2441| 16500060 | A service connection error happened, please try again later. | 2442| 16501000 | An internal functional error occurred. | 2443| 16501003 | The form can not be operated by the current application. | 2444 2445For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md). 2446 2447**Example** 2448 2449```ts 2450import formHost from '@ohos.app.form.formHost'; 2451import Base from '@ohos.base'; 2452import Want from '@ohos.app.ability.Want'; 2453 2454try { 2455 let formIds: string[] = [ '12400633174999288' ]; 2456 formHost.recoverForms(formIds, (err: Base.BusinessError) => { 2457 if (err) { 2458 console.error(`recoverForms error, code: ${err.code}, message: ${err.message}`); 2459 } 2460 }); 2461} catch(error) { 2462 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 2463} 2464``` 2465 2466## 2467