提交 399aa740 编写于 作者: X xuzhihao

Bugfix: 示例代码arkTs整改

Signed-off-by: Nxuzhihao <xuzhihao16@huawei.com>
上级 5c46bbab
...@@ -42,21 +42,18 @@ On the widget page, the **postCardAction** API can be used to trigger a message ...@@ -42,21 +42,18 @@ On the widget page, the **postCardAction** API can be used to trigger a message
import formProvider from '@ohos.app.form.formProvider'; import formProvider from '@ohos.app.form.formProvider';
export default class EntryFormAbility extends FormExtensionAbility { export default class EntryFormAbility extends FormExtensionAbility {
onFormEvent(formId, message) { onFormEvent(formId: string, message: string) {
// Called when a specified message event defined by the form provider is triggered. // Called when a specified message event defined by the form provider is triggered.
console.info(`FormAbility onEvent, formId = ${formId}, message: ${JSON.stringify(message)}`); console.info(`FormAbility onEvent, formId = ${formId}, message: ${JSON.stringify(message)}`);
let formData = { let formData = new Map<Object, string>();
'title':'Title Update Success.', // Matches the widget layout. formData.set('title', 'Title Update.'); // It matches the widget layout.
'detail':'Detail Update Success.', // Matches the widget layout. formData.set('detail', 'Description update success.'); // It matches the widget layout.
};
let formInfo = formBindingData.createFormBindingData(formData) let formInfo = formBindingData.createFormBindingData(formData)
formProvider.updateForm(formId, formInfo).then((data) => { formProvider.updateForm(formId, formInfo).then((data) => {
console.info('FormAbility updateForm success.' + JSON.stringify(data)); console.info('FormAbility updateForm success.' + JSON.stringify(data));
}).catch((error) => {
console.error('FormAbility updateForm failed: ' + JSON.stringify(error));
}) })
} }
... ...
} }
``` ```
......
...@@ -66,11 +66,14 @@ import fs from '@ohos.file.fs'; ...@@ -66,11 +66,14 @@ import fs from '@ohos.file.fs';
try { try {
let fd = fs.openSync('/path/to/form.png'); let fd = fs.openSync('/path/to/form.png');
let obj = {
'temperature': '21°', let createFormBindingDataParam = new Map<Object, string | object>()
'formImages': { 'image': fd } let formImagesParam = new Map<Object, object>()
}; formImagesParam.set('image', fd)
formBindingData.createFormBindingData(obj); createFormBindingDataParam.set("name", '21°')
createFormBindingDataParam.set('formImages', formImagesParam)
formBindingData.createFormBindingData(createFormBindingDataParam);
} catch (error) { } catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`); console.error(`catch error, code: ${error.code}, message: ${error.message}`);
} }
......
...@@ -50,18 +50,24 @@ Displays a notification. ...@@ -50,18 +50,24 @@ Displays a notification.
| options | ShowNotificationOptions | No| Notification title.| | options | ShowNotificationOptions | No| Notification title.|
**Example** **Example**
```javascript ```ts
export default { class NotificationClass {
show() { show: Function
notification.show({ }
contentTitle: 'title info',
contentText: 'text', let notificationObj: NotificationClass = {
clickAction: { show() {
bundleName: 'com.example.testapp', notification.show({
abilityName: 'notificationDemo', contentTitle: 'title info',
uri: '/path/to/notification' contentText: 'text',
} clickAction: {
}); bundleName: 'com.example.testapp',
} abilityName: 'notificationDemo',
uri: '/path/to/notification'
}
});
}
} }
export default notificationObj
``` ```
...@@ -45,21 +45,18 @@ ...@@ -45,21 +45,18 @@
import formProvider from '@ohos.app.form.formProvider'; import formProvider from '@ohos.app.form.formProvider';
export default class EntryFormAbility extends FormExtensionAbility { export default class EntryFormAbility extends FormExtensionAbility {
onFormEvent(formId, message) { onFormEvent(formId: string, message: string) {
// Called when a specified message event defined by the form provider is triggered. // Called when a specified message event defined by the form provider is triggered.
console.info(`FormAbility onEvent, formId = ${formId}, message: ${JSON.stringify(message)}`); console.info(`FormAbility onEvent, formId = ${formId}, message: ${JSON.stringify(message)}`);
let formData = { let formData = new Map<Object, string>();
'title': 'Title Update.', // 和卡片布局中对应 formData.set('title', 'Title Update.'); // 和卡片布局中对应
'detail': 'Description update success.', // 和卡片布局中对应 formData.set('detail', 'Description update success.'); // 和卡片布局中对应
};
let formInfo = formBindingData.createFormBindingData(formData) let formInfo = formBindingData.createFormBindingData(formData)
formProvider.updateForm(formId, formInfo).then((data) => { formProvider.updateForm(formId, formInfo).then((data) => {
console.info('FormAbility updateForm success.' + JSON.stringify(data)); console.info('FormAbility updateForm success.' + JSON.stringify(data));
}).catch((error) => {
console.error('FormAbility updateForm failed: ' + JSON.stringify(error));
}) })
} }
... ...
} }
``` ```
......
...@@ -66,12 +66,17 @@ import fs from '@ohos.file.fs'; ...@@ -66,12 +66,17 @@ import fs from '@ohos.file.fs';
try { try {
let fd = fs.openSync('/path/to/form.png'); let fd = fs.openSync('/path/to/form.png');
let obj = {
'temperature': '21°', let createFormBindingDataParam = new Map<Object, string | object>()
'formImages': { 'image': fd } let formImagesParam = new Map<Object, object>()
}; formImagesParam.set('image', fd)
formBindingData.createFormBindingData(obj); createFormBindingDataParam.set("name", '21°')
createFormBindingDataParam.set('formImages', formImagesParam)
formBindingData.createFormBindingData(createFormBindingDataParam);
} catch (error) { } catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`); let code = (error as Base.BusinessError).code;
let message = (error as Base.BusinessError).message;
console.error(`catch error, code: ${code}, message: ${message}`);
} }
``` ```
\ No newline at end of file
...@@ -46,18 +46,19 @@ onAddForm(want: Want): formBindingData.FormBindingData ...@@ -46,18 +46,19 @@ onAddForm(want: Want): formBindingData.FormBindingData
```ts ```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formBindingData from '@ohos.app.form.formBindingData'; import formBindingData from '@ohos.app.form.formBindingData';
import Want from '@ohos.app.ability.Want';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onAddForm(want) { onAddForm(want: Want) {
console.log(`FormExtensionAbility onAddForm, want: ${want.abilityName}`); console.log(`FormExtensionAbility onAddForm, want: ${want.abilityName}`);
let dataObj1 = { let dataObj1 = new Map<Object, string>();
temperature: '11c', dataObj1.set('temperature', '11c');
'time': '11:00' dataObj1.set('time', '11:00');
};
let obj1 = formBindingData.createFormBindingData(dataObj1); let obj1 = formBindingData.createFormBindingData(dataObj1);
return obj1; return obj1;
} }
}; }
``` ```
## onCastToNormalForm ## onCastToNormalForm
...@@ -80,7 +81,7 @@ onCastToNormalForm(formId: string): void ...@@ -80,7 +81,7 @@ onCastToNormalForm(formId: string): void
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onCastToNormalForm(formId) { onCastToNormalForm(formId: string) {
console.log(`FormExtensionAbility onCastToNormalForm, formId: ${formId}`); console.log(`FormExtensionAbility onCastToNormalForm, formId: ${formId}`);
} }
}; };
...@@ -108,16 +109,18 @@ import formBindingData from '@ohos.app.form.formBindingData'; ...@@ -108,16 +109,18 @@ import formBindingData from '@ohos.app.form.formBindingData';
import formProvider from '@ohos.app.form.formProvider'; import formProvider from '@ohos.app.form.formProvider';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onUpdateForm(formId) { onUpdateForm(formId: string) {
console.log(`FormExtensionAbility onUpdateForm, formId: ${formId}`); console.log(`FormExtensionAbility onUpdateForm, formId: ${formId}`);
class createFormBindingDataParam {
temperature: string
time: string
}
let obj2 = formBindingData.createFormBindingData({ let obj2 = formBindingData.createFormBindingData({
temperature: '22c', temperature: '22c',
time: '22:00' time: '22:00'
}); } as createFormBindingDataParam);
formProvider.updateForm(formId, obj2).then((data) => { formProvider.updateForm(formId, obj2).then((data) => {
console.log(`FormExtensionAbility context updateForm, data: ${data}`); console.log(`FormExtensionAbility context updateForm, data: ${data}`);
}).catch((error) => {
console.error(`Operation updateForm failed. Cause: ${error}`);
}); });
} }
}; };
...@@ -144,13 +147,24 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; ...@@ -144,13 +147,24 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formBindingData from '@ohos.app.form.formBindingData'; import formBindingData from '@ohos.app.form.formBindingData';
import formProvider from '@ohos.app.form.formProvider'; import formProvider from '@ohos.app.form.formProvider';
// 由于arkTs中无Object.keys,且无法使用for..in...
// 若报arkTs问题,请将此方法单独抽离至一个ts文件中并暴露,在需要用到的ets文件中引入使用
function getObjKeys(obj: Object): string[] {
let keys = Object.keys(obj);
return keys;
}
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onChangeFormVisibility(newStatus) { onChangeFormVisibility(newStatus) {
console.log(`FormExtensionAbility onChangeFormVisibility, newStatus: ${newStatus}`); console.log(`FormExtensionAbility onChangeFormVisibility, newStatus: ${newStatus}`);
class createFormBindingDataParam {
temperature: string
time: string
}
let obj2 = formBindingData.createFormBindingData({ let obj2 = formBindingData.createFormBindingData({
temperature: '22c', temperature: '22c',
time: '22:00' time: '22:00'
}); } as createFormBindingDataParam);
for (let key in newStatus) { for (let key in newStatus) {
console.log(`FormExtensionAbility onChangeFormVisibility, key: ${key}, value= ${newStatus[key]}`); console.log(`FormExtensionAbility onChangeFormVisibility, key: ${key}, value= ${newStatus[key]}`);
...@@ -185,7 +199,7 @@ onFormEvent(formId: string, message: string): void ...@@ -185,7 +199,7 @@ onFormEvent(formId: string, message: string): void
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onFormEvent(formId, message) { onFormEvent(formId: string, message: string) {
console.log(`FormExtensionAbility onFormEvent, formId: ${formId}, message: ${message}`); console.log(`FormExtensionAbility onFormEvent, formId: ${formId}, message: ${message}`);
} }
}; };
...@@ -211,7 +225,7 @@ onRemoveForm(formId: string): void ...@@ -211,7 +225,7 @@ onRemoveForm(formId: string): void
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onRemoveForm(formId) { onRemoveForm(formId: string) {
console.log(`FormExtensionAbility onRemoveForm, formId: ${formId}`); console.log(`FormExtensionAbility onRemoveForm, formId: ${formId}`);
} }
}; };
...@@ -235,9 +249,10 @@ onConfigurationUpdate(newConfig: Configuration): void; ...@@ -235,9 +249,10 @@ onConfigurationUpdate(newConfig: Configuration): void;
```ts ```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import { Configuration } from '@ohos.app.ability.Configuration';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onConfigurationUpdate(config) { onConfigurationUpdate(config: Configuration) {
console.log(`onConfigurationUpdate, config: ${JSON.stringify(config)}`); console.log(`onConfigurationUpdate, config: ${JSON.stringify(config)}`);
} }
}; };
...@@ -262,9 +277,10 @@ onAcquireFormState?(want: Want): formInfo.FormState; ...@@ -262,9 +277,10 @@ onAcquireFormState?(want: Want): formInfo.FormState;
```ts ```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formInfo from '@ohos.app.form.formInfo'; import formInfo from '@ohos.app.form.formInfo';
import Want from '@ohos.app.ability.Want';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onAcquireFormState(want) { onAcquireFormState(want: Want) {
console.log(`FormExtensionAbility onAcquireFormState, want: ${want}`); console.log(`FormExtensionAbility onAcquireFormState, want: ${want}`);
return formInfo.FormState.UNKNOWN; return formInfo.FormState.UNKNOWN;
} }
...@@ -299,11 +315,11 @@ onShareForm?(formId: string): { [key: string]: Object } ...@@ -299,11 +315,11 @@ onShareForm?(formId: string): { [key: string]: Object }
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onShareForm(formId) { onShareForm(formId: string) {
console.log(`FormExtensionAbility onShareForm, formId: ${formId}`); console.log(`FormExtensionAbility onShareForm, formId: ${formId}`);
let wantParams = { let wantParams = {
'temperature': '20', 'temperature': '20',
'time': '2022-8-8 09:59', 'time': '2022-8-8 09:59',s
}; };
return wantParams; return wantParams;
} }
...@@ -338,7 +354,7 @@ onAcquireFormData?(formId: string): { [key: string]: Object } ...@@ -338,7 +354,7 @@ onAcquireFormData?(formId: string): { [key: string]: Object }
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onAcquireFormData(formId) { onAcquireFormData(formId: string) {
console.log('FormExtensionAbility onAcquireFormData, formId: ${formId}'); console.log('FormExtensionAbility onAcquireFormData, formId: ${formId}');
let wantParams = { let wantParams = {
'temperature': '20', 'temperature': '20',
......
...@@ -9,6 +9,7 @@ FormProvider模块提供了卡片提供方相关接口的能力,开发者在 ...@@ -9,6 +9,7 @@ FormProvider模块提供了卡片提供方相关接口的能力,开发者在
```ts ```ts
import formProvider from '@ohos.app.form.formProvider'; import formProvider from '@ohos.app.form.formProvider';
import Base from '@ohos.base';
``` ```
## setFormNextRefreshTime ## setFormNextRefreshTime
...@@ -45,9 +46,9 @@ setFormNextRefreshTime(formId: string, minute: number, callback: AsyncCallback&l ...@@ -45,9 +46,9 @@ setFormNextRefreshTime(formId: string, minute: number, callback: AsyncCallback&l
**示例:** **示例:**
```ts ```ts
let formId = '12400633174999288'; let formId: string = '12400633174999288';
try { try {
formProvider.setFormNextRefreshTime(formId, 5, (error) => { formProvider.setFormNextRefreshTime(formId, 5, (error: Base.BusinessError) => {
if (error) { if (error) {
console.error(`callback error, code: ${error.code}, message: ${error.message})`); console.error(`callback error, code: ${error.code}, message: ${error.message})`);
return; return;
...@@ -98,11 +99,11 @@ setFormNextRefreshTime(formId: string, minute: number): Promise&lt;void&gt; ...@@ -98,11 +99,11 @@ setFormNextRefreshTime(formId: string, minute: number): Promise&lt;void&gt;
**示例:** **示例:**
```ts ```ts
let formId = '12400633174999288'; let formId: string = '12400633174999288';
try { try {
formProvider.setFormNextRefreshTime(formId, 5).then(() => { formProvider.setFormNextRefreshTime(formId, 5).then(() => {
console.log(`formProvider setFormNextRefreshTime success`); console.log(`formProvider setFormNextRefreshTime success`);
}).catch((error) => { }).catch((error: Base.BusinessError) => {
console.error(`promise error, code: ${error.code}, message: ${error.message})`); console.error(`promise error, code: ${error.code}, message: ${error.message})`);
}); });
} catch (error) { } catch (error) {
...@@ -145,10 +146,18 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData,call ...@@ -145,10 +146,18 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData,call
```ts ```ts
import formBindingData from '@ohos.app.form.formBindingData'; import formBindingData from '@ohos.app.form.formBindingData';
let formId = '12400633174999288'; let formId: string = '12400633174999288';
try { try {
let obj = formBindingData.createFormBindingData({temperature:'22c', time:'22:00'}); class createFormBindingDataParamType {
formProvider.updateForm(formId, obj, (error) => { temperature: string
time: string
}
let createFormBindingDataParam: createFormBindingDataParamType = {
temperature:'22c',
time:'22:00'
};
let obj = formBindingData.createFormBindingData(createFormBindingDataParam);
formProvider.updateForm(formId, obj, (error: Base.BusinessError) => {
if (error) { if (error) {
console.error(`callback error, code: ${error.code}, message: ${error.message})`); console.error(`callback error, code: ${error.code}, message: ${error.message})`);
return; return;
...@@ -200,12 +209,20 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Pr ...@@ -200,12 +209,20 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Pr
```ts ```ts
import formBindingData from '@ohos.app.form.formBindingData'; import formBindingData from '@ohos.app.form.formBindingData';
let formId = '12400633174999288'; let formId: string = '12400633174999288';
let obj = formBindingData.createFormBindingData({ temperature: '22c', time: '22:00' }); class createFormBindingDataParamType {
temperature: string
time: string
}
let createFormBindingDataParam: createFormBindingDataParamType = {
temperature:'22c',
time:'22:00'
};
let obj = formBindingData.createFormBindingData(createFormBindingDataParam);
try { try {
formProvider.updateForm(formId, obj).then(() => { formProvider.updateForm(formId, obj).then(() => {
console.log(`formProvider updateForm success`); console.log(`formProvider updateForm success`);
}).catch((error) => { }).catch((error: Base.BusinessError) => {
console.error(`promise error, code: ${error.code}, message: ${error.message})`); console.error(`promise error, code: ${error.code}, message: ${error.message})`);
}); });
} catch (error) { } catch (error) {
...@@ -247,7 +264,7 @@ try { ...@@ -247,7 +264,7 @@ try {
console.error(`callback error, code: ${error.code}, message: ${error.message})`); console.error(`callback error, code: ${error.code}, message: ${error.message})`);
return; return;
} }
console.log('formProvider getFormsInfo, data: ${JSON.stringify(data)}'); console.log(`formProvider getFormsInfo, data: ${JSON.stringify(data)}`);
}); });
} catch (error) { } catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message})`); console.error(`catch error, code: ${error.code}, message: ${error.message})`);
...@@ -294,7 +311,7 @@ try { ...@@ -294,7 +311,7 @@ try {
console.error(`callback error, code: ${error.code}, message: ${error.message})`); console.error(`callback error, code: ${error.code}, message: ${error.message})`);
return; return;
} }
console.log('formProvider getFormsInfo, data: ${JSON.stringify(data)}'); console.log(`formProvider getFormsInfo, data: ${JSON.stringify(data)}`);
}); });
} catch (error) { } catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message})`); console.error(`catch error, code: ${error.code}, message: ${error.message})`);
...@@ -342,9 +359,9 @@ const filter: formInfo.FormInfoFilter = { ...@@ -342,9 +359,9 @@ const filter: formInfo.FormInfoFilter = {
moduleName: 'entry' moduleName: 'entry'
}; };
try { try {
formProvider.getFormsInfo(filter).then((data) => { formProvider.getFormsInfo(filter).then((data: formInfo.FormInfo[]) => {
console.log('formProvider getFormsInfo, data: ${JSON.stringify(data)}'); console.log(`formProvider getFormsInfo, data: ${JSON.stringify(data)}`);
}).catch((error) => { }).catch((error: Base.BusinessError) => {
console.error(`promise error, code: ${error.code}, message: ${error.message})`); console.error(`promise error, code: ${error.code}, message: ${error.message})`);
}); });
} catch (error) { } catch (error) {
...@@ -386,8 +403,9 @@ requestPublishForm(want: Want, formBindingData: formBindingData.FormBindingData, ...@@ -386,8 +403,9 @@ requestPublishForm(want: Want, formBindingData: formBindingData.FormBindingData,
```ts ```ts
import formBindingData from '@ohos.app.form.formBindingData'; import formBindingData from '@ohos.app.form.formBindingData';
import Want from '@ohos.app.ability.Want';
let want = { let want: Want = {
abilityName: 'FormAbility', abilityName: 'FormAbility',
parameters: { parameters: {
'ohos.extra.param.key.form_dimension': 2, 'ohos.extra.param.key.form_dimension': 2,
...@@ -396,8 +414,16 @@ let want = { ...@@ -396,8 +414,16 @@ let want = {
} }
}; };
try { try {
let obj = formBindingData.createFormBindingData({ temperature: '22c', time: '22:00' }); class createFormBindingDataParamType {
formProvider.requestPublishForm(want, obj, (error, data) => { temperature: string
time: string
}
let createFormBindingDataParam: createFormBindingDataParamType = {
temperature:'22c',
time:'22:00'
};
let obj = formBindingData.createFormBindingData(createFormBindingDataParam);
formProvider.requestPublishForm(want, obj, (error: Base.BusinessError, data: string) => {
if (error) { if (error) {
console.error(`callback error, code: ${error.code}, message: ${error.message})`); console.error(`callback error, code: ${error.code}, message: ${error.message})`);
return; return;
...@@ -441,7 +467,9 @@ requestPublishForm(want: Want, callback: AsyncCallback&lt;string&gt;): void ...@@ -441,7 +467,9 @@ requestPublishForm(want: Want, callback: AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```ts ```ts
let want = { import Want from '@ohos.app.ability.Want';
let want: Want = {
abilityName: 'FormAbility', abilityName: 'FormAbility',
parameters: { parameters: {
'ohos.extra.param.key.form_dimension': 2, 'ohos.extra.param.key.form_dimension': 2,
...@@ -450,12 +478,12 @@ let want = { ...@@ -450,12 +478,12 @@ let want = {
} }
}; };
try { try {
formProvider.requestPublishForm(want, (error, data) => { formProvider.requestPublishForm(want, (error: Base.BusinessError, data: string) => {
if (error) { if (error) {
console.error(`callback error, code: ${error.code}, message: ${error.message})`); console.error(`callback error, code: ${error.code}, message: ${error.message})`);
return; return;
} }
console.log('formProvider requestPublishForm, form ID is: ${JSON.stringify(data)}'); console.log(`formProvider requestPublishForm, form ID is: ${JSON.stringify(data)}`);
}); });
} catch (error) { } catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message})`); console.error(`catch error, code: ${error.code}, message: ${error.message})`);
...@@ -500,7 +528,9 @@ requestPublishForm(want: Want, formBindingData?: formBindingData.FormBindingData ...@@ -500,7 +528,9 @@ requestPublishForm(want: Want, formBindingData?: formBindingData.FormBindingData
**示例:** **示例:**
```ts ```ts
let want = { import Want from '@ohos.app.ability.Want';
let want: Want = {
abilityName: 'FormAbility', abilityName: 'FormAbility',
parameters: { parameters: {
'ohos.extra.param.key.form_dimension': 2, 'ohos.extra.param.key.form_dimension': 2,
...@@ -509,9 +539,9 @@ let want = { ...@@ -509,9 +539,9 @@ let want = {
} }
}; };
try { try {
formProvider.requestPublishForm(want).then((data) => { formProvider.requestPublishForm(want).then((data: string) => {
console.log('formProvider requestPublishForm success, form ID is : ${JSON.stringify(data)}'); console.log(`formProvider requestPublishForm success, form ID is : ${JSON.stringify(data)}`);
}).catch((error) => { }).catch((error: Base.BusinessError) => {
console.error(`promise error, code: ${error.code}, message: ${error.message})`); console.error(`promise error, code: ${error.code}, message: ${error.message})`);
}); });
} catch (error) { } catch (error) {
...@@ -549,13 +579,15 @@ isRequestPublishFormSupported(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -549,13 +579,15 @@ isRequestPublishFormSupported(callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```ts ```ts
import Want from '@ohos.app.ability.Want';
try { try {
formProvider.isRequestPublishFormSupported((error, isSupported) => { formProvider.isRequestPublishFormSupported((error: Base.BusinessError, isSupported: boolean) => {
if (error) { if (error) {
console.error(`callback error, code: ${error.code}, message: ${error.message})`); console.error(`callback error, code: ${error.code}, message: ${error.message})`);
} else { } else {
if (isSupported) { if (isSupported) {
var want = { let want: Want = {
abilityName: 'FormAbility', abilityName: 'FormAbility',
parameters: { parameters: {
'ohos.extra.param.key.form_dimension': 2, 'ohos.extra.param.key.form_dimension': 2,
...@@ -564,12 +596,12 @@ try { ...@@ -564,12 +596,12 @@ try {
} }
}; };
try { try {
formProvider.requestPublishForm(want, (error, data) => { formProvider.requestPublishForm(want, (error: Base.BusinessError, data: string) => {
if (error) { if (error) {
console.error(`callback error, code: ${error.code}, message: ${error.message})`); console.error(`callback error, code: ${error.code}, message: ${error.message})`);
return; return;
} }
console.log('formProvider requestPublishForm, form ID is: ${JSON.stringify(data)}'); console.log(`formProvider requestPublishForm, form ID is: ${JSON.stringify(data)}`);
}); });
} catch (error) { } catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message})`); console.error(`catch error, code: ${error.code}, message: ${error.message})`);
...@@ -611,10 +643,12 @@ isRequestPublishFormSupported(): Promise&lt;boolean&gt; ...@@ -611,10 +643,12 @@ isRequestPublishFormSupported(): Promise&lt;boolean&gt;
**示例:** **示例:**
```ts ```ts
import Want from '@ohos.app.ability.Want';
try { try {
formProvider.isRequestPublishFormSupported().then((isSupported) => { formProvider.isRequestPublishFormSupported().then((isSupported: boolean) => {
if (isSupported) { if (isSupported) {
var want = { let want: Want = {
abilityName: 'FormAbility', abilityName: 'FormAbility',
parameters: { parameters: {
'ohos.extra.param.key.form_dimension': 2, 'ohos.extra.param.key.form_dimension': 2,
...@@ -623,16 +657,16 @@ try { ...@@ -623,16 +657,16 @@ try {
} }
}; };
try { try {
formProvider.requestPublishForm(want).then((data) => { formProvider.requestPublishForm(want).then((data: string) => {
console.log('formProvider requestPublishForm success, form ID is : ${JSON.stringify(data)}'); console.log(`formProvider requestPublishForm success, form ID is : ${JSON.stringify(data)}`);
}).catch((error) => { }).catch((error: Base.BusinessError) => {
console.error(`promise error, code: ${error.code}, message: ${error.message})`); console.error(`promise error, code: ${error.code}, message: ${error.message})`);
}); });
} catch (error) { } catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message})`); console.error(`catch error, code: ${error.code}, message: ${error.message})`);
} }
} }
}).catch((error) => { }).catch((error: Base.BusinessError) => {
console.error(`promise error, code: ${error.code}, message: ${error.message})`); console.error(`promise error, code: ${error.code}, message: ${error.message})`);
}); });
} catch (error) { } catch (error) {
......
...@@ -53,11 +53,13 @@ import fs from '@ohos.file.fs'; ...@@ -53,11 +53,13 @@ import fs from '@ohos.file.fs';
try { try {
let fd = fs.openSync('/path/to/form.png'); let fd = fs.openSync('/path/to/form.png');
let obj = { let createFormBindingDataParam = new Map<Object, string | object>();
'temperature': '21°', let formImagesParam = new Map<Object, object>();
'formImages': { 'image': fd } formImagesParam.set('image', fd);
}; createFormBindingDataParam.set("name", '21°');
formBindingData.createFormBindingData(obj); createFormBindingDataParam.set('formImages', formImagesParam);
formBindingData.createFormBindingData(createFormBindingDataParam);
} catch (error) { } catch (error) {
console.error('catch error, error: ${JSON.stringify(error)}'); console.error('catch error, error: ${JSON.stringify(error)}');
} }
......
...@@ -12,6 +12,7 @@ formHost模块提供了卡片使用方相关接口的能力,包括对使用方 ...@@ -12,6 +12,7 @@ formHost模块提供了卡片使用方相关接口的能力,包括对使用方
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
import Base from '@ohos.base';
``` ```
## deleteForm ## deleteForm
...@@ -36,7 +37,7 @@ deleteForm(formId: string, callback: AsyncCallback&lt;void&gt;): void ...@@ -36,7 +37,7 @@ deleteForm(formId: string, callback: AsyncCallback&lt;void&gt;): void
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formId = '12400633174999288'; let formId: string = '12400633174999288';
formHost.deleteForm(formId, (error, data) => { formHost.deleteForm(formId, (error, data) => {
if (error.code) { if (error.code) {
console.error('formHost deleteForm, error: ${JSON.stringify(error)}'); console.error('formHost deleteForm, error: ${JSON.stringify(error)}');
...@@ -71,10 +72,10 @@ deleteForm(formId: string): Promise&lt;void&gt; ...@@ -71,10 +72,10 @@ deleteForm(formId: string): Promise&lt;void&gt;
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formId = '12400633174999288'; let formId: string = '12400633174999288';
formHost.deleteForm(formId).then(() => { formHost.deleteForm(formId).then(() => {
console.log('formHost deleteForm success'); console.log('formHost deleteForm success');
}).catch((error) => { }).catch((error: Base.BusinessError) => {
console.error('formHost deleteForm, error: ${JSON.stringify(error)}'); console.error('formHost deleteForm, error: ${JSON.stringify(error)}');
}); });
``` ```
...@@ -101,8 +102,8 @@ releaseForm(formId: string, callback: AsyncCallback&lt;void&gt;): void ...@@ -101,8 +102,8 @@ releaseForm(formId: string, callback: AsyncCallback&lt;void&gt;): void
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formId = '12400633174999288'; let formId: string = '12400633174999288';
formHost.releaseForm(formId, (error, data) => { formHost.releaseForm(formId, (error: Base.BusinessError) => {
if (error.code) { if (error.code) {
console.error('formHost releaseForm, error: ${JSON.stringify(error)}'); console.error('formHost releaseForm, error: ${JSON.stringify(error)}');
} else { } else {
...@@ -134,8 +135,8 @@ releaseForm(formId: string, isReleaseCache: boolean, callback: AsyncCallback&lt; ...@@ -134,8 +135,8 @@ releaseForm(formId: string, isReleaseCache: boolean, callback: AsyncCallback&lt;
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formId = '12400633174999288'; let formId: string = '12400633174999288';
formHost.releaseForm(formId, true, (error, data) => { formHost.releaseForm(formId, true, (error: Base.BusinessError) => {
if (error.code) { if (error.code) {
console.error('formHost releaseForm, error: ${JSON.stringify(error)}'); console.error('formHost releaseForm, error: ${JSON.stringify(error)}');
} else { } else {
...@@ -172,10 +173,10 @@ releaseForm(formId: string, isReleaseCache?: boolean): Promise&lt;void&gt; ...@@ -172,10 +173,10 @@ releaseForm(formId: string, isReleaseCache?: boolean): Promise&lt;void&gt;
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formId = '12400633174999288'; let formId: string = '12400633174999288';
formHost.releaseForm(formId, true).then(() => { formHost.releaseForm(formId, true).then(() => {
console.log('formHost releaseForm success'); console.log('formHost releaseForm success');
}).catch((error) => { }).catch((error: Base.BusinessError) => {
console.error('formHost releaseForm, error: ${JSON.stringify(error)}'); console.error('formHost releaseForm, error: ${JSON.stringify(error)}');
}); });
``` ```
...@@ -202,8 +203,8 @@ requestForm(formId: string, callback: AsyncCallback&lt;void&gt;): void ...@@ -202,8 +203,8 @@ requestForm(formId: string, callback: AsyncCallback&lt;void&gt;): void
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formId = '12400633174999288'; let formId: string = '12400633174999288';
formHost.requestForm(formId, (error, data) => { formHost.requestForm(formId, (error: Base.BusinessError) => {
if (error.code) { if (error.code) {
console.error('formHost requestForm, error: ${JSON.stringify(error)}'); console.error('formHost requestForm, error: ${JSON.stringify(error)}');
} }
...@@ -237,10 +238,10 @@ requestForm(formId: string): Promise&lt;void&gt; ...@@ -237,10 +238,10 @@ requestForm(formId: string): Promise&lt;void&gt;
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formId = '12400633174999288'; let formId: string = '12400633174999288';
formHost.requestForm(formId).then(() => { formHost.requestForm(formId).then(() => {
console.log('formHost requestForm success'); console.log('formHost requestForm success');
}).catch((error) => { }).catch((error: Base.BusinessError) => {
console.error('formHost requestForm, error: ${JSON.stringify(error)}'); console.error('formHost requestForm, error: ${JSON.stringify(error)}');
}); });
``` ```
...@@ -267,8 +268,8 @@ castTempForm(formId: string, callback: AsyncCallback&lt;void&gt;): void ...@@ -267,8 +268,8 @@ castTempForm(formId: string, callback: AsyncCallback&lt;void&gt;): void
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formId = '12400633174999288'; let formId: string = '12400633174999288';
formHost.castTempForm(formId, (error, data) => { formHost.castTempForm(formId, (error: Base.BusinessError) => {
if (error.code) { if (error.code) {
console.error('formHost castTempForm, error: ${JSON.stringify(error)}'); console.error('formHost castTempForm, error: ${JSON.stringify(error)}');
} }
...@@ -302,10 +303,10 @@ castTempForm(formId: string): Promise&lt;void&gt; ...@@ -302,10 +303,10 @@ castTempForm(formId: string): Promise&lt;void&gt;
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formId = '12400633174999288'; let formId: string = '12400633174999288';
formHost.castTempForm(formId).then(() => { formHost.castTempForm(formId).then(() => {
console.log('formHost castTempForm success'); console.log('formHost castTempForm success');
}).catch((error) => { }).catch((error: Base.BusinessError) => {
console.error('formHost castTempForm, error: ${JSON.stringify(error)}'); console.error('formHost castTempForm, error: ${JSON.stringify(error)}');
}); });
``` ```
...@@ -332,8 +333,8 @@ notifyVisibleForms(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;void ...@@ -332,8 +333,8 @@ notifyVisibleForms(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;void
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formId = ['12400633174999288']; let formId: string[] = ['12400633174999288'];
formHost.notifyVisibleForms(formId, (error, data) => { formHost.notifyVisibleForms(formId, (error: Base.BusinessError) => {
if (error.code) { if (error.code) {
console.error('formHost notifyVisibleForms, error: ${JSON.stringify(error)}'); console.error('formHost notifyVisibleForms, error: ${JSON.stringify(error)}');
} }
...@@ -367,10 +368,10 @@ notifyVisibleForms(formIds: Array&lt;string&gt;): Promise&lt;void&gt; ...@@ -367,10 +368,10 @@ notifyVisibleForms(formIds: Array&lt;string&gt;): Promise&lt;void&gt;
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formId = ['12400633174999288']; let formId: string[] = ['12400633174999288'];
formHost.notifyVisibleForms(formId).then(() => { formHost.notifyVisibleForms(formId).then(() => {
console.log('formHost notifyVisibleForms success'); console.log('formHost notifyVisibleForms success');
}).catch((error) => { }).catch((error: Base.BusinessError) => {
console.error('formHost notifyVisibleForms, error: ${JSON.stringify(error)}'); console.error('formHost notifyVisibleForms, error: ${JSON.stringify(error)}');
}); });
``` ```
...@@ -397,8 +398,8 @@ notifyInvisibleForms(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;vo ...@@ -397,8 +398,8 @@ notifyInvisibleForms(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;vo
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formId = ['12400633174999288']; let formId: string[] = ['12400633174999288'];
formHost.notifyInvisibleForms(formId, (error, data) => { formHost.notifyInvisibleForms(formId, (error: Base.BusinessError) => {
if (error.code) { if (error.code) {
console.error('formHost notifyInvisibleForms, error: ${JSON.stringify(error)}'); console.error('formHost notifyInvisibleForms, error: ${JSON.stringify(error)}');
} }
...@@ -432,10 +433,10 @@ notifyInvisibleForms(formIds: Array&lt;string&gt;): Promise&lt;void&gt; ...@@ -432,10 +433,10 @@ notifyInvisibleForms(formIds: Array&lt;string&gt;): Promise&lt;void&gt;
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formId = ['12400633174999288']; let formId: string[] = ['12400633174999288'];
formHost.notifyInvisibleForms(formId).then(() => { formHost.notifyInvisibleForms(formId).then(() => {
console.log('formHost notifyInvisibleForms success'); console.log('formHost notifyInvisibleForms success');
}).catch((error) => { }).catch((error: Base.BusinessError) => {
console.error('formHost notifyInvisibleForms, error: ${JSON.stringify(error)}'); console.error('formHost notifyInvisibleForms, error: ${JSON.stringify(error)}');
}); });
``` ```
...@@ -462,8 +463,8 @@ enableFormsUpdate(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;void& ...@@ -462,8 +463,8 @@ enableFormsUpdate(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;void&
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formId = ['12400633174999288']; let formId: string[] = ['12400633174999288'];
formHost.enableFormsUpdate(formId, (error, data) => { formHost.enableFormsUpdate(formId, (error: Base.BusinessError) => {
if (error.code) { if (error.code) {
console.error('formHost enableFormsUpdate, error: ${JSON.stringify(error)}'); console.error('formHost enableFormsUpdate, error: ${JSON.stringify(error)}');
} }
...@@ -497,10 +498,10 @@ enableFormsUpdate(formIds: Array&lt;string&gt;): Promise&lt;void&gt; ...@@ -497,10 +498,10 @@ enableFormsUpdate(formIds: Array&lt;string&gt;): Promise&lt;void&gt;
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formId = ['12400633174999288']; let formId: string[] = ['12400633174999288'];
formHost.enableFormsUpdate(formId).then(() => { formHost.enableFormsUpdate(formId).then(() => {
console.log('formHost enableFormsUpdate success'); console.log('formHost enableFormsUpdate success');
}).catch((error) => { }).catch((error: Base.BusinessError) => {
console.error('formHost enableFormsUpdate, error: ${JSON.stringify(error)}'); console.error('formHost enableFormsUpdate, error: ${JSON.stringify(error)}');
}); });
``` ```
...@@ -527,8 +528,8 @@ disableFormsUpdate(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;void ...@@ -527,8 +528,8 @@ disableFormsUpdate(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;void
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formId = ['12400633174999288']; let formId: string[] = ['12400633174999288'];
formHost.disableFormsUpdate(formId, (error, data) => { formHost.disableFormsUpdate(formId, (error: Base.BusinessError) => {
if (error.code) { if (error.code) {
console.error('formHost disableFormsUpdate, error: ${JSON.stringify(error)}'); console.error('formHost disableFormsUpdate, error: ${JSON.stringify(error)}');
} }
...@@ -562,10 +563,10 @@ disableFormsUpdate(formIds: Array&lt;string&gt;): Promise&lt;void&gt; ...@@ -562,10 +563,10 @@ disableFormsUpdate(formIds: Array&lt;string&gt;): Promise&lt;void&gt;
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formId = ['12400633174999288']; let formId: string[] = ['12400633174999288'];
formHost.disableFormsUpdate(formId).then(() => { formHost.disableFormsUpdate(formId).then(() => {
console.log('formHost disableFormsUpdate success'); console.log('formHost disableFormsUpdate success');
}).catch((error) => { }).catch((error: Base.BusinessError) => {
console.error('formHost disableFormsUpdate, error: ${JSON.stringify(error)}'); console.error('formHost disableFormsUpdate, error: ${JSON.stringify(error)}');
}); });
``` ```
...@@ -589,8 +590,8 @@ isSystemReady(callback: AsyncCallback&lt;void&gt;): void ...@@ -589,8 +590,8 @@ isSystemReady(callback: AsyncCallback&lt;void&gt;): void
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formId = '12400633174999288'; let formId: string = '12400633174999288';
formHost.isSystemReady((error, data) => { formHost.isSystemReady((error: Base.BusinessError) => {
if (error.code) { if (error.code) {
console.error('formHost isSystemReady, error: ${JSON.stringify(error)}'); console.error('formHost isSystemReady, error: ${JSON.stringify(error)}');
} }
...@@ -616,10 +617,10 @@ isSystemReady(): Promise&lt;void&gt; ...@@ -616,10 +617,10 @@ isSystemReady(): Promise&lt;void&gt;
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formId = '12400633174999288'; let formId: string = '12400633174999288';
formHost.isSystemReady().then(() => { formHost.isSystemReady().then(() => {
console.log('formHost isSystemReady success'); console.log('formHost isSystemReady success');
}).catch((error) => { }).catch((error: Base.BusinessError) => {
console.error('formHost isSystemReady, error: ${JSON.stringify(error)}'); console.error('formHost isSystemReady, error: ${JSON.stringify(error)}');
}); });
``` ```
...@@ -644,8 +645,9 @@ getAllFormsInfo(callback: AsyncCallback&lt;Array&lt;formInfo.FormInfo&gt;&gt;): ...@@ -644,8 +645,9 @@ getAllFormsInfo(callback: AsyncCallback&lt;Array&lt;formInfo.FormInfo&gt;&gt;):
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
import formInfo from '@ohos.app.form.formInfo';
formHost.getAllFormsInfo((error, data) => { formHost.getAllFormsInfo((error: Base.BusinessError, data: formInfo.FormInfo[]) => {
if (error.code) { if (error.code) {
console.error('formHost getAllFormsInfo, error: ${JSON.stringify(error)}'); console.error('formHost getAllFormsInfo, error: ${JSON.stringify(error)}');
} else { } else {
...@@ -674,10 +676,11 @@ getAllFormsInfo(): Promise&lt;Array&lt;formInfo.FormInfo&gt;&gt; ...@@ -674,10 +676,11 @@ getAllFormsInfo(): Promise&lt;Array&lt;formInfo.FormInfo&gt;&gt;
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
import formInfo from '@ohos.app.form.formInfo';
formHost.getAllFormsInfo().then((data) => { formHost.getAllFormsInfo().then((data: formInfo.FormInfo[]) => {
console.log('formHost getAllFormsInfo data: ${JSON.stringify(data)}'); console.log('formHost getAllFormsInfo data: ${JSON.stringify(data)}');
}).catch((error) => { }).catch((error: Base.BusinessError) => {
console.error('formHost getAllFormsInfo, error: ${JSON.stringify(error)}'); console.error('formHost getAllFormsInfo, error: ${JSON.stringify(error)}');
}); });
``` ```
...@@ -703,12 +706,13 @@ getFormsInfo(bundleName: string, callback: AsyncCallback&lt;Array&lt;formInfo.Fo ...@@ -703,12 +706,13 @@ getFormsInfo(bundleName: string, callback: AsyncCallback&lt;Array&lt;formInfo.Fo
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
import formInfo from '@ohos.app.form.formInfo';
formHost.getFormsInfo('com.example.ohos.formjsdemo', (error, data) => { formHost.getFormsInfo('com.example.ohos.formjsdemo', (error: Base.BusinessError, data: formInfo.FormInfo[]) => {
if (error.code) { if (error.code) {
console.error('formHost getFormsInfo, error: ${JSON.stringify(error)}'); console.error(`formHost getFormsInfo, error: ${JSON.stringify(error)}`);
} else { } else {
console.log('formHost getFormsInfo, data: ${JSON.stringify(data)}'); console.log(`formHost getFormsInfo, data: ${JSON.stringify(data)}`);
} }
}); });
``` ```
...@@ -735,8 +739,9 @@ getFormsInfo(bundleName: string, moduleName: string, callback: AsyncCallback&lt; ...@@ -735,8 +739,9 @@ getFormsInfo(bundleName: string, moduleName: string, callback: AsyncCallback&lt;
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
import formInfo from '@ohos.app.form.formInfo';
formHost.getFormsInfo('com.example.ohos.formjsdemo', 'entry', (error, data) => { formHost.getFormsInfo('com.example.ohos.formjsdemo', 'entry', (error: Base.BusinessError, data: formInfo.FormInfo[]) => {
if (error.code) { if (error.code) {
console.error('formHost getFormsInfo, error: ${JSON.stringify(error)}'); console.error('formHost getFormsInfo, error: ${JSON.stringify(error)}');
} else { } else {
...@@ -773,10 +778,10 @@ getFormsInfo(bundleName: string, moduleName?: string): Promise&lt;Array&lt;formI ...@@ -773,10 +778,10 @@ getFormsInfo(bundleName: string, moduleName?: string): Promise&lt;Array&lt;formI
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
formHost.getFormsInfo('com.example.ohos.formjsdemo', 'entry').then((data) => { formHost.getFormsInfo('com.example.ohos.formjsdemo', 'entry').then((data: formInfo.FormInfo[]) => {
console.log('formHost getFormsInfo, data: ${JSON.stringify(data)}'); console.log(`formHost getFormsInfo, data: ${JSON.stringify(data)}`);
}).catch((error) => { }).catch((error: Base.BusinessError) => {
console.error('formHost getFormsInfo, error: ${JSON.stringify(error)}'); console.error(`formHost getFormsInfo, error: ${JSON.stringify(error)}`);
}); });
``` ```
...@@ -802,12 +807,12 @@ deleteInvalidForms(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;numb ...@@ -802,12 +807,12 @@ deleteInvalidForms(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;numb
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formIds = new Array('12400633174999288', '12400633174999289'); let formIds: string[] = new Array('12400633174999288', '12400633174999289');
formHost.deleteInvalidForms(formIds, (error, data) => { formHost.deleteInvalidForms(formIds, (error: Base.BusinessError, data: number) => {
if (error.code) { if (error.code) {
console.error('formHost deleteInvalidForms, error: ${JSON.stringify(error)}'); console.error(`formHost deleteInvalidForms, error: ${JSON.stringify(error)}`);
} else { } else {
console.log('formHost deleteInvalidForms, data: ${JSON.stringify(data)}'); console.log(`formHost deleteInvalidForms, data: ${JSON.stringify(data)}`);
} }
}); });
``` ```
...@@ -839,11 +844,11 @@ deleteInvalidForms(formIds: Array&lt;string&gt;): Promise&lt;number&gt; ...@@ -839,11 +844,11 @@ deleteInvalidForms(formIds: Array&lt;string&gt;): Promise&lt;number&gt;
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formIds = new Array('12400633174999288', '12400633174999289'); let formIds: string[] = new Array('12400633174999288', '12400633174999289');
formHost.deleteInvalidForms(formIds).then((data) => { formHost.deleteInvalidForms(formIds).then((data: number) => {
console.log('formHost deleteInvalidForms, data: ${JSON.stringify(data)}'); console.log(`formHost deleteInvalidForms, data: ${JSON.stringify(data)}`);
}).catch((error) => { }).catch((error: Base.BusinessError) => {
console.error('formHost deleteInvalidForms, error: ${JSON.stringify(error)}'); console.error(`formHost deleteInvalidForms, error: ${JSON.stringify(error)}`);
}); });
``` ```
...@@ -868,8 +873,10 @@ acquireFormState(want: Want, callback: AsyncCallback&lt;formInfo.FormStateInfo&g ...@@ -868,8 +873,10 @@ acquireFormState(want: Want, callback: AsyncCallback&lt;formInfo.FormStateInfo&g
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
import Want from '@ohos.app.ability.Want';
import formInfo from '@ohos.app.form.formInfo';
let want = { let want: Want = {
'deviceId': '', 'deviceId': '',
'bundleName': 'ohos.samples.FormApplication', 'bundleName': 'ohos.samples.FormApplication',
'abilityName': 'FormAbility', 'abilityName': 'FormAbility',
...@@ -879,11 +886,11 @@ let want = { ...@@ -879,11 +886,11 @@ let want = {
'ohos.extra.param.key.form_dimension': 2 'ohos.extra.param.key.form_dimension': 2
} }
}; };
formHost.acquireFormState(want, (error, data) => { formHost.acquireFormState(want, (error:Base.BusinessError, data: formInfo.FormStateInfo) => {
if (error.code) { if (error.code) {
console.error('formHost acquireFormState, error: ${JSON.stringify(error)}'); console.error(`formHost acquireFormState, error: ${JSON.stringify(error)}`);
} else { } else {
console.log('formHost acquireFormState, data: ${JSON.stringify(data)}'); console.log(`formHost acquireFormState, data: ${JSON.stringify(data)}`);
} }
}); });
``` ```
...@@ -914,8 +921,10 @@ acquireFormState(want: Want): Promise&lt;formInfo.FormStateInfo&gt; ...@@ -914,8 +921,10 @@ acquireFormState(want: Want): Promise&lt;formInfo.FormStateInfo&gt;
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
import Want from '@ohos.app.ability.Want';
import formInfo from '@ohos.app.form.formInfo';
let want = { let want: Want = {
'deviceId': '', 'deviceId': '',
'bundleName': 'ohos.samples.FormApplication', 'bundleName': 'ohos.samples.FormApplication',
'abilityName': 'FormAbility', 'abilityName': 'FormAbility',
...@@ -925,10 +934,10 @@ let want = { ...@@ -925,10 +934,10 @@ let want = {
'ohos.extra.param.key.form_dimension': 2 'ohos.extra.param.key.form_dimension': 2
} }
}; };
formHost.acquireFormState(want).then((data) => { formHost.acquireFormState(want).then((data: formInfo.FormStateInfo) => {
console.log('formHost acquireFormState, data: ${JSON.stringify(data)}'); console.log(`formHost acquireFormState, data: ${JSON.stringify(data)}`);
}).catch((error) => { }).catch((error: Base.BusinessError) => {
console.error('formHost acquireFormState, error: ${JSON.stringify(error)}'); console.error(`formHost acquireFormState, error: ${JSON.stringify(error)}`);
}); });
``` ```
...@@ -952,10 +961,9 @@ on(type: 'formUninstall', callback: Callback&lt;string&gt;): void ...@@ -952,10 +961,9 @@ on(type: 'formUninstall', callback: Callback&lt;string&gt;): void
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let callback = function(formId) { formHost.on('formUninstall', (formId: string) => {
console.log('formHost on formUninstall, formId: ${formId}'); console.log(`formHost on formUninstall, formId: ${formId}`);
}; });
formHost.on('formUninstall', callback);
``` ```
## off('formUninstall') ## off('formUninstall')
...@@ -978,10 +986,9 @@ off(type: 'formUninstall', callback?: Callback&lt;string&gt;): void ...@@ -978,10 +986,9 @@ off(type: 'formUninstall', callback?: Callback&lt;string&gt;): void
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let callback = function(formId) { formHost.off('formUninstall', (formId: string) => {
console.log('formHost on formUninstall, formId: ${formId}'); console.log(`formHost on formUninstall, formId: ${formId}`);
}; });
formHost.off('formUninstall', callback);
``` ```
## notifyFormsVisible ## notifyFormsVisible
...@@ -1007,10 +1014,10 @@ notifyFormsVisible(formIds: Array&lt;string&gt;, isVisible: boolean, callback: A ...@@ -1007,10 +1014,10 @@ notifyFormsVisible(formIds: Array&lt;string&gt;, isVisible: boolean, callback: A
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formIds = new Array('12400633174999288', '12400633174999289'); let formIds: string[]= new Array('12400633174999288', '12400633174999289');
formHost.notifyFormsVisible(formIds, true, (error, data) => { formHost.notifyFormsVisible(formIds, true, (error: Base.BusinessError) => {
if (error.code) { if (error.code) {
console.error('formHost notifyFormsVisible, error: ${JSON.stringify(error)}'); console.error(`formHost notifyFormsVisible, error: ${JSON.stringify(error)}`);
} }
}); });
``` ```
...@@ -1043,11 +1050,11 @@ notifyFormsVisible(formIds: Array&lt;string&gt;, isVisible: boolean): Promise&lt ...@@ -1043,11 +1050,11 @@ notifyFormsVisible(formIds: Array&lt;string&gt;, isVisible: boolean): Promise&lt
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formIds = new Array('12400633174999288', '12400633174999289'); let formIds: string[] = new Array('12400633174999288', '12400633174999289');
formHost.notifyFormsVisible(formIds, true).then(() => { formHost.notifyFormsVisible(formIds, true).then(() => {
console.log('formHost notifyFormsVisible success'); console.log('formHost notifyFormsVisible success');
}).catch((error) => { }).catch((error: Base.BusinessError) => {
console.error('formHost notifyFormsVisible, error: ${JSON.stringify(error)}'); console.error(`formHost notifyFormsVisible, error: ${JSON.stringify(error)}`);
}); });
``` ```
...@@ -1074,8 +1081,8 @@ notifyFormsEnableUpdate(formIds: Array&lt;string&gt;, isEnableUpdate: boolean, c ...@@ -1074,8 +1081,8 @@ notifyFormsEnableUpdate(formIds: Array&lt;string&gt;, isEnableUpdate: boolean, c
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formIds = new Array('12400633174999288', '12400633174999289'); let formIds: string[] = new Array('12400633174999288', '12400633174999289');
formHost.notifyFormsEnableUpdate(formIds, true, (error, data) => { formHost.notifyFormsEnableUpdate(formIds, true, (error: Base.BusinessError) => {
if (error.code) { if (error.code) {
console.error('formHost notifyFormsEnableUpdate, error: ${JSON.stringify(error)}'); console.error('formHost notifyFormsEnableUpdate, error: ${JSON.stringify(error)}');
} }
...@@ -1110,10 +1117,10 @@ notifyFormsEnableUpdate(formIds: Array&lt;string&gt;, isEnableUpdate: boolean): ...@@ -1110,10 +1117,10 @@ notifyFormsEnableUpdate(formIds: Array&lt;string&gt;, isEnableUpdate: boolean):
```ts ```ts
import formHost from '@ohos.application.formHost'; import formHost from '@ohos.application.formHost';
let formIds = new Array('12400633174999288', '12400633174999289'); let formIds: string[] = new Array('12400633174999288', '12400633174999289');
formHost.notifyFormsEnableUpdate(formIds, true).then(() => { formHost.notifyFormsEnableUpdate(formIds, true).then(() => {
console.log('formHost notifyFormsEnableUpdate success'); console.log('formHost notifyFormsEnableUpdate success');
}).catch((error) => { }).catch((error: Base.BusinessError) => {
console.error('formHost notifyFormsEnableUpdate, error: ${JSON.stringify(error)}'); console.error(`formHost notifyFormsEnableUpdate, error: ${JSON.stringify(error)}`);
}); });
``` ```
...@@ -10,6 +10,7 @@ FormProvider模块提供了卡片提供方相关接口的能力,开发者在 ...@@ -10,6 +10,7 @@ FormProvider模块提供了卡片提供方相关接口的能力,开发者在
```ts ```ts
import formProvider from '@ohos.application.formProvider'; import formProvider from '@ohos.application.formProvider';
import Base from '@ohos.base'
``` ```
## setFormNextRefreshTime ## setFormNextRefreshTime
...@@ -31,8 +32,8 @@ setFormNextRefreshTime(formId: string, minute: number, callback: AsyncCallback&l ...@@ -31,8 +32,8 @@ setFormNextRefreshTime(formId: string, minute: number, callback: AsyncCallback&l
**示例:** **示例:**
```ts ```ts
let formId = '12400633174999288'; let formId: string = '12400633174999288';
formProvider.setFormNextRefreshTime(formId, 5, (error, data) => { formProvider.setFormNextRefreshTime(formId, 5, (error: Base.BusinessError) => {
if (error.code) { if (error.code) {
console.error('formProvider setFormNextRefreshTime, error: ${JSON.stringify(error)}'); console.error('formProvider setFormNextRefreshTime, error: ${JSON.stringify(error)}');
} }
...@@ -63,11 +64,11 @@ setFormNextRefreshTime(formId: string, minute: number): Promise&lt;void&gt; ...@@ -63,11 +64,11 @@ setFormNextRefreshTime(formId: string, minute: number): Promise&lt;void&gt;
**示例:** **示例:**
```ts ```ts
let formId = '12400633174999288'; let formId: string = '12400633174999288';
formProvider.setFormNextRefreshTime(formId, 5).then(() => { formProvider.setFormNextRefreshTime(formId, 5).then(() => {
console.log('formProvider setFormNextRefreshTime success'); console.log('formProvider setFormNextRefreshTime success');
}).catch((error) => { }).catch((error: Base.BusinessError) => {
console.error('formProvider setFormNextRefreshTime, error: ${JSON.stringify(error)}'); console.error(`formProvider setFormNextRefreshTime, error: ${JSON.stringify(error)}`);
}); });
``` ```
...@@ -93,10 +94,18 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData,call ...@@ -93,10 +94,18 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData,call
import formBindingData from '@ohos.app.form.formBindingData'; import formBindingData from '@ohos.app.form.formBindingData';
let formId = '12400633174999288'; let formId = '12400633174999288';
let obj = formBindingData.createFormBindingData({temperature:'22c', time:'22:00'}); class createBindingDataType {
formProvider.updateForm(formId, obj, (error, data) => { temperature: string
time: string
};
let createBindingDataParam: createBindingDataType = {
temperature:'22c',
time:'22:00'
};
let obj = formBindingData.createFormBindingData(createBindingDataParam);
formProvider.updateForm(formId, obj, (error: Base.BusinessError) => {
if (error.code) { if (error.code) {
console.error('formProvider updateForm, error: ${JSON.stringify(error)}'); console.error(`formProvider updateForm, error: ${JSON.stringify(error)}`);
} }
}); });
``` ```
...@@ -127,12 +136,20 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Pr ...@@ -127,12 +136,20 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Pr
```ts ```ts
import formBindingData from '@ohos.application.formBindingData'; import formBindingData from '@ohos.application.formBindingData';
let formId = '12400633174999288'; let formId: string = '12400633174999288';
let obj = formBindingData.createFormBindingData({temperature:'22c', time:'22:00'}); class createBindingDataType {
temperature: string
time: string
};
let createBindingDataParam: createBindingDataType = {
temperature:'22c',
time:'22:00'
};
let obj = formBindingData.createFormBindingData(createBindingDataParam);
formProvider.updateForm(formId, obj).then(() => { formProvider.updateForm(formId, obj).then(() => {
console.log('formProvider updateForm success'); console.log('formProvider updateForm success');
}).catch((error) => { }).catch((error: Base.BusinessError) => {
console.error('formProvider updateForm, error: ${JSON.stringify(error)}'); console.error(`formProvider updateForm, error: ${JSON.stringify(error)}`);
}); });
``` ```
......
...@@ -13,6 +13,7 @@ FormExtensionContext模块提供FormExtensionAbility具有的接口和能力。 ...@@ -13,6 +13,7 @@ FormExtensionContext模块提供FormExtensionAbility具有的接口和能力。
```ts ```ts
import common from '@ohos.app.ability.common'; import common from '@ohos.app.ability.common';
import Base from '@ohos.base';
``` ```
## FormExtensionContext.startAbility ## FormExtensionContext.startAbility
...@@ -49,12 +50,13 @@ startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void ...@@ -49,12 +50,13 @@ startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void
```ts ```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import Want from '@ohos.app.ability.Want';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onFormEvent(formId, message) { onFormEvent(formId: string, message: string) {
// 当触发卡片message事件时,执行startAbility // 当触发卡片message事件时,执行startAbility
console.log('FormExtensionAbility onFormEvent, formId: ${formId}, message:${message}'); console.log(`FormExtensionAbility onFormEvent, formId: ${formId}, message:${message}`);
let want = { let want: Want = {
deviceId: '', deviceId: '',
bundleName: 'com.example.formstartability', bundleName: 'com.example.formstartability',
abilityName: 'EntryAbility', abilityName: 'EntryAbility',
...@@ -62,7 +64,7 @@ export default class MyFormExtensionAbility extends FormExtensionAbility { ...@@ -62,7 +64,7 @@ export default class MyFormExtensionAbility extends FormExtensionAbility {
'message': message 'message': message
} }
}; };
this.context.startAbility(want, (error) => { this.context.startAbility(want, (error: Base.BusinessError) => {
if (error) { if (error) {
console.error('FormExtensionContext startAbility, error:${JSON.stringify(error)}'); console.error('FormExtensionContext startAbility, error:${JSON.stringify(error)}');
} else { } else {
...@@ -112,12 +114,13 @@ startAbility(want: Want): Promise&lt;void&gt; ...@@ -112,12 +114,13 @@ startAbility(want: Want): Promise&lt;void&gt;
```ts ```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import Want from '@ohos.app.ability.Want';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onFormEvent(formId, message) { onFormEvent(formId: string, message: string) {
// 当触发卡片message事件时,执行startAbility // 当触发卡片message事件时,执行startAbility
console.log('FormExtensionAbility onFormEvent, formId:${formId}, message:${message}'); console.log(`FormExtensionAbility onFormEvent, formId:${formId}, message:${message}`);
let want = { let want: Want = {
deviceId: '', deviceId: '',
bundleName: 'com.example.formstartability', bundleName: 'com.example.formstartability',
abilityName: 'EntryAbility', abilityName: 'EntryAbility',
...@@ -127,7 +130,7 @@ export default class MyFormExtensionAbility extends FormExtensionAbility { ...@@ -127,7 +130,7 @@ export default class MyFormExtensionAbility extends FormExtensionAbility {
}; };
this.context.startAbility(want).then(() => { this.context.startAbility(want).then(() => {
console.info('StartAbility Success'); console.info('StartAbility Success');
}).catch((error) => { }).catch((error: Base.BusinessError) => {
console.error('StartAbility failed'); console.error('StartAbility failed');
}); });
} }
...@@ -175,41 +178,44 @@ connectServiceExtensionAbility(want: Want, options: ConnectOptions): number; ...@@ -175,41 +178,44 @@ connectServiceExtensionAbility(want: Want, options: ConnectOptions): number;
**示例:** **示例:**
```ts ```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import Want from '@ohos.app.ability.Want';
let commRemote = null; import rpc from '@ohos.rpc';
export default class MyFormExtensionAbility extends FormExtensionAbility { import common from '@ohos.app.ability.common';
onFormEvent(formId, message) {
// 当触发卡片message事件时,执行connectServiceExtensionAbility let commRemote: rpc.IRemoteObject | null = null;
console.log(`FormExtensionAbility onFormEvent, formId:${formId}, message:${message}`); export default class MyFormExtensionAbility extends FormExtensionAbility {
let want = { onFormEvent(formId: string, message: string) {
deviceId: '', // 当触发卡片message事件时,执行connectServiceExtensionAbility
bundleName: 'com.example.formstartability', console.log(`FormExtensionAbility onFormEvent, formId:${formId}, message:${message}`);
abilityName: 'EntryAbility', let want: Want = {
parameters: { deviceId: '',
'message': message bundleName: 'com.example.formstartability',
} abilityName: 'EntryAbility',
}; parameters: {
let options = { 'message': message
onConnect(elementName, remote) {
commRemote = remote; // remote 用于与ServiceExtensionAbility进行通信
console.log('----------- onConnect -----------');
},
onDisconnect(elementName) { console.log('----------- onDisconnect -----------') },
onFailed(code) { console.error('----------- onFailed -----------') }
};
let connection = null;
try {
connection = this.context.connectServiceExtensionAbility(want, options);
} catch (paramError) {
// 处理入参错误异常
console.error(`error.code: ${paramError.code}, error.message: ${paramError.message}`);
} }
};
let options: common.ConnectOptions = {
onConnect(elementName, remote) {
commRemote = remote; // remote 用于与ServiceExtensionAbility进行通信
console.log('----------- onConnect -----------');
},
onDisconnect(elementName) { console.log('----------- onDisconnect -----------') },
onFailed(code) { console.error('----------- onFailed -----------') }
};
let connection: number | null = null;
try {
connection = this.context.connectServiceExtensionAbility(want, options);
} catch (paramError) {
// 处理入参错误异常
console.error(`error.code: ${paramError.code}, error.message: ${paramError.message}`);
} }
}; }
``` };
```
## FormExtensionContext.disconnectServiceExtensionAbility<sup>10+</sup> ## FormExtensionContext.disconnectServiceExtensionAbility<sup>10+</sup>
...@@ -239,36 +245,38 @@ disconnectServiceExtensionAbility(connection: number, callback:AsyncCallback&lt; ...@@ -239,36 +245,38 @@ disconnectServiceExtensionAbility(connection: number, callback:AsyncCallback&lt;
**示例:** **示例:**
```ts ```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import rpc from '@ohos.rpc';
import common from '@ohos.app.ability.common';
// commRemote为onConnect回调内返回的remote对象,此处定义为null无任何实际意义,仅作示例 // commRemote为onConnect回调内返回的remote对象,此处定义为null无任何实际意义,仅作示例
let commRemote = null; let commRemote: rpc.IRemoteObject | null = null;
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onFormEvent(formId, message) { onFormEvent(formId: string, message: string) {
// 实际使用时,connection为connectServiceExtensionAbility中的返回值,此处定义为1无任何实际意义,仅作示例 // 实际使用时,connection为connectServiceExtensionAbility中的返回值,此处定义为1无任何实际意义,仅作示例
let connection = 1; let connection: number = 1;
try { try {
this.context.disconnectServiceExtensionAbility(connection, (error) => { this.context.disconnectServiceExtensionAbility(connection, (error: Base.BusinessError) => {
commRemote = null;
if (error.code) {
// 处理业务逻辑错误
console.error(
`disconnectServiceExtensionAbility failed, error.code: ${error.code}, error.message: ${error.message}`);
return;
}
// 执行正常业务
console.log('disconnectServiceExtensionAbility succeed');
});
} catch (paramError) {
commRemote = null; commRemote = null;
// 处理入参错误异常 if (error.code) {
console.error(`error.code: ${paramError.code}, error.message: ${paramError.message}`); // 处理业务逻辑错误
} console.error(
`disconnectServiceExtensionAbility failed, error.code: ${error.code}, error.message: ${error.message}`);
return;
}
// 执行正常业务
console.log('disconnectServiceExtensionAbility succeed');
});
} catch (paramError) {
commRemote = null;
// 处理入参错误异常
console.error(`error.code: ${paramError.code}, error.message: ${paramError.message}`);
} }
}; }
``` };
```
## FormExtensionContext.disconnectServiceExtensionAbility<sup>10+</sup> ## FormExtensionContext.disconnectServiceExtensionAbility<sup>10+</sup>
...@@ -303,34 +311,36 @@ disconnectServiceExtensionAbility(connection: number): Promise&lt;void&gt;; ...@@ -303,34 +311,36 @@ disconnectServiceExtensionAbility(connection: number): Promise&lt;void&gt;;
**示例:** **示例:**
```ts ```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import rpc from '@ohos.rpc';
// commRemote为onConnect回调内返回的remote对象,此处定义为null无任何实际意义,仅作示例 import common from '@ohos.app.ability.common';
let commRemote = null;
export default class MyFormExtensionAbility extends FormExtensionAbility { // commRemote为onConnect回调内返回的remote对象,此处定义为null无任何实际意义,仅作示例
onFormEvent(formId, message) { let commRemote: rpc.IRemoteObject | null = null;
// 实际使用时,connection为connectServiceExtensionAbility中的返回值,此处定义为1无任何实际意义,仅作示例 export default class MyFormExtensionAbility extends FormExtensionAbility {
let connection = 1; onFormEvent(formId: string, message: string) {
// 实际使用时,connection为connectServiceExtensionAbility中的返回值,此处定义为1无任何实际意义,仅作示例
try { let connection: number = 1;
this.context.disconnectServiceExtensionAbility(connection)
.then((data) => { try {
commRemote = null; this.context.disconnectServiceExtensionAbility(connection)
// 执行正常业务 .then(() => {
console.log('disconnectServiceExtensionAbility succeed'); commRemote = null;
}) // 执行正常业务
.catch((error) => { console.log('disconnectServiceExtensionAbility succeed');
commRemote = null; })
// 处理业务逻辑错误 .catch((error: Base.BusinessError) => {
console.error( commRemote = null;
`disconnectServiceExtensionAbility failed, error.code: ${error.code}, error.message: ${error.message}`); // 处理业务逻辑错误
}); console.error(
} catch (paramError) { `disconnectServiceExtensionAbility failed, error.code: ${error.code}, error.message: ${error.message}`);
commRemote = null; });
// 处理入参错误异常 } catch (paramError) {
console.error(`error.code: ${paramError.code}, error.message: ${paramError.message}`); commRemote = null;
} // 处理入参错误异常
console.error(`error.code: ${paramError.code}, error.message: ${paramError.message}`);
} }
}; }
``` };
```
...@@ -28,7 +28,7 @@ import missionManager from '@ohos.app.ability.missionManager'; ...@@ -28,7 +28,7 @@ import missionManager from '@ohos.app.ability.missionManager';
**示例:** **示例:**
```ts ```ts
import ElementName from '@ohos.bundle'; import ElementName from '@ohos.bundle.bundleManager';
import image from '@ohos.multimedia.image'; import image from '@ohos.multimedia.image';
import missionManager from '@ohos.app.ability.missionManager'; import missionManager from '@ohos.app.ability.missionManager';
......
...@@ -50,18 +50,24 @@ show(options?: ShowNotificationOptions): void ...@@ -50,18 +50,24 @@ show(options?: ShowNotificationOptions): void
| options | ShowNotificationOptions | 否 | 通知标题。 | | options | ShowNotificationOptions | 否 | 通知标题。 |
**示例:** **示例:**
```javascript ```ts
export default { class NotificationClass {
show() { show: Function
notification.show({ }
contentTitle: 'title info',
contentText: 'text', let notificationObj: NotificationClass = {
clickAction: { show() {
bundleName: 'com.example.testapp', notification.show({
abilityName: 'notificationDemo', contentTitle: 'title info',
uri: '/path/to/notification' contentText: 'text',
} clickAction: {
}); bundleName: 'com.example.testapp',
} abilityName: 'notificationDemo',
uri: '/path/to/notification'
}
});
}
} }
export default notificationObj
``` ```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册