回复
鸿蒙原生应用/元服务开发-Stage模型能力接口(十)下
鸿蒙时代
发布于 2023-12-26 14:07
浏览
0收藏
@ohos.app.form.FormExtensionAbility (FormExtensionAbility)
系统能力:SystemCapability.Ability.Form
示例
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formBindingData from '@ohos.app.form.formBindingData';
import formProvider from '@ohos.app.form.formProvider';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onChangeFormVisibility(newStatus) {
console.log('FormExtensionAbility onChangeFormVisibility, newStatus: ${newStatus}');
let obj2 = formBindingData.createFormBindingData({
temperature: '22c',
time: '22:00'
});
for (let key in newStatuvalue= ${newStatus[key]}');
fs) {
console.log('FormExtensionAbility onChangeFormVisibility, key: ${key}, ormProvider.updateForm(key, obj2).then((data) => {
console.log('FormExtensionAbility context updateForm, data: ${data}');
}).catch((error) => {
console.error('Operation updateForm failed. Cause: ${error}');
});
}
}
};
onFormEvent
onFormEvent(formId: string, message: string): void
卡片提供方接收处理卡片事件的通知接口。
系统能力:SystemCapability.Ability.Form
示例:
export default class MyFormExtension extends FormExtensionAbility {
onFormEvent(formId, message) {
console.log('FormExtensionAbility onFormEvent, formId:' + formId + ', message:' + message);
}
}
onRemoveForm
onRemoveForm(formId: string): void
卡片提供方接收销毁卡片的通知接口。
系统能力:SystemCapability.Ability.Form
示例:
export default class MyFormExtensionAbility extends FormExtensionAbility {
onRemoveForm(formId) {
console.log('FormExtensionAbility onRemoveForm, formId:' + formId);
}
}
onConfigurationUpdate
onConfigurationUpdate(newConfig: Configuration): void;
当系统配置更新时调用。
系统能力:SystemCapability.Ability.Form
示例:
class MyFormExtensionAbility extends FormExtensionAbility {
onConfigurationUpdate(config) {
console.log('onConfigurationUpdate, config:' + JSON.stringify(config));
}
}
onAcquireFormState
onAcquireFormState?(want: Want): formInfo.FormState;
卡片提供方接收查询卡片状态通知接口。默认返回卡片初始状态。
系统能力:SystemCapability.Ability.Form
示例:
import formInfo from '@ohos.app.form.formInfo';
class MyFormExtensionAbility extends FormExtensionAbility {
onAcquireFormState(want) {
console.log('FormExtensionAbility onAcquireFormState, want:' + want);
return formInfo.FormState.UNKNOWN;
}
}
本文根据HarmonyOS官方开发文档整理
分类
标签
赞
收藏
回复
相关推荐