From c51121dd0370a800e7e5ce8ef939255da84c42e3 Mon Sep 17 00:00:00 2001 From: yangzk Date: Mon, 26 Dec 2022 17:50:23 +0800 Subject: [PATCH] =?UTF-8?q?IssueNo:=20#I67IH1=20Description:=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96formExtensionContext=E5=8F=82=E8=80=83=E6=96=87?= =?UTF-8?q?=E6=A1=A3=20Sig:=20SIG=5FApplicationFramework=20Feature=20or=20?= =?UTF-8?q?Bugfix:=20Feature=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangzk Change-Id: I613f37477a4b364f466c2d59eee15062f0b842ee --- ...-inner-application-formExtensionContext.md | 107 ++++++++++-------- 1 file changed, 60 insertions(+), 47 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-inner-application-formExtensionContext.md b/zh-cn/application-dev/reference/apis/js-apis-inner-application-formExtensionContext.md index 5e0784c672..17779dc827 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inner-application-formExtensionContext.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inner-application-formExtensionContext.md @@ -1,8 +1,8 @@ # FormExtensionContext -FormExtensionContext模块是FormExtension的上下文环境,继承自ExtensionContext。 +FormExtensionContext模块是FormExtensionAbility的上下文环境,继承自ExtensionContext。 -FormExtensionContext模块提供FormExtension具有的接口和能力。 +FormExtensionContext模块提供FormExtensionAbility具有的接口和能力。 > **说明:** > @@ -11,23 +11,24 @@ FormExtensionContext模块提供FormExtension具有的接口和能力。 ## 使用说明 -在使用FormExtensionContext的功能前,需要通过FormExtension获取。 +在使用FormExtensionContext的功能前,需要通过FormExtensionAbility获取。 ```ts import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; import formBindingData from '@ohos.app.form.formBindingData'; + export default class MyFormExtensionAbility extends FormExtensionAbility { - onAddForm() { - let formContext = this.context; // 获取FormExtensionContext - // ... - let dataObj1 = { - temperature:"11c", - "time":"11:00" - }; - let obj1 = formBindingData.createFormBindingData(dataObj1); - return obj1; - } -} + onAddForm(want) { + let formContext = this.context; // 获取FormExtensionContext + // ... + let dataObj1 = { + temperature: "11c", + "time": "11:00" + }; + let obj1 = formBindingData.createFormBindingData(dataObj1); + return obj1; + } +}; ``` ## startAbility @@ -50,23 +51,29 @@ startAbility(want: Want, callback: AsyncCallback<void>): void **示例:** ```ts -var want = { - deviceId: "", - bundleName: "com.example.formstartability", - abilityName: "MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: {} -} -this.context.startAbility(want, (error, data) => { - if (error) { - console.log('FormExtensionContext startAbility, error:' + JSON.stringify(error)); - } else { - console.log(`FormExtensionContext startAbility success`); - } -}) +import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; + +export default class MyFormExtensionAbility extends FormExtensionAbility { + onFormEvent(formId, message) { + // 当触发卡片message事件时,执行startAbility + console.log('FormExtensionAbility onFormEvent, formId:' + formId + ", message:" + message); + let want = { + deviceId: "", + bundleName: "com.example.formstartability", + abilityName: "MainAbility", + parameters: { + "message": message + } + }; + this.context.startAbility(want, (error, data) => { + if (error) { + console.log('FormExtensionContext startAbility, error:' + JSON.stringify(error)); + } else { + console.log('FormExtensionContext startAbility success'); + } + }); + } +}; ``` ## startAbility @@ -89,24 +96,30 @@ startAbility(want: Want): Promise<void> | 类型 | 说明 | | ------------ | ---------------------------------- | -| Promise<void< | 无返回结果的Promise对象。 | +| Promise<void> | 无返回结果的Promise对象。 | **示例:** ```ts -var want = { - deviceId: "", - bundleName: "com.example.formstartability", - abilityName: "MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: {} -} -this.context.startAbility(want).then(() => { - console.info("StartAbility Success"); -}).catch((error) => { - console.info("StartAbility failed"); -}); +import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; + +export default class MyFormExtensionAbility extends FormExtensionAbility { + onFormEvent(formId, message) { + // 当触发卡片message事件时,执行startAbility + console.log('FormExtensionAbility onFormEvent, formId:' + formId + ", message:" + message); + let want = { + deviceId: "", + bundleName: "com.example.formstartability", + abilityName: "MainAbility", + parameters: { + "message": message + } + }; + this.context.startAbility(want).then(() => { + console.info("StartAbility Success"); + }).catch((error) => { + console.info("StartAbility failed"); + }); + } +}; ``` \ No newline at end of file -- GitLab