• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.form.formProvider (formProvider) (System API)
2
3The **formProvider** module provides APIs to obtain widget information, update widgets, set the update time, and request a widget release.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8> This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.app.form.formProvider (formProvider)](./js-apis-app-form-formProvider.md).
9
10## Modules to Import
11
12```ts
13import { formProvider } from '@kit.FormKit';
14```
15
16
17## requestPublishForm
18
19requestPublishForm(want: Want, formBindingData: formBindingData.FormBindingData, callback: AsyncCallback\<string>): void
20
21Requests to publish a widget carrying data to the widget host (usually the home screen). This API uses an asynchronous callback to return the result.
22
23**System capability**: SystemCapability.Ability.Form
24
25**System API**: This is a system API.
26
27**Parameters**
28
29| Name| Type                                                                   | Mandatory| Description            |
30| ------ | ---------------------------------------------------------------------- | ---- | ---------------- |
31| want | [Want](../apis-ability-kit/js-apis-app-ability-want.md)                           | Yes  | Publish request, which must contain the following fields:<br>Information about the target widget.<br>**abilityName**: ability of the target widget.<br>**parameters**:<br>'ohos.extra.param.key.form_dimension'<br>'ohos.extra.param.key.form_name'<br>'ohos.extra.param.key.module_name' |
32| formBindingData | [formBindingData.FormBindingData](js-apis-app-form-formBindingData.md#formbindingdata) | Yes  | Data used for creating the widget.|
33| callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the widget ID.|
34
35**Error codes**
36
37For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Form Error Codes](errorcode-form.md).
38
39| Error Code ID| Error Message|
40| -------- | -------- |
41| 202 | The application is not a system application. |
42| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. |
43| 16500050 | IPC connection error. |
44| 16500100 | Failed to obtain the configuration information. |
45| 16501000 | An internal functional error occurred. |
46
47**Example**
48
49```ts
50import { formBindingData, formProvider } from '@kit.FormKit';
51import { Want } from '@kit.AbilityKit';
52import { BusinessError } from '@kit.BasicServicesKit';
53
54let want: Want = {
55  abilityName: 'FormAbility',
56  parameters: {
57    'ohos.extra.param.key.form_dimension': 2,
58    'ohos.extra.param.key.form_name': 'widget',
59    'ohos.extra.param.key.module_name': 'entry'
60  }
61};
62try {
63  let param: Record<string, string> = {
64    'temperature': '22c',
65    'time': '22:00'
66  }
67  let obj: formBindingData.FormBindingData = formBindingData.createFormBindingData(param);
68  formProvider.requestPublishForm(want, obj, (error: BusinessError, data: string) => {
69    if (error) {
70      console.error(`callback error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`);
71      return;
72    }
73    console.log(`formProvider requestPublishForm, form ID is: ${JSON.stringify(data)}`);
74  });
75} catch (error) {
76  console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`);
77}
78```
79
80## requestPublishForm
81
82requestPublishForm(want: Want, callback: AsyncCallback&lt;string&gt;): void
83
84Requests to publish a widget to the widget host (usually the home screen). This API uses an asynchronous callback to return the result.
85
86**System capability**: SystemCapability.Ability.Form
87
88**System API**: This is a system API.
89
90**Parameters**
91
92| Name  | Type                               | Mandatory| Description                                                        |
93| -------- | ----------------------------------- | ---- | ------------------------------------------------------------ |
94| want     | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes  | Publish request, which must contain the following fields:<br>Information about the target widget.<br>**abilityName**: ability of the target widget.<br>**parameters**:<br>'ohos.extra.param.key.form_dimension'<br>'ohos.extra.param.key.form_name'<br>'ohos.extra.param.key.module_name' |
95| callback | AsyncCallback&lt;string&gt;         | Yes  |  Callback used to return the widget ID.|
96
97**Error codes**
98
99For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Form Error Codes](errorcode-form.md).
100
101| Error Code ID| Error Message|
102| -------- | -------- |
103| 202 | The application is not a system application. |
104| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. |
105| 16500050 | IPC connection error. |
106| 16500100 | Failed to obtain the configuration information. |
107| 16501000 | An internal functional error occurred. |
108
109**Example**
110
111```ts
112import { formProvider } from '@kit.FormKit';
113import { Want } from '@kit.AbilityKit';
114import { BusinessError } from '@kit.BasicServicesKit';
115
116let want: Want = {
117  abilityName: 'FormAbility',
118  parameters: {
119    'ohos.extra.param.key.form_dimension': 2,
120    'ohos.extra.param.key.form_name': 'widget',
121    'ohos.extra.param.key.module_name': 'entry'
122  }
123};
124try {
125  formProvider.requestPublishForm(want, (error: BusinessError, data: string) => {
126    if (error) {
127      console.error(`callback error, code: ${error.code}, message: ${error.message})`);
128      return;
129    }
130    console.log(`formProvider requestPublishForm, form ID is: ${JSON.stringify(data)}`);
131  });
132} catch (error) {
133  console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`);
134}
135```
136
137## requestPublishForm
138
139requestPublishForm(want: Want, formBindingData?: formBindingData.FormBindingData): Promise&lt;string&gt;
140
141Requests to publish a widget to the widget host (usually the home screen). This API uses a promise to return the result.
142
143**System capability**: SystemCapability.Ability.Form
144
145**System API**: This is a system API.
146
147**Parameters**
148
149| Name         | Type                                                        | Mandatory| Description                                                        |
150| --------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
151| want            | [Want](../apis-ability-kit/js-apis-app-ability-want.md)                          | Yes  | Publish request, which must contain the following fields:<br>Information about the target widget.<br>**abilityName**: ability of the target widget.<br>**parameters**:<br>'ohos.extra.param.key.form_dimension'<br>'ohos.extra.param.key.form_name'<br>'ohos.extra.param.key.module_name' |
152| formBindingData | [formBindingData.FormBindingData](js-apis-app-form-formBindingData.md#formbindingdata) | No  | Data used for creating the widget. By default, no value is passed, indicating that no data is provided.                                     |
153
154**Return value**
155
156| Type         | Description                               |
157| :------------ | :---------------------------------- |
158| Promise&lt;string&gt; | Promise used to return the widget ID.|
159
160**Error codes**
161
162For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Form Error Codes](errorcode-form.md).
163
164| Error Code ID| Error Message|
165| -------- | -------- |
166| 202 | The application is not a system application. |
167| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. |
168| 16500050 | IPC connection error. |
169| 16500100 | Failed to obtain the configuration information. |
170| 16501000 | An internal functional error occurred. |
171
172**Example**
173
174```ts
175import { formProvider } from '@kit.FormKit';
176import { Want } from '@kit.AbilityKit';
177import { BusinessError } from '@kit.BasicServicesKit';
178
179let want: Want = {
180  abilityName: 'FormAbility',
181  parameters: {
182    'ohos.extra.param.key.form_dimension': 2,
183    'ohos.extra.param.key.form_name': 'widget',
184    'ohos.extra.param.key.module_name': 'entry'
185  }
186};
187try {
188  formProvider.requestPublishForm(want).then((data: string) => {
189    console.log(`formProvider requestPublishForm success, form ID is : ${JSON.stringify(data)}`);
190  }).catch((error: BusinessError) => {
191    console.error(`promise error, code: ${error.code}, message: ${error.message})`);
192  });
193} catch (error) {
194  console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`);
195}
196```
197
198## isRequestPublishFormSupported
199
200isRequestPublishFormSupported(callback: AsyncCallback&lt;boolean&gt;): void
201
202Checks whether a widget can be published to the widget host. This API uses an asynchronous callback to return the result.
203
204**System API**: This is a system API.
205
206**System capability**: SystemCapability.Ability.Form
207
208**Parameters**
209
210| Name| Type   | Mandatory| Description   |
211| ------ | ------ | ---- | ------- |
212| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback function that returns the query result.<br>**true**: The widget can be added to the widget host.<br>**false**: The widget cannot be added to the widget host.|
213
214**Error codes**
215
216For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Form Error Codes](errorcode-form.md).
217
218| Error Code ID| Error Message|
219| -------- | -------- |
220| 202 | The application is not a system application. |
221| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. |
222| 16500050 | IPC connection error. |
223| 16501000 | An internal functional error occurred. |
224
225**Example**
226
227```ts
228import { formProvider } from '@kit.FormKit';
229import { Want } from '@kit.AbilityKit';
230import { BusinessError } from '@kit.BasicServicesKit';
231
232try {
233  formProvider.isRequestPublishFormSupported((error: BusinessError, isSupported: boolean) => {
234    if (error) {
235      console.error(`callback error, code: ${error.code}, message: ${error.message})`);
236    } else {
237      if (isSupported) {
238        let want: Want = {
239          abilityName: 'FormAbility',
240          parameters: {
241            'ohos.extra.param.key.form_dimension': 2,
242            'ohos.extra.param.key.form_name': 'widget',
243            'ohos.extra.param.key.module_name': 'entry'
244          }
245        };
246        try {
247          formProvider.requestPublishForm(want, (error: BusinessError, data: string) => {
248            if (error) {
249              console.error(`callback error, code: ${error.code}, message: ${error.message})`);
250              return;
251            }
252            console.log(`formProvider requestPublishForm, form ID is: ${JSON.stringify(data)}`);
253          });
254        } catch (error) {
255          console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`);
256        }
257      }
258    }
259  });
260} catch (error) {
261  console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`);
262}
263```
264
265## isRequestPublishFormSupported
266
267isRequestPublishFormSupported(): Promise&lt;boolean&gt;
268
269Checks whether a widget can be published to the widget host. This API uses a promise to return the result.
270
271**System API**: This is a system API.
272
273**System capability**: SystemCapability.Ability.Form
274
275**Return value**
276
277| Type         | Description                               |
278| :------------ | :---------------------------------- |
279| Promise&lt;boolean&gt; | Promise that returns whether a widget can be added to the widget host.<br>**true**: The widget can be added to the widget host.<br>**false**: The widget cannot be added to the widget host.|
280
281**Error codes**
282
283For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Form Error Codes](errorcode-form.md).
284
285| Error Code ID| Error Message|
286| -------- | -------- |
287| 202 | The application is not a system application. |
288| 16500050 | IPC connection error. |
289| 16501000 | An internal functional error occurred. |
290
291**Example**
292
293```ts
294import { formProvider } from '@kit.FormKit';
295import { Want } from '@kit.AbilityKit';
296import { BusinessError } from '@kit.BasicServicesKit';
297
298try {
299  formProvider.isRequestPublishFormSupported().then((isSupported: boolean) => {
300    if (isSupported) {
301      let want: Want = {
302        abilityName: 'FormAbility',
303        parameters: {
304          'ohos.extra.param.key.form_dimension': 2,
305          'ohos.extra.param.key.form_name': 'widget',
306          'ohos.extra.param.key.module_name': 'entry'
307        }
308      };
309      try {
310        formProvider.requestPublishForm(want).then((data: string) => {
311          console.log(`formProvider requestPublishForm success, form ID is : ${JSON.stringify(data)}`);
312        }).catch((error: BusinessError) => {
313          console.error(`promise error, code: ${error.code}, message: ${error.message})`);
314        });
315      } catch (error) {
316        console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`);
317      }
318    }
319  }).catch((error: BusinessError) => {
320    console.error(`promise error, code: ${error.code}, message: ${error.message})`);
321  });
322} catch (error) {
323  console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`);
324}
325```
326
327## activateSceneAnimation<sup>20+</sup>
328
329activateSceneAnimation(formId: string): Promise&lt;void&gt;
330
331Requests to activate a widget. This API takes effect only for [scene-based widgets](../../form/arkts-ui-widget-configuration.md#sceneanimationparams-field). This API uses a promise to return the result. An interactive widget can be in the active or inactive state. In the inactive state, the widget is the same as a common widget. In the active state, the widget can start the **LiveFormExtensionAbility** process developed by the widget host to implement animations.
332
333**System capability**: SystemCapability.Ability.Form
334
335**System API**: This is a system API.
336
337**Parameters**
338
339| Name| Type   | Mandatory| Description   |
340| ------ | ------ | ---- |-------|
341| formId | string | Yes| Widget ID.|
342
343**Return value**
344
345| Type| Description|
346| -------- | -------- |
347| Promise&lt;void&gt; | Promise that returns no value.|
348
349**Error codes**
350
351For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Form Error Codes](errorcode-form.md).
352
353| Error Code ID| Error Message|
354| -------- | -------- |
355| 202 | The application is not a system application. |
356| 801 | Capability not supported.function activateSceneAnimation can not work correctly due to limited device capabilities. |
357| 16500050 | IPC connection error. |
358| 16500060 | Service connection error. |
359| 16500100 | Failed to obtain the configuration information. |
360| 16501000 | An internal functional error occurred. |
361| 16501001 | The ID of the form to be operated does not exist. |
362| 16501003 | The form cannot be operated by the current application. |
363| 16501011 | The form can not support this operation. |
364
365**Example**
366
367```ts
368import { formProvider } from '@kit.FormKit';
369import { BusinessError } from '@kit.BasicServicesKit';
370
371let formId: string = '12400633174999288';
372
373try {
374  formProvider.activateSceneAnimation(formId).then(() => {
375    console.info('activateSceneAnimation succeed.');
376  }).catch((error: BusinessError) => {
377    console.error(`promise error, code: ${error.code}, message: ${error.message})`);
378  });
379} catch (error) {
380  console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`);
381}
382```
383
384## deactivateSceneAnimation<sup>20+</sup>
385
386deactivateSceneAnimation(formId: string): Promise&lt;void&gt;
387
388Requests to deactivate a widget. This API takes effect only for [scene-based widgets](../../form/arkts-ui-widget-configuration.md#sceneanimationparams-field). This API uses a promise to return the result. An interactive widget can be in the active or inactive state. In the inactive state, the widget is the same as a common widget. In the active state, the widget can start the **LiveFormExtensionAbility** process developed by the widget host to implement animations.
389
390**System capability**: SystemCapability.Ability.Form
391
392**System API**: This is a system API.
393
394**Parameters**
395
396| Name| Type   | Mandatory| Description   |
397| ------ | ------ | ---- |-------|
398| formId | string | Yes| Widget ID.|
399
400**Return value**
401
402| Type| Description|
403| -------- | -------- |
404| Promise&lt;void&gt; | Promise that returns no value.|
405
406**Error codes**
407
408For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Form Error Codes](errorcode-form.md).
409
410| Error Code ID| Error Message|
411| -------- | -------- |
412| 202 | The application is not a system application. |
413| 801 | Capability not supported.function deactivateSceneAnimation can not work correctly due to limited device capabilities. |
414| 16500050 | IPC connection error. |
415| 16500060 | Service connection error. |
416| 16500100 | Failed to obtain the configuration information. |
417| 16501000 | An internal functional error occurred. |
418| 16501001 | The ID of the form to be operated does not exist. |
419| 16501003 | The form cannot be operated by the current application. |
420| 16501011 | The form can not support this operation. |
421
422**Example**
423
424```ts
425import { formProvider } from '@kit.FormKit';
426import { BusinessError } from '@kit.BasicServicesKit';
427
428let formId: string = '12400633174999288';
429
430try {
431  formProvider.deactivateSceneAnimation(formId).then(() => {
432    console.info('deactivateSceneAnimation succeed.');
433  }).catch((error: BusinessError) => {
434    console.error(`promise error, code: ${error.code}, message: ${error.message})`);
435  });
436} catch (error) {
437  console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`);
438}
439```
440