1e41f4b71Sopenharmony_ci# AutoFillExtensionContext (系统接口) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciAutoFillExtensionContext模块是AutoFillExtensionAbility的上下文环境,继承自[ExtensionContext](js-apis-inner-application-extensionContext.md)。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明:** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 11开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8e41f4b71Sopenharmony_ci> 本模块接口仅可在Stage模型下使用。 9e41f4b71Sopenharmony_ci> 本模块接口为系统接口。 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## 使用说明 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci在使用AutoFillExtensionContext的功能前,需要通过AutoFillExtensionAbility子类实例获取。 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci```ts 16e41f4b71Sopenharmony_ciimport { AutoFillExtensionAbility } from '@kit.AbilityKit'; 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ciclass MyAutoFillExtensionAbility extends AutoFillExtensionAbility { 19e41f4b71Sopenharmony_ci onCreate() { 20e41f4b71Sopenharmony_ci let AutoFillExtensionContext = this.context; 21e41f4b71Sopenharmony_ci } 22e41f4b71Sopenharmony_ci} 23e41f4b71Sopenharmony_ci``` 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci## AutoFillExtensionContext.reloadInModal<sup>12+</sup> 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_cireloadInModal(customData: CustomData): Promise\<void> 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci拉起模态页面。 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci**参数:** 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 36e41f4b71Sopenharmony_ci| ---------- | --------------------------------------------------------- | ---- | ---------------------------- | 37e41f4b71Sopenharmony_ci| customData | [CustomData](js-apis-inner-application-customData-sys.md) | 是 | 拉起模态页面时的自定义信息。 | 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci**返回值:** 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci| 类型 | 说明 | 42e41f4b71Sopenharmony_ci| ------------------- | ------------------------- | 43e41f4b71Sopenharmony_ci| Promise<void> | 无返回结果的Promise对象。 | 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci**错误码:** 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 50e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 51e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 52e41f4b71Sopenharmony_ci| 401 | If the input parameter is not valid parameter. | 53e41f4b71Sopenharmony_ci| 16000011 | The context does not exist. | 54e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci**示例:** 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci通过点击账号密码输入框触发自动填充服务时,在[AutoFillExtensionAbility](js-apis-app-ability-autoFillExtensionAbility-sys.md)的onFillRequest生命周期中拉起账号选择界面。 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci当点击账号选择界面选择任意账号时,调用reloadInModal接口再次触发自动填充服务时,在AutoFillExtensionAbility的onFillRequest生命周期中拉起模态页面。 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ci```ts 63e41f4b71Sopenharmony_ci// AutoFillAbility.ts 64e41f4b71Sopenharmony_ciimport { AutoFillExtensionAbility, autoFillManager, UIExtensionContentSession } from '@kit.AbilityKit'; 65e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit'; 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ciexport default class AutoFillAbility extends AutoFillExtensionAbility { 68e41f4b71Sopenharmony_ci // ... 69e41f4b71Sopenharmony_ci onFillRequest(session: UIExtensionContentSession, 70e41f4b71Sopenharmony_ci request: autoFillManager.FillRequest, 71e41f4b71Sopenharmony_ci callback: autoFillManager.FillRequestCallback) { 72e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', '%{public}s', 'autofill onFillRequest'); 73e41f4b71Sopenharmony_ci try { 74e41f4b71Sopenharmony_ci let storage_fill: LocalStorage = new LocalStorage( 75e41f4b71Sopenharmony_ci { 76e41f4b71Sopenharmony_ci 'session': session, 77e41f4b71Sopenharmony_ci 'message': "AutoFill Page", 78e41f4b71Sopenharmony_ci 'fillCallback': callback, 79e41f4b71Sopenharmony_ci 'viewData': request.viewData, 80e41f4b71Sopenharmony_ci 'autoFillExtensionContext': this.context, 81e41f4b71Sopenharmony_ci 'customData': request.customData 82e41f4b71Sopenharmony_ci }); 83e41f4b71Sopenharmony_ci if (request.customData == undefined) { 84e41f4b71Sopenharmony_ci // 加载自动填充处理界面 85e41f4b71Sopenharmony_ci session.loadContent('pages/AccountPage', storage_fill); 86e41f4b71Sopenharmony_ci } else { 87e41f4b71Sopenharmony_ci // 拉起模态页面 88e41f4b71Sopenharmony_ci session.loadContent('pages/ReloadInModal', storage_fill); 89e41f4b71Sopenharmony_ci } 90e41f4b71Sopenharmony_ci } catch (err) { 91e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', '%{public}s', 'autofill failed to load content'); 92e41f4b71Sopenharmony_ci } 93e41f4b71Sopenharmony_ci } 94e41f4b71Sopenharmony_ci} 95e41f4b71Sopenharmony_ci``` 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci当点击账号选择界面选择任意账号时,调用reloadInModal接口。 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci```ts 100e41f4b71Sopenharmony_ci// AccountPage.ets 101e41f4b71Sopenharmony_ciimport { autoFillManager, common } from '@kit.AbilityKit'; 102e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_cilet storage: LocalStorage = LocalStorage.getShared(); 105e41f4b71Sopenharmony_cilet viewData: autoFillManager.ViewData | undefined = storage.get<autoFillManager.ViewData>('viewData'); 106e41f4b71Sopenharmony_cilet context: common.AutoFillExtensionContext | undefined = storage.get<common.AutoFillExtensionContext>('autoFillExtensionContext'); 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ci@Entry 109e41f4b71Sopenharmony_ci@Component 110e41f4b71Sopenharmony_cistruct AccountPage { 111e41f4b71Sopenharmony_ci build() { 112e41f4b71Sopenharmony_ci Row() { 113e41f4b71Sopenharmony_ci Column() { 114e41f4b71Sopenharmony_ci List({ space: 10, initialIndex: 0 }) { 115e41f4b71Sopenharmony_ci ListItem() { 116e41f4b71Sopenharmony_ci Text('HelloWorld789456') 117e41f4b71Sopenharmony_ci .width('100%') 118e41f4b71Sopenharmony_ci .height(40) 119e41f4b71Sopenharmony_ci .fontSize(16) 120e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 121e41f4b71Sopenharmony_ci .borderRadius(5) 122e41f4b71Sopenharmony_ci } 123e41f4b71Sopenharmony_ci .onClick(() => { 124e41f4b71Sopenharmony_ci if (viewData != undefined) { 125e41f4b71Sopenharmony_ci if (context != undefined) { 126e41f4b71Sopenharmony_ci context.reloadInModal({ data: { viewData: 20, text: 'HelloWorld789456' } }).then(() => { 127e41f4b71Sopenharmony_ci console.info('reloadInModal successfully.') 128e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 129e41f4b71Sopenharmony_ci console.error('reloadInModal failed.') 130e41f4b71Sopenharmony_ci }) 131e41f4b71Sopenharmony_ci } 132e41f4b71Sopenharmony_ci } 133e41f4b71Sopenharmony_ci }) 134e41f4b71Sopenharmony_ci } 135e41f4b71Sopenharmony_ci // ... 136e41f4b71Sopenharmony_ci } 137e41f4b71Sopenharmony_ci .width('100%') 138e41f4b71Sopenharmony_ci .shadow(ShadowStyle.OUTER_FLOATING_SM) 139e41f4b71Sopenharmony_ci } 140e41f4b71Sopenharmony_ci .height('100%') 141e41f4b71Sopenharmony_ci .shadow(ShadowStyle.OUTER_FLOATING_SM) 142e41f4b71Sopenharmony_ci } 143e41f4b71Sopenharmony_ci} 144e41f4b71Sopenharmony_ci``` 145