1e41f4b71Sopenharmony_ci# @ohos.app.form.formObserver (formObserver) (System API) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **formObserver** module provides APIs related to widget listeners. You can use the APIs to subscribe to and unsubscribe from widget addition, removal, and visibility change events, and obtain information about running widgets. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci> The APIs provided by this module are system APIs. 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## Modules to Import 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci```ts 13e41f4b71Sopenharmony_ciimport { formObserver } from '@kit.FormKit'; 14e41f4b71Sopenharmony_ci``` 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci## on('formAdd') 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci on(type: 'formAdd', observerCallback: Callback<formInfo.RunningFormInfo>): void 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ciSubscribes to widget addition events. This API uses an asynchronous callback to return the information about the new widget. 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci**Parameters** 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 29e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 30e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value **'formAdd'** indicates a widget addition event.| 31e41f4b71Sopenharmony_ci| observerCallback | Callback<formInfo.[RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)> | Yes| Callback used to return the information about the new widget.| 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci**Error codes** 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci| ID| Error Message | 36e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 37e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 38e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ciFor details about the error codes, see [Form Error Codes](errorcode-form.md). 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci**Example** 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci```ts 45e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_cilet callback = (data: formInfo.RunningFormInfo) => { 48e41f4b71Sopenharmony_ci console.log(`a new form added, data: ${JSON.stringify(data)}`); 49e41f4b71Sopenharmony_ci} 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ciformObserver.on('formAdd', callback); 52e41f4b71Sopenharmony_ci``` 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci## on('formAdd') 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci on(type: 'formAdd', hostBundleName: string, observerCallback: Callback<formInfo.RunningFormInfo>): void 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ciSubscribes to widget addition events for a given bundle that functions as the widget host. This API uses an asynchronous callback to return the information about the new widget. 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci**Parameters** 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 67e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 68e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value **'formAdd'** indicates a widget addition event.| 69e41f4b71Sopenharmony_ci| hostBundleName | string | Yes| Name of the bundle that functions as the widget host. If no value is passed in, widget addition events of all widget hosts are subscribed to.| 70e41f4b71Sopenharmony_ci| observerCallback | Callback<formInfo.[RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)> | Yes| Callback used to return the information about the new widget.| 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci**Error codes** 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci| ID| Error Message | 75e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 76e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 77e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci**Example** 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci```ts 82e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_cilet bundleName: string = 'ohos.samples.FormApplication'; 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_cilet callback = (data: formInfo.RunningFormInfo) => { 87e41f4b71Sopenharmony_ci console.log(`a new form added, data: ${JSON.stringify(data)}`); 88e41f4b71Sopenharmony_ci} 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ciformObserver.on('formAdd', bundleName, callback); 91e41f4b71Sopenharmony_ci``` 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci## off('formAdd') 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci off(type: "formAdd", hostBundleName?: string, observerCallback?: Callback<formInfo.RunningFormInfo>): void 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ciUnsubscribes from widget addition events. This API uses an asynchronous callback to return the information about the new widget. 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci**Parameters** 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 106e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 107e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value **'formAdd'** indicates a widget addition event.| 108e41f4b71Sopenharmony_ci| hostBundleName | string | No| Name of the bundle that functions as the widget host.<br> To cancel the subscription for a given bundle name, this parameter must be set to the same value as **bundleName** in **on('formAdd')**.<br> If no value is passed in, the subscriptions for all the widget hosts are canceled.| 109e41f4b71Sopenharmony_ci| observerCallback | Callback<formInfo.[RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)> | No| Callback used to return the information about the new widget. If no value is passed in, all the subscriptions to the specified event are canceled.<br> To cancel the subscription with a given callback, this parameter must be set to the same value as **callback** in **on('formAdd')**.| 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci**Error codes** 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci| ID| Error Message | 114e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 115e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 116e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci**Example** 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci```ts 121e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_cilet bundleName: string = 'ohos.samples.FormApplication'; 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_cilet callback = (data: formInfo.RunningFormInfo) => { 126e41f4b71Sopenharmony_ci console.log(`a new form added, data: ${JSON.stringify(data)}`); 127e41f4b71Sopenharmony_ci} 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ciformObserver.off('formAdd', bundleName, callback); 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci``` 132e41f4b71Sopenharmony_ci> **NOTE** 133e41f4b71Sopenharmony_ci> 134e41f4b71Sopenharmony_ci> **on('formAdd', callback)** and **off('formAdd', callback)** must be used in pairs. 135e41f4b71Sopenharmony_ci> **on('formAdd', bundleName, callback)** and **off('formAdd', bundleName, callback)** must be used in pairs. 136e41f4b71Sopenharmony_ci> To cancel the subscription with a given callback or for a given bundle name, the **callback** or **bundleName** parameter in **off()** must be set to the same value as that in **on()**. 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_ci## on('formRemove') 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ci on(type: 'formRemove', observerCallback: Callback<formInfo.RunningFormInfo>): void 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ciSubscribes to widget removal events. This API uses an asynchronous callback to return the information about the widget removed. 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ci**Parameters** 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 151e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 152e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value **'formRemove'** indicates a widget removal event.| 153e41f4b71Sopenharmony_ci| observerCallback | Callback<formInfo.[RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)> | Yes| Callback used to return the information about the widget removed.| 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ci**Error codes** 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci| ID| Error Message | 158e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 159e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 160e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 161e41f4b71Sopenharmony_ci 162e41f4b71Sopenharmony_ci**Example** 163e41f4b71Sopenharmony_ci 164e41f4b71Sopenharmony_ci```ts 165e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_cilet callback = (data: formInfo.RunningFormInfo) => { 168e41f4b71Sopenharmony_ci console.log(`form deleted, data: ${JSON.stringify(data)}`); 169e41f4b71Sopenharmony_ci} 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ciformObserver.on('formRemove', callback); 172e41f4b71Sopenharmony_ci``` 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci## on('formRemove') 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci on(type: 'formRemove', hostBundleName: string, observerCallback: Callback<formInfo.RunningFormInfo>): void 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ciSubscribes to widget removal events for a given bundle that functions as the widget host. This API uses an asynchronous callback to return the information about the widget removed. 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci**Parameters** 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 187e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 188e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value **'formRemove'** indicates a widget removal event.| 189e41f4b71Sopenharmony_ci| hostBundleName | string | Yes| Name of the bundle that functions as the widget host. If no value is passed in, widget removal events of all widget hosts are subscribed to.| 190e41f4b71Sopenharmony_ci| observerCallback | Callback<formInfo.[RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)> | Yes| Callback used to return the information about the widget removed.| 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ci**Error codes** 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ci| ID| Error Message | 195e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 196e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 197e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 198e41f4b71Sopenharmony_ci 199e41f4b71Sopenharmony_ci**Example** 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci```ts 202e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 203e41f4b71Sopenharmony_ci 204e41f4b71Sopenharmony_cilet bundleName: string = 'ohos.samples.FormApplication'; 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_cilet callback = (data: formInfo.RunningFormInfo) => { 207e41f4b71Sopenharmony_ci console.log(`form deleted, data: ${JSON.stringify(data)}`); 208e41f4b71Sopenharmony_ci} 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ciformObserver.on('formRemove', bundleName, callback); 211e41f4b71Sopenharmony_ci``` 212e41f4b71Sopenharmony_ci 213e41f4b71Sopenharmony_ci## off('formRemove') 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_cioff(type: "formRemove", hostBundleName?: string, observerCallback?: Callback<formInfo.RunningFormInfo>): void 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_ciUnsubscribes from widget removal events. This API uses an asynchronous callback to return the information about the widget removed. 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 222e41f4b71Sopenharmony_ci 223e41f4b71Sopenharmony_ci**Parameters** 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 226e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 227e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value **'formRemove'** indicates a widget removal event.| 228e41f4b71Sopenharmony_ci| hostBundleName | string | No| Name of the bundle that functions as the widget host.<br>To cancel the subscription for a given bundle name, this parameter must be set to the same value as **bundleName** in **on('formRemove')**.<br> If no value is passed in, the subscriptions for all the widget hosts are canceled.| 229e41f4b71Sopenharmony_ci| observerCallback | Callback<formInfo.[RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)> | No| Callback used to return the information about the widget removed. If no value is passed in, all the subscriptions to the specified event are canceled.<br> To cancel the subscription with a given callback, this parameter must be set to the same value as **callback** in **on('formRemove')**.| 230e41f4b71Sopenharmony_ci 231e41f4b71Sopenharmony_ci**Error codes** 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ci| ID| Error Message | 234e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 235e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 236e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 237e41f4b71Sopenharmony_ci 238e41f4b71Sopenharmony_ci**Example** 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_ci```ts 241e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 242e41f4b71Sopenharmony_ci 243e41f4b71Sopenharmony_cilet bundleName: string = 'ohos.samples.FormApplication'; 244e41f4b71Sopenharmony_ci 245e41f4b71Sopenharmony_cilet callback = (data: formInfo.RunningFormInfo) => { 246e41f4b71Sopenharmony_ci console.log(`a new form added, data: ${JSON.stringify(data)}`); 247e41f4b71Sopenharmony_ci} 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_ciformObserver.off('formRemove', bundleName, callback); 250e41f4b71Sopenharmony_ci``` 251e41f4b71Sopenharmony_ci> **NOTE** 252e41f4b71Sopenharmony_ci> 253e41f4b71Sopenharmony_ci> **on('formRemove', callback)** and **off('formRemove', callback)** must be used in pairs. 254e41f4b71Sopenharmony_ci> **on('formRemove', bundleName, callback)** and **off('formRemove', bundleName, callback)** must be used in pairs. 255e41f4b71Sopenharmony_ci> To cancel the subscription with a given callback or for a given bundle name, the **callback** or **bundleName** parameter in **off()** must be set to the same value as that in **on()**. 256e41f4b71Sopenharmony_ci 257e41f4b71Sopenharmony_ci## on('notifyVisible') 258e41f4b71Sopenharmony_ci 259e41f4b71Sopenharmony_ci on(type: 'notifyVisible', observerCallback: Callback<Array<formInfo.RunningFormInfo>>): void 260e41f4b71Sopenharmony_ci 261e41f4b71Sopenharmony_ciSubscribes to events indicating that a widget becomes visible. This API uses an asynchronous callback to return the result. 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_ciThe event is triggered when [notifyVisibleForms](js-apis-app-form-formHost-sys.md#notifyvisibleforms) is called to notify that the widget becomes visible. 264e41f4b71Sopenharmony_ci 265e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 266e41f4b71Sopenharmony_ci 267e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 268e41f4b71Sopenharmony_ci 269e41f4b71Sopenharmony_ci**Parameters** 270e41f4b71Sopenharmony_ci 271e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 272e41f4b71Sopenharmony_ci| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 273e41f4b71Sopenharmony_ci| type | string | Yes | Event type. This value **'notifyVisible'** indicates a widget visibility event. | 274e41f4b71Sopenharmony_ci| observerCallback | Callback <Array<[formInfo.RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)>> | Yes | Callback used to return an array of widgets that have subscribed to the event. | 275e41f4b71Sopenharmony_ci 276e41f4b71Sopenharmony_ci**Error codes** 277e41f4b71Sopenharmony_ci 278e41f4b71Sopenharmony_ci| ID| Error Message | 279e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 280e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 281e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_ci**Example** 284e41f4b71Sopenharmony_ci 285e41f4b71Sopenharmony_ci```ts 286e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 287e41f4b71Sopenharmony_ci 288e41f4b71Sopenharmony_cilet callback = (data: formInfo.RunningFormInfo[]) => { 289e41f4b71Sopenharmony_ci console.log(`form change visibility, data: ${JSON.stringify(data)}`); 290e41f4b71Sopenharmony_ci} 291e41f4b71Sopenharmony_ci 292e41f4b71Sopenharmony_ciformObserver.on('notifyVisible', callback); 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ci``` 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci## on('notifyVisible') 297e41f4b71Sopenharmony_ci 298e41f4b71Sopenharmony_ci on(type: 'notifyVisible', hostBundleName: string, observerCallback: Callback<Array<formInfo.RunningFormInfo>>): void 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ciSubscribes to events indicating that a widget becomes visible for a given bundle that functions as the widget host. This API uses an asynchronous callback to return the result. 301e41f4b71Sopenharmony_ci 302e41f4b71Sopenharmony_ciThe event is triggered when [notifyVisibleForms](js-apis-app-form-formHost-sys.md#notifyvisibleforms) is called to notify that the widget becomes visible. 303e41f4b71Sopenharmony_ci 304e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 305e41f4b71Sopenharmony_ci 306e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_ci**Parameters** 309e41f4b71Sopenharmony_ci 310e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 311e41f4b71Sopenharmony_ci| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 312e41f4b71Sopenharmony_ci| type | string | Yes | Event type. This value **'notifyVisible'** indicates a widget visibility event. | 313e41f4b71Sopenharmony_ci| hostBundleName | string | Yes | Name of the bundle that functions as the widget host, on which the widget visibility state changes are subscribed.| 314e41f4b71Sopenharmony_ci| observerCallback | Callback <Array<[formInfo.RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)>> | Yes | Callback used to return an array of widgets that have subscribed to the event. | 315e41f4b71Sopenharmony_ci 316e41f4b71Sopenharmony_ci**Error codes** 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_ci| ID| Error Message | 319e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 320e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 321e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 322e41f4b71Sopenharmony_ci 323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_ci**Example** 325e41f4b71Sopenharmony_ci 326e41f4b71Sopenharmony_ci```ts 327e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 328e41f4b71Sopenharmony_ci 329e41f4b71Sopenharmony_cilet bundleName: string = 'ohos.samples.FormApplication'; 330e41f4b71Sopenharmony_ci 331e41f4b71Sopenharmony_cilet callback = (data: formInfo.RunningFormInfo[]) => { 332e41f4b71Sopenharmony_ci console.log(`form change visibility, data: ${JSON.stringify(data)}`); 333e41f4b71Sopenharmony_ci} 334e41f4b71Sopenharmony_ci 335e41f4b71Sopenharmony_ciformObserver.on('notifyVisible', bundleName, callback); 336e41f4b71Sopenharmony_ci``` 337e41f4b71Sopenharmony_ci 338e41f4b71Sopenharmony_ci## off('notifyVisible') 339e41f4b71Sopenharmony_ci 340e41f4b71Sopenharmony_ci off(type: "notifyVisible", hostBundleName?: string, observerCallback?: Callback<Array<formInfo.RunningFormInfo>>): void 341e41f4b71Sopenharmony_ci 342e41f4b71Sopenharmony_ciUnsubscribes from events indicating that a widget becomes visible. This API uses an asynchronous callback to return the result. 343e41f4b71Sopenharmony_ci 344e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 345e41f4b71Sopenharmony_ci 346e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 347e41f4b71Sopenharmony_ci 348e41f4b71Sopenharmony_ci**Parameters** 349e41f4b71Sopenharmony_ci 350e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 351e41f4b71Sopenharmony_ci| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 352e41f4b71Sopenharmony_ci| type | string | Yes | Event type. This value **'notifyVisible'** indicates a widget visibility event.| 353e41f4b71Sopenharmony_ci| hostBundleName | string | No | Name of the bundle that functions as the widget host, on which the widget visibility state changes are subscribed.<br> To cancel the subscription for a given bundle name, this parameter must be set to the same value as **bundleName** in **on('notifyVisible')**.| 354e41f4b71Sopenharmony_ci| observerCallback | Callback <Array<[formInfo.RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)>> | No | Callback used to return an array of widgets that have unsubscribed from the event. If no value is passed in, all the subscriptions to the specified event are canceled.<br> To cancel the subscription with a given callback, this parameter must be set to the same value as **callback** in **on('notifyVisible')**.| 355e41f4b71Sopenharmony_ci 356e41f4b71Sopenharmony_ci**Error codes** 357e41f4b71Sopenharmony_ci 358e41f4b71Sopenharmony_ci| ID| Error Message | 359e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 360e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 361e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 362e41f4b71Sopenharmony_ci 363e41f4b71Sopenharmony_ci**Example** 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_ci```ts 366e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 367e41f4b71Sopenharmony_ci 368e41f4b71Sopenharmony_cilet bundleName: string = 'ohos.samples.FormApplication'; 369e41f4b71Sopenharmony_ci 370e41f4b71Sopenharmony_cilet callback = (data: formInfo.RunningFormInfo[]) => { 371e41f4b71Sopenharmony_ci console.log(`form change visibility, data: ${JSON.stringify(data)}`); 372e41f4b71Sopenharmony_ci} 373e41f4b71Sopenharmony_ci 374e41f4b71Sopenharmony_ciformObserver.off('notifyVisible', bundleName, callback); 375e41f4b71Sopenharmony_ci``` 376e41f4b71Sopenharmony_ci 377e41f4b71Sopenharmony_ci> **NOTE** 378e41f4b71Sopenharmony_ci> 379e41f4b71Sopenharmony_ci> **on('notifyVisible', callback)** and **off('notifyVisible', callback)** must be used in pairs. 380e41f4b71Sopenharmony_ci> **on('notifyVisible', bundleName, callback)** and **off('notifyVisible', bundleName, callback)** must be used in pairs. 381e41f4b71Sopenharmony_ci> To cancel the subscription with a given callback or for a given bundle name, the **callback** or **bundleName** parameter in **off()** must be set to the same value as that in **on()**. 382e41f4b71Sopenharmony_ci 383e41f4b71Sopenharmony_ci## on('notifyInvisible') 384e41f4b71Sopenharmony_ci 385e41f4b71Sopenharmony_ci on(type: 'notifyInvisible', observerCallback: Callback<Array<formInfo.RunningFormInfo>>): void 386e41f4b71Sopenharmony_ci 387e41f4b71Sopenharmony_ciSubscribes to events indicating that a widget becomes invisible. This API uses an asynchronous callback to return the result. 388e41f4b71Sopenharmony_ci 389e41f4b71Sopenharmony_ciThe event is triggered when [notifyInvisibleForms](js-apis-app-form-formHost-sys.md#notifyinvisibleforms) is called to notify that the widget becomes invisible. 390e41f4b71Sopenharmony_ci 391e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 392e41f4b71Sopenharmony_ci 393e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 394e41f4b71Sopenharmony_ci 395e41f4b71Sopenharmony_ci**Parameters** 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 398e41f4b71Sopenharmony_ci| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 399e41f4b71Sopenharmony_ci| type | string | Yes | Event type. This value **'notifyInvisible'** indicates a widget invisibility event. | 400e41f4b71Sopenharmony_ci| observerCallback | Callback <Array<[formInfo.RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)>> | Yes | Callback used to return an array of widgets that have subscribed to the event. | 401e41f4b71Sopenharmony_ci 402e41f4b71Sopenharmony_ci**Error codes** 403e41f4b71Sopenharmony_ci 404e41f4b71Sopenharmony_ci| ID| Error Message | 405e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 406e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 407e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 408e41f4b71Sopenharmony_ci 409e41f4b71Sopenharmony_ci**Example** 410e41f4b71Sopenharmony_ci 411e41f4b71Sopenharmony_ci```ts 412e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 413e41f4b71Sopenharmony_ci 414e41f4b71Sopenharmony_cilet callback = (data: formInfo.RunningFormInfo[]) => { 415e41f4b71Sopenharmony_ci console.log(`form change invisibility, data: ${JSON.stringify(data)}`); 416e41f4b71Sopenharmony_ci} 417e41f4b71Sopenharmony_ci 418e41f4b71Sopenharmony_ciformObserver.on('notifyInvisible', callback); 419e41f4b71Sopenharmony_ci``` 420e41f4b71Sopenharmony_ci 421e41f4b71Sopenharmony_ci 422e41f4b71Sopenharmony_ci## on('notifyInvisible') 423e41f4b71Sopenharmony_ci 424e41f4b71Sopenharmony_ci on(type: 'notifyInvisible', hostBundleName: string, observerCallback: Callback<Array<formInfo.RunningFormInfo>>): void 425e41f4b71Sopenharmony_ci 426e41f4b71Sopenharmony_ciSubscribes to events indicating that a widget becomes invisible for a given bundle, which functions as the widget host. This API uses an asynchronous callback to return the result. 427e41f4b71Sopenharmony_ci 428e41f4b71Sopenharmony_ciThe event is triggered when [notifyInvisibleForms](js-apis-app-form-formHost-sys.md#notifyinvisibleforms) is called to notify that the widget becomes invisible. 429e41f4b71Sopenharmony_ci 430e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 431e41f4b71Sopenharmony_ci 432e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 433e41f4b71Sopenharmony_ci 434e41f4b71Sopenharmony_ci**Parameters** 435e41f4b71Sopenharmony_ci 436e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 437e41f4b71Sopenharmony_ci| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 438e41f4b71Sopenharmony_ci| type | string | Yes | Event type. This value **'notifyInvisible'** indicates a widget invisibility event. | 439e41f4b71Sopenharmony_ci| hostBundleName | string | Yes | Name of the bundle that functions as the widget host, on which the widget visibility state changes are subscribed.| 440e41f4b71Sopenharmony_ci| observerCallback | Callback <Array<[formInfo.RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)>> | Yes | Callback used to return an array of widgets that have subscribed to the event. | 441e41f4b71Sopenharmony_ci 442e41f4b71Sopenharmony_ci**Error codes** 443e41f4b71Sopenharmony_ci 444e41f4b71Sopenharmony_ci| ID| Error Message | 445e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 446e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 447e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 448e41f4b71Sopenharmony_ci 449e41f4b71Sopenharmony_ci**Example** 450e41f4b71Sopenharmony_ci 451e41f4b71Sopenharmony_ci```ts 452e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 453e41f4b71Sopenharmony_ci 454e41f4b71Sopenharmony_cilet bundleName: string = 'ohos.samples.FormApplication'; 455e41f4b71Sopenharmony_ci 456e41f4b71Sopenharmony_cilet callback = (data: formInfo.RunningFormInfo[]) => { 457e41f4b71Sopenharmony_ci console.log(`form change invisibility, data: ${JSON.stringify(data)}`); 458e41f4b71Sopenharmony_ci} 459e41f4b71Sopenharmony_ci 460e41f4b71Sopenharmony_ciformObserver.on('notifyInvisible', bundleName, callback); 461e41f4b71Sopenharmony_ci``` 462e41f4b71Sopenharmony_ci 463e41f4b71Sopenharmony_ci## off('notifyInvisible') 464e41f4b71Sopenharmony_ci 465e41f4b71Sopenharmony_ci off(type: "notifyInvisible", hostBundleName?: string, observerCallback?: Callback<Array<formInfo.RunningFormInfo>>): void 466e41f4b71Sopenharmony_ci 467e41f4b71Sopenharmony_ciUnsubscribes from events indicating that a widget becomes invisible. This API uses an asynchronous callback to return the result. 468e41f4b71Sopenharmony_ci 469e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 470e41f4b71Sopenharmony_ci 471e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 472e41f4b71Sopenharmony_ci 473e41f4b71Sopenharmony_ci**Parameters** 474e41f4b71Sopenharmony_ci 475e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 476e41f4b71Sopenharmony_ci| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 477e41f4b71Sopenharmony_ci| type | string | Yes | Event type. This value **'notifyInvisible'** indicates a widget invisibility event. | 478e41f4b71Sopenharmony_ci| hostBundleName | string | No | Name of the bundle that functions as the widget host, on which the widget visibility state changes are subscribed.<br> To cancel the subscription for a given bundle name, this parameter must be set to the same value as **bundleName** in **on('notifyVisible')**.<br> | 479e41f4b71Sopenharmony_ci| observerCallback | Callback <Array<[formInfo.RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)>> | No | Callback used to return an array of widgets that have unsubscribed from the event. If no value is passed in, all the subscriptions to the specified event are canceled.<br> To cancel the subscription with a given callback, this parameter must be set to the same value as **callback** in **on('notifyInvisible')**.| 480e41f4b71Sopenharmony_ci 481e41f4b71Sopenharmony_ci**Error codes** 482e41f4b71Sopenharmony_ci 483e41f4b71Sopenharmony_ci| ID| Error Message | 484e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 485e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 486e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 487e41f4b71Sopenharmony_ci 488e41f4b71Sopenharmony_ci**Example** 489e41f4b71Sopenharmony_ci 490e41f4b71Sopenharmony_ci```ts 491e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 492e41f4b71Sopenharmony_ci 493e41f4b71Sopenharmony_cilet bundleName: string = 'ohos.samples.FormApplication'; 494e41f4b71Sopenharmony_ci 495e41f4b71Sopenharmony_cilet callback = (data: formInfo.RunningFormInfo[]) => { 496e41f4b71Sopenharmony_ci console.log(`form change invisibility, data: ${JSON.stringify(data)}`); 497e41f4b71Sopenharmony_ci} 498e41f4b71Sopenharmony_ci 499e41f4b71Sopenharmony_ciformObserver.off('notifyInvisible', bundleName, callback); 500e41f4b71Sopenharmony_ci``` 501e41f4b71Sopenharmony_ci 502e41f4b71Sopenharmony_ci> **NOTE** 503e41f4b71Sopenharmony_ci> 504e41f4b71Sopenharmony_ci> **on('notifyInvisible', callback)** and **off('notifyInvisible', callback)** must be used in pairs. 505e41f4b71Sopenharmony_ci> **on('notifyInvisible', bundleName, callback)** and **off('notifyInvisible', bundleName, callback)** must be used in pairs. 506e41f4b71Sopenharmony_ci> To cancel the subscription with a given callback or for a given bundle name, the **callback** or **bundleName** parameter in **off()** must be set to the same value as that in **on()**. 507e41f4b71Sopenharmony_ci 508e41f4b71Sopenharmony_ci 509e41f4b71Sopenharmony_ci## getRunningFormInfos 510e41f4b71Sopenharmony_ci 511e41f4b71Sopenharmony_cigetRunningFormInfos(callback: AsyncCallback<Array<formInfo.RunningFormInfo>>, hostBundleName?: string): void 512e41f4b71Sopenharmony_ci 513e41f4b71Sopenharmony_ciObtains the information about all non-temporary widgets running on the device. This API uses an asynchronous callback to return the result. 514e41f4b71Sopenharmony_ci 515e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 516e41f4b71Sopenharmony_ci 517e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 518e41f4b71Sopenharmony_ci 519e41f4b71Sopenharmony_ci**Parameters** 520e41f4b71Sopenharmony_ci 521e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 522e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 523e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<formInfo.[RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)>> | Yes| Callback used to return the information about all non-temporary widgets. If the widget information is obtained, **error** is **undefined**, and **data** is the information obtained.| 524e41f4b71Sopenharmony_ci| hostBundleName | string | No| Name of the bundle that functions as the widget host. If a value is passed in, only the information about the non-temporary widgets that are running under the widget host is returned.<br> If no value is passed in, information about all running non-temporary widgets on the device is returned.| 525e41f4b71Sopenharmony_ci 526e41f4b71Sopenharmony_ci**Error codes** 527e41f4b71Sopenharmony_ciFor details about the error codes, see [Form Error Codes](errorcode-form.md). 528e41f4b71Sopenharmony_ci 529e41f4b71Sopenharmony_ci| ID| Error Message| 530e41f4b71Sopenharmony_ci| -------- | -------- | 531e41f4b71Sopenharmony_ci| 201 | Permissions denied. | 532e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 533e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 534e41f4b71Sopenharmony_ci| 16500050 | IPC connection error. | 535e41f4b71Sopenharmony_ci| 16500060 | Service connection error. | 536e41f4b71Sopenharmony_ci 537e41f4b71Sopenharmony_ci**Example** 538e41f4b71Sopenharmony_ci 539e41f4b71Sopenharmony_ci```ts 540e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 541e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 542e41f4b71Sopenharmony_ci 543e41f4b71Sopenharmony_citry { 544e41f4b71Sopenharmony_ci formObserver.getRunningFormInfos((error: BusinessError, data: formInfo.RunningFormInfo[]) => { 545e41f4b71Sopenharmony_ci if (error) { 546e41f4b71Sopenharmony_ci console.error(`error, code: ${error.code}, message: ${error.message}`); 547e41f4b71Sopenharmony_ci } else { 548e41f4b71Sopenharmony_ci console.log(`formObserver getRunningFormInfos, data: ${JSON.stringify(data)}`); 549e41f4b71Sopenharmony_ci } 550e41f4b71Sopenharmony_ci }, 'com.example.ohos.formjsdemo'); 551e41f4b71Sopenharmony_ci} catch(error) { 552e41f4b71Sopenharmony_ci console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}`); 553e41f4b71Sopenharmony_ci} 554e41f4b71Sopenharmony_ci``` 555e41f4b71Sopenharmony_ci 556e41f4b71Sopenharmony_ci## getRunningFormInfos<sup>11+</sup> 557e41f4b71Sopenharmony_ci 558e41f4b71Sopenharmony_cigetRunningFormInfos(callback: AsyncCallback<Array<formInfo.RunningFormInfo>>, isUnusedIncluded: boolean, hostBundleName?: string): void 559e41f4b71Sopenharmony_ci 560e41f4b71Sopenharmony_ciObtains the information about all non-temporary widgets running on the device. This API uses an asynchronous callback to return the result. 561e41f4b71Sopenharmony_ci 562e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 563e41f4b71Sopenharmony_ci 564e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 565e41f4b71Sopenharmony_ci 566e41f4b71Sopenharmony_ci**Parameters** 567e41f4b71Sopenharmony_ci 568e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 569e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 570e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<formInfo.[RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)>> | Yes| Callback used to return the information about all non-temporary widgets. If the widget information is obtained, **error** is **undefined**, and **data** is the information obtained.| 571e41f4b71Sopenharmony_ci| isUnusedIncluded | boolean | Yes| Whether an unused widget is included.| 572e41f4b71Sopenharmony_ci| hostBundleName | string | No| Name of the bundle that functions as the widget host. If a value is passed in, only the information about the non-temporary widgets that are running under the widget host is returned.<br> If no value is passed in, information about all running non-temporary widgets on the device is returned.| 573e41f4b71Sopenharmony_ci 574e41f4b71Sopenharmony_ci**Error codes** 575e41f4b71Sopenharmony_ci 576e41f4b71Sopenharmony_ciFor details about the error codes, see [Form Error Codes](errorcode-form.md). 577e41f4b71Sopenharmony_ci 578e41f4b71Sopenharmony_ci| ID| Error Message| 579e41f4b71Sopenharmony_ci| -------- | -------- | 580e41f4b71Sopenharmony_ci| 201 | Permissions denied. | 581e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 582e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 583e41f4b71Sopenharmony_ci| 16500050 | IPC connection error. | 584e41f4b71Sopenharmony_ci| 16500060 | Service connection error. | 585e41f4b71Sopenharmony_ci 586e41f4b71Sopenharmony_ci**Example** 587e41f4b71Sopenharmony_ci 588e41f4b71Sopenharmony_ci```ts 589e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 590e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 591e41f4b71Sopenharmony_ci 592e41f4b71Sopenharmony_citry { 593e41f4b71Sopenharmony_ci formObserver.getRunningFormInfos((error: BusinessError, data: formInfo.RunningFormInfo[]) => { 594e41f4b71Sopenharmony_ci if (error) { 595e41f4b71Sopenharmony_ci console.error(`error, code: ${error.code}, message: ${error.message}`); 596e41f4b71Sopenharmony_ci } else { 597e41f4b71Sopenharmony_ci console.log(`formObserver getRunningFormInfos, data: ${JSON.stringify(data)}`); 598e41f4b71Sopenharmony_ci } 599e41f4b71Sopenharmony_ci }, true, 'com.example.ohos.formjsdemo'); 600e41f4b71Sopenharmony_ci} catch(error) { 601e41f4b71Sopenharmony_ci console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}`); 602e41f4b71Sopenharmony_ci} 603e41f4b71Sopenharmony_ci``` 604e41f4b71Sopenharmony_ci 605e41f4b71Sopenharmony_ci## getRunningFormInfos 606e41f4b71Sopenharmony_ci 607e41f4b71Sopenharmony_cigetRunningFormInfos(hostBundleName?: string): Promise<Array<formInfo.RunningFormInfo>> 608e41f4b71Sopenharmony_ci 609e41f4b71Sopenharmony_ciObtains the information about all non-temporary widgets running on the device. This API uses a promise to return the result. 610e41f4b71Sopenharmony_ci 611e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 612e41f4b71Sopenharmony_ci 613e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 614e41f4b71Sopenharmony_ci 615e41f4b71Sopenharmony_ci**Parameters** 616e41f4b71Sopenharmony_ci 617e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 618e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 619e41f4b71Sopenharmony_ci| hostBundleName | string | No| Name of the bundle that functions as the widget host. If a value is passed in, only the information about the non-temporary widgets that are running under the widget host is returned.<br>If no value is passed in, information about all running non-temporary widgets on the device is returned.| 620e41f4b71Sopenharmony_ci 621e41f4b71Sopenharmony_ci**Return value** 622e41f4b71Sopenharmony_ci 623e41f4b71Sopenharmony_ci| Type | Description | 624e41f4b71Sopenharmony_ci| :----------------------------------------------------------- | :---------------------------------- | 625e41f4b71Sopenharmony_ci| Promise<Array<[formInfo.RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)>> | Promise used to return the information about all non-temporary widgets.| 626e41f4b71Sopenharmony_ci 627e41f4b71Sopenharmony_ci**Error codes** 628e41f4b71Sopenharmony_ci 629e41f4b71Sopenharmony_ciFor details about the error codes, see [Form Error Codes](errorcode-form.md). 630e41f4b71Sopenharmony_ci 631e41f4b71Sopenharmony_ci| ID| Error Message| 632e41f4b71Sopenharmony_ci| -------- | -------- | 633e41f4b71Sopenharmony_ci| 201 | Permissions denied. | 634e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 635e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 636e41f4b71Sopenharmony_ci| 16500050 | IPC connection error. | 637e41f4b71Sopenharmony_ci| 16500060 | Service connection error. | 638e41f4b71Sopenharmony_ci 639e41f4b71Sopenharmony_ci**Example** 640e41f4b71Sopenharmony_ci 641e41f4b71Sopenharmony_ci```ts 642e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 643e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 644e41f4b71Sopenharmony_ci 645e41f4b71Sopenharmony_citry { 646e41f4b71Sopenharmony_ci formObserver.getRunningFormInfos('com.example.ohos.formjsdemo').then((data: formInfo.RunningFormInfo[]) => { 647e41f4b71Sopenharmony_ci console.log(`formObserver getRunningFormInfos, data: ${JSON.stringify(data)}`); 648e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 649e41f4b71Sopenharmony_ci console.error(`error, code: ${error.code}, message: ${error.message}`); 650e41f4b71Sopenharmony_ci }); 651e41f4b71Sopenharmony_ci} catch(error) { 652e41f4b71Sopenharmony_ci console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}`); 653e41f4b71Sopenharmony_ci} 654e41f4b71Sopenharmony_ci``` 655e41f4b71Sopenharmony_ci 656e41f4b71Sopenharmony_ci## getRunningFormInfos<sup>11+</sup> 657e41f4b71Sopenharmony_ci 658e41f4b71Sopenharmony_cigetRunningFormInfos(isUnusedIncluded: boolean, hostBundleName?: string): Promise<Array<formInfo.RunningFormInfo>> 659e41f4b71Sopenharmony_ci 660e41f4b71Sopenharmony_ciObtains the information about all non-temporary widgets running on the device. This API uses a promise to return the result. 661e41f4b71Sopenharmony_ci 662e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 663e41f4b71Sopenharmony_ci 664e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 665e41f4b71Sopenharmony_ci 666e41f4b71Sopenharmony_ci**Parameters** 667e41f4b71Sopenharmony_ci 668e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 669e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 670e41f4b71Sopenharmony_ci| isUnusedIncluded | boolean | Yes| Whether an unused widget is included.| 671e41f4b71Sopenharmony_ci| hostBundleName | string | No| Name of the bundle that functions as the widget host. If a value is passed in, only the information about the non-temporary widgets that are running under the widget host is returned.<br> If no value is passed in, information about all running non-temporary widgets on the device is returned.| 672e41f4b71Sopenharmony_ci 673e41f4b71Sopenharmony_ci**Return value** 674e41f4b71Sopenharmony_ci 675e41f4b71Sopenharmony_ci| Type | Description | 676e41f4b71Sopenharmony_ci| :----------------------------------------------------------- | :---------------------------------- | 677e41f4b71Sopenharmony_ci| Promise<Array<[formInfo.RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)>> | Promise used to return the information about all non-temporary widgets.| 678e41f4b71Sopenharmony_ci 679e41f4b71Sopenharmony_ci**Error codes** 680e41f4b71Sopenharmony_ci 681e41f4b71Sopenharmony_ciFor details about the error codes, see [Form Error Codes](errorcode-form.md). 682e41f4b71Sopenharmony_ci 683e41f4b71Sopenharmony_ci| ID| Error Message| 684e41f4b71Sopenharmony_ci| -------- | -------- | 685e41f4b71Sopenharmony_ci| 201 | Permissions denied. | 686e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 687e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 688e41f4b71Sopenharmony_ci| 16500050 | IPC connection error. | 689e41f4b71Sopenharmony_ci| 16500060 | Service connection error. | 690e41f4b71Sopenharmony_ci 691e41f4b71Sopenharmony_ci**Example** 692e41f4b71Sopenharmony_ci 693e41f4b71Sopenharmony_ci```ts 694e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 695e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 696e41f4b71Sopenharmony_ci 697e41f4b71Sopenharmony_citry { 698e41f4b71Sopenharmony_ci formObserver.getRunningFormInfos(true, 'com.example.ohos.formjsdemo').then((data: formInfo.RunningFormInfo[]) => { 699e41f4b71Sopenharmony_ci console.log(`formObserver getRunningFormInfos, data: ${JSON.stringify(data)}`); 700e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 701e41f4b71Sopenharmony_ci console.error(`error, code: ${error.code}, message: ${error.message}`); 702e41f4b71Sopenharmony_ci }); 703e41f4b71Sopenharmony_ci} catch(error) { 704e41f4b71Sopenharmony_ci console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}`); 705e41f4b71Sopenharmony_ci} 706e41f4b71Sopenharmony_ci``` 707e41f4b71Sopenharmony_ci 708e41f4b71Sopenharmony_ci## getRunningFormInfosByFilter 709e41f4b71Sopenharmony_ci 710e41f4b71Sopenharmony_cigetRunningFormInfosByFilter(formProviderFilter: formInfo.FormProviderFilter): Promise<Array<formInfo.RunningFormInfo>> 711e41f4b71Sopenharmony_ci 712e41f4b71Sopenharmony_ciObtains the information about widgets based on the widget provider. This API uses a promise to return the result. 713e41f4b71Sopenharmony_ci 714e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model. 715e41f4b71Sopenharmony_ci 716e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 717e41f4b71Sopenharmony_ci 718e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 719e41f4b71Sopenharmony_ci 720e41f4b71Sopenharmony_ci**Parameters** 721e41f4b71Sopenharmony_ci 722e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 723e41f4b71Sopenharmony_ci| ----------- | --------------- | ---- | -------------------------------- | 724e41f4b71Sopenharmony_ci| formProviderFilter | [formInfo.FormProviderFilter](js-apis-app-form-formInfo-sys.md#formproviderfilter10) | Yes | Information about the widget provider.| 725e41f4b71Sopenharmony_ci 726e41f4b71Sopenharmony_ci**Return value** 727e41f4b71Sopenharmony_ci 728e41f4b71Sopenharmony_ci| Type | Description | 729e41f4b71Sopenharmony_ci| ------------------- | ------------------------- | 730e41f4b71Sopenharmony_ci| Promise<Array<[formInfo.RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)>> | Promise used to return an array of the widgets.| 731e41f4b71Sopenharmony_ci 732e41f4b71Sopenharmony_ci**Error codes** 733e41f4b71Sopenharmony_ci 734e41f4b71Sopenharmony_ciFor details about the error codes, see [Form Error Codes](errorcode-form.md). 735e41f4b71Sopenharmony_ci 736e41f4b71Sopenharmony_ci| ID| Error Message| 737e41f4b71Sopenharmony_ci| -------- | -------- | 738e41f4b71Sopenharmony_ci| 201 | Permissions denied. | 739e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 740e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 741e41f4b71Sopenharmony_ci| 16500050 | IPC connection error. | 742e41f4b71Sopenharmony_ci| 16500100 | Failed to obtain the configuration information. | 743e41f4b71Sopenharmony_ci| 16501000 | An internal functional error occurred. | 744e41f4b71Sopenharmony_ci 745e41f4b71Sopenharmony_ci 746e41f4b71Sopenharmony_ci```ts 747e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 748e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 749e41f4b71Sopenharmony_ci 750e41f4b71Sopenharmony_cilet formInstanceFilter: formInfo.FormProviderFilter = { 751e41f4b71Sopenharmony_ci bundleName: "com.example.formprovide", 752e41f4b71Sopenharmony_ci abilityName: "EntryFormAbility", 753e41f4b71Sopenharmony_ci formName: "widget", 754e41f4b71Sopenharmony_ci moduleName: "entry" 755e41f4b71Sopenharmony_ci} 756e41f4b71Sopenharmony_citry { 757e41f4b71Sopenharmony_ci formObserver.getRunningFormInfosByFilter(formInstanceFilter).then((data: formInfo.RunningFormInfo[]) => { 758e41f4b71Sopenharmony_ci console.info('formObserver getRunningFormInfosByFilter success, data:' + JSON.stringify(data)); 759e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 760e41f4b71Sopenharmony_ci console.error(`error, code: ${error.code}, message: ${error.message}`); 761e41f4b71Sopenharmony_ci }); 762e41f4b71Sopenharmony_ci} catch(error) { 763e41f4b71Sopenharmony_ci console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}`); 764e41f4b71Sopenharmony_ci} 765e41f4b71Sopenharmony_ci``` 766e41f4b71Sopenharmony_ci 767e41f4b71Sopenharmony_ci## getRunningFormInfosByFilter 768e41f4b71Sopenharmony_ci 769e41f4b71Sopenharmony_cigetRunningFormInfosByFilter(formProviderFilter: formInfo.FormProviderFilter, callback: AsyncCallback<Array<formInfo.RunningFormInfo>>): void 770e41f4b71Sopenharmony_ci 771e41f4b71Sopenharmony_ciObtains the information about widgets based on the widget provider. This API uses an asynchronous callback to return the result. 772e41f4b71Sopenharmony_ci 773e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model. 774e41f4b71Sopenharmony_ci 775e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 776e41f4b71Sopenharmony_ci 777e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 778e41f4b71Sopenharmony_ci 779e41f4b71Sopenharmony_ci**Parameters** 780e41f4b71Sopenharmony_ci 781e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 782e41f4b71Sopenharmony_ci| ----------- | --------------- | ---- | -------------------------------- | 783e41f4b71Sopenharmony_ci| formProviderFilter | [formInfo.FormProviderFilter](js-apis-app-form-formInfo-sys.md#formproviderfilter10) | Yes | Information about the widget provider.| 784e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<[formInfo.RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)>> | Yes| Callback used to used to return an array of the widgets. If the widget information is obtained, **error** is **undefined**, and **data** is the information obtained. Otherwise, **error** is an error object.| 785e41f4b71Sopenharmony_ci 786e41f4b71Sopenharmony_ci**Error codes** 787e41f4b71Sopenharmony_ci 788e41f4b71Sopenharmony_ciFor details about the error codes, see [Form Error Codes](errorcode-form.md). 789e41f4b71Sopenharmony_ci 790e41f4b71Sopenharmony_ci| ID| Error Message| 791e41f4b71Sopenharmony_ci| -------- | -------- | 792e41f4b71Sopenharmony_ci| 201 | Permissions denied. | 793e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 794e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 795e41f4b71Sopenharmony_ci| 16500050 | IPC connection error. | 796e41f4b71Sopenharmony_ci| 16500100 | Failed to obtain the configuration information. | 797e41f4b71Sopenharmony_ci| 16501000 | An internal functional error occurred. | 798e41f4b71Sopenharmony_ci 799e41f4b71Sopenharmony_ci**Example** 800e41f4b71Sopenharmony_ci 801e41f4b71Sopenharmony_ci```ts 802e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 803e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 804e41f4b71Sopenharmony_ci 805e41f4b71Sopenharmony_cilet formInstanceFilter: formInfo.FormProviderFilter = { 806e41f4b71Sopenharmony_ci bundleName: "com.example.formprovide", 807e41f4b71Sopenharmony_ci abilityName: "EntryFormAbility", 808e41f4b71Sopenharmony_ci formName: "widget", 809e41f4b71Sopenharmony_ci moduleName: "entry" 810e41f4b71Sopenharmony_ci} 811e41f4b71Sopenharmony_citry { 812e41f4b71Sopenharmony_ci formObserver.getRunningFormInfosByFilter(formInstanceFilter,(error: BusinessError, data: formInfo.RunningFormInfo[]) => { 813e41f4b71Sopenharmony_ci if (error) { 814e41f4b71Sopenharmony_ci console.error(`error, code: ${error.code}, message: ${error.message}`); 815e41f4b71Sopenharmony_ci } else { 816e41f4b71Sopenharmony_ci console.log(`formObserver getRunningFormInfosByFilter, data: ${JSON.stringify(data)}`); 817e41f4b71Sopenharmony_ci } 818e41f4b71Sopenharmony_ci }); 819e41f4b71Sopenharmony_ci} catch(error) { 820e41f4b71Sopenharmony_ci console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}`); 821e41f4b71Sopenharmony_ci} 822e41f4b71Sopenharmony_ci``` 823e41f4b71Sopenharmony_ci 824e41f4b71Sopenharmony_ci## getRunningFormInfoById 825e41f4b71Sopenharmony_ci 826e41f4b71Sopenharmony_cigetRunningFormInfoById(formId: string): Promise<formInfo.RunningFormInfo> 827e41f4b71Sopenharmony_ci 828e41f4b71Sopenharmony_ciObtains the information about the widget based on the widget ID. This API uses a promise to return the result. 829e41f4b71Sopenharmony_ci 830e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model. 831e41f4b71Sopenharmony_ci 832e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 833e41f4b71Sopenharmony_ci 834e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 835e41f4b71Sopenharmony_ci 836e41f4b71Sopenharmony_ci**Parameters** 837e41f4b71Sopenharmony_ci 838e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 839e41f4b71Sopenharmony_ci| ----------- | --------------- | ---- | -------------------------------- | 840e41f4b71Sopenharmony_ci| formId | string | Yes | Widget ID.| 841e41f4b71Sopenharmony_ci 842e41f4b71Sopenharmony_ci**Return value** 843e41f4b71Sopenharmony_ci 844e41f4b71Sopenharmony_ci| Type | Description | 845e41f4b71Sopenharmony_ci| ------------------- | ------------------------- | 846e41f4b71Sopenharmony_ci| Promise<[formInfo.RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)> | Promise used to return the widget information.| 847e41f4b71Sopenharmony_ci 848e41f4b71Sopenharmony_ci**Error codes** 849e41f4b71Sopenharmony_ci 850e41f4b71Sopenharmony_ciFor details about the error codes, see [Form Error Codes](errorcode-form.md). 851e41f4b71Sopenharmony_ci 852e41f4b71Sopenharmony_ci| ID| Error Message| 853e41f4b71Sopenharmony_ci| -------- | -------- | 854e41f4b71Sopenharmony_ci| 201 | Permissions denied. | 855e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 856e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 857e41f4b71Sopenharmony_ci| 16500050 | IPC connection error. | 858e41f4b71Sopenharmony_ci| 16500100 | Failed to obtain the configuration information. | 859e41f4b71Sopenharmony_ci| 16501000 | An internal functional error occurred. | 860e41f4b71Sopenharmony_ci 861e41f4b71Sopenharmony_ci**Example** 862e41f4b71Sopenharmony_ci 863e41f4b71Sopenharmony_ci```ts 864e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 865e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 866e41f4b71Sopenharmony_ci 867e41f4b71Sopenharmony_cilet formId: string = '12400633174999288'; 868e41f4b71Sopenharmony_citry { 869e41f4b71Sopenharmony_ci formObserver.getRunningFormInfoById(formId).then((data: formInfo.RunningFormInfo) => { 870e41f4b71Sopenharmony_ci console.info('formObserver getRunningFormInfoById success, data:' + JSON.stringify(data)); 871e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 872e41f4b71Sopenharmony_ci console.error(`error, code: ${error.code}, message: ${error.message}`); 873e41f4b71Sopenharmony_ci }); 874e41f4b71Sopenharmony_ci} catch(error) { 875e41f4b71Sopenharmony_ci console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}`); 876e41f4b71Sopenharmony_ci} 877e41f4b71Sopenharmony_ci``` 878e41f4b71Sopenharmony_ci 879e41f4b71Sopenharmony_ci## getRunningFormInfoById<sup>11+</sup> 880e41f4b71Sopenharmony_ci 881e41f4b71Sopenharmony_cigetRunningFormInfoById(formId: string, isUnusedIncluded: boolean): Promise<formInfo.RunningFormInfo> 882e41f4b71Sopenharmony_ci 883e41f4b71Sopenharmony_ciObtains the information about the widget based on the widget ID. This API uses a promise to return the result. 884e41f4b71Sopenharmony_ci 885e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model. 886e41f4b71Sopenharmony_ci 887e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 888e41f4b71Sopenharmony_ci 889e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 890e41f4b71Sopenharmony_ci 891e41f4b71Sopenharmony_ci**Parameters** 892e41f4b71Sopenharmony_ci 893e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 894e41f4b71Sopenharmony_ci| ----------- | --------------- | ---- | -------------------------------- | 895e41f4b71Sopenharmony_ci| formId | string | Yes | Widget ID.| 896e41f4b71Sopenharmony_ci| isUnusedIncluded | boolean | Yes | Whether an unused widget is included.| 897e41f4b71Sopenharmony_ci 898e41f4b71Sopenharmony_ci**Return value** 899e41f4b71Sopenharmony_ci 900e41f4b71Sopenharmony_ci| Type | Description | 901e41f4b71Sopenharmony_ci| ------------------- | ------------------------- | 902e41f4b71Sopenharmony_ci| Promise<[formInfo.RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)> | Promise used to return the widget information.| 903e41f4b71Sopenharmony_ci 904e41f4b71Sopenharmony_ci**Error codes** 905e41f4b71Sopenharmony_ci 906e41f4b71Sopenharmony_ciFor details about the error codes, see [Form Error Codes](errorcode-form.md). 907e41f4b71Sopenharmony_ci 908e41f4b71Sopenharmony_ci| ID| Error Message| 909e41f4b71Sopenharmony_ci| -------- | -------- | 910e41f4b71Sopenharmony_ci| 201 | Permissions denied. | 911e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 912e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 913e41f4b71Sopenharmony_ci| 16500050 | IPC connection error. | 914e41f4b71Sopenharmony_ci| 16500100 | Failed to obtain the configuration information. | 915e41f4b71Sopenharmony_ci| 16501000 | An internal functional error occurred. | 916e41f4b71Sopenharmony_ci 917e41f4b71Sopenharmony_ci**Example** 918e41f4b71Sopenharmony_ci 919e41f4b71Sopenharmony_ci```ts 920e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 921e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 922e41f4b71Sopenharmony_ci 923e41f4b71Sopenharmony_cilet formId: string = '12400633174999288'; 924e41f4b71Sopenharmony_citry { 925e41f4b71Sopenharmony_ci formObserver.getRunningFormInfoById(formId, true).then((data: formInfo.RunningFormInfo) => { 926e41f4b71Sopenharmony_ci console.info('formObserver getRunningFormInfoById success, data:' + JSON.stringify(data)); 927e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 928e41f4b71Sopenharmony_ci console.error(`error, code: ${error.code}, message: ${error.message}`); 929e41f4b71Sopenharmony_ci }); 930e41f4b71Sopenharmony_ci} catch(error) { 931e41f4b71Sopenharmony_ci console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}`); 932e41f4b71Sopenharmony_ci} 933e41f4b71Sopenharmony_ci``` 934e41f4b71Sopenharmony_ci 935e41f4b71Sopenharmony_ci## getRunningFormInfoById 936e41f4b71Sopenharmony_ci 937e41f4b71Sopenharmony_cigetRunningFormInfoById(formId: string, callback: AsyncCallback<formInfo.RunningFormInfo>): void 938e41f4b71Sopenharmony_ci 939e41f4b71Sopenharmony_ciObtains the information about the widget based on the widget ID. This API uses an asynchronous callback to return the result. 940e41f4b71Sopenharmony_ci 941e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model. 942e41f4b71Sopenharmony_ci 943e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 944e41f4b71Sopenharmony_ci 945e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 946e41f4b71Sopenharmony_ci 947e41f4b71Sopenharmony_ci**Parameters** 948e41f4b71Sopenharmony_ci 949e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 950e41f4b71Sopenharmony_ci| ----------- | --------------- | ---- | -------------------------------- | 951e41f4b71Sopenharmony_ci| formId | string | Yes | Widget ID.| 952e41f4b71Sopenharmony_ci| callback | AsyncCallback<[formInfo.RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)> | Yes| Callback used to used to return the widget information. If the widget information is obtained, **error** is **undefined**, and **data** is the information obtained. Otherwise, **error** is an error object.| 953e41f4b71Sopenharmony_ci 954e41f4b71Sopenharmony_ci**Error codes** 955e41f4b71Sopenharmony_ci 956e41f4b71Sopenharmony_ciFor details about the error codes, see [Form Error Codes](errorcode-form.md). 957e41f4b71Sopenharmony_ci 958e41f4b71Sopenharmony_ci| ID| Error Message| 959e41f4b71Sopenharmony_ci| -------- | -------- | 960e41f4b71Sopenharmony_ci| 201 | Permissions denied. | 961e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 962e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 963e41f4b71Sopenharmony_ci| 16500050 | IPC connection error. | 964e41f4b71Sopenharmony_ci| 16500100 | Failed to obtain the configuration information. | 965e41f4b71Sopenharmony_ci| 16501000 | An internal functional error occurred. | 966e41f4b71Sopenharmony_ci 967e41f4b71Sopenharmony_ci**Example** 968e41f4b71Sopenharmony_ci 969e41f4b71Sopenharmony_ci```ts 970e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 971e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 972e41f4b71Sopenharmony_ci 973e41f4b71Sopenharmony_cilet formId: string = '12400633174999288'; 974e41f4b71Sopenharmony_citry { 975e41f4b71Sopenharmony_ci formObserver.getRunningFormInfoById(formId,(error: BusinessError, data: formInfo.RunningFormInfo) => { 976e41f4b71Sopenharmony_ci if (error) { 977e41f4b71Sopenharmony_ci console.error(`error, code: ${error.code}, message: ${error.message}`); 978e41f4b71Sopenharmony_ci } else { 979e41f4b71Sopenharmony_ci console.log(`formObserver getRunningFormInfoById, data: ${JSON.stringify(data)}`); 980e41f4b71Sopenharmony_ci } 981e41f4b71Sopenharmony_ci }); 982e41f4b71Sopenharmony_ci} catch(error) { 983e41f4b71Sopenharmony_ci console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}`); 984e41f4b71Sopenharmony_ci} 985e41f4b71Sopenharmony_ci``` 986e41f4b71Sopenharmony_ci 987e41f4b71Sopenharmony_ci## getRunningFormInfoById<sup>11+</sup> 988e41f4b71Sopenharmony_ci 989e41f4b71Sopenharmony_cigetRunningFormInfoById(formId: string, isUnusedIncluded: boolean, callback: AsyncCallback<formInfo.RunningFormInfo>): void 990e41f4b71Sopenharmony_ci 991e41f4b71Sopenharmony_ciObtains the information about the widget based on the widget ID. This API uses an asynchronous callback to return the result. 992e41f4b71Sopenharmony_ci 993e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model. 994e41f4b71Sopenharmony_ci 995e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 996e41f4b71Sopenharmony_ci 997e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 998e41f4b71Sopenharmony_ci 999e41f4b71Sopenharmony_ci**Parameters** 1000e41f4b71Sopenharmony_ci 1001e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1002e41f4b71Sopenharmony_ci| ----------- | --------------- | ---- | -------------------------------- | 1003e41f4b71Sopenharmony_ci| formId | string | Yes | Widget ID.| 1004e41f4b71Sopenharmony_ci| isUnusedIncluded | boolean | Yes | Whether an unused widget is included.| 1005e41f4b71Sopenharmony_ci| callback | AsyncCallback<[formInfo.RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)> | Yes| Callback used to used to return the widget information. If the widget information is obtained, **error** is **undefined**, and **data** is the information obtained. Otherwise, **error** is an error object.| 1006e41f4b71Sopenharmony_ci 1007e41f4b71Sopenharmony_ci**Error codes** 1008e41f4b71Sopenharmony_ci 1009e41f4b71Sopenharmony_ciFor details about the error codes, see [Form Error Codes](errorcode-form.md). 1010e41f4b71Sopenharmony_ci 1011e41f4b71Sopenharmony_ci| ID| Error Message| 1012e41f4b71Sopenharmony_ci| -------- | -------- | 1013e41f4b71Sopenharmony_ci| 201 | Permissions denied. | 1014e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 1015e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 1016e41f4b71Sopenharmony_ci| 16500050 | IPC connection error. | 1017e41f4b71Sopenharmony_ci| 16500100 | Failed to obtain the configuration information. | 1018e41f4b71Sopenharmony_ci| 16501000 | An internal functional error occurred. | 1019e41f4b71Sopenharmony_ci 1020e41f4b71Sopenharmony_ci**Example** 1021e41f4b71Sopenharmony_ci 1022e41f4b71Sopenharmony_ci```ts 1023e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 1024e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1025e41f4b71Sopenharmony_ci 1026e41f4b71Sopenharmony_cilet formId: string = '12400633174999288'; 1027e41f4b71Sopenharmony_citry { 1028e41f4b71Sopenharmony_ci formObserver.getRunningFormInfoById(formId, true, (error: BusinessError, data: formInfo.RunningFormInfo) => { 1029e41f4b71Sopenharmony_ci if (error) { 1030e41f4b71Sopenharmony_ci console.error(`error, code: ${error.code}, message: ${error.message}`); 1031e41f4b71Sopenharmony_ci } else { 1032e41f4b71Sopenharmony_ci console.log(`formObserver getRunningFormInfoById, data: ${JSON.stringify(data)}`); 1033e41f4b71Sopenharmony_ci } 1034e41f4b71Sopenharmony_ci }); 1035e41f4b71Sopenharmony_ci} catch(error) { 1036e41f4b71Sopenharmony_ci console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}`); 1037e41f4b71Sopenharmony_ci} 1038e41f4b71Sopenharmony_ci``` 1039e41f4b71Sopenharmony_ci 1040e41f4b71Sopenharmony_ci## on('router')<sup>11+</sup> 1041e41f4b71Sopenharmony_ci 1042e41f4b71Sopenharmony_ci on(type: 'router', observerCallback: Callback<formInfo.RunningFormInfo>): void 1043e41f4b71Sopenharmony_ci 1044e41f4b71Sopenharmony_ciSubscribes to widget router events. This API uses an asynchronous callback to return the information of the widget that triggers the router event. 1045e41f4b71Sopenharmony_ci 1046e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 1047e41f4b71Sopenharmony_ci 1048e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 1049e41f4b71Sopenharmony_ci 1050e41f4b71Sopenharmony_ci**Parameters** 1051e41f4b71Sopenharmony_ci 1052e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1053e41f4b71Sopenharmony_ci| ---------------- | ---------------------------------------- | ---- | ----------------------------------------- | 1054e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value **'router'** indicates a widget router event. | 1055e41f4b71Sopenharmony_ci| observerCallback | Callback<[formInfo.RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)> | Yes | Callback used to return the widget information.| 1056e41f4b71Sopenharmony_ci 1057e41f4b71Sopenharmony_ci**Error codes** 1058e41f4b71Sopenharmony_ci 1059e41f4b71Sopenharmony_ciFor details about the error codes, see [Form Error Codes](errorcode-form.md). 1060e41f4b71Sopenharmony_ci 1061e41f4b71Sopenharmony_ci| ID| Error Message| 1062e41f4b71Sopenharmony_ci| -------- | -------- | 1063e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 1064e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 1065e41f4b71Sopenharmony_ci 1066e41f4b71Sopenharmony_ci**Example** 1067e41f4b71Sopenharmony_ci 1068e41f4b71Sopenharmony_ci```ts 1069e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 1070e41f4b71Sopenharmony_ci 1071e41f4b71Sopenharmony_cilet callback = (data: formInfo.RunningFormInfo) => { 1072e41f4b71Sopenharmony_ci console.log('Router event listening in registered form.' + JSON.stringify(data)); 1073e41f4b71Sopenharmony_ci}; 1074e41f4b71Sopenharmony_ciformObserver.on('router', callback); 1075e41f4b71Sopenharmony_ci``` 1076e41f4b71Sopenharmony_ci 1077e41f4b71Sopenharmony_ci## on('router')<sup>11+</sup> 1078e41f4b71Sopenharmony_ci 1079e41f4b71Sopenharmony_ci on(type: 'router', hostBundleName: string, observerCallback: Callback<formInfo.RunningFormInfo>): void 1080e41f4b71Sopenharmony_ci 1081e41f4b71Sopenharmony_ciSubscribes to widget router events for a given bundle that functions as the widget host. This API uses an asynchronous callback to return the information of the widget that triggers the router event. 1082e41f4b71Sopenharmony_ci 1083e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 1084e41f4b71Sopenharmony_ci 1085e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 1086e41f4b71Sopenharmony_ci 1087e41f4b71Sopenharmony_ci**Parameters** 1088e41f4b71Sopenharmony_ci 1089e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1090e41f4b71Sopenharmony_ci| ---------------- | ---------------------------------------- | ---- | ------------------------------------------------------------ | 1091e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value **'router'** indicates a widget router event. | 1092e41f4b71Sopenharmony_ci| hostBundleName | string | Yes | Name of the bundle that functions as the widget host. If no value is passed in, widget router events of all widget hosts are subscribed to.| 1093e41f4b71Sopenharmony_ci| observerCallback | Callback<[formInfo.RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)> | Yes | Callback used to return the widget information. | 1094e41f4b71Sopenharmony_ci 1095e41f4b71Sopenharmony_ci**Error codes** 1096e41f4b71Sopenharmony_ci 1097e41f4b71Sopenharmony_ciFor details about the error codes, see [Form Error Codes](errorcode-form.md). 1098e41f4b71Sopenharmony_ci 1099e41f4b71Sopenharmony_ci| ID| Error Message| 1100e41f4b71Sopenharmony_ci| -------- | -------- | 1101e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 1102e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 1103e41f4b71Sopenharmony_ci 1104e41f4b71Sopenharmony_ci**Example** 1105e41f4b71Sopenharmony_ci 1106e41f4b71Sopenharmony_ci```ts 1107e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 1108e41f4b71Sopenharmony_ci 1109e41f4b71Sopenharmony_cilet hostBundleName: string = 'ohos.samples.FormApplication'; 1110e41f4b71Sopenharmony_cilet callback = (data: formInfo.RunningFormInfo) => { 1111e41f4b71Sopenharmony_ci console.log('Router event listening in registered form.' + JSON.stringify(data)); 1112e41f4b71Sopenharmony_ci}; 1113e41f4b71Sopenharmony_ciformObserver.on('router', hostBundleName, callback); 1114e41f4b71Sopenharmony_ci``` 1115e41f4b71Sopenharmony_ci 1116e41f4b71Sopenharmony_ci## off('router')<sup>11+</sup> 1117e41f4b71Sopenharmony_ci 1118e41f4b71Sopenharmony_ci off(type: "router", hostBundleName?: string, observerCallback?: Callback<formInfo.RunningFormInfo>): void 1119e41f4b71Sopenharmony_ci 1120e41f4b71Sopenharmony_ciUnsubscribes from widget router events. This API uses an asynchronous callback to return the information of the widget that triggers the router event. 1121e41f4b71Sopenharmony_ci 1122e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 1123e41f4b71Sopenharmony_ci 1124e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 1125e41f4b71Sopenharmony_ci 1126e41f4b71Sopenharmony_ci**Parameters** 1127e41f4b71Sopenharmony_ci 1128e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1129e41f4b71Sopenharmony_ci| ---------------- | ---------------------------------------- | ---- | ------------------------------------------------------------ | 1130e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value **'router'** indicates a widget router event. | 1131e41f4b71Sopenharmony_ci| hostBundleName | string | No | Name of the bundle that functions as the widget host.<br>To cancel the subscription for a given bundle name, this parameter must be set to the same value as **bundleName** in **on('router')**.<br>If no value is passed in, the subscriptions for all the widget hosts are canceled.| 1132e41f4b71Sopenharmony_ci| observerCallback | Callback<[formInfo.RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)> | No | Callback used to return the widget information. If no value is passed in, all the subscriptions to the specified event are canceled.<br>To cancel the subscription with a given callback, this parameter must be set to the same value as **callback** in **on('router')**.| 1133e41f4b71Sopenharmony_ci 1134e41f4b71Sopenharmony_ci**Error codes** 1135e41f4b71Sopenharmony_ci 1136e41f4b71Sopenharmony_ciFor details about the error codes, see [Form Error Codes](errorcode-form.md). 1137e41f4b71Sopenharmony_ci 1138e41f4b71Sopenharmony_ci| ID| Error Message| 1139e41f4b71Sopenharmony_ci| -------- | -------- | 1140e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 1141e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 1142e41f4b71Sopenharmony_ci 1143e41f4b71Sopenharmony_ci**Example** 1144e41f4b71Sopenharmony_ci 1145e41f4b71Sopenharmony_ci```ts 1146e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 1147e41f4b71Sopenharmony_ci 1148e41f4b71Sopenharmony_cilet hostBundleName: string = 'ohos.samples.FormApplication'; 1149e41f4b71Sopenharmony_cilet callback = (data: formInfo.RunningFormInfo) => { 1150e41f4b71Sopenharmony_ci console.log('Unregister form router event Listening.' + JSON.stringify(data)); 1151e41f4b71Sopenharmony_ci}; 1152e41f4b71Sopenharmony_ciformObserver.off('router', hostBundleName, callback); 1153e41f4b71Sopenharmony_ci``` 1154e41f4b71Sopenharmony_ci 1155e41f4b71Sopenharmony_ci## on('message')<sup>11+</sup> 1156e41f4b71Sopenharmony_ci 1157e41f4b71Sopenharmony_ci on(type: 'message', observerCallback: Callback<formInfo.RunningFormInfo>): void 1158e41f4b71Sopenharmony_ci 1159e41f4b71Sopenharmony_ciSubscribes to widget message events. This API uses an asynchronous callback to return the information of the widget that triggers the message event. 1160e41f4b71Sopenharmony_ci 1161e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 1162e41f4b71Sopenharmony_ci 1163e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 1164e41f4b71Sopenharmony_ci 1165e41f4b71Sopenharmony_ci**Parameters** 1166e41f4b71Sopenharmony_ci 1167e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1168e41f4b71Sopenharmony_ci| ---------------- | ---------------------------------------- | ---- | ----------------------------------------- | 1169e41f4b71Sopenharmony_ci| type | string | Yes | Event type. This value **'message'** indicates a widget message event. | 1170e41f4b71Sopenharmony_ci| observerCallback | Callback<[formInfo.RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)> | Yes | Callback used to return the widget information.| 1171e41f4b71Sopenharmony_ci 1172e41f4b71Sopenharmony_ci**Error codes** 1173e41f4b71Sopenharmony_ci 1174e41f4b71Sopenharmony_ciFor details about the error codes, see [Form Error Codes](errorcode-form.md). 1175e41f4b71Sopenharmony_ci 1176e41f4b71Sopenharmony_ci| ID| Error Message| 1177e41f4b71Sopenharmony_ci| -------- | -------- | 1178e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 1179e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 1180e41f4b71Sopenharmony_ci 1181e41f4b71Sopenharmony_ci**Example** 1182e41f4b71Sopenharmony_ci 1183e41f4b71Sopenharmony_ci```ts 1184e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 1185e41f4b71Sopenharmony_ci 1186e41f4b71Sopenharmony_cilet callback = (data: formInfo.RunningFormInfo) => { 1187e41f4b71Sopenharmony_ci console.log('Message event listening in registered form.' + JSON.stringify(data)); 1188e41f4b71Sopenharmony_ci}; 1189e41f4b71Sopenharmony_ciformObserver.on('message', callback); 1190e41f4b71Sopenharmony_ci``` 1191e41f4b71Sopenharmony_ci 1192e41f4b71Sopenharmony_ci## on('message')<sup>11+</sup> 1193e41f4b71Sopenharmony_ci 1194e41f4b71Sopenharmony_ci on(type: 'message', hostBundleName: string, observerCallback: Callback<formInfo.RunningFormInfo>): void 1195e41f4b71Sopenharmony_ci 1196e41f4b71Sopenharmony_ciSubscribes to widget message events for a given bundle that functions as the widget host. This API uses an asynchronous callback to return the information of the widget that triggers the message event. 1197e41f4b71Sopenharmony_ci 1198e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 1199e41f4b71Sopenharmony_ci 1200e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 1201e41f4b71Sopenharmony_ci 1202e41f4b71Sopenharmony_ci**Parameters** 1203e41f4b71Sopenharmony_ci 1204e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1205e41f4b71Sopenharmony_ci| ---------------- | ---------------------------------------- | ---- | ------------------------------------------------------------ | 1206e41f4b71Sopenharmony_ci| type | string | Yes | Event type. This value **'message'** indicates a widget message event. | 1207e41f4b71Sopenharmony_ci| hostBundleName | string | Yes | Name of the bundle that functions as the widget host. If no value is passed in, widget message events of all widget hosts are subscribed to.| 1208e41f4b71Sopenharmony_ci| observerCallback | Callback<[formInfo.RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)> | Yes | Callback used to return the widget information. | 1209e41f4b71Sopenharmony_ci 1210e41f4b71Sopenharmony_ci**Error codes** 1211e41f4b71Sopenharmony_ci 1212e41f4b71Sopenharmony_ciFor details about the error codes, see [Form Error Codes](errorcode-form.md). 1213e41f4b71Sopenharmony_ci 1214e41f4b71Sopenharmony_ci| ID| Error Message| 1215e41f4b71Sopenharmony_ci| -------- | -------- | 1216e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 1217e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 1218e41f4b71Sopenharmony_ci 1219e41f4b71Sopenharmony_ci**Example** 1220e41f4b71Sopenharmony_ci 1221e41f4b71Sopenharmony_ci```ts 1222e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 1223e41f4b71Sopenharmony_ci 1224e41f4b71Sopenharmony_cilet hostBundleName: string = 'ohos.samples.FormApplication'; 1225e41f4b71Sopenharmony_cilet callback = (data: formInfo.RunningFormInfo) => { 1226e41f4b71Sopenharmony_ci console.log('Message event listening in registered form.' + JSON.stringify(data)); 1227e41f4b71Sopenharmony_ci}; 1228e41f4b71Sopenharmony_ciformObserver.on('message', hostBundleName, callback); 1229e41f4b71Sopenharmony_ci``` 1230e41f4b71Sopenharmony_ci 1231e41f4b71Sopenharmony_ci## off('message')<sup>11+</sup> 1232e41f4b71Sopenharmony_ci 1233e41f4b71Sopenharmony_ci off(type: "message", hostBundleName?: string, observerCallback?: Callback<formInfo.RunningFormInfo>): void 1234e41f4b71Sopenharmony_ci 1235e41f4b71Sopenharmony_ciUnsubscribes from widget message events. This API uses an asynchronous callback to return the information of the widget that triggers the message event. 1236e41f4b71Sopenharmony_ci 1237e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 1238e41f4b71Sopenharmony_ci 1239e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 1240e41f4b71Sopenharmony_ci 1241e41f4b71Sopenharmony_ci**Parameters** 1242e41f4b71Sopenharmony_ci 1243e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1244e41f4b71Sopenharmony_ci| ---------------- | ---------------------------------------- | ---- | ------------------------------------------------------------ | 1245e41f4b71Sopenharmony_ci| type | string | Yes | Event type. This value **'message'** indicates a widget message event. | 1246e41f4b71Sopenharmony_ci| hostBundleName | string | No | Name of the bundle that functions as the widget host.<br>To cancel the subscription for a given bundle name, this parameter must be set to the same value as **bundleName** in **on('message')**.<br>If no value is passed in, the subscriptions for all the widget hosts are canceled.| 1247e41f4b71Sopenharmony_ci| observerCallback | Callback<[formInfo.RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)> | No | Callback used to return the widget information. If no value is passed in, all the subscriptions to the specified event are canceled.<br>To cancel the subscription with a given callback, this parameter must be set to the same value as **callback** in **on('message')**.| 1248e41f4b71Sopenharmony_ci 1249e41f4b71Sopenharmony_ci**Error codes** 1250e41f4b71Sopenharmony_ci 1251e41f4b71Sopenharmony_ciFor details about the error codes, see [Form Error Codes](errorcode-form.md). 1252e41f4b71Sopenharmony_ci 1253e41f4b71Sopenharmony_ci| ID| Error Message| 1254e41f4b71Sopenharmony_ci| -------- | -------- | 1255e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 1256e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 1257e41f4b71Sopenharmony_ci 1258e41f4b71Sopenharmony_ci**Example** 1259e41f4b71Sopenharmony_ci 1260e41f4b71Sopenharmony_ci```ts 1261e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 1262e41f4b71Sopenharmony_ci 1263e41f4b71Sopenharmony_cilet hostBundleName: string = 'ohos.samples.FormApplication'; 1264e41f4b71Sopenharmony_cilet callback = (data: formInfo.RunningFormInfo) => { 1265e41f4b71Sopenharmony_ci console.log('Unregister form Message event Listening.' + JSON.stringify(data)); 1266e41f4b71Sopenharmony_ci}; 1267e41f4b71Sopenharmony_ciformObserver.off('message', hostBundleName, callback); 1268e41f4b71Sopenharmony_ci``` 1269e41f4b71Sopenharmony_ci 1270e41f4b71Sopenharmony_ci## on('call')<sup>11+</sup> 1271e41f4b71Sopenharmony_ci 1272e41f4b71Sopenharmony_ci on(type: 'call', observerCallback: Callback<formInfo.RunningFormInfo>): void 1273e41f4b71Sopenharmony_ci 1274e41f4b71Sopenharmony_ciSubscribes to widget call events. This API uses an asynchronous callback to return the information of the widget that triggers the call event. 1275e41f4b71Sopenharmony_ci 1276e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 1277e41f4b71Sopenharmony_ci 1278e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 1279e41f4b71Sopenharmony_ci 1280e41f4b71Sopenharmony_ci**Parameters** 1281e41f4b71Sopenharmony_ci 1282e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1283e41f4b71Sopenharmony_ci| ---------------- | ---------------------------------------- | ---- | ----------------------------------------- | 1284e41f4b71Sopenharmony_ci| type | string | Yes | Event type. This value **'call'** indicates a widget call event. | 1285e41f4b71Sopenharmony_ci| observerCallback | Callback<[formInfo.RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)> | Yes | Callback used to return the widget information.| 1286e41f4b71Sopenharmony_ci 1287e41f4b71Sopenharmony_ci**Error codes** 1288e41f4b71Sopenharmony_ci 1289e41f4b71Sopenharmony_ciFor details about the error codes, see [Form Error Codes](errorcode-form.md). 1290e41f4b71Sopenharmony_ci 1291e41f4b71Sopenharmony_ci| ID| Error Message| 1292e41f4b71Sopenharmony_ci| -------- | -------- | 1293e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 1294e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 1295e41f4b71Sopenharmony_ci 1296e41f4b71Sopenharmony_ci**Example** 1297e41f4b71Sopenharmony_ci 1298e41f4b71Sopenharmony_ci```ts 1299e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 1300e41f4b71Sopenharmony_ci 1301e41f4b71Sopenharmony_cilet callback = (data: formInfo.RunningFormInfo) => { 1302e41f4b71Sopenharmony_ci console.log('Call event listening in registered form.' + JSON.stringify(data)); 1303e41f4b71Sopenharmony_ci}; 1304e41f4b71Sopenharmony_ciformObserver.on('call', callback); 1305e41f4b71Sopenharmony_ci``` 1306e41f4b71Sopenharmony_ci 1307e41f4b71Sopenharmony_ci## on('call')<sup>11+</sup> 1308e41f4b71Sopenharmony_ci 1309e41f4b71Sopenharmony_ci on(type: 'call', hostBundleName: string, observerCallback: Callback<formInfo.RunningFormInfo>): void 1310e41f4b71Sopenharmony_ci 1311e41f4b71Sopenharmony_ciSubscribes to widget call events for a given bundle that functions as the widget host. This API uses an asynchronous callback to return the information of the widget that triggers the call event. 1312e41f4b71Sopenharmony_ci 1313e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 1314e41f4b71Sopenharmony_ci 1315e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 1316e41f4b71Sopenharmony_ci 1317e41f4b71Sopenharmony_ci**Parameters** 1318e41f4b71Sopenharmony_ci 1319e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1320e41f4b71Sopenharmony_ci| ---------------- | ---------------------------------------- | ---- | ------------------------------------------------------------ | 1321e41f4b71Sopenharmony_ci| type | string | Yes | Event type. This value **'call'** indicates a widget call event. | 1322e41f4b71Sopenharmony_ci| hostBundleName | string | Yes | Name of the bundle that functions as the widget host. If no value is passed in, widget call events of all widget hosts are subscribed to.| 1323e41f4b71Sopenharmony_ci| observerCallback | Callback<[formInfo.RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)> | Yes | Callback used to return the widget information. | 1324e41f4b71Sopenharmony_ci 1325e41f4b71Sopenharmony_ci**Error codes** 1326e41f4b71Sopenharmony_ci 1327e41f4b71Sopenharmony_ciFor details about the error codes, see [Form Error Codes](errorcode-form.md). 1328e41f4b71Sopenharmony_ci 1329e41f4b71Sopenharmony_ci| ID| Error Message| 1330e41f4b71Sopenharmony_ci| -------- | -------- | 1331e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 1332e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 1333e41f4b71Sopenharmony_ci 1334e41f4b71Sopenharmony_ci**Example** 1335e41f4b71Sopenharmony_ci 1336e41f4b71Sopenharmony_ci```ts 1337e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 1338e41f4b71Sopenharmony_ci 1339e41f4b71Sopenharmony_cilet hostBundleName: string = 'ohos.samples.FormApplication'; 1340e41f4b71Sopenharmony_cilet callback = (data: formInfo.RunningFormInfo) => { 1341e41f4b71Sopenharmony_ci console.log('Call event listening in registered form.' + JSON.stringify(data)); 1342e41f4b71Sopenharmony_ci}; 1343e41f4b71Sopenharmony_ciformObserver.on('call', hostBundleName, callback); 1344e41f4b71Sopenharmony_ci``` 1345e41f4b71Sopenharmony_ci 1346e41f4b71Sopenharmony_ci## off('call')<sup>11+</sup> 1347e41f4b71Sopenharmony_ci 1348e41f4b71Sopenharmony_ci off(type: "call", hostBundleName?: string, observerCallback?: Callback<formInfo.RunningFormInfo>): void 1349e41f4b71Sopenharmony_ci 1350e41f4b71Sopenharmony_ciUnsubscribes from widget call events. This API uses an asynchronous callback to return the information of the widget that triggers the call event. 1351e41f4b71Sopenharmony_ci 1352e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.OBSERVE_FORM_RUNNING 1353e41f4b71Sopenharmony_ci 1354e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.Form 1355e41f4b71Sopenharmony_ci 1356e41f4b71Sopenharmony_ci**Parameters** 1357e41f4b71Sopenharmony_ci 1358e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1359e41f4b71Sopenharmony_ci| ---------------- | ---------------------------------------- | ---- | ------------------------------------------------------------ | 1360e41f4b71Sopenharmony_ci| type | string | Yes | Event type. This value **'call'** indicates a widget call event. | 1361e41f4b71Sopenharmony_ci| hostBundleName | string | No | Name of the bundle that functions as the widget host.<br>To cancel the subscription for a given bundle name, this parameter must be set to the same value as **bundleName** in **on('call')**.<br>If no value is passed in, the subscriptions for all the widget hosts are canceled.| 1362e41f4b71Sopenharmony_ci| observerCallback | Callback<[formInfo.RunningFormInfo](js-apis-app-form-formInfo-sys.md#runningforminfo10)> | No | Callback used to return the widget information. If no value is passed in, all the subscriptions to the specified event are canceled.<br>To cancel the subscription with a given callback, this parameter must be set to the same value as **callback** in **on('call')**.| 1363e41f4b71Sopenharmony_ci 1364e41f4b71Sopenharmony_ci**Error codes** 1365e41f4b71Sopenharmony_ci 1366e41f4b71Sopenharmony_ciFor details about the error codes, see [Form Error Codes](errorcode-form.md). 1367e41f4b71Sopenharmony_ci 1368e41f4b71Sopenharmony_ci| ID| Error Message| 1369e41f4b71Sopenharmony_ci| -------- | -------- | 1370e41f4b71Sopenharmony_ci| 202 | The application is not a system application. | 1371e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 1372e41f4b71Sopenharmony_ci 1373e41f4b71Sopenharmony_ci**Example** 1374e41f4b71Sopenharmony_ci 1375e41f4b71Sopenharmony_ci```ts 1376e41f4b71Sopenharmony_ciimport { formInfo, formObserver } from '@kit.FormKit'; 1377e41f4b71Sopenharmony_ci 1378e41f4b71Sopenharmony_cilet hostBundleName: string = 'ohos.samples.FormApplication'; 1379e41f4b71Sopenharmony_cilet callback = (data: formInfo.RunningFormInfo) => { 1380e41f4b71Sopenharmony_ci console.log('Unregister form Call event Listening.' + JSON.stringify(data)); 1381e41f4b71Sopenharmony_ci}; 1382e41f4b71Sopenharmony_ciformObserver.off('call', hostBundleName, callback); 1383e41f4b71Sopenharmony_ci``` 1384