HarmonyOS/OpenHarmony应用开发-Stage模型ArkTS语言FormExtensio

鸿蒙时代
发布于 2023-4-25 10:51
浏览
0收藏

HarmonyOS/OpenHarmony应用开发-Stage模型ArkTS语言FormExtensio-鸿蒙开发者社区
接口示例:

import formInfo from '@ohos.app.form.formInfo';
import formBindingData from '@ohos.app.form.formBindingData';
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formProvider from '@ohos.app.form.formProvider';

export default class formExtensionAbility extends FormExtensionAbility {
  onAddForm(want) {
    //卡片提供方接收创建卡片的通知接口。
    console.log('FormExtensionAbility onAddForm, want:' + want.abilityName);
    let dataObj1 = {
      name:"张三",
    };
    let obj1 = formBindingData.createFormBindingData(dataObj1);
    return obj1;
  }

  onCastToNormalForm(formId) {
    //卡片提供方接收临时卡片转常态卡片的通知接口。
    console.log('FormExtensionAbility onCastToNormalForm, formId:' + formId);
  }

  onUpdateForm(formId) {
    //卡片提供方接收临时卡片转常态卡片的通知接口。
    console.log('FormExtensionAbility onUpdateForm, formId:' + formId);
    let obj2 = formBindingData.createFormBindingData({
      title: "张三",
    });
    formProvider.updateForm(formId, obj2).then((data) => {
      console.log('FormExtensionAbility context updateForm, data:' + data);
    }).catch((error) => {
      console.error('Operation updateForm failed. Cause: ' + error);
    });
  }

  onChangeFormVisibility(newStatus) {
    //卡片提供方接收临时卡片转常态卡片的通知接口。
    console.log('FormExtensionAbility onChangeFormVisibility, newStatus:' + newStatus);
    let obj2 = formBindingData.createFormBindingData({
      temperature: "22c",
      time: "22:00"
    });

    for (let key in newStatus) {
      console.log('FormExtensionAbility onChangeFormVisibility, key:' + key + ", value=" + newStatus[key]);
      formProvider.updateForm(key, obj2).then((data) => {
        console.log('FormExtensionAbility context updateForm, data:' + data);
      }).catch((error) => {
        console.error('Operation updateForm failed. Cause: ' + error);
      });
    }
  }

  onFormEvent(formId, message) {
    //卡片提供方接收处理卡片事件的通知接口。
    console.log('FormExtensionAbility onFormEvent, formId:' + formId + ", message:" + message);
  }

  onRemoveForm(formId) {
    //卡片提供方接收销毁卡片的通知接口。
    console.log('FormExtensionAbility onRemoveForm, formId:' + formId);
  }

  onConfigurationUpdate(config) {
    //当系统配置更新时调用。
    console.log('onConfigurationUpdate, config:' + JSON.stringify(config));
  }

  onAcquireFormState(want) {
    //卡片提供方接收查询卡片状态通知接口。默认返回卡片初始状态。
    console.log('FormExtensionAbility onAcquireFormState, want:' + want);
    return formInfo.FormState.UNKNOWN;
  }
}

标签
HarmonyOSOpenHarmony应用开发-stage模型Ar.docx 21.9K 16次下载
收藏
回复
举报
回复
    相关推荐