1# @ohos.app.form.formHost (formHost) 2 3formHost模块提供了卡片使用方相关接口的能力,包括对使用方同一用户下安装的卡片进行删除、释放、请求更新、获取卡片信息、状态等操作。 4 5> **说明:** 6> 7> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8> 本模块接口均为系统接口。 9 10## 导入模块 11 12```ts 13import formHost from '@ohos.app.form.formHost'; 14``` 15 16## deleteForm 17 18deleteForm(formId: string, callback: AsyncCallback<void>): void 19 20删除指定的卡片。调用此方法后,应用程序将无法使用该卡片,卡片管理器服务不再保留有关该卡片的信息。使用callback异步回调。 21 22**需要权限**:ohos.permission.REQUIRE_FORM 23 24**系统能力**:SystemCapability.Ability.Form 25 26**参数:** 27 28| 参数名 | 类型 | 必填 | 说明 | 29| ------ | ------ | ---- | ------- | 30| formId | string | 是 | 卡片标识。 | 31| callback | AsyncCallback<void> | 是 | 回调函数。当删除指定的卡片成功,error为undefined,否则为错误对象 | 32 33**错误码:** 34 35| 错误码ID | 错误信息 | 36| -------- | -------- | 37| 201 | Permissions denied. | 38| 202 | The application is not a system application. | 39| 401 | If the input parameter is not valid parameter. | 40| 16500050 | An IPC connection error happened. | 41| 16500060 | A service connection error happened, please try again later. | 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 46以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 47 48**示例:** 49 50```ts 51import formHost from '@ohos.app.form.formHost'; 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 72删除指定的卡片。调用此方法后,应用程序将无法使用该卡片,卡片管理器服务不再保留有关该卡片的信息。使用Promise异步回调。 73 74**需要权限**:ohos.permission.REQUIRE_FORM 75 76**系统能力**:SystemCapability.Ability.Form 77 78**参数:** 79 80| 参数名 | 类型 | 必填 | 说明 | 81| ------ | ------ | ---- | ------- | 82| formId | string | 是 | 卡片标识。 | 83 84**返回值:** 85 86| 类型 | 说明 | 87| -------- | -------- | 88| Promise<void> | 无返回结果的Promise对象。 | 89 90 91**错误码:** 92 93| 错误码ID | 错误信息 | 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 104以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 105 106**参数:** 107 108```ts 109import formHost from '@ohos.app.form.formHost'; 110import Base from '@ohos.base'; 111 112try { 113 let formId: string = '12400633174999288'; 114 formHost.deleteForm(formId).then(() => { 115 console.log('formHost deleteForm success'); 116 }).catch((error: Base.BusinessError) => { 117 console.error(`formHost deleteForm, error: ${JSON.stringify(error)}`); 118 }); 119} catch(error) { 120 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 121} 122``` 123 124## releaseForm 125 126releaseForm(formId: string, callback: AsyncCallback<void>): void 127 128释放指定的卡片。调用此方法后,应用程序将无法使用该卡片,但卡片管理器服务仍然保留有关该卡片的缓存信息和存储信息。使用callback异步回调。 129 130**需要权限**:ohos.permission.REQUIRE_FORM 131 132**系统能力**:SystemCapability.Ability.Form 133 134**参数:** 135 136| 参数名 | 类型 | 必填 | 说明 | 137| ------ | ------ | ---- | ------- | 138| formId | string | 是 | 卡片标识。 | 139| callback | AsyncCallback<void> | 是 | 回调函数。当释放指定的卡片成功,error为undefined;否则为错误对象。| 140 141**错误码:** 142 143| 错误码ID | 错误信息 | 144| -------- | -------- | 145| 201 | Permissions denied. | 146| 202 | The application is not a system application. | 147| 401 | If the input parameter is not valid parameter. | 148| 16500050 | An IPC connection error happened. | 149| 16500060 | A service connection error happened, please try again later. | 150| 16501000 | An internal functional error occurred. | 151| 16501001 | The ID of the form to be operated does not exist. | 152| 16501003 | The form can not be operated by the current application. | 153 154以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 155 156**示例:** 157 158```ts 159import formHost from '@ohos.app.form.formHost'; 160import Base from '@ohos.base'; 161 162try { 163 let formId: string = '12400633174999288'; 164 formHost.releaseForm(formId, (error: Base.BusinessError) => { 165 if (error) { 166 console.error(`error, code: ${error.code}, message: ${error.message}`); 167 } 168 }); 169} catch(error) { 170 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 171} 172``` 173 174## releaseForm 175 176releaseForm(formId: string, isReleaseCache: boolean, callback: AsyncCallback<void>): void 177 178释放指定的卡片。调用此方法后,应用程序将无法使用该卡片,卡片管理器服务保留有关该卡片的存储信息,可以选择是否保留缓存信息。使用callback异步回调。 179 180**需要权限**:ohos.permission.REQUIRE_FORM 181 182**系统能力**:SystemCapability.Ability.Form 183 184**参数:** 185 186| 参数名 | 类型 | 必填 | 说明 | 187| -------------- | ------ | ---- | ----------- | 188| formId | string | 是 | 卡片标识。 | 189| isReleaseCache | boolean | 是 | 是否释放缓存。 | 190| callback | AsyncCallback<void> | 是 | 回调函数。当释放指定的卡片成功,error为undefined;否则为错误对象。 | 191 192**错误码:** 193 194| 错误码ID | 错误信息 | 195| -------- | -------- | 196| 201 | Permissions denied. | 197| 202 | The application is not a system application. | 198| 401 | If the input parameter is not valid parameter. | 199| 16500050 | An IPC connection error happened. | 200| 16500060 | A service connection error happened, please try again later. | 201| 16501000 | An internal functional error occurred. | 202| 16501001 | The ID of the form to be operated does not exist. | 203| 16501003 | The form can not be operated by the current application. | 204 205以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 206 207**示例:** 208 209```ts 210import formHost from '@ohos.app.form.formHost'; 211import Base from '@ohos.base'; 212 213try { 214 let formId: string = '12400633174999288'; 215 formHost.releaseForm(formId, true, (error: Base.BusinessError) => { 216 if (error) { 217 console.error(`error, code: ${error.code}, message: ${error.message}`); 218 } 219 }); 220} catch(error) { 221 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 222} 223``` 224 225## releaseForm 226 227releaseForm(formId: string, isReleaseCache?: boolean): Promise<void> 228 229释放指定的卡片。调用此方法后,应用程序将无法使用该卡片,卡片管理器服务保留有关该卡片的存储信息,可以选择是否保留缓存信息。使用Promise异步回调。 230 231**需要权限**:ohos.permission.REQUIRE_FORM 232 233**系统能力**:SystemCapability.Ability.Form 234 235**参数:** 236 237| 参数名 | 类型 | 必填 | 说明 | 238| -------------- | ------ | ---- | ----------- | 239| formId | string | 是 | 卡片标识。 | 240| isReleaseCache | boolean | 否 | 是否释放缓存,默认为false。 | 241 242**返回值:** 243 244| 类型 | 说明 | 245| -------- | -------- | 246| Promise<void> | 无返回结果的Promise对象。 | 247 248**错误码:** 249 250| 错误码ID | 错误信息 | 251| -------- | -------- | 252| 201 | Permissions denied. | 253| 202 | The application is not a system application. | 254| 401 | If the input parameter is not valid parameter. | 255| 16500050 | An IPC connection error happened. | 256| 16500060 | A service connection error happened, please try again later. | 257| 16501000 | An internal functional error occurred. | 258| 16501001 | The ID of the form to be operated does not exist. | 259| 16501003 | The form can not be operated by the current application. | 260 261以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 262 263**示例:** 264 265```ts 266import formHost from '@ohos.app.form.formHost'; 267import Base from '@ohos.base'; 268 269try { 270 let formId: string = '12400633174999288'; 271 formHost.releaseForm(formId, true).then(() => { 272 console.log('formHost releaseForm success'); 273 }).catch((error: Base.BusinessError) => { 274 console.error(`error, code: ${error.code}, message: ${error.message}`); 275 }); 276} catch(error) { 277 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 278} 279``` 280 281## requestForm 282 283requestForm(formId: string, callback: AsyncCallback<void>): void 284 285请求卡片更新。使用callback异步回调。 286 287**需要权限**:ohos.permission.REQUIRE_FORM 288 289**系统能力**:SystemCapability.Ability.Form 290 291**参数:** 292 293| 参数名 | 类型 | 必填 | 说明 | 294| ------ | ------ | ---- | ------- | 295| formId | string | 是 | 卡片标识。 | 296| callback | AsyncCallback<void> | 是 | 回调函数。当请求卡片更新成功,error为undefined;否则为错误对象。 | 297 298**错误码:** 299 300| 错误码ID | 错误信息 | 301| -------- | -------- | 302| 201 | Permissions denied. | 303| 202 | The application is not a system application. | 304| 401 | If the input parameter is not valid parameter. | 305| 16500050 | An IPC connection error happened. | 306| 16500060 | A service connection error happened, please try again later. | 307| 16501000 | An internal functional error occurred. | 308| 16501001 | The ID of the form to be operated does not exist. | 309| 16501003 | The form can not be operated by the current application. | 310 311以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 312 313**示例:** 314 315```ts 316import formHost from '@ohos.app.form.formHost'; 317import Base from '@ohos.base'; 318 319try { 320 let formId: string = '12400633174999288'; 321 formHost.requestForm(formId, (error: Base.BusinessError) => { 322 if (error) { 323 console.error(`error, code: ${error.code}, message: ${error.message}`); 324 } 325 }); 326} catch(error) { 327 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 328} 329``` 330 331## requestForm 332 333requestForm(formId: string): Promise<void> 334 335请求卡片更新。使用Promise异步回调。 336 337**需要权限**:ohos.permission.REQUIRE_FORM 338 339**系统能力**:SystemCapability.Ability.Form 340 341**参数:** 342 343| 参数名 | 类型 | 必填 | 说明 | 344| ------ | ------ | ---- | ------- | 345| formId | string | 是 | 卡片标识。 | 346 347**返回值:** 348 349| 类型 | 说明 | 350| -------- | -------- | 351| Promise<void> | 无返回结果的Promise对象。 | 352 353**错误码:** 354 355| 错误码ID | 错误信息 | 356| -------- | -------- | 357| 201 | Permissions denied. | 358| 202 | The application is not a system application. | 359| 401 | If the input parameter is not valid parameter. | 360| 16500050 | An IPC connection error happened. | 361| 16500060 | A service connection error happened, please try again later. | 362| 16501000 | An internal functional error occurred. | 363| 16501001 | The ID of the form to be operated does not exist. | 364| 16501003 | The form can not be operated by the current application. | 365 366以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 367 368**示例:** 369 370```ts 371import formHost from '@ohos.app.form.formHost'; 372import Base from '@ohos.base'; 373 374try { 375 let formId: string = '12400633174999288'; 376 formHost.requestForm(formId).then(() => { 377 console.log('formHost requestForm success'); 378 }).catch((error: Base.BusinessError) => { 379 console.error(`error, code: ${error.code}, message: ${error.message}`); 380 }); 381} catch(error) { 382 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 383} 384 385``` 386 387## castToNormalForm 388 389castToNormalForm(formId: string, callback: AsyncCallback<void>): void 390 391将指定的临时卡片转换为普通卡片。使用callback异步回调。 392 393**需要权限**:ohos.permission.REQUIRE_FORM 394 395**系统能力**:SystemCapability.Ability.Form 396 397**参数:** 398 399| 参数名 | 类型 | 必填 | 说明 | 400| ------ | ------ | ---- | ------- | 401| formId | string | 是 | 卡片标识。 | 402| callback | AsyncCallback<void> | 是 | 回调函数。当将指定的临时卡片转换为普通卡片成功,error为undefined,否则为错误对象。 | 403 404**错误码:** 405 406| 错误码ID | 错误信息 | 407| -------- | -------- | 408| 201 | Permissions denied. | 409| 202 | The application is not a system application. | 410| 401 | If the input parameter is not valid parameter. | 411| 16500050 | An IPC connection error happened. | 412| 16501000 | An internal functional error occurred. | 413| 16501001 | The ID of the form to be operated does not exist. | 414| 16501002 | The number of forms exceeds upper bound. | 415| 16501003 | The form can not be operated by the current application. | 416 417以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 418 419**示例:** 420 421```ts 422import formHost from '@ohos.app.form.formHost'; 423import Base from '@ohos.base'; 424 425try { 426 let formId: string = '12400633174999288'; 427 formHost.castToNormalForm(formId, (error: Base.BusinessError) => { 428 if (error) { 429 console.error(`error, code: ${error.code}, message: ${error.message}`); 430 } 431 }); 432} catch(error) { 433 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 434} 435``` 436 437## castToNormalForm 438 439castToNormalForm(formId: string): Promise<void> 440 441将指定的临时卡片转换为普通卡片。使用Promise异步回调。 442 443**需要权限**:ohos.permission.REQUIRE_FORM 444 445**系统能力**:SystemCapability.Ability.Form 446 447**参数:** 448 449| 参数名 | 类型 | 必填 | 说明 | 450| ------ | ------ | ---- | ------- | 451| formId | string | 是 | 卡片标识。 | 452 453**返回值:** 454 455| 类型 | 说明 | 456| -------- | -------- | 457| Promise<void> | 无返回结果的Promise对象。| 458 459**错误码:** 460 461| 错误码ID | 错误信息 | 462| -------- | -------- | 463| 201 | Permissions denied. | 464| 202 | The application is not a system application. | 465| 401 | If the input parameter is not valid parameter. | 466| 16500050 | An IPC connection error happened. | 467| 16501000 | An internal functional error occurred. | 468| 16501001 | The ID of the form to be operated does not exist. | 469| 16501002 | The number of forms exceeds upper bound. | 470| 16501003 | The form can not be operated by the current application. | 471 472以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 473 474**示例:** 475 476```ts 477import formHost from '@ohos.app.form.formHost'; 478import Base from '@ohos.base'; 479 480try { 481 let formId: string = '12400633174999288'; 482 formHost.castToNormalForm(formId).then(() => { 483 console.log('formHost castTempForm success'); 484 }).catch((error: Base.BusinessError) => { 485 console.error(`error, code: ${error.code}, message: ${error.message}`); 486 }); 487} catch(error) { 488 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 489} 490``` 491 492## notifyVisibleForms 493 494notifyVisibleForms(formIds: Array<string>, callback: AsyncCallback<void>): void 495 496向卡片框架发送通知以使指定的卡片可见。该方法调用成功后,会调用onVisibilityChange通知卡片提供方。使用callback异步回调。 497 498**需要权限**:ohos.permission.REQUIRE_FORM 499 500**系统能力**:SystemCapability.Ability.Form 501 502**参数:** 503 504| 参数名 | 类型 | 必填 | 说明 | 505| ------ | ------ | ---- | ------- | 506| formIds | Array<string> | 是 | 卡片标识列表。 | 507| callback | AsyncCallback<void> | 是 | 回调函数。当向卡片框架发送通知以使指定的卡片可见成功,error为undefined,否则为错误对象。 | 508 509**错误码:** 510 511| 错误码ID | 错误信息 | 512| -------- | -------- | 513| 201 | Permissions denied. | 514| 202 | The application is not a system application. | 515| 401 | If the input parameter is not valid parameter. | 516| 16500050 | An IPC connection error happened. | 517| 16500060 | A service connection error happened, please try again later. | 518| 16501000 | An internal functional error occurred. | 519 520以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 521 522**示例:** 523 524```ts 525import formHost from '@ohos.app.form.formHost'; 526import Base from '@ohos.base'; 527 528try { 529 let formId: string[] = ['12400633174999288']; 530 formHost.notifyVisibleForms(formId, (error: Base.BusinessError) => { 531 if (error) { 532 console.error(`error, code: ${error.code}, message: ${error.message}`); 533 } 534 }); 535} catch(error) { 536 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 537} 538``` 539 540## notifyVisibleForms 541 542notifyVisibleForms(formIds: Array<string>): Promise<void> 543 544向卡片框架发送通知以使指定的卡片可见。该方法调用成功后,会调用onVisibilityChange通知卡片提供方。使用Promise异步回调。 545 546**需要权限**:ohos.permission.REQUIRE_FORM 547 548**系统能力**:SystemCapability.Ability.Form 549 550**参数:** 551 552| 参数名 | 类型 | 必填 | 说明 | 553| ------ | ------ | ---- | ------- | 554| formIds | Array<string> | 是 | 卡片标识列表。 | 555 556**返回值:** 557 558| 类型 | 说明 | 559| -------- | -------- | 560| Promise<void> | 无返回结果的Promise对象。 | 561 562**错误码:** 563 564| 错误码ID | 错误信息 | 565| -------- | -------- | 566| 201 | Permissions denied. | 567| 202 | The application is not a system application. | 568| 401 | If the input parameter is not valid parameter. | 569| 16500050 | An IPC connection error happened. | 570| 16500060 | A service connection error happened, please try again later. | 571| 16501000 | An internal functional error occurred. | 572 573以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 574 575**示例:** 576 577```ts 578import formHost from '@ohos.app.form.formHost'; 579import Base from '@ohos.base'; 580 581try { 582 let formId: string[] = ['12400633174999288']; 583 formHost.notifyVisibleForms(formId).then(() => { 584 console.log('formHost notifyVisibleForms success'); 585 }).catch((error: Base.BusinessError) => { 586 console.error(`error, code: ${error.code}, message: ${error.message}`); 587 }); 588} catch(error) { 589 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 590} 591``` 592 593## notifyInvisibleForms 594 595notifyInvisibleForms(formIds: Array<string>, callback: AsyncCallback<void>): void 596 597向卡片框架发送通知以使指定的卡片不可见。该方法调用成功后,会调用onVisibilityChange通知卡片提供方。使用callback异步回调。 598 599**需要权限**:ohos.permission.REQUIRE_FORM 600 601**系统能力**:SystemCapability.Ability.Form 602 603**参数:** 604 605| 参数名 | 类型 | 必填 | 说明 | 606| ------ | ------ | ---- | ------- | 607| formIds | Array<string> | 是 | 卡片标识列表。| 608| callback | AsyncCallback<void> | 是 | 回调函数。当向卡片框架发送通知以使指定的卡片不可见成功,error为undefined,否则为错误对象。 | 609 610**错误码:** 611 612| 错误码ID | 错误信息 | 613| -------- | -------- | 614| 201 | Permissions denied. | 615| 202 | The application is not a system application. | 616| 401 | If the input parameter is not valid parameter. | 617| 16500050 | An IPC connection error happened. | 618| 16500060 | A service connection error happened, please try again later. | 619| 16501000 | An internal functional error occurred. | 620 621以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 622 623**示例:** 624 625```ts 626import formHost from '@ohos.app.form.formHost'; 627import Base from '@ohos.base'; 628 629try { 630 let formId: string[] = ['12400633174999288']; 631 formHost.notifyInvisibleForms(formId, (error: Base.BusinessError) => { 632 if (error) { 633 console.error(`error, code: ${error.code}, message: ${error.message}`); 634 } 635 }); 636} catch(error) { 637 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 638} 639``` 640 641## notifyInvisibleForms 642 643notifyInvisibleForms(formIds: Array<string>): Promise<void> 644 645向卡片框架发送通知以使指定的卡片不可见。该方法调用成功后,会调用onVisibilityChange通知卡片提供方。使用Promise异步回调。 646 647**需要权限**:ohos.permission.REQUIRE_FORM 648 649**系统能力**:SystemCapability.Ability.Form 650 651**参数:** 652 653| 参数名 | 类型 | 必填 | 说明 | 654| ------ | ------ | ---- | ------- | 655| formIds | Array<string> | 是 | 卡片标识列表。 | 656 657**返回值:** 658 659| 类型 | 说明 | 660| -------- | -------- | 661| Promise<void> | 无返回结果的Promise对象。| 662 663**错误码:** 664 665| 错误码ID | 错误信息 | 666| -------- | -------- | 667| 201 | Permissions denied. | 668| 202 | The application is not a system application. | 669| 401 | If the input parameter is not valid parameter. | 670| 16500050 | An IPC connection error happened. | 671| 16500060 | A service connection error happened, please try again later. | 672| 16501000 | An internal functional error occurred. | 673 674以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 675 676**示例:** 677 678```ts 679import formHost from '@ohos.app.form.formHost'; 680import Base from '@ohos.base'; 681 682try { 683 let formId: string[] = ['12400633174999288']; 684 formHost.notifyInvisibleForms(formId).then(() => { 685 console.log('formHost notifyInvisibleForms success'); 686 }).catch((error: Base.BusinessError) => { 687 console.error(`error, code: ${error.code}, message: ${error.message}`); 688 }); 689} catch(error) { 690 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 691} 692``` 693 694## enableFormsUpdate 695 696enableFormsUpdate(formIds: Array<string>, callback: AsyncCallback<void>): void 697 698向卡片框架发送通知以使指定的卡片可以更新。该方法调用成功后,卡片刷新状态设置为使能,卡片可以接收来自卡片提供方的更新。使用callback异步回调。 699 700**需要权限**:ohos.permission.REQUIRE_FORM 701 702**系统能力**:SystemCapability.Ability.Form 703 704**参数:** 705 706| 参数名 | 类型 | 必填 | 说明 | 707| ------ | ------ | ---- | ------- | 708| formIds | Array<string> | 是 | 卡片标识列表。 | 709| callback | AsyncCallback<void> | 是 | 回调函数。当向卡片框架发送通知以使指定的卡片可以更新成功,error为undefined,否则为错误对象。 | 710 711**错误码:** 712 713| 错误码ID | 错误信息 | 714| -------- | -------- | 715| 201 | Permissions denied. | 716| 202 | The application is not a system application. | 717| 401 | If the input parameter is not valid parameter. | 718| 16500050 | An IPC connection error happened. | 719| 16500060 | A service connection error happened, please try again later. | 720| 16501000 | An internal functional error occurred. | 721| 16501003 | The form can not be operated by the current application. | 722 723以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 724 725**示例:** 726 727```ts 728import formHost from '@ohos.app.form.formHost'; 729import Base from '@ohos.base'; 730 731try { 732 let formId: string[] = ['12400633174999288']; 733 formHost.enableFormsUpdate(formId, (error: Base.BusinessError) => { 734 if (error) { 735 console.error(`error, code: ${error.code}, message: ${error.message}`); 736 } 737 }); 738} catch(error) { 739 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 740} 741``` 742 743## enableFormsUpdate 744 745enableFormsUpdate(formIds: Array<string>): Promise<void> 746 747向卡片框架发送通知以使指定的卡片可以更新。该方法调用成功后,卡片刷新状态设置为使能,卡片可以接收来自卡片提供方的更新。使用Promise异步回调。 748 749**需要权限**:ohos.permission.REQUIRE_FORM 750 751**系统能力**:SystemCapability.Ability.Form 752 753**参数:** 754 755| 参数名 | 类型 | 必填 | 说明 | 756| ------ | ------ | ---- | ------- | 757| formIds | Array<string> | 是 | 卡片标识列表。 | 758 759**返回值:** 760 761| 类型 | 说明 | 762| -------- | -------- | 763| Promise<void> | 无返回结果的Promise对象。 | 764 765**错误码:** 766 767| 错误码ID | 错误信息 | 768| -------- | -------- | 769| 201 | Permissions denied. | 770| 202 | The application is not a system application. | 771| 401 | If the input parameter is not valid parameter. | 772| 16500050 | An IPC connection error happened. | 773| 16500060 | A service connection error happened, please try again later. | 774| 16501000 | An internal functional error occurred. | 775| 16501003 | The form can not be operated by the current application. | 776 777以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 778 779**示例:** 780 781```ts 782import formHost from '@ohos.app.form.formHost'; 783import Base from '@ohos.base'; 784 785try { 786 let formId: string[] = ['12400633174999288']; 787 formHost.enableFormsUpdate(formId).then(() => { 788 console.log('formHost enableFormsUpdate success'); 789 }).catch((error: Base.BusinessError) => { 790 console.error(`error, code: ${error.code}, message: ${error.message}`); 791 }); 792} catch(error) { 793 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 794} 795``` 796 797## disableFormsUpdate 798 799disableFormsUpdate(formIds: Array<string>, callback: AsyncCallback<void>): void 800 801向卡片框架发送通知以使指定的卡片不可以更新。该方法调用成功后,卡片刷新状态设置为去使能,卡片不可以接收来自卡片提供方的更新。使用callback异步回调。 802 803**需要权限**:ohos.permission.REQUIRE_FORM 804 805**系统能力**:SystemCapability.Ability.Form 806 807**参数:** 808 809| 参数名 | 类型 | 必填 | 说明 | 810| ------ | ------ | ---- | ------- | 811| formIds | Array<string> | 是 | 卡片标识列表。 | 812| callback | AsyncCallback<void> | 是 | 回调函数。当向卡片框架发送通知以使指定的卡片不可以更新成功,error为undefined,否则为错误对象。 | 813 814**错误码:** 815 816| 错误码ID | 错误信息 | 817| -------- | -------- | 818| 201 | Permissions denied. | 819| 202 | The application is not a system application. | 820| 401 | If the input parameter is not valid parameter. | 821| 16500050 | An IPC connection error happened. | 822| 16500060 | A service connection error happened, please try again later. | 823| 16501000 | An internal functional error occurred. | 824| 16501001 | The ID of the form to be operated does not exist. | 825| 16501003 | The form can not be operated by the current application. | 826 827以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 828 829**示例:** 830 831```ts 832import formHost from '@ohos.app.form.formHost'; 833import Base from '@ohos.base'; 834 835try { 836 let formId: string[] = ['12400633174999288']; 837 formHost.disableFormsUpdate(formId, (error: Base.BusinessError) => { 838 if (error) { 839 console.error(`error, code: ${error.code}, message: ${error.message}`); 840 } 841 }); 842} catch(error) { 843 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 844} 845``` 846 847## disableFormsUpdate 848 849disableFormsUpdate(formIds: Array<string>): Promise<void> 850 851向卡片框架发送通知以使指定的卡片不可以更新。该方法调用成功后,卡片刷新状态设置为去使能,卡片不可以接收来自卡片提供方的更新。使用Promise异步回调。 852 853**需要权限**:ohos.permission.REQUIRE_FORM 854 855**系统能力**:SystemCapability.Ability.Form 856 857**参数:** 858 859| 参数名 | 类型 | 必填 | 说明 | 860| ------ | ------ | ---- | ------- | 861| formIds | Array<string> | 是 | 卡片标识列表。 | 862 863**返回值:** 864 865| 类型 | 说明 | 866| -------- | -------- | 867| Promise<void> | 无返回结果的Promise对象。 | 868 869**错误码:** 870 871| 错误码ID | 错误信息 | 872| -------- | -------- | 873| 201 | Permissions denied. | 874| 202 | The application is not a system application. | 875| 401 | If the input parameter is not valid parameter. | 876| 16500050 | An IPC connection error happened. | 877| 16500060 | A service connection error happened, please try again later. | 878| 16501000 | An internal functional error occurred. | 879| 16501001 | The ID of the form to be operated does not exist. | 880| 16501003 | The form can not be operated by the current application. | 881 882以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 883 884**示例:** 885 886```ts 887import formHost from '@ohos.app.form.formHost'; 888import Base from '@ohos.base'; 889 890try { 891 let formId: string[] = ['12400633174999288']; 892 formHost.disableFormsUpdate(formId).then(() => { 893 console.log('formHost disableFormsUpdate success'); 894 }).catch((error: Base.BusinessError) => { 895 console.error(`error, code: ${error.code}, message: ${error.message}`); 896 }); 897} catch(error) { 898 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 899} 900``` 901 902## isSystemReady 903 904isSystemReady(callback: AsyncCallback<void>): void 905 906检查系统是否准备好。使用callback异步回调。 907 908**系统能力**:SystemCapability.Ability.Form 909 910**参数:** 911 912| 参数名 | 类型 | 必填 | 说明 | 913| ------ | ------ | ---- | ------- | 914| callback | AsyncCallback<void> | 是 | 回调函数。当检查系统是否准备好成功,error为undefined,否则为错误对象。 | 915 916**错误码:** 917 918| 错误码ID | 错误信息 | 919| -------- | -------- | 920| 202 | The application is not a system application. | 921| 401 | If the input parameter is not valid parameter. | 922 923以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 924 925**示例:** 926 927```ts 928import formHost from '@ohos.app.form.formHost'; 929import Base from '@ohos.base'; 930 931try { 932 formHost.isSystemReady((error: Base.BusinessError) => { 933 if (error) { 934 console.error(`error, code: ${error.code}, message: ${error.message}`); 935 } 936 }); 937} catch(error) { 938 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 939} 940``` 941 942## isSystemReady 943 944isSystemReady(): Promise<void> 945 946检查系统是否准备好。使用Promise异步回调。 947 948**系统能力**:SystemCapability.Ability.Form 949 950**返回值:** 951 952| 类型 | 说明 | 953| -------- | -------- | 954| Promise<void> | 无返回结果的Promise对象。 | 955 956**错误码:** 957 958| 错误码ID | 错误信息 | 959| -------- | -------- | 960| 202 | The application is not a system application. | 961 962以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 963 964**示例:** 965 966```ts 967import formHost from '@ohos.app.form.formHost'; 968import Base from '@ohos.base'; 969 970try { 971 formHost.isSystemReady().then(() => { 972 console.log('formHost isSystemReady success'); 973 }).catch((error: Base.BusinessError) => { 974 console.error(`error, code: ${error.code}, message: ${error.message}`); 975 }); 976} catch(error) { 977 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 978} 979``` 980 981## getAllFormsInfo 982 983getAllFormsInfo(callback: AsyncCallback<Array<formInfo.FormInfo>>): void 984 985获取设备上所有应用提供的卡片信息。使用callback异步回调。 986 987**需要权限**:ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 988 989**系统能力**:SystemCapability.Ability.Form 990 991**错误码:** 992 993| 错误码ID | 错误信息 | 994| -------- | -------- | 995| 201 | Permissions denied. | 996| 202 | The application is not a system application. | 997| 401 | If the input parameter is not valid parameter. | 998| 16500050 | An IPC connection error happened. | 999| 16500060 | A service connection error happened, please try again later. | 1000| 16501000 | An internal functional error occurred. | 1001 1002以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 1003 1004**参数:** 1005 1006| 参数名 | 类型 | 必填 | 说明 | 1007| ------ | ------ | ---- | ------- | 1008| callback | AsyncCallback<Array<[formInfo.FormInfo](js-apis-app-form-formInfo.md)>> | 是 | 回调函数。当获取设备上所有应用提供的卡片信息成功,error为undefined,data为查询到的卡片信息;否则为错误对象。 | 1009 1010**示例:** 1011 1012```ts 1013import formHost from '@ohos.app.form.formHost'; 1014import formInfo from '@ohos.app.form.formInfo'; 1015import Base from '@ohos.base'; 1016 1017try { 1018 formHost.getAllFormsInfo((error: Base.BusinessError, data: formInfo.FormInfo[]) => { 1019 if (error) { 1020 console.error(`error, code: ${error.code}, message: ${error.message}`); 1021 } else { 1022 console.log(`formHost getAllFormsInfo, data: ${JSON.stringify(data)}`); 1023 } 1024 }); 1025} catch(error) { 1026 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1027} 1028``` 1029 1030## getAllFormsInfo 1031 1032getAllFormsInfo(): Promise<Array<formInfo.FormInfo>> 1033 1034获取设备上所有应用提供的卡片信息。使用Promise异步回调。 1035 1036**需要权限**:ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1037 1038**系统能力**:SystemCapability.Ability.Form 1039 1040**错误码:** 1041 1042| 错误码ID | 错误信息 | 1043| -------- | -------- | 1044| 201 | Permissions denied. | 1045| 202 | The application is not a system application. | 1046| 16500050 | An IPC connection error happened. | 1047| 16500060 | A service connection error happened, please try again later. | 1048| 16501000 | An internal functional error occurred. | 1049 1050以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 1051 1052**返回值:** 1053 1054| 类型 | 说明 | 1055| :----------------------------------------------------------- | :---------------------------------- | 1056| Promise<Array<[formInfo.FormInfo](js-apis-app-form-formInfo.md)>> | Promise对象,返回查询到的卡片信息。 | 1057 1058**示例:** 1059 1060```ts 1061import formHost from '@ohos.app.form.formHost'; 1062import formInfo from '@ohos.app.form.formInfo'; 1063import Base from '@ohos.base'; 1064 1065try { 1066 formHost.getAllFormsInfo().then((data: formInfo.FormInfo[]) => { 1067 console.log(`formHost getAllFormsInfo data: ${JSON.stringify(data)}`); 1068 }).catch((error: Base.BusinessError) => { 1069 console.error(`error, code: ${error.code}, message: ${error.message}`); 1070 }); 1071} catch(error) { 1072 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1073} 1074``` 1075 1076## getFormsInfo 1077 1078getFormsInfo(bundleName: string, callback: AsyncCallback<Array<formInfo.FormInfo>>): void 1079 1080获取设备上指定应用程序提供的卡片信息。使用callback异步回调。 1081 1082**需要权限**:ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1083 1084**系统能力**:SystemCapability.Ability.Form 1085 1086**参数:** 1087 1088| 参数名 | 类型 | 必填 | 说明 | 1089| ------ | ------ | ---- | ------- | 1090| bundleName | string | 是 | 要查询的应用Bundle名称。 | 1091| callback | AsyncCallback<Array<[formInfo.FormInfo](js-apis-app-form-formInfo.md)>> | 是 | 回调函数。当获取设备上指定应用程序提供的卡片信息成功,error为undefined,data为查询到的卡片信息;否则为错误对象。 | 1092 1093**错误码:** 1094 1095| 错误码ID | 错误信息 | 1096| -------- | -------- | 1097| 201 | Permissions denied. | 1098| 202 | The application is not a system application. | 1099| 401 | If the input parameter is not valid parameter. | 1100| 16500050 | An IPC connection error happened. | 1101| 16500060 | A service connection error happened, please try again later. | 1102| 16500100 | Failed to obtain the configuration information. | 1103| 16501000 | An internal functional error occurred. | 1104 1105以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 1106 1107**示例:** 1108 1109```ts 1110import formHost from '@ohos.app.form.formHost'; 1111import formInfo from '@ohos.app.form.formInfo'; 1112import Base from '@ohos.base'; 1113 1114try { 1115 formHost.getFormsInfo('com.example.ohos.formjsdemo', (error: Base.BusinessError, data: formInfo.FormInfo[]) => { 1116 if (error) { 1117 console.error(`error, code: ${error.code}, message: ${error.message}`); 1118 } else { 1119 console.log(`formHost getFormsInfo, data: ${JSON.stringify(data)}`); 1120 } 1121 }); 1122} catch(error) { 1123 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1124} 1125``` 1126 1127## getFormsInfo 1128 1129getFormsInfo(bundleName: string, moduleName: string, callback: AsyncCallback<Array<formInfo.FormInfo>>): void 1130 1131获取设备上指定应用程序提供的卡片信息。使用callback异步回调。 1132 1133**需要权限**:ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1134 1135**系统能力**:SystemCapability.Ability.Form 1136 1137**参数:** 1138 1139| 参数名 | 类型 | 必填 | 说明 | 1140| ------ | ------ | ---- | ------- | 1141| bundleName | string | 是 | 要查询的应用Bundle名称。 | 1142| moduleName | string | 是 | 要查询的模块名称。 | 1143| callback | AsyncCallback<Array<[formInfo.FormInfo](js-apis-app-form-formInfo.md)>> | 是 | 回调函数。当获取设备上指定应用程序提供的卡片信息成功,error为undefined,data为查询到的卡片信息;否则为错误对象。 | 1144 1145**错误码:** 1146 1147| 错误码ID | 错误信息 | 1148| -------- | -------- | 1149| 201 | Permissions denied. | 1150| 202 | The application is not a system application. | 1151| 401 | If the input parameter is not valid parameter. | 1152| 16500050 | An IPC connection error happened. | 1153| 16500060 | A service connection error happened, please try again later. | 1154| 16500100 | Failed to obtain the configuration information. | 1155| 16501000 | An internal functional error occurred. | 1156 1157以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 1158 1159**示例:** 1160 1161```ts 1162import formHost from '@ohos.app.form.formHost'; 1163import formInfo from '@ohos.app.form.formInfo'; 1164import Base from '@ohos.base'; 1165 1166try { 1167 formHost.getFormsInfo('com.example.ohos.formjsdemo', 'entry', (error: Base.BusinessError, data: formInfo.FormInfo[]) => { 1168 if (error) { 1169 console.error(`error, code: ${error.code}, message: ${error.message}`); 1170 } else { 1171 console.log('formHost getFormsInfo, data: ${JSON.stringify(data)}'); 1172 } 1173 }); 1174} catch(error) { 1175 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1176} 1177``` 1178 1179## getFormsInfo 1180 1181getFormsInfo(bundleName: string, moduleName?: string): Promise<Array<formInfo.FormInfo>> 1182 1183获取设备上指定应用程序提供的卡片信息。使用Promise异步回调。 1184 1185**需要权限**:ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1186 1187**系统能力**:SystemCapability.Ability.Form 1188 1189**参数:** 1190 1191| 参数名 | 类型 | 必填 | 说明 | 1192| ------ | ------ | ---- | ------- | 1193| bundleName | string | 是 | 要查询的应用Bundle名称。 | 1194| moduleName | string | 否 | 要查询的模块名称,缺省默认为空。 | 1195 1196**返回值:** 1197 1198| 类型 | 说明 | 1199| :----------------------------------------------------------- | :---------------------------------- | 1200| Promise<Array<[formInfo.FormInfo](js-apis-app-form-formInfo.md)>> | Promise对象,返回查询到的卡片信息。 | 1201 1202**错误码:** 1203 1204| 错误码ID | 错误信息 | 1205| -------- | -------- | 1206| 201 | Permissions denied. | 1207| 202 | The application is not a system application. | 1208| 401 | If the input parameter is not valid parameter. | 1209| 16500050 | An IPC connection error happened. | 1210| 16500060 | A service connection error happened, please try again later. | 1211| 16500100 | Failed to obtain the configuration information. | 1212| 16501000 | An internal functional error occurred. | 1213 1214以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 1215 1216**示例:** 1217 1218```ts 1219import formHost from '@ohos.app.form.formHost'; 1220import formInfo from '@ohos.app.form.formInfo'; 1221import Base from '@ohos.base'; 1222 1223try { 1224 formHost.getFormsInfo('com.example.ohos.formjsdemo', 'entry').then((data: formInfo.FormInfo[]) => { 1225 console.log(`formHost getFormsInfo, data: ${JSON.stringify(data)}`); 1226 }).catch((error: Base.BusinessError) => { 1227 console.error(`error, code: ${error.code}, message: ${error.message}`); 1228 }); 1229} catch(error) { 1230 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1231} 1232``` 1233 1234## deleteInvalidForms 1235 1236deleteInvalidForms(formIds: Array<string>, callback: AsyncCallback<number>): void 1237 1238根据列表删除应用程序的无效卡片。使用callback异步回调。 1239 1240**需要权限**:ohos.permission.REQUIRE_FORM 1241 1242**系统能力**:SystemCapability.Ability.Form 1243 1244**参数:** 1245 1246| 参数名 | 类型 | 必填 | 说明 | 1247| ------ | ------ | ---- | ------- | 1248| formIds | Array<string> | 是 | 有效卡片标识列表。 | 1249| callback | AsyncCallback<number> | 是 | 回调函数。当根据列表删除应用程序的无效卡片成功,error为undefined,data为删除的卡片个数;否则为错误对象。 | 1250 1251**错误码:** 1252 1253| 错误码ID | 错误信息 | 1254| -------- | -------- | 1255| 201 | Permissions denied. | 1256| 202 | The application is not a system application. | 1257| 401 | If the input parameter is not valid parameter. | 1258| 16500050 | An IPC connection error happened. | 1259| 16500060 | A service connection error happened, please try again later. | 1260| 16501000 | An internal functional error occurred. | 1261 1262以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 1263 1264**示例:** 1265 1266```ts 1267import formHost from '@ohos.app.form.formHost'; 1268import Base from '@ohos.base'; 1269 1270try { 1271 let formIds: string[] = new Array('12400633174999288', '12400633174999289'); 1272 formHost.deleteInvalidForms(formIds, (error: Base.BusinessError, data: number) => { 1273 if (error) { 1274 console.error(`error, code: ${error.code}, message: ${error.message}`); 1275 } else { 1276 console.log(`formHost deleteInvalidForms, data: ${JSON.stringify(data)}`); 1277 } 1278 }); 1279} catch(error) { 1280 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1281} 1282``` 1283 1284## deleteInvalidForms 1285 1286deleteInvalidForms(formIds: Array<string>): Promise<number> 1287 1288根据列表删除应用程序的无效卡片。使用Promise异步回调。 1289 1290**需要权限**:ohos.permission.REQUIRE_FORM 1291 1292**系统能力**:SystemCapability.Ability.Form 1293 1294**参数:** 1295 1296| 参数名 | 类型 | 必填 | 说明 | 1297| ------ | ------ | ---- | ------- | 1298| formIds | Array<string> | 是 | 有效卡片标识列表。 | 1299 1300**返回值:** 1301 1302| 类型 | 说明 | 1303| :------------ | :---------------------------------- | 1304| Promise<number> | Promise对象,返回删除的卡片个数。 | 1305 1306**错误码:** 1307 1308| 错误码ID | 错误信息 | 1309| -------- | -------- | 1310| 201 | Permissions denied. | 1311| 202 | The application is not a system application. | 1312| 401 | If the input parameter is not valid parameter. | 1313| 16500050 | An IPC connection error happened. | 1314| 16500060 | A service connection error happened, please try again later. | 1315| 16501000 | An internal functional error occurred. | 1316 1317以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 1318 1319**示例:** 1320 1321```ts 1322import formHost from '@ohos.app.form.formHost'; 1323import Base from '@ohos.base'; 1324 1325try { 1326 let formIds: string[] = new Array('12400633174999288', '12400633174999289'); 1327 formHost.deleteInvalidForms(formIds).then((data: number) => { 1328 console.log(`formHost deleteInvalidForms, data: ${JSON.stringify(data)}`); 1329 }).catch((error: Base.BusinessError) => { 1330 console.error(`error, code: ${error.code}, message: ${error.message}`); 1331 }); 1332} catch(error) { 1333 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1334} 1335``` 1336 1337## acquireFormState 1338 1339acquireFormState(want: Want, callback: AsyncCallback<formInfo.FormStateInfo>): void 1340 1341获取卡片状态。使用callback异步回调。 1342 1343**需要权限**:ohos.permission.REQUIRE_FORM 和 ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1344 1345**系统能力**:SystemCapability.Ability.Form 1346 1347**参数:** 1348 1349| 参数名 | 类型 | 必填 | 说明 | 1350| ------ | ------ | ---- | ------- | 1351| want | [Want](js-apis-app-ability-want.md) | 是 | 查询卡片状态时携带的want信息。需要包含bundle名、ability名、module名、卡片名、卡片规格等。 | 1352| callback | AsyncCallback<[formInfo.FormStateInfo](js-apis-app-form-formInfo.md#formstateinfo)> | 是 | 回调函数。当获取卡片状态成功,error为undefined,data为获取到的卡片状态;否则为错误对象。 | 1353 1354**错误码:** 1355 1356| 错误码ID | 错误信息 | 1357| -------- | -------- | 1358| 201 | Permissions denied. | 1359| 202 | The application is not a system application. | 1360| 401 | If the input parameter is not valid parameter. | 1361| 16500050 | An IPC connection error happened. | 1362| 16500060 | A service connection error happened, please try again later. | 1363| 16500100 | Failed to obtain the configuration information. | 1364| 16501000 | An internal functional error occurred. | 1365 1366以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 1367 1368**示例:** 1369 1370```ts 1371import formHost from '@ohos.app.form.formHost'; 1372import Want from '@ohos.app.ability.Want'; 1373import formInfo from '@ohos.app.form.formInfo'; 1374import Base from '@ohos.base'; 1375 1376let want: Want = { 1377 'deviceId': '', 1378 'bundleName': 'ohos.samples.FormApplication', 1379 'abilityName': 'FormAbility', 1380 'parameters': { 1381 'ohos.extra.param.key.module_name': 'entry', 1382 'ohos.extra.param.key.form_name': 'widget', 1383 'ohos.extra.param.key.form_dimension': 2 1384 } 1385}; 1386try { 1387 formHost.acquireFormState(want, (error:Base.BusinessError, data: formInfo.FormStateInfo) => { 1388 if (error) { 1389 console.error(`error, code: ${error.code}, message: ${error.message}`); 1390 } else { 1391 console.log(`formHost acquireFormState, data: ${JSON.stringify(data)}`); 1392 } 1393 }); 1394} catch(error) { 1395 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1396} 1397``` 1398 1399## acquireFormState 1400 1401acquireFormState(want: Want): Promise<formInfo.FormStateInfo> 1402 1403获取卡片状态。使用Promise异步回调。 1404 1405**需要权限**:ohos.permission.REQUIRE_FORM 和 ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1406 1407**系统能力**:SystemCapability.Ability.Form 1408 1409**参数:** 1410 1411| 参数名 | 类型 | 必填 | 说明 | 1412| ------ | ------ | ---- | ------- | 1413| want | [Want](js-apis-app-ability-want.md) | 是 | 查询卡片状态时携带的want信息。需要包含bundle名、ability名、module名、卡片名、卡片规格等。 | 1414 1415**返回值:** 1416 1417| 类型 | 说明 | 1418| :------------ | :---------------------------------- | 1419| Promise<[formInfo.FormStateInfo](js-apis-app-form-formInfo.md#formstateinfo)> | Promise对象,返回卡片状态。 | 1420 1421**错误码:** 1422 1423| 错误码ID | 错误信息 | 1424| -------- | -------- | 1425| 201 | Permissions denied. | 1426| 202 | The application is not a system application. | 1427| 401 | If the input parameter is not valid parameter. | 1428| 16500050 | An IPC connection error happened. | 1429| 16500060 | A service connection error happened, please try again later. | 1430| 16500100 | Failed to obtain the configuration information. | 1431| 16501000 | An internal functional error occurred. | 1432 1433以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 1434 1435**示例:** 1436 1437```ts 1438import formHost from '@ohos.app.form.formHost'; 1439import Want from '@ohos.app.ability.Want'; 1440import formInfo from '@ohos.app.form.formInfo'; 1441import Base from '@ohos.base'; 1442 1443let want: Want = { 1444 'deviceId': '', 1445 'bundleName': 'ohos.samples.FormApplication', 1446 'abilityName': 'FormAbility', 1447 'parameters': { 1448 'ohos.extra.param.key.module_name': 'entry', 1449 'ohos.extra.param.key.form_name': 'widget', 1450 'ohos.extra.param.key.form_dimension': 2 1451 } 1452}; 1453try { 1454 formHost.acquireFormState(want).then((data: formInfo.FormStateInfo) => { 1455 console.log(`formHost acquireFormState, data: ${JSON.stringify(data)}`); 1456 }).catch((error: Base.BusinessError) => { 1457 console.error(`error, code: ${error.code}, message: ${error.message}`); 1458 }); 1459} catch(error) { 1460 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1461} 1462``` 1463 1464## on('formUninstall') 1465 1466on(type: 'formUninstall', callback: Callback<string>): void 1467 1468订阅卡片卸载事件。使用callback异步回调。 1469 1470**系统能力**:SystemCapability.Ability.Form 1471 1472**参数:** 1473 1474| 参数名 | 类型 | 必填 | 说明 | 1475| ------ | ------ | ---- | ------- | 1476| type | string | 是 | 填写'formUninstall',表示卡片卸载事件。 | 1477| callback | Callback<string> | 是 | 回调函数。返回卡片标识。 | 1478 1479**错误码:** 1480 1481| 错误码ID | 错误信息 | 1482| -------- | -------- | 1483| 202 | The application is not a system application. | 1484| 401 | If the input parameter is not valid parameter. | 1485 1486以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 1487 1488**示例:** 1489 1490```ts 1491import formHost from '@ohos.app.form.formHost'; 1492 1493formHost.on('formUninstall', (formId: string) => { 1494 console.log(`formHost on formUninstall, formId: ${formId}`); 1495}); 1496``` 1497 1498## off('formUninstall') 1499 1500off(type: 'formUninstall', callback?: Callback<string>): void 1501 1502取消订阅卡片卸载事件。使用callback异步回调。 1503 1504**系统能力**:SystemCapability.Ability.Form 1505 1506**参数:** 1507 1508| 参数名 | 类型 | 必填 | 说明 | 1509| ------ | ------ | ---- | ------- | 1510| type | string | 是 | 填写'formUninstall',表示卡片卸载事件。 | 1511| callback | Callback<string> | 否 | 回调函数。返回卡片标识。缺省时,表示注销所有已注册事件回调。<br> 需与对应on('formUninstall')的callback一致。| 1512 1513**错误码:** 1514 1515| 错误码ID | 错误信息 | 1516| -------- | -------- | 1517| 202 | The application is not a system application. | 1518| 401 | If the input parameter is not valid parameter. | 1519 1520以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 1521 1522**示例:** 1523 1524```ts 1525import formHost from '@ohos.app.form.formHost'; 1526 1527formHost.off('formUninstall', (formId: string) => { 1528 console.log(`formHost on formUninstall, formId: ${formId}`); 1529}); 1530``` 1531 1532## notifyFormsVisible 1533 1534notifyFormsVisible(formIds: Array<string>, isVisible: boolean, callback: AsyncCallback<void>): void 1535 1536通知卡片是否可见。使用callback异步回调。 1537 1538**需要权限**:ohos.permission.REQUIRE_FORM 1539 1540**系统能力**:SystemCapability.Ability.Form 1541 1542**参数:** 1543 1544| 参数名 | 类型 | 必填 | 说明 | 1545| ------ | ------ | ---- | ------- | 1546| formIds | Array<string> | 是 | 卡片标识列表。 | 1547| isVisible | boolean | 是 | 是否可见。 | 1548| callback | AsyncCallback<void> | 是 | 回调函数。当通知卡片是否可见成功,error为undefined,否则为错误对象。 | 1549 1550**错误码:** 1551 1552| 错误码ID | 错误信息 | 1553| -------- | -------- | 1554| 201 | Permissions denied. | 1555| 202 | The application is not a system application. | 1556| 401 | If the input parameter is not valid parameter. | 1557| 16500050 | An IPC connection error happened. | 1558| 16500060 | A service connection error happened, please try again later. | 1559| 16501000 | An internal functional error occurred. | 1560| 16501003 | The form can not be operated by the current application. | 1561 1562以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 1563 1564**示例:** 1565 1566```ts 1567import formHost from '@ohos.app.form.formHost'; 1568import Base from '@ohos.base'; 1569 1570let formIds: string[] = new Array('12400633174999288', '12400633174999289'); 1571try { 1572 formHost.notifyFormsVisible(formIds, true, (error: Base.BusinessError) => { 1573 if (error) { 1574 console.error(`error, code: ${error.code}, message: ${error.message}`); 1575 } 1576 }); 1577} catch(error) { 1578 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1579} 1580``` 1581 1582## notifyFormsVisible 1583 1584notifyFormsVisible(formIds: Array<string>, isVisible: boolean): Promise<void> 1585 1586通知卡片是否可见。使用Promise异步回调。 1587 1588**需要权限**:ohos.permission.REQUIRE_FORM 1589 1590**系统能力**:SystemCapability.Ability.Form 1591 1592**参数:** 1593 1594| 参数名 | 类型 | 必填 | 说明 | 1595| ------ | ------ | ---- | ------- | 1596| formIds | Array<string> | 是 | 卡片标识列表。 | 1597| isVisible | boolean | 是 | 是否可见。 | 1598 1599**返回值:** 1600 1601| 类型 | 说明 | 1602| -------- | -------- | 1603| Promise<void> | 无返回结果的Promise对象。 | 1604 1605**错误码:** 1606 1607| 错误码ID | 错误信息 | 1608| -------- | -------- | 1609| 201 | Permissions denied. | 1610| 202 | The application is not a system application. | 1611| 401 | If the input parameter is not valid parameter. | 1612| 16500050 | An IPC connection error happened. | 1613| 16500060 | A service connection error happened, please try again later. | 1614| 16501000 | An internal functional error occurred. | 1615| 16501003 | The form can not be operated by the current application. | 1616 1617以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 1618 1619**示例:** 1620 1621```ts 1622import formHost from '@ohos.app.form.formHost'; 1623import Base from '@ohos.base'; 1624 1625let formIds: string[] = new Array('12400633174999288', '12400633174999289'); 1626try { 1627 formHost.notifyFormsVisible(formIds, true).then(() => { 1628 console.log('formHost notifyFormsVisible success'); 1629 }).catch((error: Base.BusinessError) => { 1630 console.error(`error, code: ${error.code}, message: ${error.message}`); 1631 }); 1632} catch(error) { 1633 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1634} 1635``` 1636 1637## notifyFormsEnableUpdate 1638 1639notifyFormsEnableUpdate(formIds: Array<string>, isEnableUpdate: boolean, callback: AsyncCallback<void>): void 1640 1641通知卡片是否启用更新状态。使用callback异步回调。 1642 1643**需要权限**:ohos.permission.REQUIRE_FORM 1644 1645**系统能力**:SystemCapability.Ability.Form 1646 1647**参数:** 1648 1649| 参数名 | 类型 | 必填 | 说明 | 1650| ------ | ------ | ---- | ------- | 1651| formIds | Array<string> | 是 | 卡片标识列表。 | 1652| isEnableUpdate | boolean | 是 | 是否使能更新。 | 1653| callback | AsyncCallback<void> | 是 | 回调函数。当通知卡片是否启用更新状态成功,error为undefined,否则为错误对象。 | 1654 1655**错误码:** 1656 1657| 错误码ID | 错误信息 | 1658| -------- | -------- | 1659| 201 | Permissions denied. | 1660| 202 | The application is not a system application. | 1661| 401 | If the input parameter is not valid parameter. | 1662| 16500050 | An IPC connection error happened. | 1663| 16500060 | A service connection error happened, please try again later. | 1664| 16501000 | An internal functional error occurred. | 1665| 16501003 | The form can not be operated by the current application. | 1666 1667以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 1668 1669**示例:** 1670 1671```ts 1672import formHost from '@ohos.app.form.formHost'; 1673import Base from '@ohos.base'; 1674 1675let formIds: string[] = new Array('12400633174999288', '12400633174999289'); 1676try { 1677 formHost.notifyFormsEnableUpdate(formIds, true, (error: Base.BusinessError) => { 1678 if (error) { 1679 console.error(`error, code: ${error.code}, message: ${error.message}`); 1680 } 1681 }); 1682} catch(error) { 1683 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1684} 1685``` 1686 1687## notifyFormsEnableUpdate 1688 1689notifyFormsEnableUpdate(formIds: Array<string>, isEnableUpdate: boolean): Promise<void> 1690 1691通知卡片是否启用更新状态。使用Promise异步回调。 1692 1693**需要权限**:ohos.permission.REQUIRE_FORM 1694 1695**系统能力**:SystemCapability.Ability.Form 1696 1697**参数:** 1698 1699| 参数名 | 类型 | 必填 | 说明 | 1700| ------ | ------ | ---- | ------- | 1701| formIds | Array<string> | 是 | 卡片标识列表。 | 1702| isEnableUpdate | boolean | 是 | 是否使能更新。 | 1703 1704**返回值:** 1705 1706| 类型 | 说明 | 1707| -------- | -------- | 1708| Promise<void> | 无返回结果的Promise对象。 | 1709 1710**错误码:** 1711 1712| 错误码ID | 错误信息 | 1713| -------- | -------- | 1714| 201 | Permissions denied. | 1715| 202 | The application is not a system application. | 1716| 401 | If the input parameter is not valid parameter. | 1717| 16500050 | An IPC connection error happened. | 1718| 16500060 | A service connection error happened, please try again later. | 1719| 16501000 | An internal functional error occurred. | 1720| 16501003 | The form can not be operated by the current application. | 1721 1722以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 1723 1724**示例:** 1725 1726```ts 1727import formHost from '@ohos.app.form.formHost'; 1728import Base from '@ohos.base'; 1729 1730let formIds: string[] = new Array('12400633174999288', '12400633174999289'); 1731try { 1732 formHost.notifyFormsEnableUpdate(formIds, true).then(() => { 1733 console.log('formHost notifyFormsEnableUpdate success'); 1734 }).catch((error: Base.BusinessError) => { 1735 console.error(`error, code: ${error.code}, message: ${error.message}`); 1736 }); 1737} catch(error) { 1738 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1739} 1740``` 1741## shareForm 1742 1743shareForm(formId: string, deviceId: string, callback: AsyncCallback<void>): void 1744 1745指定formId和远程设备Id进行卡片分享。使用callback异步回调。 1746 1747**需要权限**:ohos.permission.REQUIRE_FORM 和 ohos.permission.DISTRIBUTED_DATASYNC 1748 1749**系统能力**:SystemCapability.Ability.Form 1750 1751**参数:** 1752 1753| 参数名 | 类型 | 必填 | 说明 | 1754| ------ | ------ | ---- | ------- | 1755| formId | string | 是 | 卡片标识。 | 1756| deviceId | string | 是 | 远程设备标识。 | 1757| callback | AsyncCallback<void> | 是 | 回调函数。当指定formId和远程设备Id进行卡片分享成功,error为undefined,否则为错误对象。 | 1758 1759**错误码:** 1760 1761| 错误码ID | 错误信息 | 1762| -------- | -------- | 1763| 201 | Permissions denied. | 1764| 202 | The application is not a system application. | 1765| 401 | If the input parameter is not valid parameter. | 1766| 16500050 | An IPC connection error happened. | 1767| 16501000 | An internal functional error occurred. | 1768| 16501001 | The ID of the form to be operated does not exist. | 1769| 16501003 | The form can not be operated by the current application. | 1770 1771以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 1772 1773**示例:** 1774 1775```ts 1776import formHost from '@ohos.app.form.formHost'; 1777import Base from '@ohos.base'; 1778 1779let formId: string = '12400633174999288'; 1780let deviceId: string = 'EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2'; 1781try { 1782 formHost.shareForm(formId, deviceId, (error: Base.BusinessError) => { 1783 if (error) { 1784 console.error(`error, code: ${error.code}, message: ${error.message}`); 1785 } 1786 }); 1787} catch(error) { 1788 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1789} 1790``` 1791 1792## shareForm 1793 1794shareForm(formId: string, deviceId: string): Promise<void> 1795 1796指定formId和远程设备Id进行卡片分享。使用Promise异步回调。 1797 1798**需要权限**:ohos.permission.REQUIRE_FORM 和 ohos.permission.DISTRIBUTED_DATASYNC 1799 1800**系统能力**:SystemCapability.Ability.Form 1801 1802**参数:** 1803 1804| 参数名 | 类型 | 必填 | 说明 | 1805| ------ | ------ | ---- | ------- | 1806| formId | string | 是 | 卡片标识。 | 1807| deviceId | string | 是 | 远程设备标识。 | 1808 1809**返回值:** 1810 1811| 类型 | 说明 | 1812| -------- | -------- | 1813| Promise<void> | 无返回结果的Promise对象。 | 1814 1815**错误码:** 1816 1817| 错误码ID | 错误信息 | 1818| -------- | -------- | 1819| 201 | Permissions denied. | 1820| 202 | The application is not a system application. | 1821| 401 | If the input parameter is not valid parameter. | 1822| 16500050 | An IPC connection error happened. | 1823| 16501000 | An internal functional error occurred. | 1824| 16501001 | The ID of the form to be operated does not exist. | 1825| 16501003 | The form can not be operated by the current application. | 1826 1827以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 1828 1829**示例:** 1830 1831```ts 1832import formHost from '@ohos.app.form.formHost'; 1833import Base from '@ohos.base'; 1834 1835let formId: string = '12400633174999288'; 1836let deviceId: string = 'EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2'; 1837try { 1838 formHost.shareForm(formId, deviceId).then(() => { 1839 console.log('formHost shareForm success'); 1840 }).catch((error: Base.BusinessError) => { 1841 console.error(`error, code: ${error.code}, message: ${error.message}`); 1842 }); 1843} catch(error) { 1844 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1845} 1846``` 1847 1848## notifyFormsPrivacyProtected 1849 1850notifyFormsPrivacyProtected(formIds: Array\<string>, isProtected: boolean, callback: AsyncCallback\<void>): void 1851 1852通知指定卡片隐私保护状态改变。使用callback异步回调。 1853 1854**需要权限**:ohos.permission.REQUIRE_FORM 1855 1856**系统能力**:SystemCapability.Ability.Form 1857 1858**参数:** 1859 1860| 参数名 | 类型 | 必填 | 说明 | 1861| ------ | ------ | ---- | ------- | 1862| formIds | Array\<string\> | 是 | 需要修改隐私保护的卡片标识列表。 | 1863| isProtected | boolean | 是 | 是否进行隐私保护。 | 1864| callback | AsyncCallback\<void> | 是 | 回调函数。当指定卡片设置隐私保护属性成功,error为undefined,否则为错误对象。 | 1865 1866**错误码:** 1867 1868| 错误码ID | 错误信息 | 1869| -------- | -------- | 1870| 201 | Permissions denied. | 1871| 202 | The application is not a system application. | 1872| 401 | If the input parameter is not valid parameter. | 1873| 16500050 | An IPC connection error happened. | 1874| 16500060 | A service connection error happened, please try again later. | 1875| 16501000 | An internal functional error occurred. | 1876 1877以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 1878 1879**示例:** 1880 1881```ts 1882import formHost from '@ohos.app.form.formHost'; 1883import Base from '@ohos.base'; 1884 1885let formIds: string[] = new Array('12400633174999288', '12400633174999289'); 1886try { 1887 formHost.notifyFormsPrivacyProtected(formIds, true, (error: Base.BusinessError) => { 1888 if (error) { 1889 console.error(`error, code: ${error.code}, message: ${error.message}`); 1890 } 1891 }); 1892} catch(error) { 1893 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1894} 1895``` 1896 1897## notifyFormsPrivacyProtected 1898 1899notifyFormsPrivacyProtected(formIds: Array\<string\>, isProtected: boolean): Promise\<void\>; 1900 1901通知指定卡片隐私保护状态改变。使用Promise异步回调。 1902 1903**需要权限**:ohos.permission.REQUIRE_FORM 1904 1905**系统能力**:SystemCapability.Ability.Form 1906 1907**参数:** 1908 1909| 参数名 | 类型 | 必填 | 说明 | 1910| ----------- | --------------- | ---- | -------------------------------- | 1911| formIds | Array\<string\> | 是 | 需要修改隐私保护的卡片标识列表。 | 1912| isProtected | boolean | 是 | 是否进行隐私保护。 | 1913 1914**返回值:** 1915 1916| 类型 | 说明 | 1917| ------------------- | ------------------------- | 1918| Promise<void> | 无返回结果的Promise对象。 | 1919 1920**错误码:** 1921 1922| 错误码ID | 错误信息 | 1923| -------- | -------- | 1924| 201 | Permissions denied. | 1925| 202 | The application is not a system application. | 1926| 401 | If the input parameter is not valid parameter. | 1927| 16500050 | An IPC connection error happened. | 1928| 16500060 | A service connection error happened, please try again later. | 1929| 16501000 | An internal functional error occurred. | 1930 1931以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 1932 1933```ts 1934import formHost from '@ohos.app.form.formHost'; 1935import Base from '@ohos.base'; 1936 1937let formIds: string[] = new Array('12400633174999288', '12400633174999289'); 1938try { 1939 formHost.notifyFormsPrivacyProtected(formIds, true).then(() => { 1940 console.log('formHost notifyFormsPrivacyProtected success'); 1941 }).catch((error: Base.BusinessError) => { 1942 console.error(`error, code: ${error.code}, message: ${error.message}`); 1943 }); 1944} catch(error) { 1945 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1946} 1947``` 1948 1949## acquireFormData<sup>10+</sup> 1950 1951acquireFormData(formId: string, callback: AsyncCallback<{[key: string]: Object}>): void; 1952 1953请求卡片提供方数据。使用callback异步回调。 1954 1955**模型约束:** 此接口仅可在Stage模型下使用。 1956 1957**需要权限**:ohos.permission.REQUIRE_FORM 1958 1959**系统能力**:SystemCapability.Ability.Form 1960 1961**参数:** 1962 1963| 参数名 | 类型 | 必填 | 说明 | 1964| ------ | ------ | ---- | ------- | 1965| formId | string | 是 | 卡片标识。 | 1966| callback | AsyncCallback<{[key: string]: Object} | 是 | 以callback方式返回接口运行结果及分享数据。 | 1967 1968**错误码:** 1969 1970| 错误码ID | 错误信息 | 1971| -------- | -------- | 1972| 201 | Permissions denied. | 1973| 401 | If the input parameter is not valid parameter. | 1974| 16500050 | An IPC connection error happened. | 1975| 16500060 | A service connection error happened, please try again later. | 1976| 16500100 | Failed to obtain the configuration information. | 1977| 16501000 | An internal functional error occurred. | 1978 1979以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 1980 1981**示例:** 1982 1983```ts 1984import formHost from '@ohos.app.form.formHost'; 1985import Base from '@ohos.base'; 1986 1987let formId: string = '12400633174999288'; 1988try { 1989 formHost.acquireFormData(formId, (error, data) => { 1990 if (error) { 1991 console.error(`error, code: ${error.code}, message: ${error.message}`); 1992 } else { 1993 console.log(`formHost acquireFormData, data: ${JSON.stringify(data)}`); 1994 } 1995 }); 1996} catch(error) { 1997 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 1998} 1999``` 2000 2001## acquireFormData<sup>10+</sup> 2002 2003acquireFormData(formId: string): Promise<{[key: string]: Object}>; 2004 2005请求卡片提供方数据。使用Promise异步回调。 2006 2007**模型约束:** 此接口仅可在Stage模型下使用。 2008 2009**需要权限**:ohos.permission.REQUIRE_FORM 2010 2011**系统能力**:SystemCapability.Ability.Form 2012 2013**参数:** 2014 2015| 参数名 | 类型 | 必填 | 说明 | 2016| ----------- | --------------- | ---- | -------------------------------- | 2017| formId | string | 是 | 卡片标识。 | 2018 2019**返回值:** 2020 2021| 类型 | 说明 | 2022| ------------------- | ------------------------- | 2023| Promise<{[key: string]: Object}>| 以Promise方式返回接口运行结果及分享数据。 | 2024 2025**错误码:** 2026 2027| 错误码ID | 错误信息 | 2028| -------- | -------- | 2029| 201 | Permissions denied. | 2030| 401 | If the input parameter is not valid parameter. | 2031| 16500050 | An IPC connection error happened. | 2032| 16500060 | A service connection error happened, please try again later. | 2033| 16500100 | Failed to obtain the configuration information. | 2034| 16501000 | An internal functional error occurred. | 2035 2036以上错误码的详细介绍请参见[卡片错误码](../errorcodes/errorcode-form.md)。 2037 2038```ts 2039import formHost from '@ohos.app.form.formHost'; 2040import Base from '@ohos.base'; 2041 2042let formId: string = '12400633174999288'; 2043try { 2044 formHost.acquireFormData(formId).then((data) => { 2045 console.log('formHost acquireFormData success' + data); 2046 }).catch((error: Base.BusinessError) => { 2047 console.error(`error, code: ${error.code}, message: ${error.message}`); 2048 }); 2049} catch(error) { 2050 console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`); 2051} 2052``` 2053