未验证 提交 b1f95d17 编写于 作者: O openharmony_ci 提交者: Gitee

!23400 元能力ArkTs整改

Merge pull request !23400 from xuzhihao/master
......@@ -48,21 +48,18 @@ On the widget page, the **postCardAction** API can be used to trigger a message
import formProvider from '@ohos.app.form.formProvider';
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.
console.info(`FormAbility onEvent, formId = ${formId}, message: ${JSON.stringify(message)}`);
let formData = {
'title':'Title Update.', // It matches the widget layout.
'detail':'Description update success.', // It matches the widget layout.
};
let formData = new Map<Object, string>();
formData.set('title', 'Title Update.'); // It matches the widget layout.
formData.set('detail', 'Description update success.'); // It matches the widget layout.
let formInfo = formBindingData.createFormBindingData(formData)
formProvider.updateForm(formId, formInfo).then((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';
try {
let fd = fs.openSync('/path/to/form.png');
let obj = {
'temperature': '21°',
'formImages': { 'image': fd }
};
formBindingData.createFormBindingData(obj);
let createFormBindingDataParam = new Map<Object, string | object>()
let formImagesParam = new Map<Object, object>()
formImagesParam.set('image', fd)
createFormBindingDataParam.set("name", '21°')
createFormBindingDataParam.set('formImages', formImagesParam)
formBindingData.createFormBindingData(createFormBindingDataParam);
} catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
}
......
......@@ -50,18 +50,24 @@ Displays a notification.
| options | ShowNotificationOptions | No| Notification title.|
**Example**
```javascript
export default {
show() {
notification.show({
contentTitle: 'title info',
contentText: 'text',
clickAction: {
bundleName: 'com.example.testapp',
abilityName: 'notificationDemo',
uri: '/path/to/notification'
}
});
}
```ts
class NotificationClass {
show: Function
}
let notificationObj: NotificationClass = {
show() {
notification.show({
contentTitle: 'title info',
contentText: 'text',
clickAction: {
bundleName: 'com.example.testapp',
abilityName: 'notificationDemo',
uri: '/path/to/notification'
}
});
}
}
export default notificationObj
```
......@@ -46,21 +46,18 @@
import formProvider from '@ohos.app.form.formProvider';
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.
console.info(`FormAbility onEvent, formId = ${formId}, message: ${JSON.stringify(message)}`);
let formData = {
'title': 'Title Update.', // 和卡片布局中对应
'detail': 'Description update success.', // 和卡片布局中对应
};
let formData = new Map<Object, string>();
formData.set('title', 'Title Update.'); // 和卡片布局中对应
formData.set('detail', 'Description update success.'); // 和卡片布局中对应
let formInfo = formBindingData.createFormBindingData(formData)
formProvider.updateForm(formId, formInfo).then((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';
try {
let fd = fs.openSync('/path/to/form.png');
let obj = {
'temperature': '21°',
'formImages': { 'image': fd }
};
formBindingData.createFormBindingData(obj);
let createFormBindingDataParam = new Map<Object, string | object>()
let formImagesParam = new Map<Object, object>()
formImagesParam.set('image', fd)
createFormBindingDataParam.set("name", '21°')
createFormBindingDataParam.set('formImages', formImagesParam)
formBindingData.createFormBindingData(createFormBindingDataParam);
} 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
```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formBindingData from '@ohos.app.form.formBindingData';
import Want from '@ohos.app.ability.Want';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onAddForm(want) {
onAddForm(want: Want) {
console.log(`FormExtensionAbility onAddForm, want: ${want.abilityName}`);
let dataObj1 = {
temperature: '11c',
'time': '11:00'
};
let dataObj1 = new Map<Object, string>();
dataObj1.set('temperature', '11c');
dataObj1.set('time', '11:00');
let obj1 = formBindingData.createFormBindingData(dataObj1);
return obj1;
}
};
}
```
## onCastToNormalForm
......@@ -80,7 +81,7 @@ onCastToNormalForm(formId: string): void
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onCastToNormalForm(formId) {
onCastToNormalForm(formId: string) {
console.log(`FormExtensionAbility onCastToNormalForm, formId: ${formId}`);
}
};
......@@ -108,16 +109,18 @@ import formBindingData from '@ohos.app.form.formBindingData';
import formProvider from '@ohos.app.form.formProvider';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onUpdateForm(formId) {
onUpdateForm(formId: string) {
console.log(`FormExtensionAbility onUpdateForm, formId: ${formId}`);
class createFormBindingDataParam {
temperature: string
time: string
}
let obj2 = formBindingData.createFormBindingData({
temperature: '22c',
time: '22:00'
});
} as createFormBindingDataParam);
formProvider.updateForm(formId, obj2).then((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';
import formBindingData from '@ohos.app.form.formBindingData';
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 {
onChangeFormVisibility(newStatus) {
console.log(`FormExtensionAbility onChangeFormVisibility, newStatus: ${newStatus}`);
class createFormBindingDataParam {
temperature: string
time: string
}
let obj2 = formBindingData.createFormBindingData({
temperature: '22c',
time: '22:00'
});
} as createFormBindingDataParam);
for (let key in newStatus) {
console.log(`FormExtensionAbility onChangeFormVisibility, key: ${key}, value= ${newStatus[key]}`);
......@@ -185,7 +199,7 @@ onFormEvent(formId: string, message: string): void
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onFormEvent(formId, message) {
onFormEvent(formId: string, message: string) {
console.log(`FormExtensionAbility onFormEvent, formId: ${formId}, message: ${message}`);
}
};
......@@ -211,7 +225,7 @@ onRemoveForm(formId: string): void
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onRemoveForm(formId) {
onRemoveForm(formId: string) {
console.log(`FormExtensionAbility onRemoveForm, formId: ${formId}`);
}
};
......@@ -235,9 +249,10 @@ onConfigurationUpdate(newConfig: Configuration): void;
```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import { Configuration } from '@ohos.app.ability.Configuration';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onConfigurationUpdate(config) {
onConfigurationUpdate(config: Configuration) {
console.log(`onConfigurationUpdate, config: ${JSON.stringify(config)}`);
}
};
......@@ -262,9 +277,10 @@ onAcquireFormState?(want: Want): formInfo.FormState;
```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formInfo from '@ohos.app.form.formInfo';
import Want from '@ohos.app.ability.Want';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onAcquireFormState(want) {
onAcquireFormState(want: Want) {
console.log(`FormExtensionAbility onAcquireFormState, want: ${want}`);
return formInfo.FormState.UNKNOWN;
}
......@@ -299,11 +315,11 @@ onShareForm?(formId: string): { [key: string]: Object }
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onShareForm(formId) {
onShareForm(formId: string) {
console.log(`FormExtensionAbility onShareForm, formId: ${formId}`);
let wantParams = {
'temperature': '20',
'time': '2022-8-8 09:59',
'time': '2022-8-8 09:59',s
};
return wantParams;
}
......@@ -338,7 +354,7 @@ onAcquireFormData?(formId: string): { [key: string]: Object }
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onAcquireFormData(formId) {
onAcquireFormData(formId: string) {
console.log('FormExtensionAbility onAcquireFormData, formId: ${formId}');
let wantParams = {
'temperature': '20',
......
......@@ -11,6 +11,7 @@ formHost模块提供了卡片使用方相关接口的能力,包括对使用方
```ts
import formHost from '@ohos.app.form.formHost';
import Base from '@ohos.base';
```
## deleteForm
......@@ -51,8 +52,8 @@ deleteForm(formId: string, callback: AsyncCallback&lt;void&gt;): void
import formHost from '@ohos.app.form.formHost';
try {
let formId = '12400633174999288';
formHost.deleteForm(formId, (error) => {
let formId: string = '12400633174999288';
formHost.deleteForm(formId, (error: Base.BusinessError) => {
if (error) {
console.error(`error, code: ${error.code}, message: ${error.message}`);
} else {
......@@ -108,11 +109,11 @@ deleteForm(formId: string): Promise&lt;void&gt;
import formHost from '@ohos.app.form.formHost';
try {
let formId = '12400633174999288';
let formId: string = '12400633174999288';
formHost.deleteForm(formId).then(() => {
console.log('formHost deleteForm success');
}).catch((error) => {
console.error(`error, code: ${error.code}, message: ${error.message}`);
}).catch((error: Base.BusinessError) => {
console.error('formHost deleteForm, error: ${JSON.stringify(error)}');
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
......@@ -157,8 +158,8 @@ releaseForm(formId: string, callback: AsyncCallback&lt;void&gt;): void
import formHost from '@ohos.app.form.formHost';
try {
let formId = '12400633174999288';
formHost.releaseForm(formId, (error) => {
let formId: string = '12400633174999288';
formHost.releaseForm(formId, (error: Base.BusinessError) => {
if (error) {
console.error(`error, code: ${error.code}, message: ${error.message}`);
}
......@@ -207,8 +208,8 @@ releaseForm(formId: string, isReleaseCache: boolean, callback: AsyncCallback&lt;
import formHost from '@ohos.app.form.formHost';
try {
let formId = '12400633174999288';
formHost.releaseForm(formId, true, (error) => {
let formId: string = '12400633174999288';
formHost.releaseForm(formId, true, (error: Base.BusinessError) => {
if (error) {
console.error(`error, code: ${error.code}, message: ${error.message}`);
}
......@@ -262,10 +263,10 @@ releaseForm(formId: string, isReleaseCache?: boolean): Promise&lt;void&gt;
import formHost from '@ohos.app.form.formHost';
try {
let formId = '12400633174999288';
let formId: string = '12400633174999288';
formHost.releaseForm(formId, true).then(() => {
console.log('formHost releaseForm success');
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
......@@ -311,8 +312,8 @@ requestForm(formId: string, callback: AsyncCallback&lt;void&gt;): void
import formHost from '@ohos.app.form.formHost';
try {
let formId = '12400633174999288';
formHost.requestForm(formId, (error) => {
let formId: string = '12400633174999288';
formHost.requestForm(formId, (error: Base.BusinessError) => {
if (error) {
console.error(`error, code: ${error.code}, message: ${error.message}`);
}
......@@ -365,10 +366,10 @@ requestForm(formId: string): Promise&lt;void&gt;
import formHost from '@ohos.app.form.formHost';
try {
let formId = '12400633174999288';
let formId: string = '12400633174999288';
formHost.requestForm(formId).then(() => {
console.log('formHost requestForm success');
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
......@@ -415,8 +416,8 @@ castToNormalForm(formId: string, callback: AsyncCallback&lt;void&gt;): void
import formHost from '@ohos.app.form.formHost';
try {
let formId = '12400633174999288';
formHost.castToNormalForm(formId, (error) => {
let formId: string = '12400633174999288';
formHost.castToNormalForm(formId, (error: Base.BusinessError) => {
if (error) {
console.error(`error, code: ${error.code}, message: ${error.message}`);
}
......@@ -469,10 +470,10 @@ castToNormalForm(formId: string): Promise&lt;void&gt;
import formHost from '@ohos.app.form.formHost';
try {
let formId = '12400633174999288';
let formId: string = '12400633174999288';
formHost.castToNormalForm(formId).then(() => {
console.log('formHost castTempForm success');
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
......@@ -516,8 +517,8 @@ notifyVisibleForms(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;void
import formHost from '@ohos.app.form.formHost';
try {
let formId = ['12400633174999288'];
formHost.notifyVisibleForms(formId, (error) => {
let formId: string[] = ['12400633174999288'];
formHost.notifyVisibleForms(formId, (error: Base.BusinessError) => {
if (error) {
console.error(`error, code: ${error.code}, message: ${error.message}`);
}
......@@ -568,10 +569,10 @@ notifyVisibleForms(formIds: Array&lt;string&gt;): Promise&lt;void&gt;
import formHost from '@ohos.app.form.formHost';
try {
let formId = ['12400633174999288'];
let formId: string[] = ['12400633174999288'];
formHost.notifyVisibleForms(formId).then(() => {
console.log('formHost notifyVisibleForms success');
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
......@@ -615,8 +616,8 @@ notifyInvisibleForms(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;vo
import formHost from '@ohos.app.form.formHost';
try {
let formId = ['12400633174999288'];
formHost.notifyInvisibleForms(formId, (error) => {
let formId: string[] = ['12400633174999288'];
formHost.notifyInvisibleForms(formId, (error: Base.BusinessError) => {
if (error) {
console.error(`error, code: ${error.code}, message: ${error.message}`);
}
......@@ -667,10 +668,10 @@ notifyInvisibleForms(formIds: Array&lt;string&gt;): Promise&lt;void&gt;
import formHost from '@ohos.app.form.formHost';
try {
let formId = ['12400633174999288'];
let formId: string[] = ['12400633174999288'];
formHost.notifyInvisibleForms(formId).then(() => {
console.log('formHost notifyInvisibleForms success');
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
......@@ -715,8 +716,8 @@ enableFormsUpdate(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;void&
import formHost from '@ohos.app.form.formHost';
try {
let formId = ['12400633174999288'];
formHost.enableFormsUpdate(formId, (error) => {
let formId: string[] = ['12400633174999288'];
formHost.enableFormsUpdate(formId, (error: Base.BusinessError) => {
if (error) {
console.error(`error, code: ${error.code}, message: ${error.message}`);
}
......@@ -768,10 +769,10 @@ enableFormsUpdate(formIds: Array&lt;string&gt;): Promise&lt;void&gt;
import formHost from '@ohos.app.form.formHost';
try {
let formId = ['12400633174999288'];
let formId: string[] = ['12400633174999288'];
formHost.enableFormsUpdate(formId).then(() => {
console.log('formHost enableFormsUpdate success');
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
......@@ -817,8 +818,8 @@ disableFormsUpdate(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;void
import formHost from '@ohos.app.form.formHost';
try {
let formId = ['12400633174999288'];
formHost.disableFormsUpdate(formId, (error) => {
let formId: string[] = ['12400633174999288'];
formHost.disableFormsUpdate(formId, (error: Base.BusinessError) => {
if (error) {
console.error(`error, code: ${error.code}, message: ${error.message}`);
}
......@@ -871,10 +872,10 @@ disableFormsUpdate(formIds: Array&lt;string&gt;): Promise&lt;void&gt;
import formHost from '@ohos.app.form.formHost';
try {
let formId = ['12400633174999288'];
let formId: string[] = ['12400633174999288'];
formHost.disableFormsUpdate(formId).then(() => {
console.log('formHost disableFormsUpdate success');
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
......@@ -911,7 +912,7 @@ isSystemReady(callback: AsyncCallback&lt;void&gt;): void
import formHost from '@ohos.app.form.formHost';
try {
formHost.isSystemReady((error, data) => {
formHost.isSystemReady((error: Base.BusinessError) => {
if (error) {
console.error(`error, code: ${error.code}, message: ${error.message}`);
}
......@@ -951,7 +952,7 @@ import formHost from '@ohos.app.form.formHost';
try {
formHost.isSystemReady().then(() => {
console.log('formHost isSystemReady success');
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
......@@ -992,13 +993,14 @@ getAllFormsInfo(callback: AsyncCallback&lt;Array&lt;formInfo.FormInfo&gt;&gt;):
```ts
import formHost from '@ohos.app.form.formHost';
import formInfo from '@ohos.app.form.formInfo';
try {
formHost.getAllFormsInfo((error, data) => {
formHost.getAllFormsInfo((error: Base.BusinessError, data: formInfo.FormInfo[]) => {
if (error) {
console.error(`error, code: ${error.code}, message: ${error.message}`);
} else {
console.log('formHost getAllFormsInfo, data: ${JSON.stringify(data)}');
console.log(`formHost getAllFormsInfo, data: ${JSON.stringify(data)}`);
}
});
} catch(error) {
......@@ -1038,11 +1040,12 @@ getAllFormsInfo(): Promise&lt;Array&lt;formInfo.FormInfo&gt;&gt;
```ts
import formHost from '@ohos.app.form.formHost';
import formInfo from '@ohos.app.form.formInfo';
try {
formHost.getAllFormsInfo().then((data) => {
console.log('formHost getAllFormsInfo data: ${JSON.stringify(data)}');
}).catch((error) => {
formHost.getAllFormsInfo().then((data: formInfo.FormInfo[]) => {
console.log(`formHost getAllFormsInfo data: ${JSON.stringify(data)}`);
}).catch((error: Base.BusinessError) => {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
......@@ -1085,13 +1088,14 @@ getFormsInfo(bundleName: string, callback: AsyncCallback&lt;Array&lt;formInfo.Fo
```ts
import formHost from '@ohos.app.form.formHost';
import formInfo from '@ohos.app.form.formInfo';
try {
formHost.getFormsInfo('com.example.ohos.formjsdemo', (error, data) => {
formHost.getFormsInfo('com.example.ohos.formjsdemo', (error: Base.BusinessError, data: formInfo.FormInfo[]) => {
if (error) {
console.error(`error, code: ${error.code}, message: ${error.message}`);
} else {
console.log('formHost getFormsInfo, data: ${JSON.stringify(data)}');
console.log(`formHost getFormsInfo, data: ${JSON.stringify(data)}`);
}
});
} catch(error) {
......@@ -1135,9 +1139,10 @@ getFormsInfo(bundleName: string, moduleName: string, callback: AsyncCallback&lt;
```ts
import formHost from '@ohos.app.form.formHost';
import formInfo from '@ohos.app.form.formInfo';
try {
formHost.getFormsInfo('com.example.ohos.formjsdemo', 'entry', (error, data) => {
formHost.getFormsInfo('com.example.ohos.formjsdemo', 'entry', (error: Base.BusinessError, data: formInfo.FormInfo[]) => {
if (error) {
console.error(`error, code: ${error.code}, message: ${error.message}`);
} else {
......@@ -1190,11 +1195,12 @@ getFormsInfo(bundleName: string, moduleName?: string): Promise&lt;Array&lt;formI
```ts
import formHost from '@ohos.app.form.formHost';
import formInfo from '@ohos.app.form.formInfo';
try {
formHost.getFormsInfo('com.example.ohos.formjsdemo', 'entry').then((data) => {
console.log('formHost getFormsInfo, data: ${JSON.stringify(data)}');
}).catch((error) => {
formHost.getFormsInfo('com.example.ohos.formjsdemo', 'entry').then((data: formInfo.FormInfo[]) => {
console.log(`formHost getFormsInfo, data: ${JSON.stringify(data)}`);
}).catch((error: Base.BusinessError) => {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
......@@ -1238,12 +1244,12 @@ deleteInvalidForms(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;numb
import formHost from '@ohos.app.form.formHost';
try {
let formIds = new Array('12400633174999288', '12400633174999289');
formHost.deleteInvalidForms(formIds, (error, data) => {
let formIds: string[] = new Array('12400633174999288', '12400633174999289');
formHost.deleteInvalidForms(formIds, (error: Base.BusinessError, data: number) => {
if (error) {
console.error(`error, code: ${error.code}, message: ${error.message}`);
} else {
console.log('formHost deleteInvalidForms, data: ${JSON.stringify(data)}');
console.log(`formHost deleteInvalidForms, data: ${JSON.stringify(data)}`);
}
});
} catch(error) {
......@@ -1292,10 +1298,10 @@ deleteInvalidForms(formIds: Array&lt;string&gt;): Promise&lt;number&gt;
import formHost from '@ohos.app.form.formHost';
try {
let formIds = new Array('12400633174999288', '12400633174999289');
formHost.deleteInvalidForms(formIds).then((data) => {
console.log('formHost deleteInvalidForms, data: ${JSON.stringify(data)}');
}).catch((error) => {
let formIds: string[] = new Array('12400633174999288', '12400633174999289');
formHost.deleteInvalidForms(formIds).then((data: number) => {
console.log(`formHost deleteInvalidForms, data: ${JSON.stringify(data)}`);
}).catch((error: Base.BusinessError) => {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
......@@ -1338,8 +1344,10 @@ acquireFormState(want: Want, callback: AsyncCallback&lt;formInfo.FormStateInfo&g
```ts
import formHost from '@ohos.app.form.formHost';
import Want from '@ohos.app.ability.Want';
import formInfo from '@ohos.app.form.formInfo';
let want = {
let want: Want = {
'deviceId': '',
'bundleName': 'ohos.samples.FormApplication',
'abilityName': 'FormAbility',
......@@ -1350,11 +1358,11 @@ let want = {
}
};
try {
formHost.acquireFormState(want, (error, data) => {
formHost.acquireFormState(want, (error:Base.BusinessError, data: formInfo.FormStateInfo) => {
if (error) {
console.error(`error, code: ${error.code}, message: ${error.message}`);
} else {
console.log('formHost acquireFormState, data: ${JSON.stringify(data)}');
console.log(`formHost acquireFormState, data: ${JSON.stringify(data)}`);
}
});
} catch(error) {
......@@ -1402,8 +1410,10 @@ acquireFormState(want: Want): Promise&lt;formInfo.FormStateInfo&gt;
```ts
import formHost from '@ohos.app.form.formHost';
import Want from '@ohos.app.ability.Want';
import formInfo from '@ohos.app.form.formInfo';
let want = {
let want: Want = {
'deviceId': '',
'bundleName': 'ohos.samples.FormApplication',
'abilityName': 'FormAbility',
......@@ -1414,9 +1424,9 @@ let want = {
}
};
try {
formHost.acquireFormState(want).then((data) => {
console.log('formHost acquireFormState, data: ${JSON.stringify(data)}');
}).catch((error) => {
formHost.acquireFormState(want).then((data: formInfo.FormStateInfo) => {
console.log(`formHost acquireFormState, data: ${JSON.stringify(data)}`);
}).catch((error: Base.BusinessError) => {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
......@@ -1453,10 +1463,9 @@ on(type: 'formUninstall', callback: Callback&lt;string&gt;): void
```ts
import formHost from '@ohos.app.form.formHost';
let callback = function(formId) {
console.log('formHost on formUninstall, formId: ${formId}');
}
formHost.on('formUninstall', callback);
formHost.on('formUninstall', (formId: string) => {
console.log(`formHost on formUninstall, formId: ${formId}`);
});
```
## off('formUninstall')
......@@ -1488,10 +1497,9 @@ off(type: 'formUninstall', callback?: Callback&lt;string&gt;): void
```ts
import formHost from '@ohos.app.form.formHost';
let callback = function(formId) {
console.log('formHost on formUninstall, formId: ${formId}');
}
formHost.off('formUninstall', callback);
formHost.off('formUninstall', (formId: string) => {
console.log(`formHost on formUninstall, formId: ${formId}`);
});
```
## notifyFormsVisible
......@@ -1531,9 +1539,9 @@ notifyFormsVisible(formIds: Array&lt;string&gt;, isVisible: boolean, callback: A
```ts
import formHost from '@ohos.app.form.formHost';
let formIds = new Array('12400633174999288', '12400633174999289');
let formIds: string[] = new Array('12400633174999288', '12400633174999289');
try {
formHost.notifyFormsVisible(formIds, true, (error) => {
formHost.notifyFormsVisible(formIds, true, (error: Base.BusinessError) => {
if (error) {
console.error(`error, code: ${error.code}, message: ${error.message}`);
}
......@@ -1585,11 +1593,11 @@ notifyFormsVisible(formIds: Array&lt;string&gt;, isVisible: boolean): Promise&lt
```ts
import formHost from '@ohos.app.form.formHost';
let formIds = new Array('12400633174999288', '12400633174999289');
let formIds: string[] = new Array('12400633174999288', '12400633174999289');
try {
formHost.notifyFormsVisible(formIds, true).then(() => {
console.log('formHost notifyFormsVisible success');
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
......@@ -1634,9 +1642,9 @@ notifyFormsEnableUpdate(formIds: Array&lt;string&gt;, isEnableUpdate: boolean, c
```ts
import formHost from '@ohos.app.form.formHost';
let formIds = new Array('12400633174999288', '12400633174999289');
let formIds: string[] = new Array('12400633174999288', '12400633174999289');
try {
formHost.notifyFormsEnableUpdate(formIds, true, (error) => {
formHost.notifyFormsEnableUpdate(formIds, true, (error: Base.BusinessError) => {
if (error) {
console.error(`error, code: ${error.code}, message: ${error.message}`);
}
......@@ -1688,11 +1696,11 @@ notifyFormsEnableUpdate(formIds: Array&lt;string&gt;, isEnableUpdate: boolean):
```ts
import formHost from '@ohos.app.form.formHost';
let formIds = new Array('12400633174999288', '12400633174999289');
let formIds: string[] = new Array('12400633174999288', '12400633174999289');
try {
formHost.notifyFormsEnableUpdate(formIds, true).then(() => {
console.log('formHost notifyFormsEnableUpdate success');
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
......@@ -1736,10 +1744,10 @@ shareForm(formId: string, deviceId: string, callback: AsyncCallback&lt;void&gt;)
```ts
import formHost from '@ohos.app.form.formHost';
let formId = '12400633174999288';
let deviceId = 'EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2';
let formId: string = '12400633174999288';
let deviceId: string = 'EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2';
try {
formHost.shareForm(formId, deviceId, (error) => {
formHost.shareForm(formId, deviceId, (error: Base.BusinessError) => {
if (error) {
console.error(`error, code: ${error.code}, message: ${error.message}`);
}
......@@ -1791,12 +1799,12 @@ shareForm(formId: string, deviceId: string): Promise&lt;void&gt;
```ts
import formHost from '@ohos.app.form.formHost';
let formId = '12400633174999288';
let deviceId = 'EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2';
let formId: string = '12400633174999288';
let deviceId: string = 'EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2';
try {
formHost.shareForm(formId, deviceId).then(() => {
console.log('formHost shareForm success');
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
......@@ -1840,9 +1848,9 @@ notifyFormsPrivacyProtected(formIds: Array\<string>, isProtected: boolean, callb
```ts
import formHost from '@ohos.app.form.formHost';
let formIds = new Array('12400633174999288', '12400633174999289');
let formIds: string[] = new Array('12400633174999288', '12400633174999289');
try {
formHost.notifyFormsPrivacyProtected(formIds, true, (error) => {
formHost.notifyFormsPrivacyProtected(formIds, true, (error: Base.BusinessError) => {
if (error) {
console.error(`error, code: ${error.code}, message: ${error.message}`);
}
......@@ -1891,11 +1899,11 @@ notifyFormsPrivacyProtected(formIds: Array\<string\>, isProtected: boolean): Pro
```ts
import formHost from '@ohos.app.form.formHost';
let formIds = new Array('12400633174999288', '12400633174999289');
let formIds: string[] = new Array('12400633174999288', '12400633174999289');
try {
formHost.notifyFormsPrivacyProtected(formIds, true).then(() => {
console.log('formHost notifyFormsPrivacyProtected success');
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
......@@ -1937,13 +1945,13 @@ acquireFormData(formId: string, callback: AsyncCallback<{[key: string]: Object}>
```ts
import formHost from '@ohos.app.form.formHost';
let formId = '12400633174999288';
let formId: string = '12400633174999288';
try {
formHost.acquireFormData(formId, (error, data) => {
if (error) {
console.error(`error, code: ${error.code}, message: ${error.message}`);
} else {
console.log('formHost acquireFormData, data: ${JSON.stringify(data)}');
console.log(`formHost acquireFormData, data: ${JSON.stringify(data)}`);
}
});
} catch(error) {
......@@ -1989,11 +1997,11 @@ acquireFormData(formId: string): Promise<{[key: string]: Object}>;
```ts
import formHost from '@ohos.app.form.formHost';
let formId = '12400633174999288';
let formId: string = '12400633174999288';
try {
formHost.acquireFormData(formId).then((data) => {
console.log('formHost acquireFormData success' + data);
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
......
......@@ -9,6 +9,7 @@ FormProvider模块提供了卡片提供方相关接口的能力,开发者在
```ts
import formProvider from '@ohos.app.form.formProvider';
import Base from '@ohos.base';
```
## setFormNextRefreshTime
......@@ -45,9 +46,9 @@ setFormNextRefreshTime(formId: string, minute: number, callback: AsyncCallback&l
**示例:**
```ts
let formId = '12400633174999288';
let formId: string = '12400633174999288';
try {
formProvider.setFormNextRefreshTime(formId, 5, (error) => {
formProvider.setFormNextRefreshTime(formId, 5, (error: Base.BusinessError) => {
if (error) {
console.error(`callback error, code: ${error.code}, message: ${error.message})`);
return;
......@@ -98,11 +99,11 @@ setFormNextRefreshTime(formId: string, minute: number): Promise&lt;void&gt;
**示例:**
```ts
let formId = '12400633174999288';
let formId: string = '12400633174999288';
try {
formProvider.setFormNextRefreshTime(formId, 5).then(() => {
console.log(`formProvider setFormNextRefreshTime success`);
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error(`promise error, code: ${error.code}, message: ${error.message})`);
});
} catch (error) {
......@@ -145,10 +146,18 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData,call
```ts
import formBindingData from '@ohos.app.form.formBindingData';
let formId = '12400633174999288';
let formId: string = '12400633174999288';
try {
let obj = formBindingData.createFormBindingData({temperature:'22c', time:'22:00'});
formProvider.updateForm(formId, obj, (error) => {
class createFormBindingDataParamType {
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) {
console.error(`callback error, code: ${error.code}, message: ${error.message})`);
return;
......@@ -200,12 +209,20 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Pr
```ts
import formBindingData from '@ohos.app.form.formBindingData';
let formId = '12400633174999288';
let obj = formBindingData.createFormBindingData({ temperature: '22c', time: '22:00' });
let formId: string = '12400633174999288';
class createFormBindingDataParamType {
temperature: string
time: string
}
let createFormBindingDataParam: createFormBindingDataParamType = {
temperature:'22c',
time:'22:00'
};
let obj = formBindingData.createFormBindingData(createFormBindingDataParam);
try {
formProvider.updateForm(formId, obj).then(() => {
console.log(`formProvider updateForm success`);
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error(`promise error, code: ${error.code}, message: ${error.message})`);
});
} catch (error) {
......@@ -247,7 +264,7 @@ try {
console.error(`callback error, code: ${error.code}, message: ${error.message})`);
return;
}
console.log('formProvider getFormsInfo, data: ${JSON.stringify(data)}');
console.log(`formProvider getFormsInfo, data: ${JSON.stringify(data)}`);
});
} catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message})`);
......@@ -294,7 +311,7 @@ try {
console.error(`callback error, code: ${error.code}, message: ${error.message})`);
return;
}
console.log('formProvider getFormsInfo, data: ${JSON.stringify(data)}');
console.log(`formProvider getFormsInfo, data: ${JSON.stringify(data)}`);
});
} catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message})`);
......@@ -342,9 +359,9 @@ const filter: formInfo.FormInfoFilter = {
moduleName: 'entry'
};
try {
formProvider.getFormsInfo(filter).then((data) => {
console.log('formProvider getFormsInfo, data: ${JSON.stringify(data)}');
}).catch((error) => {
formProvider.getFormsInfo(filter).then((data: formInfo.FormInfo[]) => {
console.log(`formProvider getFormsInfo, data: ${JSON.stringify(data)}`);
}).catch((error: Base.BusinessError) => {
console.error(`promise error, code: ${error.code}, message: ${error.message})`);
});
} catch (error) {
......@@ -386,8 +403,9 @@ requestPublishForm(want: Want, formBindingData: formBindingData.FormBindingData,
```ts
import formBindingData from '@ohos.app.form.formBindingData';
import Want from '@ohos.app.ability.Want';
let want = {
let want: Want = {
abilityName: 'FormAbility',
parameters: {
'ohos.extra.param.key.form_dimension': 2,
......@@ -396,8 +414,16 @@ let want = {
}
};
try {
let obj = formBindingData.createFormBindingData({ temperature: '22c', time: '22:00' });
formProvider.requestPublishForm(want, obj, (error, data) => {
class createFormBindingDataParamType {
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) {
console.error(`callback error, code: ${error.code}, message: ${error.message})`);
return;
......@@ -441,7 +467,9 @@ requestPublishForm(want: Want, callback: AsyncCallback&lt;string&gt;): void
**示例:**
```ts
let want = {
import Want from '@ohos.app.ability.Want';
let want: Want = {
abilityName: 'FormAbility',
parameters: {
'ohos.extra.param.key.form_dimension': 2,
......@@ -450,12 +478,12 @@ let want = {
}
};
try {
formProvider.requestPublishForm(want, (error, data) => {
formProvider.requestPublishForm(want, (error: Base.BusinessError, data: string) => {
if (error) {
console.error(`callback error, code: ${error.code}, message: ${error.message})`);
return;
}
console.log('formProvider requestPublishForm, form ID is: ${JSON.stringify(data)}');
console.log(`formProvider requestPublishForm, form ID is: ${JSON.stringify(data)}`);
});
} catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message})`);
......@@ -500,7 +528,9 @@ requestPublishForm(want: Want, formBindingData?: formBindingData.FormBindingData
**示例:**
```ts
let want = {
import Want from '@ohos.app.ability.Want';
let want: Want = {
abilityName: 'FormAbility',
parameters: {
'ohos.extra.param.key.form_dimension': 2,
......@@ -509,9 +539,9 @@ let want = {
}
};
try {
formProvider.requestPublishForm(want).then((data) => {
console.log('formProvider requestPublishForm success, form ID is : ${JSON.stringify(data)}');
}).catch((error) => {
formProvider.requestPublishForm(want).then((data: string) => {
console.log(`formProvider requestPublishForm success, form ID is : ${JSON.stringify(data)}`);
}).catch((error: Base.BusinessError) => {
console.error(`promise error, code: ${error.code}, message: ${error.message})`);
});
} catch (error) {
......@@ -549,13 +579,15 @@ isRequestPublishFormSupported(callback: AsyncCallback&lt;boolean&gt;): void
**示例:**
```ts
import Want from '@ohos.app.ability.Want';
try {
formProvider.isRequestPublishFormSupported((error, isSupported) => {
formProvider.isRequestPublishFormSupported((error: Base.BusinessError, isSupported: boolean) => {
if (error) {
console.error(`callback error, code: ${error.code}, message: ${error.message})`);
} else {
if (isSupported) {
var want = {
let want: Want = {
abilityName: 'FormAbility',
parameters: {
'ohos.extra.param.key.form_dimension': 2,
......@@ -564,12 +596,12 @@ try {
}
};
try {
formProvider.requestPublishForm(want, (error, data) => {
formProvider.requestPublishForm(want, (error: Base.BusinessError, data: string) => {
if (error) {
console.error(`callback error, code: ${error.code}, message: ${error.message})`);
return;
}
console.log('formProvider requestPublishForm, form ID is: ${JSON.stringify(data)}');
console.log(`formProvider requestPublishForm, form ID is: ${JSON.stringify(data)}`);
});
} catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message})`);
......@@ -611,10 +643,12 @@ isRequestPublishFormSupported(): Promise&lt;boolean&gt;
**示例:**
```ts
import Want from '@ohos.app.ability.Want';
try {
formProvider.isRequestPublishFormSupported().then((isSupported) => {
formProvider.isRequestPublishFormSupported().then((isSupported: boolean) => {
if (isSupported) {
var want = {
let want: Want = {
abilityName: 'FormAbility',
parameters: {
'ohos.extra.param.key.form_dimension': 2,
......@@ -623,16 +657,16 @@ try {
}
};
try {
formProvider.requestPublishForm(want).then((data) => {
console.log('formProvider requestPublishForm success, form ID is : ${JSON.stringify(data)}');
}).catch((error) => {
formProvider.requestPublishForm(want).then((data: string) => {
console.log(`formProvider requestPublishForm success, form ID is : ${JSON.stringify(data)}`);
}).catch((error: Base.BusinessError) => {
console.error(`promise error, code: ${error.code}, message: ${error.message})`);
});
} catch (error) {
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})`);
});
} catch (error) {
......
......@@ -53,11 +53,13 @@ import fs from '@ohos.file.fs';
try {
let fd = fs.openSync('/path/to/form.png');
let obj = {
'temperature': '21°',
'formImages': { 'image': fd }
};
formBindingData.createFormBindingData(obj);
let createFormBindingDataParam = new Map<Object, string | object>();
let formImagesParam = new Map<Object, object>();
formImagesParam.set('image', fd);
createFormBindingDataParam.set("name", '21°');
createFormBindingDataParam.set('formImages', formImagesParam);
formBindingData.createFormBindingData(createFormBindingDataParam);
} catch (error) {
console.error('catch error, error: ${JSON.stringify(error)}');
}
......
......@@ -12,6 +12,7 @@ formHost模块提供了卡片使用方相关接口的能力,包括对使用方
```ts
import formHost from '@ohos.application.formHost';
import Base from '@ohos.base';
```
## deleteForm
......@@ -36,7 +37,7 @@ deleteForm(formId: string, callback: AsyncCallback&lt;void&gt;): void
```ts
import formHost from '@ohos.application.formHost';
let formId = '12400633174999288';
let formId: string = '12400633174999288';
formHost.deleteForm(formId, (error, data) => {
if (error.code) {
console.error('formHost deleteForm, error: ${JSON.stringify(error)}');
......@@ -71,10 +72,10 @@ deleteForm(formId: string): Promise&lt;void&gt;
```ts
import formHost from '@ohos.application.formHost';
let formId = '12400633174999288';
let formId: string = '12400633174999288';
formHost.deleteForm(formId).then(() => {
console.log('formHost deleteForm success');
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error('formHost deleteForm, error: ${JSON.stringify(error)}');
});
```
......@@ -101,8 +102,8 @@ releaseForm(formId: string, callback: AsyncCallback&lt;void&gt;): void
```ts
import formHost from '@ohos.application.formHost';
let formId = '12400633174999288';
formHost.releaseForm(formId, (error, data) => {
let formId: string = '12400633174999288';
formHost.releaseForm(formId, (error: Base.BusinessError) => {
if (error.code) {
console.error('formHost releaseForm, error: ${JSON.stringify(error)}');
} else {
......@@ -134,8 +135,8 @@ releaseForm(formId: string, isReleaseCache: boolean, callback: AsyncCallback&lt;
```ts
import formHost from '@ohos.application.formHost';
let formId = '12400633174999288';
formHost.releaseForm(formId, true, (error, data) => {
let formId: string = '12400633174999288';
formHost.releaseForm(formId, true, (error: Base.BusinessError) => {
if (error.code) {
console.error('formHost releaseForm, error: ${JSON.stringify(error)}');
} else {
......@@ -172,10 +173,10 @@ releaseForm(formId: string, isReleaseCache?: boolean): Promise&lt;void&gt;
```ts
import formHost from '@ohos.application.formHost';
let formId = '12400633174999288';
let formId: string = '12400633174999288';
formHost.releaseForm(formId, true).then(() => {
console.log('formHost releaseForm success');
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error('formHost releaseForm, error: ${JSON.stringify(error)}');
});
```
......@@ -202,8 +203,8 @@ requestForm(formId: string, callback: AsyncCallback&lt;void&gt;): void
```ts
import formHost from '@ohos.application.formHost';
let formId = '12400633174999288';
formHost.requestForm(formId, (error, data) => {
let formId: string = '12400633174999288';
formHost.requestForm(formId, (error: Base.BusinessError) => {
if (error.code) {
console.error('formHost requestForm, error: ${JSON.stringify(error)}');
}
......@@ -237,10 +238,10 @@ requestForm(formId: string): Promise&lt;void&gt;
```ts
import formHost from '@ohos.application.formHost';
let formId = '12400633174999288';
let formId: string = '12400633174999288';
formHost.requestForm(formId).then(() => {
console.log('formHost requestForm success');
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error('formHost requestForm, error: ${JSON.stringify(error)}');
});
```
......@@ -267,8 +268,8 @@ castTempForm(formId: string, callback: AsyncCallback&lt;void&gt;): void
```ts
import formHost from '@ohos.application.formHost';
let formId = '12400633174999288';
formHost.castTempForm(formId, (error, data) => {
let formId: string = '12400633174999288';
formHost.castTempForm(formId, (error: Base.BusinessError) => {
if (error.code) {
console.error('formHost castTempForm, error: ${JSON.stringify(error)}');
}
......@@ -302,10 +303,10 @@ castTempForm(formId: string): Promise&lt;void&gt;
```ts
import formHost from '@ohos.application.formHost';
let formId = '12400633174999288';
let formId: string = '12400633174999288';
formHost.castTempForm(formId).then(() => {
console.log('formHost castTempForm success');
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error('formHost castTempForm, error: ${JSON.stringify(error)}');
});
```
......@@ -332,8 +333,8 @@ notifyVisibleForms(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;void
```ts
import formHost from '@ohos.application.formHost';
let formId = ['12400633174999288'];
formHost.notifyVisibleForms(formId, (error, data) => {
let formId: string[] = ['12400633174999288'];
formHost.notifyVisibleForms(formId, (error: Base.BusinessError) => {
if (error.code) {
console.error('formHost notifyVisibleForms, error: ${JSON.stringify(error)}');
}
......@@ -367,10 +368,10 @@ notifyVisibleForms(formIds: Array&lt;string&gt;): Promise&lt;void&gt;
```ts
import formHost from '@ohos.application.formHost';
let formId = ['12400633174999288'];
let formId: string[] = ['12400633174999288'];
formHost.notifyVisibleForms(formId).then(() => {
console.log('formHost notifyVisibleForms success');
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error('formHost notifyVisibleForms, error: ${JSON.stringify(error)}');
});
```
......@@ -397,8 +398,8 @@ notifyInvisibleForms(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;vo
```ts
import formHost from '@ohos.application.formHost';
let formId = ['12400633174999288'];
formHost.notifyInvisibleForms(formId, (error, data) => {
let formId: string[] = ['12400633174999288'];
formHost.notifyInvisibleForms(formId, (error: Base.BusinessError) => {
if (error.code) {
console.error('formHost notifyInvisibleForms, error: ${JSON.stringify(error)}');
}
......@@ -432,10 +433,10 @@ notifyInvisibleForms(formIds: Array&lt;string&gt;): Promise&lt;void&gt;
```ts
import formHost from '@ohos.application.formHost';
let formId = ['12400633174999288'];
let formId: string[] = ['12400633174999288'];
formHost.notifyInvisibleForms(formId).then(() => {
console.log('formHost notifyInvisibleForms success');
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error('formHost notifyInvisibleForms, error: ${JSON.stringify(error)}');
});
```
......@@ -462,8 +463,8 @@ enableFormsUpdate(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;void&
```ts
import formHost from '@ohos.application.formHost';
let formId = ['12400633174999288'];
formHost.enableFormsUpdate(formId, (error, data) => {
let formId: string[] = ['12400633174999288'];
formHost.enableFormsUpdate(formId, (error: Base.BusinessError) => {
if (error.code) {
console.error('formHost enableFormsUpdate, error: ${JSON.stringify(error)}');
}
......@@ -497,10 +498,10 @@ enableFormsUpdate(formIds: Array&lt;string&gt;): Promise&lt;void&gt;
```ts
import formHost from '@ohos.application.formHost';
let formId = ['12400633174999288'];
let formId: string[] = ['12400633174999288'];
formHost.enableFormsUpdate(formId).then(() => {
console.log('formHost enableFormsUpdate success');
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error('formHost enableFormsUpdate, error: ${JSON.stringify(error)}');
});
```
......@@ -527,8 +528,8 @@ disableFormsUpdate(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;void
```ts
import formHost from '@ohos.application.formHost';
let formId = ['12400633174999288'];
formHost.disableFormsUpdate(formId, (error, data) => {
let formId: string[] = ['12400633174999288'];
formHost.disableFormsUpdate(formId, (error: Base.BusinessError) => {
if (error.code) {
console.error('formHost disableFormsUpdate, error: ${JSON.stringify(error)}');
}
......@@ -562,10 +563,10 @@ disableFormsUpdate(formIds: Array&lt;string&gt;): Promise&lt;void&gt;
```ts
import formHost from '@ohos.application.formHost';
let formId = ['12400633174999288'];
let formId: string[] = ['12400633174999288'];
formHost.disableFormsUpdate(formId).then(() => {
console.log('formHost disableFormsUpdate success');
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error('formHost disableFormsUpdate, error: ${JSON.stringify(error)}');
});
```
......@@ -589,8 +590,8 @@ isSystemReady(callback: AsyncCallback&lt;void&gt;): void
```ts
import formHost from '@ohos.application.formHost';
let formId = '12400633174999288';
formHost.isSystemReady((error, data) => {
let formId: string = '12400633174999288';
formHost.isSystemReady((error: Base.BusinessError) => {
if (error.code) {
console.error('formHost isSystemReady, error: ${JSON.stringify(error)}');
}
......@@ -616,10 +617,10 @@ isSystemReady(): Promise&lt;void&gt;
```ts
import formHost from '@ohos.application.formHost';
let formId = '12400633174999288';
let formId: string = '12400633174999288';
formHost.isSystemReady().then(() => {
console.log('formHost isSystemReady success');
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error('formHost isSystemReady, error: ${JSON.stringify(error)}');
});
```
......@@ -644,8 +645,9 @@ getAllFormsInfo(callback: AsyncCallback&lt;Array&lt;formInfo.FormInfo&gt;&gt;):
```ts
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) {
console.error('formHost getAllFormsInfo, error: ${JSON.stringify(error)}');
} else {
......@@ -674,10 +676,11 @@ getAllFormsInfo(): Promise&lt;Array&lt;formInfo.FormInfo&gt;&gt;
```ts
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)}');
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error('formHost getAllFormsInfo, error: ${JSON.stringify(error)}');
});
```
......@@ -703,12 +706,13 @@ getFormsInfo(bundleName: string, callback: AsyncCallback&lt;Array&lt;formInfo.Fo
```ts
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) {
console.error('formHost getFormsInfo, error: ${JSON.stringify(error)}');
console.error(`formHost getFormsInfo, error: ${JSON.stringify(error)}`);
} 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;
```ts
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) {
console.error('formHost getFormsInfo, error: ${JSON.stringify(error)}');
} else {
......@@ -773,10 +778,10 @@ getFormsInfo(bundleName: string, moduleName?: string): Promise&lt;Array&lt;formI
```ts
import formHost from '@ohos.application.formHost';
formHost.getFormsInfo('com.example.ohos.formjsdemo', 'entry').then((data) => {
console.log('formHost getFormsInfo, data: ${JSON.stringify(data)}');
}).catch((error) => {
console.error('formHost getFormsInfo, error: ${JSON.stringify(error)}');
formHost.getFormsInfo('com.example.ohos.formjsdemo', 'entry').then((data: formInfo.FormInfo[]) => {
console.log(`formHost getFormsInfo, data: ${JSON.stringify(data)}`);
}).catch((error: Base.BusinessError) => {
console.error(`formHost getFormsInfo, error: ${JSON.stringify(error)}`);
});
```
......@@ -802,12 +807,12 @@ deleteInvalidForms(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;numb
```ts
import formHost from '@ohos.application.formHost';
let formIds = new Array('12400633174999288', '12400633174999289');
formHost.deleteInvalidForms(formIds, (error, data) => {
let formIds: string[] = new Array('12400633174999288', '12400633174999289');
formHost.deleteInvalidForms(formIds, (error: Base.BusinessError, data: number) => {
if (error.code) {
console.error('formHost deleteInvalidForms, error: ${JSON.stringify(error)}');
console.error(`formHost deleteInvalidForms, error: ${JSON.stringify(error)}`);
} 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;
```ts
import formHost from '@ohos.application.formHost';
let formIds = new Array('12400633174999288', '12400633174999289');
formHost.deleteInvalidForms(formIds).then((data) => {
console.log('formHost deleteInvalidForms, data: ${JSON.stringify(data)}');
}).catch((error) => {
console.error('formHost deleteInvalidForms, error: ${JSON.stringify(error)}');
let formIds: string[] = new Array('12400633174999288', '12400633174999289');
formHost.deleteInvalidForms(formIds).then((data: number) => {
console.log(`formHost deleteInvalidForms, data: ${JSON.stringify(data)}`);
}).catch((error: Base.BusinessError) => {
console.error(`formHost deleteInvalidForms, error: ${JSON.stringify(error)}`);
});
```
......@@ -868,8 +873,10 @@ acquireFormState(want: Want, callback: AsyncCallback&lt;formInfo.FormStateInfo&g
```ts
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': '',
'bundleName': 'ohos.samples.FormApplication',
'abilityName': 'FormAbility',
......@@ -879,11 +886,11 @@ let want = {
'ohos.extra.param.key.form_dimension': 2
}
};
formHost.acquireFormState(want, (error, data) => {
formHost.acquireFormState(want, (error:Base.BusinessError, data: formInfo.FormStateInfo) => {
if (error.code) {
console.error('formHost acquireFormState, error: ${JSON.stringify(error)}');
console.error(`formHost acquireFormState, error: ${JSON.stringify(error)}`);
} 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;
```ts
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': '',
'bundleName': 'ohos.samples.FormApplication',
'abilityName': 'FormAbility',
......@@ -925,10 +934,10 @@ let want = {
'ohos.extra.param.key.form_dimension': 2
}
};
formHost.acquireFormState(want).then((data) => {
console.log('formHost acquireFormState, data: ${JSON.stringify(data)}');
}).catch((error) => {
console.error('formHost acquireFormState, error: ${JSON.stringify(error)}');
formHost.acquireFormState(want).then((data: formInfo.FormStateInfo) => {
console.log(`formHost acquireFormState, data: ${JSON.stringify(data)}`);
}).catch((error: Base.BusinessError) => {
console.error(`formHost acquireFormState, error: ${JSON.stringify(error)}`);
});
```
......@@ -952,10 +961,9 @@ on(type: 'formUninstall', callback: Callback&lt;string&gt;): void
```ts
import formHost from '@ohos.application.formHost';
let callback = function(formId) {
console.log('formHost on formUninstall, formId: ${formId}');
};
formHost.on('formUninstall', callback);
formHost.on('formUninstall', (formId: string) => {
console.log(`formHost on formUninstall, formId: ${formId}`);
});
```
## off('formUninstall')
......@@ -978,10 +986,9 @@ off(type: 'formUninstall', callback?: Callback&lt;string&gt;): void
```ts
import formHost from '@ohos.application.formHost';
let callback = function(formId) {
console.log('formHost on formUninstall, formId: ${formId}');
};
formHost.off('formUninstall', callback);
formHost.off('formUninstall', (formId: string) => {
console.log(`formHost on formUninstall, formId: ${formId}`);
});
```
## notifyFormsVisible
......@@ -1007,10 +1014,10 @@ notifyFormsVisible(formIds: Array&lt;string&gt;, isVisible: boolean, callback: A
```ts
import formHost from '@ohos.application.formHost';
let formIds = new Array('12400633174999288', '12400633174999289');
formHost.notifyFormsVisible(formIds, true, (error, data) => {
let formIds: string[]= new Array('12400633174999288', '12400633174999289');
formHost.notifyFormsVisible(formIds, true, (error: Base.BusinessError) => {
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
```ts
import formHost from '@ohos.application.formHost';
let formIds = new Array('12400633174999288', '12400633174999289');
let formIds: string[] = new Array('12400633174999288', '12400633174999289');
formHost.notifyFormsVisible(formIds, true).then(() => {
console.log('formHost notifyFormsVisible success');
}).catch((error) => {
console.error('formHost notifyFormsVisible, error: ${JSON.stringify(error)}');
}).catch((error: Base.BusinessError) => {
console.error(`formHost notifyFormsVisible, error: ${JSON.stringify(error)}`);
});
```
......@@ -1074,8 +1081,8 @@ notifyFormsEnableUpdate(formIds: Array&lt;string&gt;, isEnableUpdate: boolean, c
```ts
import formHost from '@ohos.application.formHost';
let formIds = new Array('12400633174999288', '12400633174999289');
formHost.notifyFormsEnableUpdate(formIds, true, (error, data) => {
let formIds: string[] = new Array('12400633174999288', '12400633174999289');
formHost.notifyFormsEnableUpdate(formIds, true, (error: Base.BusinessError) => {
if (error.code) {
console.error('formHost notifyFormsEnableUpdate, error: ${JSON.stringify(error)}');
}
......@@ -1110,10 +1117,10 @@ notifyFormsEnableUpdate(formIds: Array&lt;string&gt;, isEnableUpdate: boolean):
```ts
import formHost from '@ohos.application.formHost';
let formIds = new Array('12400633174999288', '12400633174999289');
let formIds: string[] = new Array('12400633174999288', '12400633174999289');
formHost.notifyFormsEnableUpdate(formIds, true).then(() => {
console.log('formHost notifyFormsEnableUpdate success');
}).catch((error) => {
console.error('formHost notifyFormsEnableUpdate, error: ${JSON.stringify(error)}');
}).catch((error: Base.BusinessError) => {
console.error(`formHost notifyFormsEnableUpdate, error: ${JSON.stringify(error)}`);
});
```
......@@ -10,6 +10,7 @@ FormProvider模块提供了卡片提供方相关接口的能力,开发者在
```ts
import formProvider from '@ohos.application.formProvider';
import Base from '@ohos.base'
```
## setFormNextRefreshTime
......@@ -31,8 +32,8 @@ setFormNextRefreshTime(formId: string, minute: number, callback: AsyncCallback&l
**示例:**
```ts
let formId = '12400633174999288';
formProvider.setFormNextRefreshTime(formId, 5, (error, data) => {
let formId: string = '12400633174999288';
formProvider.setFormNextRefreshTime(formId, 5, (error: Base.BusinessError) => {
if (error.code) {
console.error('formProvider setFormNextRefreshTime, error: ${JSON.stringify(error)}');
}
......@@ -63,11 +64,11 @@ setFormNextRefreshTime(formId: string, minute: number): Promise&lt;void&gt;
**示例:**
```ts
let formId = '12400633174999288';
let formId: string = '12400633174999288';
formProvider.setFormNextRefreshTime(formId, 5).then(() => {
console.log('formProvider setFormNextRefreshTime success');
}).catch((error) => {
console.error('formProvider setFormNextRefreshTime, error: ${JSON.stringify(error)}');
}).catch((error: Base.BusinessError) => {
console.error(`formProvider setFormNextRefreshTime, error: ${JSON.stringify(error)}`);
});
```
......@@ -93,10 +94,18 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData,call
import formBindingData from '@ohos.app.form.formBindingData';
let formId = '12400633174999288';
let obj = formBindingData.createFormBindingData({temperature:'22c', time:'22:00'});
formProvider.updateForm(formId, obj, (error, data) => {
class createBindingDataType {
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) {
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
```ts
import formBindingData from '@ohos.application.formBindingData';
let formId = '12400633174999288';
let obj = formBindingData.createFormBindingData({temperature:'22c', time:'22:00'});
let formId: string = '12400633174999288';
class createBindingDataType {
temperature: string
time: string
};
let createBindingDataParam: createBindingDataType = {
temperature:'22c',
time:'22:00'
};
let obj = formBindingData.createFormBindingData(createBindingDataParam);
formProvider.updateForm(formId, obj).then(() => {
console.log('formProvider updateForm success');
}).catch((error) => {
console.error('formProvider updateForm, error: ${JSON.stringify(error)}');
}).catch((error: Base.BusinessError) => {
console.error(`formProvider updateForm, error: ${JSON.stringify(error)}`);
});
```
......
......@@ -13,6 +13,7 @@ FormExtensionContext模块提供FormExtensionAbility具有的接口和能力。
```ts
import common from '@ohos.app.ability.common';
import Base from '@ohos.base';
```
## FormExtensionContext.startAbility
......@@ -49,12 +50,13 @@ startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void
```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import Want from '@ohos.app.ability.Want';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onFormEvent(formId, message) {
onFormEvent(formId: string, message: string) {
// 当触发卡片message事件时,执行startAbility
console.log('FormExtensionAbility onFormEvent, formId: ${formId}, message:${message}');
let want = {
console.log(`FormExtensionAbility onFormEvent, formId: ${formId}, message:${message}`);
let want: Want = {
deviceId: '',
bundleName: 'com.example.formstartability',
abilityName: 'EntryAbility',
......@@ -62,7 +64,7 @@ export default class MyFormExtensionAbility extends FormExtensionAbility {
'message': message
}
};
this.context.startAbility(want, (error) => {
this.context.startAbility(want, (error: Base.BusinessError) => {
if (error) {
console.error('FormExtensionContext startAbility, error:${JSON.stringify(error)}');
} else {
......@@ -112,12 +114,13 @@ startAbility(want: Want): Promise&lt;void&gt;
```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import Want from '@ohos.app.ability.Want';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onFormEvent(formId, message) {
onFormEvent(formId: string, message: string) {
// 当触发卡片message事件时,执行startAbility
console.log('FormExtensionAbility onFormEvent, formId:${formId}, message:${message}');
let want = {
console.log(`FormExtensionAbility onFormEvent, formId:${formId}, message:${message}`);
let want: Want = {
deviceId: '',
bundleName: 'com.example.formstartability',
abilityName: 'EntryAbility',
......@@ -127,7 +130,7 @@ export default class MyFormExtensionAbility extends FormExtensionAbility {
};
this.context.startAbility(want).then(() => {
console.info('StartAbility Success');
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error('StartAbility failed');
});
}
......@@ -176,41 +179,44 @@ connectServiceExtensionAbility(want: Want, options: ConnectOptions): number;
**示例:**
```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
let commRemote = null;
export default class MyFormExtensionAbility extends FormExtensionAbility {
onFormEvent(formId, message) {
// 当触发卡片message事件时,执行connectServiceExtensionAbility
console.log(`FormExtensionAbility onFormEvent, formId:${formId}, message:${message}`);
let want = {
deviceId: '',
bundleName: 'com.example.formstartability',
abilityName: 'EntryAbility',
parameters: {
'message': message
}
};
let options = {
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}`);
```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import Want from '@ohos.app.ability.Want';
import rpc from '@ohos.rpc';
import common from '@ohos.app.ability.common';
let commRemote: rpc.IRemoteObject | null = null;
export default class MyFormExtensionAbility extends FormExtensionAbility {
onFormEvent(formId: string, message: string) {
// 当触发卡片message事件时,执行connectServiceExtensionAbility
console.log(`FormExtensionAbility onFormEvent, formId:${formId}, message:${message}`);
let want: Want = {
deviceId: '',
bundleName: 'com.example.formstartability',
abilityName: 'EntryAbility',
parameters: {
'message': 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>
......@@ -240,36 +246,38 @@ disconnectServiceExtensionAbility(connection: number, callback:AsyncCallback&lt;
**示例:**
```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import rpc from '@ohos.rpc';
import common from '@ohos.app.ability.common';
// commRemote为onConnect回调内返回的remote对象,此处定义为null无任何实际意义,仅作示例
let commRemote = null;
export default class MyFormExtensionAbility extends FormExtensionAbility {
onFormEvent(formId, message) {
// 实际使用时,connection为connectServiceExtensionAbility中的返回值,此处定义为1无任何实际意义,仅作示例
let connection = 1;
// commRemote为onConnect回调内返回的remote对象,此处定义为null无任何实际意义,仅作示例
let commRemote: rpc.IRemoteObject | null = null;
export default class MyFormExtensionAbility extends FormExtensionAbility {
onFormEvent(formId: string, message: string) {
// 实际使用时,connection为connectServiceExtensionAbility中的返回值,此处定义为1无任何实际意义,仅作示例
let connection: number = 1;
try {
this.context.disconnectServiceExtensionAbility(connection, (error) => {
commRemote = null;
if (error.code) {
// 处理业务逻辑错误
console.error(
`disconnectServiceExtensionAbility failed, error.code: ${error.code}, error.message: ${error.message}`);
return;
}
// 执行正常业务
console.log('disconnectServiceExtensionAbility succeed');
});
} catch (paramError) {
try {
this.context.disconnectServiceExtensionAbility(connection, (error: Base.BusinessError) => {
commRemote = null;
// 处理入参错误异常
console.error(`error.code: ${paramError.code}, error.message: ${paramError.message}`);
}
if (error.code) {
// 处理业务逻辑错误
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>
......@@ -304,34 +312,36 @@ disconnectServiceExtensionAbility(connection: number): Promise&lt;void&gt;;
**示例:**
```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
// commRemote为onConnect回调内返回的remote对象,此处定义为null无任何实际意义,仅作示例
let commRemote = null;
export default class MyFormExtensionAbility extends FormExtensionAbility {
onFormEvent(formId, message) {
// 实际使用时,connection为connectServiceExtensionAbility中的返回值,此处定义为1无任何实际意义,仅作示例
let connection = 1;
try {
this.context.disconnectServiceExtensionAbility(connection)
.then((data) => {
commRemote = null;
// 执行正常业务
console.log('disconnectServiceExtensionAbility succeed');
})
.catch((error) => {
commRemote = null;
// 处理业务逻辑错误
console.error(
`disconnectServiceExtensionAbility failed, error.code: ${error.code}, error.message: ${error.message}`);
});
} catch (paramError) {
commRemote = null;
// 处理入参错误异常
console.error(`error.code: ${paramError.code}, error.message: ${paramError.message}`);
}
```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import rpc from '@ohos.rpc';
import common from '@ohos.app.ability.common';
// commRemote为onConnect回调内返回的remote对象,此处定义为null无任何实际意义,仅作示例
let commRemote: rpc.IRemoteObject | null = null;
export default class MyFormExtensionAbility extends FormExtensionAbility {
onFormEvent(formId: string, message: string) {
// 实际使用时,connection为connectServiceExtensionAbility中的返回值,此处定义为1无任何实际意义,仅作示例
let connection: number = 1;
try {
this.context.disconnectServiceExtensionAbility(connection)
.then(() => {
commRemote = null;
// 执行正常业务
console.log('disconnectServiceExtensionAbility succeed');
})
.catch((error: Base.BusinessError) => {
commRemote = null;
// 处理业务逻辑错误
console.error(
`disconnectServiceExtensionAbility failed, error.code: ${error.code}, error.message: ${error.message}`);
});
} catch (paramError) {
commRemote = null;
// 处理入参错误异常
console.error(`error.code: ${paramError.code}, error.message: ${paramError.message}`);
}
};
```
}
};
```
......@@ -28,7 +28,7 @@ import missionManager from '@ohos.app.ability.missionManager';
**示例:**
```ts
import ElementName from '@ohos.bundle';
import ElementName from '@ohos.bundle.bundleManager';
import image from '@ohos.multimedia.image';
import missionManager from '@ohos.app.ability.missionManager';
......
......@@ -50,18 +50,24 @@ show(options?: ShowNotificationOptions): void
| options | ShowNotificationOptions | 否 | 通知标题。 |
**示例:**
```javascript
export default {
show() {
notification.show({
contentTitle: 'title info',
contentText: 'text',
clickAction: {
bundleName: 'com.example.testapp',
abilityName: 'notificationDemo',
uri: '/path/to/notification'
}
});
}
```ts
class NotificationClass {
show: Function
}
let notificationObj: NotificationClass = {
show() {
notification.show({
contentTitle: 'title info',
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.
先完成此消息的编辑!
想要评论请 注册