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> The APIs provided by this module are system APIs. 9 10## Modules to Import 11 12```ts 13import formHost from '@ohos.app.form.formHost'; 14``` 15 16## deleteForm 17 18deleteForm(formId: string, callback: AsyncCallback<void>): void 19 20Deletes 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. 21 22**Required permissions**: ohos.permission.REQUIRE_FORM 23 24**System capability**: SystemCapability.Ability.Form 25 26**Parameters** 27 28| Name| Type | Mandatory| Description | 29| ------ | ------ | ---- | ------- | 30| formId | string | Yes | Widget ID.| 31| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is deleted, **error** is undefined; otherwise, **error** is an error object.| 32 33**Error codes** 34 35| Error Code ID| Error Message| 36| -------- | -------- | 37| 201 | Permissions denied. | 38| 401 | If the input parameter is not valid parameter. | 39| 16500050 | An IPC connection error happened. | 40| 16500060 | A service connection error happened, please try again later. | 41| 202 | The application is not a system application. | 42| 16501000 | An internal functional error occurred. | 43| 16501001 | The ID of the form to be operated does not exist. | 44| 16501003 | The form can not be operated by the current application. | 45|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 46 47**Example** 48 49```ts 50try { 51 var formId = '12400633174999288'; 52 formHost.deleteForm(formId, (error, data) => { 53 if (error) { 54 console.log('formHost deleteForm, error:' + JSON.stringify(error)); 55 } else { 56 console.log('formHost deleteForm success'); 57 } 58 }); 59} catch (error) { 60 console.log(`catch err->${JSON.stringify(error)}`); 61} 62 63``` 64 65## deleteForm 66 67deleteForm(formId: string): Promise<void> 68 69Deletes 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. 70 71**Required permissions**: ohos.permission.REQUIRE_FORM 72 73**System capability**: SystemCapability.Ability.Form 74 75**Parameters** 76 77| Name| Type | Mandatory| Description | 78| ------ | ------ | ---- | ------- | 79| formId | string | Yes | Widget ID.| 80 81**Return value** 82 83| Type| Description| 84| -------- | -------- | 85| Promise<void> | Promise that returns no value.| 86 87 88**Error codes** 89 90| Error Code ID| Error Message| 91| -------- | -------- | 92| 201 | Permissions denied. | 93| 202 | The application is not a system application. | 94| 401 | If the input parameter is not valid parameter. | 95| 16500050 | An IPC connection error happened. | 96| 16500060 | A service connection error happened, please try again later. | 97| 16501000 | An internal functional error occurred. | 98| 16501001 | The ID of the form to be operated does not exist. | 99| 16501003 | The form can not be operated by the current application. | 100|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 101 102**Example** 103 104```ts 105try { 106 var formId = '12400633174999288'; 107 formHost.deleteForm(formId).then(() => { 108 console.log('formHost deleteForm success'); 109 }).catch((error) => { 110 console.log('formHost deleteForm, error:' + JSON.stringify(error)); 111 }); 112} catch(error) { 113 console.log(`catch err->${JSON.stringify(error)}`); 114} 115``` 116 117## releaseForm 118 119releaseForm(formId: string, callback: AsyncCallback<void>): void 120 121Releases 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. 122 123**Required permissions**: ohos.permission.REQUIRE_FORM 124 125**System capability**: SystemCapability.Ability.Form 126 127**Parameters** 128 129| Name| Type | Mandatory| Description | 130| ------ | ------ | ---- | ------- | 131| formId | string | Yes | Widget ID.| 132| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is released, **error** is undefined; otherwise, **error** is an error object.| 133 134**Error codes** 135 136| Error Code ID| Error Message| 137| -------- | -------- | 138| 201 | Permissions denied. | 139| 202 | The application is not a system application. | 140| 401 | If the input parameter is not valid parameter. | 141| 16500050 | An IPC connection error happened. | 142| 16500060 | A service connection error happened, please try again later. | 143| 16501000 | An internal functional error occurred. | 144| 16501001 | The ID of the form to be operated does not exist. | 145| 16501003 | The form can not be operated by the current application. | 146|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 147 148**Example** 149 150```ts 151try { 152 var formId = '12400633174999288'; 153 formHost.releaseForm(formId, (error, data) => { 154 if (error) { 155 console.log('formHost releaseForm, error:' + JSON.stringify(error)); 156 } 157 }); 158} catch(error) { 159 console.log(`catch err->${JSON.stringify(error)}`); 160} 161``` 162 163## releaseForm 164 165releaseForm(formId: string, isReleaseCache: boolean, callback: AsyncCallback<void>): void 166 167Releases 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. 168 169**Required permissions**: ohos.permission.REQUIRE_FORM 170 171**System capability**: SystemCapability.Ability.Form 172 173**Parameters** 174 175| Name | Type | Mandatory| Description | 176| -------------- | ------ | ---- | ----------- | 177| formId | string | Yes | Widget ID. | 178| isReleaseCache | boolean | Yes | Whether to release the cache.| 179| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is released, **error** is undefined; otherwise, **error** is an error object.| 180 181**Error codes** 182 183| Error Code ID| Error Message| 184| -------- | -------- | 185| 201 | Permissions denied. | 186| 202 | The application is not a system application. | 187| 401 | If the input parameter is not valid parameter. | 188| 16500050 | An IPC connection error happened. | 189| 16500060 | A service connection error happened, please try again later. | 190| 16501000 | An internal functional error occurred. | 191| 16501001 | The ID of the form to be operated does not exist. | 192| 16501003 | The form can not be operated by the current application. | 193|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 194 195**Example** 196 197```ts 198try { 199 var formId = '12400633174999288'; 200 formHost.releaseForm(formId, true, (error, data) => { 201 if (error) { 202 console.log('formHost releaseForm, error:' + JSON.stringify(error)); 203 } 204 }); 205} catch(error) { 206 console.log(`catch err->${JSON.stringify(error)}`); 207} 208``` 209 210## releaseForm 211 212releaseForm(formId: string, isReleaseCache?: boolean): Promise<void> 213 214Releases 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. 215 216**Required permissions**: ohos.permission.REQUIRE_FORM 217 218**System capability**: SystemCapability.Ability.Form 219 220**Parameters** 221 222| Name | Type | Mandatory| Description | 223| -------------- | ------ | ---- | ----------- | 224| formId | string | Yes | Widget ID. | 225| isReleaseCache | boolean | No | Whether to release the cache. The default value is **false**. | 226 227**Return value** 228 229| Type| Description| 230| -------- | -------- | 231| Promise<void> | Promise that returns no value.| 232 233**Error codes** 234 235| Error Code ID| Error Message| 236| -------- | -------- | 237| 201 | Permissions denied. | 238| 202 | The application is not a system application. | 239| 401 | If the input parameter is not valid parameter. | 240| 16500050 | An IPC connection error happened. | 241| 16500060 | A service connection error happened, please try again later. | 242| 16501000 | An internal functional error occurred. | 243| 16501001 | The ID of the form to be operated does not exist. | 244| 16501003 | The form can not be operated by the current application. | 245|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 246 247**Example** 248 249```ts 250try { 251 var formId = '12400633174999288'; 252 formHost.releaseForm(formId, true).then(() => { 253 console.log('formHost releaseForm success'); 254 }).catch((error) => { 255 console.log('formHost releaseForm, error:' + JSON.stringify(error)); 256 }); 257} catch(error) { 258 console.log(`catch err->${JSON.stringify(error)}`); 259} 260``` 261 262## requestForm 263 264requestForm(formId: string, callback: AsyncCallback<void>): void 265 266Requests a widget update. This API uses an asynchronous callback to return the result. 267 268**Required permissions**: ohos.permission.REQUIRE_FORM 269 270**System capability**: SystemCapability.Ability.Form 271 272**Parameters** 273 274| Name| Type | Mandatory| Description | 275| ------ | ------ | ---- | ------- | 276| formId | string | Yes | Widget ID.| 277| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is updated, **error** is undefined; otherwise, **error** is an error object.| 278 279**Error codes** 280 281| Error Code ID| Error Message| 282| -------- | -------- | 283| 201 | Permissions denied. | 284| 202 | The application is not a system application. | 285| 401 | If the input parameter is not valid parameter. | 286| 16500050 | An IPC connection error happened. | 287| 16500060 | A service connection error happened, please try again later. | 288| 16501000 | An internal functional error occurred. | 289| 16501001 | The ID of the form to be operated does not exist. | 290| 16501003 | The form can not be operated by the current application. | 291|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 292 293**Example** 294 295```ts 296try { 297 var formId = '12400633174999288'; 298 formHost.requestForm(formId, (error, data) => { 299 if (error) { 300 console.log('formHost requestForm, error:' + JSON.stringify(error)); 301 } 302 }); 303} catch(error) { 304 console.log(`catch err->${JSON.stringify(error)}`); 305} 306``` 307 308## requestForm 309 310requestForm(formId: string): Promise<void> 311 312Requests a widget update. This API uses a promise to return the result. 313 314**Required permissions**: ohos.permission.REQUIRE_FORM 315 316**System capability**: SystemCapability.Ability.Form 317 318**Parameters** 319 320| Name| Type | Mandatory| Description | 321| ------ | ------ | ---- | ------- | 322| formId | string | Yes | Widget ID.| 323 324**Return value** 325 326| Type| Description| 327| -------- | -------- | 328| Promise<void> | Promise that returns no value.| 329 330**Error codes** 331 332| Error Code ID| Error Message| 333| -------- | -------- | 334| 201 | Permissions denied. | 335| 202 | The application is not a system application. | 336| 401 | If the input parameter is not valid parameter. | 337| 16500050 | An IPC connection error happened. | 338| 16500060 | A service connection error happened, please try again later. | 339| 16501000 | An internal functional error occurred. | 340| 16501001 | The ID of the form to be operated does not exist. | 341| 16501003 | The form can not be operated by the current application. | 342|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 343 344**Example** 345 346```ts 347try { 348 var formId = '12400633174999288'; 349 formHost.requestForm(formId).then(() => { 350 console.log('formHost requestForm success'); 351 }).catch((error) => { 352 console.log('formHost requestForm, error:' + JSON.stringify(error)); 353 }); 354} catch(error) { 355 console.log(`catch err->${JSON.stringify(error)}`); 356} 357 358``` 359 360## castToNormalForm 361 362castToNormalForm(formId: string, callback: AsyncCallback<void>): void 363 364Converts a temporary widget to a normal one. This API uses an asynchronous callback to return the result. 365 366**Required permissions**: ohos.permission.REQUIRE_FORM 367 368**System capability**: SystemCapability.Ability.Form 369 370**Parameters** 371 372| Name| Type | Mandatory| Description | 373| ------ | ------ | ---- | ------- | 374| formId | string | Yes | Widget ID.| 375| 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.| 376 377**Error codes** 378 379| Error Code ID| Error Message| 380| -------- | -------- | 381| 201 | Permissions denied. | 382| 202 | The application is not a system application. | 383| 401 | If the input parameter is not valid parameter. | 384| 16500050 | An IPC connection error happened. | 385| 16501000 | An internal functional error occurred. | 386| 16501001 | The ID of the form to be operated does not exist. | 387| 16501002 | The number of forms exceeds upper bound. | 388| 16501003 | The form can not be operated by the current application. | 389|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 390 391**Example** 392 393```ts 394try { 395 var formId = '12400633174999288'; 396 formHost.castToNormalForm(formId, (error, data) => { 397 if (error) { 398 console.log('formHost castTempForm, error:' + JSON.stringify(error)); 399 } 400 }); 401} catch(error) { 402 console.log(`catch err->${JSON.stringify(error)}`); 403} 404``` 405 406## castToNormalForm 407 408castToNormalForm(formId: string): Promise<void> 409 410Converts a temporary widget to a normal one. This API uses a promise to return the result. 411 412**Required permissions**: ohos.permission.REQUIRE_FORM 413 414**System capability**: SystemCapability.Ability.Form 415 416**Parameters** 417 418| Name| Type | Mandatory| Description | 419| ------ | ------ | ---- | ------- | 420| formId | string | Yes | Widget ID.| 421 422**Return value** 423 424| Type| Description| 425| -------- | -------- | 426| Promise<void> | Promise that returns no value.| 427 428**Error codes** 429 430| Error Code ID| Error Message| 431| -------- | -------- | 432| 201 | Permissions denied. | 433| 202 | The application is not a system application. | 434| 401 | If the input parameter is not valid parameter. | 435| 16500050 | An IPC connection error happened. | 436| 16501000 | An internal functional error occurred. | 437| 16501001 | The ID of the form to be operated does not exist. | 438| 16501002 | The number of forms exceeds upper bound. | 439| 16501003 | The form can not be operated by the current application. | 440|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 441 442**Example** 443 444```ts 445try { 446 var formId = '12400633174999288'; 447 formHost.castToNormalForm(formId).then(() => { 448 console.log('formHost castTempForm success'); 449 }).catch((error) => { 450 console.log('formHost castTempForm, error:' + JSON.stringify(error)); 451 }); 452} catch(error) { 453 console.log(`catch err->${JSON.stringify(error)}`); 454} 455``` 456 457## notifyVisibleForms 458 459notifyVisibleForms(formIds: Array<string>, callback: AsyncCallback<void>): void 460 461Instructs 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. 462 463**Required permissions**: ohos.permission.REQUIRE_FORM 464 465**System capability**: SystemCapability.Ability.Form 466 467**Parameters** 468 469| Name| Type | Mandatory| Description | 470| ------ | ------ | ---- | ------- | 471| formIds | Array<string> | Yes | List of widget IDs. | 472| 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.| 473 474**Error codes** 475 476| Error Code ID| Error Message| 477| -------- | -------- | 478| 201 | Permissions denied. | 479| 202 | The application is not a system application. | 480| 401 | If the input parameter is not valid parameter. | 481| 16500050 | An IPC connection error happened. | 482| 16500060 | A service connection error happened, please try again later. | 483| 16501000 | An internal functional error occurred. | 484|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 485 486**Example** 487 488```ts 489try { 490 var formId = ['12400633174999288']; 491 formHost.notifyVisibleForms(formId, (error, data) => { 492 if (error) { 493 console.log('formHost notifyVisibleForms, error:' + JSON.stringify(error)); 494 } 495 }); 496} catch(error) { 497 console.log(`catch err->${JSON.stringify(error)}`); 498} 499``` 500 501## notifyVisibleForms 502 503notifyVisibleForms(formIds: Array<string>): Promise<void> 504 505Instructs 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. 506 507**Required permissions**: ohos.permission.REQUIRE_FORM 508 509**System capability**: SystemCapability.Ability.Form 510 511**Parameters** 512 513| Name| Type | Mandatory| Description | 514| ------ | ------ | ---- | ------- | 515| formIds | Array<string> | Yes | List of widget IDs.| 516 517**Return value** 518 519| Type| Description| 520| -------- | -------- | 521| Promise<void> | Promise that returns no value.| 522 523**Error codes** 524 525| Error Code ID| Error Message| 526| -------- | -------- | 527| 201 | Permissions denied. | 528| 202 | The application is not a system application. | 529| 401 | If the input parameter is not valid parameter. | 530| 16500050 | An IPC connection error happened. | 531| 16500060 | A service connection error happened, please try again later. | 532| 16501000 | An internal functional error occurred. | 533|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 534 535**Example** 536 537```ts 538try { 539 var formId = ['12400633174999288']; 540 formHost.notifyVisibleForms(formId).then(() => { 541 console.log('formHost notifyVisibleForms success'); 542 }).catch((error) => { 543 console.log('formHost notifyVisibleForms, error:' + JSON.stringify(error)); 544 }); 545} catch(error) { 546 console.log(`catch err->${JSON.stringify(error)}`); 547} 548``` 549 550## notifyInvisibleForms 551 552notifyInvisibleForms(formIds: Array<string>, callback: AsyncCallback<void>): void 553 554Instructs 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. 555 556**Required permissions**: ohos.permission.REQUIRE_FORM 557 558**System capability**: SystemCapability.Ability.Form 559 560**Parameters** 561 562| Name| Type | Mandatory| Description | 563| ------ | ------ | ---- | ------- | 564| formIds | Array<string> | Yes | List of widget IDs.| 565| 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.| 566 567**Error codes** 568 569| Error Code ID| Error Message| 570| -------- | -------- | 571| 201 | Permissions denied. | 572| 202 | The application is not a system application. | 573| 401 | If the input parameter is not valid parameter. | 574| 16500050 | An IPC connection error happened. | 575| 16500060 | A service connection error happened, please try again later. | 576| 16501000 | An internal functional error occurred. | 577|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 578 579**Example** 580 581```ts 582try { 583 var formId = ['12400633174999288']; 584 formHost.notifyInvisibleForms(formId, (error, data) => { 585 if (error) { 586 console.log('formHost notifyInvisibleForms, error:' + JSON.stringify(error)); 587 } 588 }); 589} catch(error) { 590 console.log(`catch err->${JSON.stringify(error)}`); 591} 592``` 593 594## notifyInvisibleForms 595 596notifyInvisibleForms(formIds: Array<string>): Promise<void> 597 598Instructs 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. 599 600**Required permissions**: ohos.permission.REQUIRE_FORM 601 602**System capability**: SystemCapability.Ability.Form 603 604**Parameters** 605 606| Name| Type | Mandatory| Description | 607| ------ | ------ | ---- | ------- | 608| formIds | Array<string> | Yes | List of widget IDs.| 609 610**Return value** 611 612| Type| Description| 613| -------- | -------- | 614| Promise<void> | Promise that returns no value.| 615 616**Error codes** 617 618| Error Code ID| Error Message| 619| -------- | -------- | 620| 201 | Permissions denied. | 621| 202 | The application is not a system application. | 622| 401 | If the input parameter is not valid parameter. | 623| 16500050 | An IPC connection error happened. | 624| 16500060 | A service connection error happened, please try again later. | 625| 16501000 | An internal functional error occurred. | 626|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 627 628**Example** 629 630```ts 631try { 632 var formId = ['12400633174999288']; 633 formHost.notifyInvisibleForms(formId).then(() => { 634 console.log('formHost notifyInvisibleForms success'); 635 }).catch((error) => { 636 console.log('formHost notifyInvisibleForms, error:' + JSON.stringify(error)); 637 }); 638} catch(error) { 639 console.log(`catch err->${JSON.stringify(error)}`); 640} 641``` 642 643## enableFormsUpdate 644 645enableFormsUpdate(formIds: Array<string>, callback: AsyncCallback<void>): void 646 647Instructs 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. 648 649**Required permissions**: ohos.permission.REQUIRE_FORM 650 651**System capability**: SystemCapability.Ability.Form 652 653**Parameters** 654 655| Name| Type | Mandatory| Description | 656| ------ | ------ | ---- | ------- | 657| formIds | Array<string> | Yes | List of widget IDs. | 658| 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.| 659 660**Error codes** 661 662| Error Code ID| Error Message| 663| -------- | -------- | 664| 201 | Permissions denied. | 665| 202 | The application is not a system application. | 666| 401 | If the input parameter is not valid parameter. | 667| 16500050 | An IPC connection error happened. | 668| 16500060 | A service connection error happened, please try again later. | 669| 16501000 | An internal functional error occurred. | 670| 16501003 | The form can not be operated by the current application. | 671|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 672 673**Example** 674 675```ts 676try { 677 var formId = ['12400633174999288']; 678 formHost.enableFormsUpdate(formId, (error, data) => { 679 if (error) { 680 console.log('formHost enableFormsUpdate, error:' + JSON.stringify(error)); 681 } 682 }); 683} catch(error) { 684 console.log(`catch err->${JSON.stringify(error)}`); 685} 686``` 687 688## enableFormsUpdate 689 690enableFormsUpdate(formIds: Array<string>): Promise<void> 691 692Instructs 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. 693 694**Required permissions**: ohos.permission.REQUIRE_FORM 695 696**System capability**: SystemCapability.Ability.Form 697 698**Parameters** 699 700| Name| Type | Mandatory| Description | 701| ------ | ------ | ---- | ------- | 702| formIds | Array<string> | Yes | List of widget IDs.| 703 704**Return value** 705 706| Type| Description| 707| -------- | -------- | 708| Promise<void> | Promise that returns no value.| 709 710**Error codes** 711 712| Error Code ID| Error Message| 713| -------- | -------- | 714| 201 | Permissions denied. | 715| 202 | The application is not a system application. | 716| 401 | If the input parameter is not valid parameter. | 717| 16500050 | An IPC connection error happened. | 718| 16500060 | A service connection error happened, please try again later. | 719| 16501000 | An internal functional error occurred. | 720| 16501003 | The form can not be operated by the current application. | 721|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 722 723**Example** 724 725```ts 726try { 727 var formId = ['12400633174999288']; 728 formHost.enableFormsUpdate(formId).then(() => { 729 console.log('formHost enableFormsUpdate success'); 730 }).catch((error) => { 731 console.log('formHost enableFormsUpdate, error:' + JSON.stringify(error)); 732 }); 733} catch(error) { 734 console.log(`catch err->${JSON.stringify(error)}`); 735} 736``` 737 738## disableFormsUpdate 739 740disableFormsUpdate(formIds: Array<string>, callback: AsyncCallback<void>): void 741 742Instructs 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. 743 744**Required permissions**: ohos.permission.REQUIRE_FORM 745 746**System capability**: SystemCapability.Ability.Form 747 748**Parameters** 749 750| Name| Type | Mandatory| Description | 751| ------ | ------ | ---- | ------- | 752| formIds | Array<string> | Yes | List of widget IDs. | 753| 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.| 754 755**Error codes** 756 757| Error Code ID| Error Message| 758| -------- | -------- | 759| 201 | Permissions denied. | 760| 202 | The application is not a system application. | 761| 401 | If the input parameter is not valid parameter. | 762| 16500050 | An IPC connection error happened. | 763| 16500060 | A service connection error happened, please try again later. | 764| 16501000 | An internal functional error occurred. | 765| 16501001 | The ID of the form to be operated does not exist. | 766| 16501003 | The form can not be operated by the current application. | 767|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 768 769**Example** 770 771```ts 772try { 773 var formId = ['12400633174999288']; 774 formHost.disableFormsUpdate(formId, (error, data) => { 775 if (error) { 776 console.log('formHost disableFormsUpdate, error:' + JSON.stringify(error)); 777 } 778 }); 779} catch(error) { 780 console.log(`catch err->${JSON.stringify(error)}`); 781} 782``` 783 784## disableFormsUpdate 785 786disableFormsUpdate(formIds: Array<string>): Promise<void> 787 788Instructs 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. 789 790**Required permissions**: ohos.permission.REQUIRE_FORM 791 792**System capability**: SystemCapability.Ability.Form 793 794**Parameters** 795 796| Name| Type | Mandatory| Description | 797| ------ | ------ | ---- | ------- | 798| formIds | Array<string> | Yes | List of widget IDs.| 799 800**Return value** 801 802| Type| Description| 803| -------- | -------- | 804| Promise<void> | Promise that returns no value.| 805 806**Error codes** 807 808| Error Code ID| Error Message| 809| -------- | -------- | 810| 201 | Permissions denied. | 811| 202 | The application is not a system application. | 812| 401 | If the input parameter is not valid parameter. | 813| 16500050 | An IPC connection error happened. | 814| 16500060 | A service connection error happened, please try again later. | 815| 16501000 | An internal functional error occurred. | 816| 16501001 | The ID of the form to be operated does not exist. | 817| 16501003 | The form can not be operated by the current application. | 818|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 819 820**Example** 821 822```ts 823try { 824 var formId = ['12400633174999288']; 825 formHost.disableFormsUpdate(formId).then(() => { 826 console.log('formHost disableFormsUpdate success'); 827 }).catch((error) => { 828 console.log('formHost disableFormsUpdate, error:' + JSON.stringify(error)); 829 }); 830} catch(error) { 831 console.log(`catch err->${JSON.stringify(error)}`); 832} 833``` 834 835## isSystemReady 836 837isSystemReady(callback: AsyncCallback<void>): void 838 839Checks whether the system is ready. This API uses an asynchronous callback to return the result. 840 841**System capability**: SystemCapability.Ability.Form 842 843**Parameters** 844 845| Name| Type | Mandatory| Description | 846| ------ | ------ | ---- | ------- | 847| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the check is successful, **error** is undefined; otherwise, **error** is an error object.| 848 849**Error codes** 850 851| Error Code ID| Error Message| 852| -------- | -------- | 853| 202 | The application is not a system application. | 854| 401 | If the input parameter is not valid parameter. | 855|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 856 857**Example** 858 859```ts 860try { 861 var formId = '12400633174999288'; 862 formHost.isSystemReady((error, data) => { 863 if (error) { 864 console.log('formHost isSystemReady, error:' + JSON.stringify(error)); 865 } 866 }); 867} catch(error) { 868 console.log(`catch err->${JSON.stringify(error)}`); 869} 870``` 871 872## isSystemReady 873 874isSystemReady(): Promise<void> 875 876Checks whether the system is ready. This API uses a promise to return the result. 877 878**System capability**: SystemCapability.Ability.Form 879 880**Return value** 881 882| Type| Description| 883| -------- | -------- | 884| Promise<void> | Promise that returns no value.| 885 886**Error codes** 887 888| Error Code ID| Error Message| 889| -------- | -------- | 890| 202 | The application is not a system application. | 891|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 892 893**Example** 894 895```ts 896try { 897 var formId = '12400633174999288'; 898 formHost.isSystemReady().then(() => { 899 console.log('formHost isSystemReady success'); 900 }).catch((error) => { 901 console.log('formHost isSystemReady, error:' + JSON.stringify(error)); 902 }); 903} catch(error) { 904 console.log(`catch err->${JSON.stringify(error)}`); 905} 906``` 907 908## getAllFormsInfo 909 910getAllFormsInfo(callback: AsyncCallback<Array<formInfo.FormInfo>>): void 911 912Obtains the widget information provided by all applications on the device. This API uses an asynchronous callback to return the result. 913 914**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 915 916**System capability**: SystemCapability.Ability.Form 917 918**Error codes** 919 920| Error Code ID| Error Message| 921| -------- | -------- | 922| 201 | Permissions denied. | 923| 202 | The application is not a system application. | 924| 401 | If the input parameter is not valid parameter. | 925| 16500050 | An IPC connection error happened. | 926| 16500060 | A service connection error happened, please try again later. | 927| 16501000 | An internal functional error occurred. | 928|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 929 930**Parameters** 931 932| Name| Type | Mandatory| Description | 933| ------ | ------ | ---- | ------- | 934| callback | AsyncCallback<Array<[FormInfo](js-apis-app-form-formInfo.md)>> | Yes| Callback used to return the result. If the widget information is obtained, **error** is undefined and **data** is the information obtained; otherwise, **error** is an error object.| 935 936**Example** 937 938```ts 939try { 940 formHost.getAllFormsInfo((error, data) => { 941 if (error) { 942 console.log('formHost getAllFormsInfo, error:' + JSON.stringify(error)); 943 } else { 944 console.log('formHost getAllFormsInfo, data:' + JSON.stringify(data)); 945 } 946 }); 947} catch(error) { 948 console.log(`catch err->${JSON.stringify(error)}`); 949} 950``` 951 952## getAllFormsInfo 953 954getAllFormsInfo(): Promise<Array<formInfo.FormInfo>> 955 956Obtains the widget information provided by all applications on the device. This API uses a promise to return the result. 957 958**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 959 960**System capability**: SystemCapability.Ability.Form 961 962**Error codes** 963 964| Error Code ID| Error Message| 965| -------- | -------- | 966| 201 | Permissions denied. | 967| 202 | The application is not a system application. | 968| 16500050 | An IPC connection error happened. | 969| 16500060 | A service connection error happened, please try again later. | 970| 16501000 | An internal functional error occurred. | 971|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 972 973**Return value** 974 975| Type | Description | 976| :----------------------------------------------------------- | :---------------------------------- | 977| Promise<Array<[FormInfo](js-apis-app-form-formInfo.md)>> | Promise used to return the information obtained.| 978 979**Example** 980 981```ts 982try { 983 formHost.getAllFormsInfo().then((data) => { 984 console.log('formHost getAllFormsInfo data:' + JSON.stringify(data)); 985 }).catch((error) => { 986 console.log('formHost getAllFormsInfo, error:' + JSON.stringify(error)); 987 }); 988} catch(error) { 989 console.log(`catch err->${JSON.stringify(error)}`); 990} 991``` 992 993## getFormsInfo 994 995getFormsInfo(bundleName: string, callback: AsyncCallback<Array<formInfo.FormInfo>>): void 996 997Obtains the widget information provided by a given application on the device. This API uses an asynchronous callback to return the result. 998 999**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1000 1001**System capability**: SystemCapability.Ability.Form 1002 1003**Parameters** 1004 1005| Name| Type | Mandatory| Description | 1006| ------ | ------ | ---- | ------- | 1007| bundleName | string | Yes| Bundle name of the application.| 1008| callback | AsyncCallback<Array<[FormInfo](js-apis-app-form-formInfo.md)>> | Yes| Callback used to return the result. If the widget information is obtained, **error** is undefined and **data** is the information obtained; otherwise, **error** is an error object.| 1009 1010**Error codes** 1011 1012| Error Code ID| Error Message| 1013| -------- | -------- | 1014| 201 | Permissions denied. | 1015| 202 | The application is not a system application. | 1016| 401 | If the input parameter is not valid parameter. | 1017| 16500050 | An IPC connection error happened. | 1018| 16500060 | A service connection error happened, please try again later. | 1019| 16500100 | Failed to obtain the configuration information. | 1020| 16501000 | An internal functional error occurred. | 1021|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 1022 1023**Example** 1024 1025```ts 1026try { 1027 formHost.getFormsInfo('com.example.ohos.formjsdemo', (error, data) => { 1028 if (error) { 1029 console.log('formHost getFormsInfo, error:' + JSON.stringify(error)); 1030 } else { 1031 console.log('formHost getFormsInfo, data:' + JSON.stringify(data)); 1032 } 1033 }); 1034} catch(error) { 1035 console.log(`catch err->${JSON.stringify(error)}`); 1036} 1037``` 1038 1039## getFormsInfo 1040 1041getFormsInfo(bundleName: string, moduleName: string, callback: AsyncCallback<Array<formInfo.FormInfo>>): void 1042 1043Obtains the widget information provided by a given application on the device. This API uses an asynchronous callback to return the result. 1044 1045**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1046 1047**System capability**: SystemCapability.Ability.Form 1048 1049**Parameters** 1050 1051| Name| Type | Mandatory| Description | 1052| ------ | ------ | ---- | ------- | 1053| bundleName | string | Yes| Bundle name of the application.| 1054| moduleName | string | Yes| Module name.| 1055| callback | AsyncCallback<Array<[FormInfo](js-apis-app-form-formInfo.md)>> | Yes| Callback used to return the result. If the widget information is obtained, **error** is undefined and **data** is the information obtained; otherwise, **error** is an error object.| 1056 1057**Error codes** 1058 1059| Error Code ID| Error Message| 1060| -------- | -------- | 1061| 201 | Permissions denied. | 1062| 202 | The application is not a system application. | 1063| 401 | If the input parameter is not valid parameter. | 1064| 16500050 | An IPC connection error happened. | 1065| 16500060 | A service connection error happened, please try again later. | 1066| 16500100 | Failed to obtain the configuration information. | 1067| 16501000 | An internal functional error occurred. | 1068|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 1069 1070**Example** 1071 1072```ts 1073try { 1074 formHost.getFormsInfo('com.example.ohos.formjsdemo', 'entry', (error, data) => { 1075 if (error) { 1076 console.log('formHost getFormsInfo, error:' + JSON.stringify(error)); 1077 } else { 1078 console.log('formHost getFormsInfo, data:' + JSON.stringify(data)); 1079 } 1080 }); 1081} catch(error) { 1082 console.log(`catch err->${JSON.stringify(error)}`); 1083} 1084``` 1085 1086## getFormsInfo 1087 1088getFormsInfo(bundleName: string, moduleName?: string): Promise<Array<formInfo.FormInfo>> 1089 1090Obtains the widget information provided by a given application on the device. This API uses a promise to return the result. 1091 1092**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1093 1094**System capability**: SystemCapability.Ability.Form 1095 1096**Parameters** 1097 1098| Name| Type | Mandatory| Description | 1099| ------ | ------ | ---- | ------- | 1100| bundleName | string | Yes| Bundle name of the application.| 1101| moduleName | string | No| Module name. By default, no value is passed.| 1102 1103**Return value** 1104 1105| Type | Description | 1106| :----------------------------------------------------------- | :---------------------------------- | 1107| Promise<Array<[FormInfo](js-apis-app-form-formInfo.md)>> | Promise used to return the information obtained.| 1108 1109**Error codes** 1110 1111| Error Code ID| Error Message| 1112| -------- | -------- | 1113| 201 | Permissions denied. | 1114| 202 | The application is not a system application. | 1115| 401 | If the input parameter is not valid parameter. | 1116| 16500050 | An IPC connection error happened. | 1117| 16500060 | A service connection error happened, please try again later. | 1118| 16500100 | Failed to obtain the configuration information. | 1119| 16501000 | An internal functional error occurred. | 1120|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 1121 1122**Example** 1123 1124```ts 1125try { 1126 formHost.getFormsInfo('com.example.ohos.formjsdemo', 'entry').then((data) => { 1127 console.log('formHost getFormsInfo, data:' + JSON.stringify(data)); 1128 }).catch((error) => { 1129 console.log('formHost getFormsInfo, error:' + JSON.stringify(error)); 1130 }); 1131} catch(error) { 1132 console.log(`catch err->${JSON.stringify(error)}`); 1133} 1134``` 1135 1136## deleteInvalidForms 1137 1138deleteInvalidForms(formIds: Array<string>, callback: AsyncCallback<number>): void 1139 1140Deletes invalid widgets from the list. This API uses an asynchronous callback to return the result. 1141 1142**Required permissions**: ohos.permission.REQUIRE_FORM 1143 1144**System capability**: SystemCapability.Ability.Form 1145 1146**Parameters** 1147 1148| Name| Type | Mandatory| Description | 1149| ------ | ------ | ---- | ------- | 1150| formIds | Array<string> | Yes | List of valid widget IDs.| 1151| 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.| 1152 1153**Error codes** 1154 1155| Error Code ID| Error Message| 1156| -------- | -------- | 1157| 201 | Permissions denied. | 1158| 202 | The application is not a system application. | 1159| 401 | If the input parameter is not valid parameter. | 1160| 16500050 | An IPC connection error happened. | 1161| 16500060 | A service connection error happened, please try again later. | 1162| 16501000 | An internal functional error occurred. | 1163|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 1164 1165**Example** 1166 1167```ts 1168try { 1169 var formIds = new Array('12400633174999288', '12400633174999289'); 1170 formHost.deleteInvalidForms(formIds, (error, data) => { 1171 if (error) { 1172 console.log('formHost deleteInvalidForms, error:' + JSON.stringify(error)); 1173 } else { 1174 console.log('formHost deleteInvalidForms, data:' + JSON.stringify(data)); 1175 } 1176 }); 1177} catch(error) { 1178 console.log(`catch err->${JSON.stringify(error)}`); 1179} 1180``` 1181 1182## deleteInvalidForms 1183 1184deleteInvalidForms(formIds: Array<string>): Promise<number> 1185 1186Deletes invalid widgets from the list. This API uses a promise to return the result. 1187 1188**Required permissions**: ohos.permission.REQUIRE_FORM 1189 1190**System capability**: SystemCapability.Ability.Form 1191 1192**Parameters** 1193 1194| Name| Type | Mandatory| Description | 1195| ------ | ------ | ---- | ------- | 1196| formIds | Array<string> | Yes | List of valid widget IDs.| 1197 1198**Return value** 1199 1200| Type | Description | 1201| :------------ | :---------------------------------- | 1202| Promise<number> | Promise used to return the number of widgets deleted.| 1203 1204**Error codes** 1205 1206| Error Code ID| Error Message| 1207| -------- | -------- | 1208| 201 | Permissions denied. | 1209| 202 | The application is not a system application. | 1210| 401 | If the input parameter is not valid parameter. | 1211| 16500050 | An IPC connection error happened. | 1212| 16500060 | A service connection error happened, please try again later. | 1213| 16501000 | An internal functional error occurred. | 1214|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 1215 1216**Example** 1217 1218```ts 1219try { 1220 var formIds = new Array('12400633174999288', '12400633174999289'); 1221 formHost.deleteInvalidForms(formIds).then((data) => { 1222 console.log('formHost deleteInvalidForms, data:' + JSON.stringify(data)); 1223 }).catch((error) => { 1224 console.log('formHost deleteInvalidForms, error:' + JSON.stringify(error)); 1225 }); 1226} catch(error) { 1227 console.log(`catch err->${JSON.stringify(error)}`); 1228} 1229``` 1230 1231## acquireFormState 1232 1233acquireFormState(want: Want, callback: AsyncCallback<formInfo.FormStateInfo>): void 1234 1235Obtains the widget state. This API uses an asynchronous callback to return the result. 1236 1237**Required permissions**: ohos.permission.REQUIRE_FORM and ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1238 1239**System capability**: SystemCapability.Ability.Form 1240 1241**Parameters** 1242 1243| Name| Type | Mandatory| Description | 1244| ------ | ------ | ---- | ------- | 1245| want | [Want](js-apis-application-want.md) | Yes | **Want** information carried to query the widget state. The information must contain the bundle name, ability name, module name, widget name, and widget dimensions.| 1246| callback | AsyncCallback<[FormStateInfo](js-apis-app-form-formInfo.md#formstateinfo)> | Yes| Callback used to return the result. If the widget state is obtained, **error** is undefined and **data** is the widget state obtained; otherwise, **error** is an error object.| 1247 1248**Error codes** 1249 1250| Error Code ID| Error Message| 1251| -------- | -------- | 1252| 201 | Permissions denied. | 1253| 202 | The application is not a system application. | 1254| 401 | If the input parameter is not valid parameter. | 1255| 16500050 | An IPC connection error happened. | 1256| 16500060 | A service connection error happened, please try again later. | 1257| 16500100 | Failed to obtain the configuration information. | 1258| 16501000 | An internal functional error occurred. | 1259|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 1260 1261**Example** 1262 1263```ts 1264var want = { 1265 'deviceId': '', 1266 'bundleName': 'ohos.samples.FormApplication', 1267 'abilityName': 'FormAbility', 1268 'parameters': { 1269 'ohos.extra.param.key.module_name': 'entry', 1270 'ohos.extra.param.key.form_name': 'widget', 1271 'ohos.extra.param.key.form_dimension': 2 1272 } 1273}; 1274try { 1275 formHost.acquireFormState(want, (error, data) => { 1276 if (error) { 1277 console.log('formHost acquireFormState, error:' + JSON.stringify(error)); 1278 } else { 1279 console.log('formHost acquireFormState, data:' + JSON.stringify(data)); 1280 } 1281 }); 1282} catch(error) { 1283 console.log(`catch err->${JSON.stringify(error)}`); 1284} 1285``` 1286 1287## acquireFormState 1288 1289acquireFormState(want: Want): Promise<formInfo.FormStateInfo> 1290 1291Obtains the widget state. This API uses a promise to return the result. 1292 1293**Required permissions**: ohos.permission.REQUIRE_FORM and ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1294 1295**System capability**: SystemCapability.Ability.Form 1296 1297**Parameters** 1298 1299| Name| Type | Mandatory| Description | 1300| ------ | ------ | ---- | ------- | 1301| want | [Want](js-apis-application-want.md) | Yes | **Want** information carried to query the widget state. The information must contain the bundle name, ability name, module name, widget name, and widget dimensions.| 1302 1303**Return value** 1304 1305| Type | Description | 1306| :------------ | :---------------------------------- | 1307| Promise<[FormStateInfo](js-apis-app-form-formInfo.md#formstateinfo)> | Promise used to return the widget state obtained.| 1308 1309**Error codes** 1310 1311| Error Code ID| Error Message| 1312| -------- | -------- | 1313| 201 | Permissions denied. | 1314| 202 | The application is not a system application. | 1315| 401 | If the input parameter is not valid parameter. | 1316| 16500050 | An IPC connection error happened. | 1317| 16500060 | A service connection error happened, please try again later. | 1318| 16500100 | Failed to obtain the configuration information. | 1319| 16501000 | An internal functional error occurred. | 1320|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 1321 1322**Example** 1323 1324```ts 1325var want = { 1326 'deviceId': '', 1327 'bundleName': 'ohos.samples.FormApplication', 1328 'abilityName': 'FormAbility', 1329 'parameters': { 1330 'ohos.extra.param.key.module_name': 'entry', 1331 'ohos.extra.param.key.form_name': 'widget', 1332 'ohos.extra.param.key.form_dimension': 2 1333 } 1334}; 1335try { 1336 formHost.acquireFormState(want).then((data) => { 1337 console.log('formHost acquireFormState, data:' + JSON.stringify(data)); 1338 }).catch((error) => { 1339 console.log('formHost acquireFormState, error:' + JSON.stringify(error)); 1340 }); 1341} catch(error) { 1342 console.log(`catch err->${JSON.stringify(error)}`); 1343} 1344``` 1345 1346## on('formUninstall') 1347 1348on(type: 'formUninstall', callback: Callback<string>): void 1349 1350Subscribes to widget uninstall events. This API uses an asynchronous callback to return the result. 1351 1352**System capability**: SystemCapability.Ability.Form 1353 1354**Parameters** 1355 1356| Name| Type | Mandatory| Description | 1357| ------ | ------ | ---- | ------- | 1358| type | string | Yes | Event type. The value **'formUninstall'** indicates a widget uninstallation event.| 1359| callback | Callback<string> | Yes| Callback used to return the widget ID.| 1360 1361**Error codes** 1362 1363| Error Code ID| Error Message| 1364| -------- | -------- | 1365| 202 | The application is not a system application. | 1366| 401 | If the input parameter is not valid parameter. | 1367|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 1368 1369**Example** 1370 1371```ts 1372let callback = function(formId) { 1373 console.log('formHost on formUninstall, formId:' + formId); 1374} 1375formHost.on('formUninstall', callback); 1376``` 1377 1378## off('formUninstall') 1379 1380off(type: 'formUninstall', callback?: Callback<string>): void 1381 1382Unsubscribes from widget uninstall events. This API uses an asynchronous callback to return the result. 1383 1384**System capability**: SystemCapability.Ability.Form 1385 1386**Parameters** 1387 1388| Name| Type | Mandatory| Description | 1389| ------ | ------ | ---- | ------- | 1390| type | string | Yes | Event type. The value **'formUninstall'** indicates a widget uninstallation event.| 1391| 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> The value must be the same as that in **on('formUninstall')**.| 1392 1393**Error codes** 1394 1395| Error Code ID| Error Message| 1396| -------- | -------- | 1397| 202 | The application is not a system application. | 1398| 401 | If the input parameter is not valid parameter. | 1399|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 1400 1401**Example** 1402 1403```ts 1404let callback = function(formId) { 1405 console.log('formHost on formUninstall, formId:' + formId); 1406} 1407formHost.off('formUninstall', callback); 1408``` 1409 1410## notifyFormsVisible 1411 1412notifyFormsVisible(formIds: Array<string>, isVisible: boolean, callback: AsyncCallback<void>): void 1413 1414Instructs the widgets to make themselves visible. This API uses an asynchronous callback to return the result. 1415 1416**Required permissions**: ohos.permission.REQUIRE_FORM 1417 1418**System capability**: SystemCapability.Ability.Form 1419 1420**Parameters** 1421 1422| Name| Type | Mandatory| Description | 1423| ------ | ------ | ---- | ------- | 1424| formIds | Array<string> | Yes | List of widget IDs.| 1425| isVisible | boolean | Yes | Whether to make the widgets visible.| 1426| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the notification is sent, **error** is undefined; otherwise, **error** is an error object.| 1427 1428**Error codes** 1429 1430| Error Code ID| Error Message| 1431| -------- | -------- | 1432| 201 | Permissions denied. | 1433| 202 | The application is not a system application. | 1434| 401 | If the input parameter is not valid parameter. | 1435| 16500050 | An IPC connection error happened. | 1436| 16500060 | A service connection error happened, please try again later. | 1437| 16501000 | An internal functional error occurred. | 1438| 16501003 | The form can not be operated by the current application. | 1439|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 1440 1441**Example** 1442 1443```ts 1444var formIds = new Array('12400633174999288', '12400633174999289'); 1445try { 1446 formHost.notifyFormsVisible(formIds, true, (error, data) => { 1447 if (error) { 1448 console.log('formHost notifyFormsVisible, error:' + JSON.stringify(error)); 1449 } 1450 }); 1451} catch(error) { 1452 console.log(`catch err->${JSON.stringify(error)}`); 1453} 1454``` 1455 1456## notifyFormsVisible 1457 1458notifyFormsVisible(formIds: Array<string>, isVisible: boolean): Promise<void> 1459 1460Instructs the widgets to make themselves visible. This API uses a promise to return the result. 1461 1462**Required permissions**: ohos.permission.REQUIRE_FORM 1463 1464**System capability**: SystemCapability.Ability.Form 1465 1466**Parameters** 1467 1468| Name| Type | Mandatory| Description | 1469| ------ | ------ | ---- | ------- | 1470| formIds | Array<string> | Yes | List of widget IDs.| 1471| isVisible | boolean | Yes | Whether to make the widgets visible.| 1472 1473**Return value** 1474 1475| Type| Description| 1476| -------- | -------- | 1477| Promise<void> | Promise that returns no value.| 1478 1479**Error codes** 1480 1481| Error Code ID| Error Message| 1482| -------- | -------- | 1483| 201 | Permissions denied. | 1484| 202 | The application is not a system application. | 1485| 401 | If the input parameter is not valid parameter. | 1486| 16500050 | An IPC connection error happened. | 1487| 16500060 | A service connection error happened, please try again later. | 1488| 16501000 | An internal functional error occurred. | 1489| 16501003 | The form can not be operated by the current application. | 1490|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 1491 1492**Example** 1493 1494```ts 1495var formIds = new Array('12400633174999288', '12400633174999289'); 1496try { 1497 formHost.notifyFormsVisible(formIds, true).then(() => { 1498 console.log('formHost notifyFormsVisible success'); 1499 }).catch((error) => { 1500 console.log('formHost notifyFormsVisible, error:' + JSON.stringify(error)); 1501 }); 1502} catch(error) { 1503 console.log(`catch err->${JSON.stringify(error)}`); 1504} 1505``` 1506 1507## notifyFormsEnableUpdate 1508 1509notifyFormsEnableUpdate(formIds: Array<string>, isEnableUpdate: boolean, callback: AsyncCallback<void>): void 1510 1511Instructs the widgets to enable or disable updates. This API uses an asynchronous callback to return the result. 1512 1513**Required permissions**: ohos.permission.REQUIRE_FORM 1514 1515**System capability**: SystemCapability.Ability.Form 1516 1517**Parameters** 1518 1519| Name| Type | Mandatory| Description | 1520| ------ | ------ | ---- | ------- | 1521| formIds | Array<string> | Yes | List of widget IDs.| 1522| isEnableUpdate | boolean | Yes | Whether to make the widgets updatable.| 1523| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the notification is sent, **error** is undefined; otherwise, **error** is an error object.| 1524 1525**Error codes** 1526 1527| Error Code ID| Error Message| 1528| -------- | -------- | 1529| 201 | Permissions denied. | 1530| 202 | The application is not a system application. | 1531| 401 | If the input parameter is not valid parameter. | 1532| 16500050 | An IPC connection error happened. | 1533| 16500060 | A service connection error happened, please try again later. | 1534| 16501000 | An internal functional error occurred. | 1535| 16501003 | The form can not be operated by the current application. | 1536|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 1537 1538**Example** 1539 1540```ts 1541var formIds = new Array('12400633174999288', '12400633174999289'); 1542try { 1543 formHost.notifyFormsEnableUpdate(formIds, true, (error, data) => { 1544 if (error) { 1545 console.log('formHost notifyFormsEnableUpdate, error:' + JSON.stringify(error)); 1546 } 1547 }); 1548} catch(error) { 1549 console.log(`catch err->${JSON.stringify(error)}`); 1550} 1551``` 1552 1553## notifyFormsEnableUpdate 1554 1555notifyFormsEnableUpdate(formIds: Array<string>, isEnableUpdate: boolean): Promise<void> 1556 1557Instructs the widgets to enable or disable updates. This API uses a promise to return the result. 1558 1559**Required permissions**: ohos.permission.REQUIRE_FORM 1560 1561**System capability**: SystemCapability.Ability.Form 1562 1563**Parameters** 1564 1565| Name| Type | Mandatory| Description | 1566| ------ | ------ | ---- | ------- | 1567| formIds | Array<string> | Yes | List of widget IDs.| 1568| isEnableUpdate | boolean | Yes | Whether to make the widgets updatable.| 1569 1570**Return value** 1571 1572| Type| Description| 1573| -------- | -------- | 1574| Promise<void> | Promise that returns no value.| 1575 1576**Error codes** 1577 1578| Error Code ID| Error Message| 1579| -------- | -------- | 1580| 201 | Permissions denied. | 1581| 202 | The application is not a system application. | 1582| 401 | If the input parameter is not valid parameter. | 1583| 16500050 | An IPC connection error happened. | 1584| 16500060 | A service connection error happened, please try again later. | 1585| 16501000 | An internal functional error occurred. | 1586| 16501003 | The form can not be operated by the current application. | 1587|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 1588 1589**Example** 1590 1591```ts 1592var formIds = new Array('12400633174999288', '12400633174999289'); 1593try { 1594 formHost.notifyFormsEnableUpdate(formIds, true).then(() => { 1595 console.log('formHost notifyFormsEnableUpdate success'); 1596 }).catch((error) => { 1597 console.log('formHost notifyFormsEnableUpdate, error:' + JSON.stringify(error)); 1598 }); 1599} catch(error) { 1600 console.log(`catch err->${JSON.stringify(error)}`); 1601} 1602``` 1603## shareForm 1604 1605shareForm(formId: string, deviceId: string, callback: AsyncCallback<void>): void 1606 1607Shares a specified widget with a remote device. This API uses an asynchronous callback to return the result. 1608 1609**Required permissions**: ohos.permission.REQUIRE_FORM and ohos.permission.DISTRIBUTED_DATASYNC 1610 1611**System capability**: SystemCapability.Ability.Form 1612 1613**Parameters** 1614 1615| Name| Type | Mandatory| Description | 1616| ------ | ------ | ---- | ------- | 1617| formId | string | Yes | Widget ID.| 1618| deviceId | string | Yes | Remote device ID.| 1619| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the widget is shared, **error** is undefined; otherwise, **error** is an error object.| 1620 1621**Error codes** 1622 1623| Error Code ID| Error Message| 1624| -------- | -------- | 1625| 201 | Permissions denied. | 1626| 202 | The application is not a system application. | 1627| 401 | If the input parameter is not valid parameter. | 1628| 16500050 | An IPC connection error happened. | 1629| 16501000 | An internal functional error occurred. | 1630| 16501001 | The ID of the form to be operated does not exist. | 1631| 16501003 | The form can not be operated by the current application. | 1632|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 1633 1634**Example** 1635 1636```ts 1637var formId = '12400633174999288'; 1638var deviceId = 'EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2'; 1639try { 1640 formHost.shareForm(formId, deviceId, (error, data) => { 1641 if (error) { 1642 console.log('formHost shareForm, error:' + JSON.stringify(error)); 1643 } 1644 }); 1645} catch(error) { 1646 console.log(`catch err->${JSON.stringify(error)}`); 1647} 1648``` 1649 1650## shareForm 1651 1652shareForm(formId: string, deviceId: string): Promise<void> 1653 1654Shares a specified widget with a remote device. This API uses a promise to return the result. 1655 1656**Required permissions**: ohos.permission.REQUIRE_FORM and ohos.permission.DISTRIBUTED_DATASYNC 1657 1658**System capability**: SystemCapability.Ability.Form 1659 1660**Parameters** 1661 1662| Name| Type | Mandatory| Description | 1663| ------ | ------ | ---- | ------- | 1664| formId | string | Yes | Widget ID.| 1665| deviceId | string | Yes | Remote device ID.| 1666 1667**Return value** 1668 1669| Type| Description| 1670| -------- | -------- | 1671| Promise<void> | Promise that returns no value.| 1672 1673**Error codes** 1674 1675| Error Code ID| Error Message| 1676| -------- | -------- | 1677| 201 | Permissions denied. | 1678| 202 | The application is not a system application. | 1679| 401 | If the input parameter is not valid parameter. | 1680| 16500050 | An IPC connection error happened. | 1681| 16501000 | An internal functional error occurred. | 1682| 16501001 | The ID of the form to be operated does not exist. | 1683| 16501003 | The form can not be operated by the current application. | 1684|For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).|| 1685 1686**Example** 1687 1688```ts 1689var formId = '12400633174999288'; 1690var deviceId = 'EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2'; 1691try { 1692 formHost.shareForm(formId, deviceId).then(() => { 1693 console.log('formHost shareForm success'); 1694 }).catch((error) => { 1695 console.log('formHost shareForm, error:' + JSON.stringify(error)); 1696 }); 1697} catch(error) { 1698 console.log(`catch err->${JSON.stringify(error)}`); 1699} 1700``` 1701 1702## notifyFormsPrivacyProtected 1703 1704notifyFormsPrivacyProtected(formIds: Array\<string>, isProtected: boolean, callback: AsyncCallback\<void>): void 1705 1706Notifies that the privacy protection status of the specified widgets changes. This API uses an asynchronous callback to return the result. 1707 1708**Required permissions**: ohos.permission.REQUIRE_FORM 1709 1710**System capability**: SystemCapability.Ability.Form 1711 1712**Parameters** 1713 1714| Name| Type | Mandatory| Description | 1715| ------ | ------ | ---- | ------- | 1716| formIds | Array\<string\> | Yes | ID of the widgets.| 1717| isProtected | boolean | Yes | Whether privacy protection is enabled.| 1718| 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.| 1719 1720**Error codes** 1721 1722| Error Code ID| Error Message| 1723| -------- | -------- | 1724| 201 | Permissions denied. | 1725| 202 | The application is not a system application. | 1726| 401 | If the input parameter is not valid parameter. | 1727| 16500050 | An IPC connection error happened. | 1728| 16500060 | A service connection error happened, please try again later. | 1729| 16501000 | An internal functional error occurred. | 1730| For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).| | 1731 1732**Example** 1733 1734```ts 1735import formHost from '@ohos.app.form.formHost'; 1736 1737let formIds = new Array('12400633174999288', '12400633174999289'); 1738try { 1739 formHost.notifyFormsPrivacyProtected(formIds, true, (error) => { 1740 if (error) { 1741 console.error(`error, code: ${error.code}, message: ${error.message}`); 1742 } 1743 }); 1744} catch(error) { 1745 console.error(`catch error, code: ${error.code}, message: ${error.message}`); 1746} 1747``` 1748 1749## notifyFormsPrivacyProtected 1750 1751function notifyFormsPrivacyProtected(formIds: Array\<string\>, isProtected: boolean): Promise\<void\>; 1752 1753Notifies that the privacy protection status of the specified widgets changes. This API uses a promise to return the result. 1754 1755**Required permissions**: ohos.permission.REQUIRE_FORM 1756 1757**System capability**: SystemCapability.Ability.Form 1758 1759**Parameters** 1760 1761| Name | Type | Mandatory| Description | 1762| ----------- | --------------- | ---- | -------------------------------- | 1763| formIds | Array\<string\> | Yes | ID of the widgets.| 1764| isProtected | boolean | Yes | Whether privacy protection is enabled. | 1765 1766**Return value** 1767 1768| Type | Description | 1769| ------------------- | ------------------------- | 1770| Promise<void> | Promise that returns no value.| 1771 1772**Error codes** 1773 1774| Error Code ID| Error Message| 1775| -------- | -------- | 1776| 201 | Permissions denied. | 1777| 202 | The application is not a system application. | 1778| 401 | If the input parameter is not valid parameter. | 1779| 16500050 | An IPC connection error happened. | 1780| 16500060 | A service connection error happened, please try again later. | 1781| 16501000 | An internal functional error occurred. | 1782| For details about the error codes, see [Form Error Codes](../errorcodes/errorcode-form.md).| | 1783 1784```ts 1785import formHost from '@ohos.app.form.formHost'; 1786 1787let formIds = new Array('12400633174999288', '12400633174999289'); 1788try { 1789 formHost.notifyFormsPrivacyProtected(formIds, true).then(() => { 1790 console.log('formHost shareForm success'); 1791 }).catch((error) => { 1792 console.log('formHost shareForm, error:' + JSON.stringify(error)); 1793 }); 1794} catch(error) { 1795 console.log(`catch err->${JSON.stringify(error)}`); 1796} 1797``` 1798