harmony(鸿蒙)FormProvider

2022-08-09 浏览 (691)

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.

Modules to Import

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

Required Permissions

None.

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
formIdstringYesID of a widget.
minutenumberYesRefresh interval, in minutes. The value must be greater than or equal to 5.
callbackAsyncCallback<void>YesCallback used to return the result.

Example

var formId = "12400633174999288";
formProvider.setFormNextRefreshTime(formId, 5, (error, data) => {
    if (error.code) {
        console.log('formProvider setFormNextRefreshTime, error:' + JSON.stringify(error));
    }
});

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
formIdstringYesID of a widget.
minutenumberYesRefresh interval, in minutes. The value must be greater than or equal to 5.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Example

var formId = "12400633174999288";
formProvider.setFormNextRefreshTime(formId, 5).then(() => {
    console.log('formProvider setFormNextRefreshTime success');
}).catch((error) => {
    console.log('formProvider setFormNextRefreshTime, error:' + JSON.stringify(error));
});

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.
formBindingDataFormBindingDataYesData to be used for the update.
callbackAsyncCallback<void>YesCallback used to return the result.

Example

import formBindingData from '@ohos.application.formBindingData';
var formId = "12400633174999288";
let obj = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
formProvider.updateForm(formId, obj, (error, data) => {
    if (error.code) {
        console.log('formProvider updateForm, error:' + JSON.stringify(error));
    }
});

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.
formBindingDataFormBindingDataYesData to be used for the update.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Example

import formBindingData from '@ohos.application.formBindingData';
var formId = "12400633174999288";
let obj = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
formProvider.updateForm(formId, obj).then(() => {
    console.log('formProvider updateForm success');
}).catch((error) => {
    console.log('formProvider updateForm, error:' + JSON.stringify(error));
});

getFormsInfo9+

getFormsInfo(callback: AsyncCallback<Array<formInfo.FormInfo>>): void;

Obtains the application's widget information on the device. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Ability.Form

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<Array<FormInfo>>YesCallback used to return the widget information.

Example

formProvider.getFormsInfo((error, data) => {
    if (error.code) {
        console.log('formProvider getFormsInfo, error:' + JSON.stringify(error));
    } else {
        console.log('formProvider getFormsInfo, data:' + JSON.stringify(data));
    }
});

getFormsInfo9+

getFormsInfo(filter: formInfo.FormInfoFilter, callback: AsyncCallback<Array<formInfo.FormInfo>>): void;

Obtains the application's widget information that meets a filter criterion on the device. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Ability.Form

Parameters

NameTypeMandatoryDescription
filterformInfo.FormInfoFilterYesFilter criterion.
callbackAsyncCallback<Array<FormInfo>>YesCallback used to return the widget information.

Example

import formInfo from '@ohos.application.formInfo';
const filter : formInfo.FormInfoFilter = {
    moduleName : "entry"
};
formProvider.getFormsInfo(filter, (error, data) => {
    if (error.code) {
        console.log('formProvider getFormsInfo, error:' + JSON.stringify(error));
    } else {
        console.log('formProvider getFormsInfo, data:' + JSON.stringify(data));
    }
});

getFormsInfo9+

getFormsInfo(filter?: formInfo.FormInfoFilter): Promise<Array<formInfo.FormInfo>>;

Obtains the application's widget information on the device. This API uses a promise to return the result.

System capability: SystemCapability.Ability.Form

Parameters

NameTypeMandatoryDescription
filterformInfo.FormInfoFilterNoFilter criterion.

Return value

TypeDescription
Promise<Array<FormInfo>>Promise used to return the widget information.

Example

import formInfo from '@ohos.application.formInfo';
const filter : formInfo.FormInfoFilter = {
    moduleName : "entry"
};
formProvider.getFormsInfo(filter).then((data) => {
    console.log('formProvider getFormsInfo, data:' + JSON.stringify(data));
}).catch((error) => {
    console.log('formProvider getFormsInfo, error:' + JSON.stringify(error));
});

requestPublishForm9+

requestPublishForm(want: Want, formBindingData: formBindingData.FormBindingData, callback: AsyncCallback<string>): void;

Requests to publish a widget carrying data to the widget host. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Ability.Form

System API: This is a system API and cannot be called by third-party applications.

Parameters

NameTypeMandatoryDescription
wantWantYesInformation about the target widget.
abilityName: ability of the target widget.
parameters:
"ohos.extra.param.key.form_dimension"
"ohos.extra.param.key.form_name"
"ohos.extra.param.key.module_name"
formBindingDataFormBindingDataYesData used for creating the widget.
callbackAsyncCallback<string>YesCallback used to return the widget ID.

Example

import formBindingData from '@ohos.application.formBindingData';
var want = {
    abilityName: "FormAbility",
    parameters: {
        "ohos.extra.param.key.form_dimension": 2,
        "ohos.extra.param.key.form_name": "widget",
        "ohos.extra.param.key.module_name": "entry"
    }
};
let obj = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
formProvider.requestPublishForm(want, obj, (error, data) => {
    if (error.code) {
        console.log('formProvider requestPublishForm, error: ' + JSON.stringify(error));
    } else {
        console.log('formProvider requestPublishForm, form ID is: ' + JSON.stringify(data));
    }
});

requestPublishForm9+

requestPublishForm(want: Want, callback: AsyncCallback<string>): void;

Requests to publish a widget to the widget host. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Ability.Form

System API: This is a system API and cannot be called by third-party applications.

Parameters

NameTypeMandatoryDescription
wantWantYesInformation about the target widget.
abilityName: ability of the target widget.
parameters:
"ohos.extra.param.key.form_dimension"
"ohos.extra.param.key.form_name"
"ohos.extra.param.key.module_name"
callbackAsyncCallback<string>YesCallback used to return the widget ID.

Example

var want = {
    abilityName: "FormAbility",
    parameters: {
        "ohos.extra.param.key.form_dimension": 2,
        "ohos.extra.param.key.form_name": "widget",
        "ohos.extra.param.key.module_name": "entry"
    }
};
formProvider.requestPublishForm(want, (error, data) => {
    if (error.code) {
        console.log('formProvider requestPublishForm, error: ' + JSON.stringify(error));
    } else {
        console.log('formProvider requestPublishForm, form ID is: ' + JSON.stringify(data));
    }
});

requestPublishForm9+

requestPublishForm(want: Want, formBindingData?: formBindingData.FormBindingData): Promise<string>;

Requests to publish a widget to the widget host. This API uses a promise to return the result.

System capability: SystemCapability.Ability.Form

System API: This is a system API and cannot be called by third-party applications.

Parameters

NameTypeMandatoryDescription
wantWantYesInformation about the target widget.
abilityName: ability of the target widget.
parameters:
"ohos.extra.param.key.form_dimension"
"ohos.extra.param.key.form_name"
"ohos.extra.param.key.module_name"
formBindingDataFormBindingDataNoData used for creating the widget.

Return value

TypeDescription
Promise<string>Promise used to return the widget ID.

Example

var want = {
    abilityName: "FormAbility",
    parameters: {
        "ohos.extra.param.key.form_dimension": 2,
        "ohos.extra.param.key.form_name": "widget",
        "ohos.extra.param.key.module_name": "entry"
    }
};
formProvider.requestPublishForm(want).then((data) => {
    console.log('formProvider requestPublishForm success, form ID is :' + JSON.stringify(data));
}).catch((error) => {
    console.log('formProvider requestPublishForm, error: ' + JSON.stringify(error));
});

isRequestPublishFormSupported9+

isRequestPublishFormSupported(callback: AsyncCallback<boolean>): void;

Checks whether a widget can be published to the widget host. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Ability.Form

System API: This is a system API and cannot be called by third-party applications.

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<boolean>YesCallback used to return the result.

Example

formProvider.isRequestPublishFormSupported((error, isSupported) => {
  if (error.code) {
    console.log('formProvider isRequestPublishFormSupported, error:' + JSON.stringify(error));
  } else {
    if (isSupported) {
      var want = {
      abilityName: "FormAbility",
      parameters: {
        "ohos.extra.param.key.form_dimension": 2,
        "ohos.extra.param.key.form_name": "widget",
        "ohos.extra.param.key.module_name": "entry"
      }
      };
      formProvider.requestPublishForm(want, (error, data) => {
        if (error.code) {
          console.log('formProvider requestPublishForm, error: ' + JSON.stringify(error));
        } else {
          console.log('formProvider requestPublishForm, form ID is: ' + JSON.stringify(data));
        }
      });
    }
  }
});

isRequestPublishFormSupported9+

isRequestPublishFormSupported(): Promise<boolean>;

Checks whether a widget can be published to the widget host. This API uses a promise to return the result.

System capability: SystemCapability.Ability.Form

System API: This is a system API and cannot be called by third-party applications.

Return value

TypeDescription
Promise<boolean>Promise used to return the result.

Example

formProvider.isRequestPublishFormSupported().then((isSupported) => {
  if (isSupported) {
    var want = {
    abilityName: "FormAbility",
    parameters: {
        "ohos.extra.param.key.form_dimension": 2,
        "ohos.extra.param.key.form_name": "widget",
        "ohos.extra.param.key.module_name": "entry"
    }
    };
    formProvider.requestPublishForm(want).then((data) => {
      console.log('formProvider requestPublishForm success, form ID is :' + JSON.stringify(data));
    }).catch((error) => {
      console.log('formProvider requestPublishForm, error: ' + JSON.stringify(error));
    });
  }
}).catch((error) => {
  console.log('formProvider isRequestPublishFormSupported, error:' + JSON.stringify(error));
});

你可能感兴趣的鸿蒙文章

harmony(鸿蒙)APIs

harmony(鸿蒙)API Reference Document Description

harmony(鸿蒙)BundleStatusCallback

harmony(鸿蒙)innerBundleManager(deprecated)

harmony(鸿蒙)distributedBundle

harmony(鸿蒙)Bundle

harmony(鸿蒙)Context

harmony(鸿蒙)DataUriUtils

harmony(鸿蒙)EnterpriseAdminExtensionAbility

harmony(鸿蒙)Work Scheduler Callbacks

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