openharmony 鸿蒙 js-apis-application-formProvider

2025-06-12 浏览 (1)

@ohos.application.formProvider (formProvider)

The FormProvider module provides APIs related to the widget provider. You can use the APIs to update a widget, set the next refresh time for a widget, obtain widget information, and request a widget release.

NOTE

The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. This module is deprecated since API version 9. You are advised to use formProvider instead.

Modules to Import

import formProvider from '@ohos.application.formProvider';

formProvider.setFormNextRefreshTime

setFormNextRefreshTime(formId: string, minute: number, callback: AsyncCallback<void>): void

Sets the next refresh time for a widget. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Ability.Form

Parameters

NameTypeMandatoryDescription
formIdstringYesWidget ID.
minutenumberYesTime for the next refresh. The value must be greater than or equal to 5, in minutes.
callbackAsyncCallback<void>YesCallback used to return the result.

Example

import Base from '@ohos.base';
import formProvider from '@ohos.application.formProvider';

let formId: string = '12400633174999288';
formProvider.setFormNextRefreshTime(formId, 5, (error: Base.BusinessError) => {
  if (error.code) {
    console.error(`formProvider setFormNextRefreshTime, error: ${JSON.stringify(error)}`);
  }
});

formProvider.setFormNextRefreshTime

setFormNextRefreshTime(formId: string, minute: number): Promise<void>

Sets the next refresh time for a widget. This API uses a promise to return the result.

System capability: SystemCapability.Ability.Form

Parameters

NameTypeMandatoryDescription
formIdstringYesWidget ID.
minutenumberYesTime for the next refresh. The value must be greater than or equal to 5, in minutes.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Example

import Base from '@ohos.base';
import formProvider from '@ohos.application.formProvider';

let formId: string = '12400633174999288';
formProvider.setFormNextRefreshTime(formId, 5).then(() => {
  console.log('formProvider setFormNextRefreshTime success');
}).catch((error: Base.BusinessError) => {
  console.error(`formProvider setFormNextRefreshTime, error: ${JSON.stringify(error)}`);
});

formProvider.updateForm

updateForm(formId: string, formBindingData: formBindingData.FormBindingData,callback: AsyncCallback<void>): void

Updates a widget. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Ability.Form

Parameters

NameTypeMandatoryDescription
formIdstringYesID of the widget to update.
formBindingDataformBindingData.FormBindingDataYesData to be used for the update.
callbackAsyncCallback<void>YesCallback used to return the result.

Example

import Base from '@ohos.base';
import formBindingData from '@ohos.application.formBindingData';
import formProvider from '@ohos.application.formProvider';

let formId: string = '12400633174999288';
let param: Record<string, string> = {
  'temperature': '22c',
  'time': '22:00'
}
let obj: formBindingData.FormBindingData = formBindingData.createFormBindingData(param);
formProvider.updateForm(formId, obj, (error: Base.BusinessError) => {
  if (error.code) {
    console.error(`formProvider updateForm, error: ${JSON.stringify(error)}`);
  }
});

formProvider.updateForm

updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Promise<void>

Updates a widget. This API uses a promise to return the result.

System capability: SystemCapability.Ability.Form

Parameters

NameTypeMandatoryDescription
formIdstringYesID of the widget to update.
formBindingDataformBindingData.FormBindingDataYesData to be used for the update.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Example

import Base from '@ohos.base';
import formBindingData from '@ohos.application.formBindingData';
import formProvider from '@ohos.application.formProvider';

let formId: string = '12400633174999288';
let param: Record<string, string> = {
  'temperature': '22c',
  'time': '22:00'
}
let obj: formBindingData.FormBindingData = formBindingData.createFormBindingData(param);
formProvider.updateForm(formId, obj).then(() => {
  console.log('formProvider updateForm success');
}).catch((error: Base.BusinessError) => {
  console.error(`formProvider updateForm, error: ${JSON.stringify(error)}`);
});

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Form Kit

harmony 鸿蒙Form Error Codes

harmony 鸿蒙@ohos.app.form.formAgent (FormAgent) (System API)

harmony 鸿蒙@ohos.app.form.formBindingData (formBindingData)

harmony 鸿蒙@ohos.app.form.FormEditExtensionAbility (FormEditExtensionAbility)

harmony 鸿蒙@ohos.app.form.FormExtensionAbility (FormExtensionAbility) (System API)

harmony 鸿蒙@ohos.app.form.FormExtensionAbility (FormExtensionAbility)

harmony 鸿蒙@ohos.app.form.formHost (formHost) (System API)

harmony 鸿蒙@ohos.app.form.formInfo (formInfo) (System API)

harmony 鸿蒙@ohos.app.form.formInfo (formInfo)

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/wmjjeE