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

!24086 元能力及事件通知ArkTs整改

Merge pull request !24086 from xuzhihao/master
......@@ -53,27 +53,48 @@
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
import Base from '@ohos.base'
import rpc from '@ohos.rpc';
import Want from '@ohos.app.ability.Want';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
function FunACall(data) {
// 获取call事件中传递的所有参数
console.info('FunACall param:' + JSON.stringify(data.readString()));
return null;
}
function FunBCall(data) {
console.info('FunBCall param:' + JSON.stringify(data.readString()));
return null;
class MyParcelable implements rpc.Parcelable {
num: number;
str: string;
constructor(num: number, str: string) {
this.num = num;
this.str = str;
}
marshalling(messageSequence: rpc.MessageSequence): boolean {
messageSequence.writeInt(this.num);
messageSequence.writeString(this.str);
return true;
}
unmarshalling(messageSequence: rpc.MessageSequence): boolean {
this.num = messageSequence.readInt();
this.str = messageSequence.readString();
return true;
}
}
export default class CameraAbility extends UIAbility {
// 如果UIAbility第一次启动,在收到call事件后会触发onCreate生命周期回调
onCreate(want, launchParam) {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
try {
// 监听call事件所需的方法
this.callee.on('funA', FunACall);
this.callee.on('funB', FunBCall);
this.callee.on('funA', (data: rpc.MessageSequence) => {
// 获取call事件中传递的所有参数
console.info('FunACall param:' + JSON.stringify(data.readString()));
return new MyParcelable(1, 'aaa');
});
this.callee.on('funB', (data: rpc.MessageSequence) => {
// 获取call事件中传递的所有参数
console.info('FunACall param:' + JSON.stringify(data.readString()));
return new MyParcelable(2, 'bbb');
});
} catch (err) {
console.error(`Failed to register callee on. Cause: ${JSON.stringify(err)}`);
console.error(`Failed to register callee on. Cause: ${JSON.stringify(err as Base.BusinessError)}`);
}
}
......@@ -85,7 +106,7 @@
this.callee.off('funA');
this.callee.off('funB');
} catch (err) {
console.error(`Failed to register callee off. Cause: ${JSON.stringify(err)}`);
console.error(`Failed to register callee off. Cause: ${JSON.stringify(err as Base.BusinessError)}`);
}
}
};
......
......@@ -52,10 +52,10 @@
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));
})
let formInfo: formBindingData.FormBindingData = formBindingData.createFormBindingData(formData);
formProvider.updateForm(formId, formInfo).then(() => {
console.info('FormAbility updateForm success.');
});
}
...
......
......@@ -54,26 +54,29 @@
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import Want from '@ohos.app.ability.Want';
import Base from '@ohos.base';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
let selectPage = "";
let currentWindowStage = null;
let selectPage: string = "";
let currentWindowStage: window.WindowStage | null = null;
export default class EntryAbility extends UIAbility {
// 如果UIAbility第一次启动,在收到Router事件后会触发onCreate生命周期回调
onCreate(want, launchParam) {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
// 获取router事件中传递的targetPage参数
console.info("onCreate want:" + JSON.stringify(want));
if (want.parameters.params !== undefined) {
let params = JSON.parse(want.parameters.params);
if (want.parameters?.params !== undefined) {
let params: Record<string, string> = JSON.parse(JSON.stringify(want.parameters?.params));
console.info("onCreate router targetPage:" + params.targetPage);
selectPage = params.targetPage;
}
}
// 如果UIAbility已在后台运行,在收到Router事件后会触发onNewWant生命周期回调
onNewWant(want, launchParam) {
onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam) {
console.info("onNewWant want:" + JSON.stringify(want));
if (want.parameters.params !== undefined) {
let params = JSON.parse(want.parameters.params);
if (want.parameters?.params !== undefined) {
let params: Record<string, string> = JSON.parse(JSON.stringify(want.parameters?.params));
console.info("onNewWant router targetPage:" + params.targetPage);
selectPage = params.targetPage;
}
......@@ -83,7 +86,7 @@
}
onWindowStageCreate(windowStage: window.WindowStage) {
let targetPage;
let targetPage: string;
// 根据传递的targetPage不同,选择拉起不同的页面
switch (selectPage) {
case 'funA':
......@@ -98,7 +101,7 @@
if (currentWindowStage === null) {
currentWindowStage = windowStage;
}
windowStage.loadContent(targetPage, (err, data) => {
windowStage.loadContent(targetPage, (err: Base.BusinessError) => {
if (err && err.code) {
console.info('Failed to load the content. Cause: %{public}s', JSON.stringify(err));
return;
......
......@@ -44,30 +44,33 @@
import formBindingData from '@ohos.app.form.formBindingData';
import formProvider from '@ohos.app.form.formProvider';
import formInfo from '@ohos.app.form.formInfo';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import Want from '@ohos.app.ability.Want';
import Base from '@ohos.base'
export default class EntryAbility extends UIAbility {
// 如果UIAbility第一次启动,在收到Router事件后会触发onCreate生命周期回调
onCreate(want, launchParam) {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
this.handleFormRouterEvent(want);
}
// 如果UIAbility已在后台运行,在收到Router事件后会触发onNewWant生命周期回调
onNewWant(want, launchParam) {
onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam) {
this.handleFormRouterEvent(want);
}
handleFormRouterEvent(want) {
handleFormRouterEvent(want: Want) {
console.info('Want:' + JSON.stringify(want));
if (want.parameters[formInfo.FormParam.IDENTITY_KEY] !== undefined) {
let curFormId = want.parameters[formInfo.FormParam.IDENTITY_KEY];
let message = JSON.parse(want.parameters.params).detail;
if (want.parameters && want.parameters[formInfo.FormParam.IDENTITY_KEY] !== undefined) {
let curFormId = JSON.stringify(want.parameters[formInfo.FormParam.IDENTITY_KEY]);
let message: string = JSON.parse(JSON.stringify(want.parameters.params)).detail;
console.info(`UpdateForm formId: ${curFormId}, message: ${message}`);
let formData = {
let formData: Record<string, string> = {
"detail": message + ': UIAbility.', // 和卡片布局中对应
};
let formMsg = formBindingData.createFormBindingData(formData)
formProvider.updateForm(curFormId, formMsg).then((data) => {
console.info('updateForm success.' + JSON.stringify(data));
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error('updateForm failed:' + JSON.stringify(error));
})
}
......@@ -83,17 +86,20 @@
```ts
import formBindingData from '@ohos.app.form.formBindingData';
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import Want from '@ohos.app.ability.Want';
export default class EntryFormAbility extends FormExtensionAbility {
onAddForm(want) {
let formId = want.parameters["ohos.extra.param.key.form_identity"];
let dataObj1 = {
onAddForm(want: Want) {
let dataObj1: Record<string, string> | undefined;
if (want.parameters && want.parameters["ohos.extra.param.key.form_identity"] != undefined) {
let formId: string = JSON.parse(JSON.stringify(want.parameters["ohos.extra.param.key.form_identity"]));
dataObj1 = {
"formId": formId
};
}
let obj1 = formBindingData.createFormBindingData(dataObj1);
return obj1;
}
...
};
```
......@@ -138,40 +144,63 @@
import UIAbility from '@ohos.app.ability.UIAbility';
import formBindingData from '@ohos.app.form.formBindingData';
import formProvider from '@ohos.app.form.formProvider';
import Want from '@ohos.app.ability.Want';
import Base from '@ohos.base'
import rpc from '@ohos.rpc';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
const MSG_SEND_METHOD: string = 'funA';
class MyParcelable implements rpc.Parcelable {
num: number;
str: string;
constructor(num: number, str: string) {
this.num = num;
this.str = str;
}
marshalling(messageSequence: rpc.MessageSequence): boolean {
messageSequence.writeInt(this.num);
messageSequence.writeString(this.str);
return true;
}
unmarshalling(messageSequence: rpc.MessageSequence): boolean {
this.num = messageSequence.readInt();
this.str = messageSequence.readString();
return true;
}
}
// 在收到call事件后会触发callee监听的方法
function FunACall(data) {
let FunACall = (data: rpc.MessageSequence) => {
// 获取call事件中传递的所有参数
let params = JSON.parse(data.readString())
let params: Record<string, string> = JSON.parse(data.readString())
if (params.formId !== undefined) {
let curFormId = params.formId;
let message = params.detail;
let curFormId: string = params.formId;
let message: string = params.detail;
console.info(`UpdateForm formId: ${curFormId}, message: ${message}`);
let formData = {
let formData: Record<string, string> = {
"detail": message
};
let formMsg = formBindingData.createFormBindingData(formData)
let formMsg: formBindingData.FormBindingData = formBindingData.createFormBindingData(formData);
formProvider.updateForm(curFormId, formMsg).then((data) => {
console.info('updateForm success.' + JSON.stringify(data));
}).catch((error) => {
}).catch((error: Base.BusinessError) => {
console.error('updateForm failed:' + JSON.stringify(error));
})
}
return null;
return new MyParcelable(1, 'aaa');
}
export default class EntryAbility extends UIAbility {
// 如果UIAbility第一次启动,call事件后会触发onCreate生命周期回调
onCreate(want, launchParam) {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
console.info('Want:' + JSON.stringify(want));
try {
// 监听call事件所需的方法
this.callee.on(MSG_SEND_METHOD, FunACall);
} catch (error) {
console.info(`${MSG_SEND_METHOD} register failed with error ${JSON.stringify(error)}`)
console.info(`${MSG_SEND_METHOD} register failed with error ${JSON.stringify(error as Base.BusinessError)}`)
}
}
...
}
```
\ No newline at end of file
......@@ -14,27 +14,30 @@
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import request from '@ohos.request';
import fs from '@ohos.file.fs';
import Want from '@ohos.app.ability.Want';
import Base from '@ohos.base';
import fileFs from '@ohos.file.fs';
export default class EntryFormAbility extends FormExtensionAbility {
...
// 在添加卡片时,打开一个本地图片并将图片内容传递给卡片页面显示
onAddForm(want) {
onAddForm(want: Want) {
// 假设在当前卡片应用的tmp目录下有一个本地图片:head.PNG
let tempDir = this.context.getApplicationContext().tempDir;
// 打开本地图片并获取其打开后的fd
let file;
let file: fileFs.File;
let formData = new Map<string, Object>();
formData.set('text', 'Image: Bear');
formData.set('imgName', 'imgBear');
formData.set('loaded', true);
try {
file = fs.openSync(tempDir + '/' + 'head.PNG');
} catch (e) {
console.error(`openSync failed: ${JSON.stringify(e)}`);
}
let formData = {
'text': 'Image: Bear',
'imgName': 'imgBear',
'formImages': {
let imgBear: Record<string, number> = {
'imgBear': file.fd
},
'loaded': true
}
formData.set('formImages', imgBear);
} catch (e) {
console.error(`openSync failed: ${JSON.stringify(e as Base.BusinessError)}`);
}
// 将fd封装在formData中并返回至卡片页面
return formBindingData.createFormBindingData(formData);
......@@ -52,10 +55,12 @@
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import request from '@ohos.request';
import fs from '@ohos.file.fs';
import Base from '@ohos.base';
import fileFs from '@ohos.file.fs';
export default class EntryFormAbility extends FormExtensionAbility {
// 在卡片页面触发message事件时,下载一个网络图片,并将网络图片内容传递给卡片页面显示
onFormEvent(formId, message) {
onFormEvent(formId: string, message: string) {
let formInfo = formBindingData.createFormBindingData({
'text': '刷新中...'
})
......@@ -69,42 +74,40 @@
request.downloadFile(this.context, {
url: netFile, filePath: tmpFile, enableMetered: true, enableRoaming: true
}).then((task) => {
task.on('complete', function callback() {
task.on('complete', () => {
console.info('ArkTSCard download complete:' + tmpFile);
let file;
let file: fileFs.File;
let formData = new Map<string, Object>();
try {
file = fs.openSync(tmpFile);
formData.set('text', 'Image: Bear' + fileName);
formData.set('imgName', 'imgBear' + fileName);
formData.set('loaded', true);
let imgBear: Record<string, number> = {
'imgBear': file.fd
};
formData.set('formImages', imgBear);
} catch (e) {
console.error(`openSync failed: ${JSON.stringify(e)}`);
console.error(`openSync failed: ${JSON.stringify(e as Base.BusinessError)}`);
}
let fileInfo = {};
fileInfo[fileName] = file.fd;
let formData = {
'text': 'Image:' + fileName,
'imgName': fileName,
'formImages': fileInfo,
'loaded': true
};
let formInfo = formBindingData.createFormBindingData(formData)
formProvider.updateForm(formId, formInfo).then((data) => {
console.info('FormAbility updateForm success.' + JSON.stringify(data));
}).catch((error) => {
let formInfo = formBindingData.createFormBindingData(formData);
formProvider.updateForm(formId, formInfo).then(() => {
console.info('FormAbility updateForm success.');
}).catch((error: Base.BusinessError) => {
console.error('FormAbility updateForm failed: ' + JSON.stringify(error));
});
})
})
task.on('fail', function callBack(err) {
task.on('fail', (err: number) => {
console.info('ArkTSCard download task failed. Cause:' + err);
let formInfo = formBindingData.createFormBindingData({
'text': '刷新失败'
})
formProvider.updateForm(formId, formInfo)
});
}).catch((err) => {
}).catch((err: Base.BusinessError) => {
console.error('Failed to request the download. Cause: ' + JSON.stringify(err));
});
}
...
};
```
......
......@@ -20,14 +20,16 @@
import formBindingData from '@ohos.app.form.formBindingData';
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formProvider from '@ohos.app.form.formProvider';
import { Configuration } from '@ohos.app.ability.Configuration';
import Want from '@ohos.app.ability.Want';
import formInfo from '@ohos.app.form.formInfo';
import Base from '@ohos.base';
export default class EntryFormAbility extends FormExtensionAbility {
onAddForm(want) {
onAddForm(want: Want) {
console.info('[EntryFormAbility] onAddForm');
// 在入参want中可以取出卡片的唯一标识:formId
let formId: string = want.parameters[formInfo.FormParam.IDENTITY_KEY];
// 使用方创建卡片时触发,提供方需要返回卡片数据绑定类
let obj = {
let obj: Record<string, string> = {
'title': 'titleOnAddForm',
'detail': 'detailOnAddForm'
};
......@@ -35,54 +37,50 @@
return formData;
}
onCastToNormalForm(formId) {
onCastToNormalForm(formId: string) {
// Called when the form provider is notified that a temporary form is successfully
// converted to a normal form.
// 使用方将临时卡片转换为常态卡片触发,提供方需要做相应的处理
console.info(`[EntryFormAbility] onCastToNormalForm, formId: ${formId}`);
}
onUpdateForm(formId) {
onUpdateForm(formId: string) {
// 若卡片支持定时更新/定点更新/卡片使用方主动请求更新功能,则提供方需要重写该方法以支持数据更新
console.info('[EntryFormAbility] onUpdateForm');
let obj = {
let obj: Record<string, string> = {
'title': 'titleOnUpdateForm',
'detail': 'detailOnUpdateForm'
};
let formData = formBindingData.createFormBindingData(obj);
formProvider.updateForm(formId, formData).catch((err) => {
if (err) {
// 异常分支打印
formProvider.updateForm(formId, formData).catch((err: Base.BusinessError) => {
console.error(`[EntryFormAbility] Failed to updateForm. Code: ${err.code}, message: ${err.message}`);
return;
}
});
}
onChangeFormVisibility(newStatus) {
onChangeFormVisibility(newStatus: Record<string, number>) {
// Called when the form provider receives form events from the system.
// 需要配置formVisibleNotify为true,且为系统应用才会回调
console.info('[EntryFormAbility] onChangeFormVisibility');
}
onFormEvent(formId, message) {
onFormEvent(formId: string, message: string) {
// Called when a specified message event defined by the form provider is triggered.
// 若卡片支持触发事件,则需要重写该方法并实现对事件的触发
console.info('[EntryFormAbility] onFormEvent');
}
onRemoveForm(formId) {
onRemoveForm(formId: string) {
// Called to notify the form provider that a specified form has been destroyed.
// 当对应的卡片删除时触发的回调,入参是被删除的卡片ID
console.info('[EntryFormAbility] onRemoveForm');
}
onConfigurationUpdate(config) {
onConfigurationUpdate(config: Configuration) {
// 当系统配置信息置更新时触发的回调
console.info('[EntryFormAbility] configurationUpdate:' + JSON.stringify(config));
}
onAcquireFormState(want) {
onAcquireFormState(want: Want) {
// Called to return a {@link FormState} object.
// 卡片提供方接收查询卡片状态通知接口,默认返回卡片初始状态。
return formInfo.FormState.READY;
......
......@@ -76,11 +76,13 @@
> key可以是uri也可以是简单字符串,subscriberId默认值为当前formId,实际取值都依赖于数据发布方的定义。
```ts
import formBindingData from '@ohos.app.form.formBindingData';
import Want from '@ohos.app.ability.Want';
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
let dataShareHelper;
onAddForm(want) {
let formData = {};
let proxies = [
export default class EntryFormAbility extends FormExtensionAbility {
onAddForm(want: Want) {
let formData: Record<string, Object> = {};
let proxies: formBindingData.ProxyData[] = [
{
"key": "detail",
"subscriberId": "11"
......@@ -90,6 +92,7 @@
formBinding["proxies"] = proxies;
return formBinding;
}
}
```
-[卡片页面文件](arkts-ui-widget-creation.md)中,通过LocalStorage变量获取订阅到的数据,LocalStorage绑定了一个字符串,以key:value的键值对格式来刷新卡片订阅数据,其中key必须与卡片提供方订阅的key保持一致。示例中,通过'detail'获取订阅的数据,并在Text组件显示。
......@@ -151,24 +154,28 @@
```ts
import formBindingData from '@ohos.app.form.formBindingData';
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import dataShare from '@ohos.data.dataShare'
let dataShareHelper;
onAddForm(want) {
let template = {
predicates : {
"list" : "select type from TBL00 limit 0,1"
import dataShare from '@ohos.data.dataShare';
import Want from '@ohos.app.ability.Want';
let dataShareHelper: dataShare.DataShareHelper;
export default class EntryFormAbility extends FormExtensionAbility {
onAddForm(want: Want) {
let template: dataShare.Template = {
predicates: {
"list": "select type from TBL00 limit 0,1"
},
scheduler: ""
}
let subscriberId = "111";
dataShare.createDataShareHelper(this.context, "datashareproxy://com.example.myapplication", {isProxy : true}).then((data) => {
let subscriberId: string = "111";
dataShare.createDataShareHelper(this.context, "datashareproxy://com.example.myapplication", {
isProxy: true
}).then((data: dataShare.DataShareHelper) => {
dataShareHelper = data;
dataShareHelper.addTemplate("datashareproxy://com.example.myapplication/test", subscriberId, template);
})
let formData = {};
let proxies = [
let formData: Record<string, Object> = {};
let proxies: formBindingData.ProxyData[] = [
{
"key": "datashareproxy://com.example.myapplication/test",
"subscriberId": subscriberId
......@@ -179,6 +186,7 @@
return formBinding;
}
}
```
-[卡片页面文件](arkts-ui-widget-creation.md)中,通过LocalStorage变量获取订阅到的数据,LocalStorage绑定了一个字符串,以key:value的键值对格式来刷新卡片订阅数据,其中key必须与卡片提供方订阅的key保持一致。示例中,通过'list'获取订阅的数据,并把第一个元素的值显示在Text组件上。
......
......@@ -96,56 +96,62 @@
import formBindingData from '@ohos.app.form.formBindingData';
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import dataPreferences from '@ohos.data.preferences';
import Want from '@ohos.app.ability.Want';
import Base from '@ohos.base';
export default class EntryFormAbility extends FormExtensionAbility {
onAddForm(want) {
let formId = want.parameters[formInfo.FormParam.IDENTITY_KEY];
let isTempCard: boolean = want.parameters[formInfo.FormParam.TEMPORARY_KEY];
onAddForm(want: Want) {
let formId: string = '';
let isTempCard: boolean;
if (want.parameters) {
formId = JSON.stringify(want.parameters[formInfo.FormParam.IDENTITY_KEY]);
isTempCard = want.parameters[formInfo.FormParam.TEMPORARY_KEY] as boolean;
if (isTempCard === false) { // 如果为常态卡片,直接进行信息持久化
console.info('Not temp card, init db for:' + formId);
let promise = dataPreferences.getPreferences(this.context, 'myStore');
promise.then(async (storeDB) => {
let promise: Promise<dataPreferences.Preferences> = dataPreferences.getPreferences(this.context, 'myStore');
promise.then(async (storeDB: dataPreferences.Preferences) => {
console.info("Succeeded to get preferences.");
await storeDB.put('A' + formId, 'false');
await storeDB.put('B' + formId, 'false');
await storeDB.flush();
}).catch((err) => {
}).catch((err: Base.BusinessError) => {
console.info(`Failed to get preferences. ${JSON.stringify(err)}`);
})
}
let formData = {};
}
let formData: Record<string, Object | string> = {};
return formBindingData.createFormBindingData(formData);
}
onRemoveForm(formId) {
onRemoveForm(formId: string) {
console.info('onRemoveForm, formId:' + formId);
let promise = dataPreferences.getPreferences(this.context, 'myStore');
promise.then(async (storeDB) => {
console.info("Succeeded to get preferences.");
await storeDB.delete('A' + formId);
await storeDB.delete('B' + formId);
}).catch((err) => {
}).catch((err: Base.BusinessError) => {
console.info(`Failed to get preferences. ${JSON.stringify(err)}`);
})
}
// 如果在添加时为临时卡片,则建议转为常态卡片时进行信息持久化
onCastToNormalForm(formId) {
onCastToNormalForm(formId: string) {
console.info('onCastToNormalForm, formId:' + formId);
let promise = dataPreferences.getPreferences(this.context, 'myStore');
promise.then(async (storeDB) => {
let promise: Promise<dataPreferences.Preferences> = dataPreferences.getPreferences(this.context, 'myStore');
promise.then(async (storeDB: dataPreferences.Preferences) => {
console.info("Succeeded to get preferences.");
await storeDB.put('A' + formId, 'false');
await storeDB.put('B' + formId, 'false');
await storeDB.flush();
}).catch((err) => {
}).catch((err: Base.BusinessError) => {
console.info(`Failed to get preferences. ${JSON.stringify(err)}`);
})
}
onUpdateForm(formId) {
let promise = dataPreferences.getPreferences(this.context, 'myStore');
promise.then(async (storeDB) => {
onUpdateForm(formId: string) {
let promise: Promise<dataPreferences.Preferences> = dataPreferences.getPreferences(this.context, 'myStore');
promise.then(async (storeDB: dataPreferences.Preferences) => {
console.info("Succeeded to get preferences.");
let stateA = await storeDB.get('A' + formId, 'false');
let stateB = await storeDB.get('B' + formId, 'false');
......@@ -160,18 +166,18 @@
await formProvider.updateForm(formId, formInfo);
}
console.info(`Update form success stateA:${stateA} stateB:${stateB}.`);
}).catch((err) => {
}).catch((err: Base.BusinessError) => {
console.info(`Failed to get preferences. ${JSON.stringify(err)}`);
})
}
onFormEvent(formId, message) {
onFormEvent(formId: string, message: string) {
// 存放卡片状态
console.info('onFormEvent formId:' + formId + 'msg:' + message);
let promise = dataPreferences.getPreferences(this.context, 'myStore');
promise.then(async (storeDB) => {
let promise: Promise<dataPreferences.Preferences> = dataPreferences.getPreferences(this.context, 'myStore');
promise.then(async (storeDB: dataPreferences.Preferences) => {
console.info("Succeeded to get preferences.");
let msg = JSON.parse(message);
let msg: Record<string, string> = JSON.parse(message);
if (msg.selectA != undefined) {
console.info('onFormEvent selectA info:' + msg.selectA);
await storeDB.put('A' + formId, msg.selectA);
......@@ -181,7 +187,7 @@
await storeDB.put('B' + formId, msg.selectB);
}
await storeDB.flush();
}).catch((err) => {
}).catch((err: Base.BusinessError) => {
console.info(`Failed to get preferences. ${JSON.stringify(err)}`);
})
}
......
......@@ -69,11 +69,12 @@
```ts
import formProvider from '@ohos.app.form.formProvider';
import Base from '@ohos.base';
let formId = '123456789'; // 实际业务场景需要使用正确的formId
let formId: string = '123456789'; // 实际业务场景需要使用正确的formId
try {
// 设置过5分钟后更新卡片内容
formProvider.setFormNextRefreshTime(formId, 5, (err, data) => {
formProvider.setFormNextRefreshTime(formId, 5, (err: Base.BusinessError) => {
if (err) {
console.error(`Failed to setFormNextRefreshTime. Code: ${err.code}, message: ${err.message}`);
return;
......@@ -82,7 +83,7 @@
}
});
} catch (err) {
console.error(`Failed to setFormNextRefreshTime. Code: ${err.code}, message: ${err.message}`);
console.error(`Failed to setFormNextRefreshTime. Code: ${(err as Base.BusinessError).code}, message: ${(err as Base.BusinessError).message}`);
}
```
......
......@@ -27,19 +27,20 @@
```ts
import commonEventManager from '@ohos.commonEventManager';
import Base from '@ohos.base';
```
2. 传入需要发布的事件名称和回调函数,发布事件。
```ts
// 发布公共事件
commonEventManager.publish("usual.event.SCREEN_OFF", (err) => {
commonEventManager.publish("usual.event.SCREEN_OFF", (err: Base.BusinessError) => {
if (err) {
console.error(`[CommonEvent] PublishCallBack err=${JSON.stringify(err)}`);
} else {
console.info(`[CommonEvent] Publish success`);
}
})
});
```
......@@ -51,13 +52,14 @@
```ts
import commonEventManager from '@ohos.commonEventManager';
import Base from '@ohos.base';
```
2. 传入需要发布的事件名称和回调函数,发布事件。
```ts
// 公共事件相关信息
let options = {
let options: commonEventManager.CommonEventPublishData = {
code: 1, // 公共事件的初始代码
data: "initial data", // 公共事件的初始数据
}
......@@ -67,11 +69,11 @@
```ts
// 发布公共事件
commonEventManager.publish("usual.event.SCREEN_OFF", options, (err) => {
commonEventManager.publish("usual.event.SCREEN_OFF", options, (err: Base.BusinessError) => {
if (err) {
console.error('[CommonEvent] PublishCallBack err=' + JSON.stringify(err));
} else {
console.info('[CommonEvent] Publish success')
}
})
});
```
......@@ -22,6 +22,7 @@
```ts
import commonEventManager from '@ohos.commonEventManager';
import Base from '@ohos.base';
```
3. 调用[`removeStickyCommonEvent()`](../reference/apis/js-apis-commonEventManager.md#commoneventmanagerremovestickycommonevent10)方法移除对应的粘性公共事件。
......@@ -31,7 +32,7 @@
> 移除的粘性公共事件,必须是本应用之前已发布的粘性公共事件,发布粘性公共事件参考[公共事件发布](common-event-publish.md)章节。
```ts
commonEventManager.removeStickyCommonEvent("sticky_event", (err) => { // sticky_event粘性公共事件名
commonEventManager.removeStickyCommonEvent("sticky_event", (err: Base.BusinessError) => { // sticky_event粘性公共事件名
if (err) {
console.error(`Failed to remove sticky common event. Code is ${err.code}, message is ${err.message}`);
return;
......
......@@ -21,10 +21,11 @@
开发者可以在[`onReceiveEvent()`](../reference/apis/js-apis-application-staticSubscriberExtensionAbility.md#staticsubscriberextensionabilityonreceiveevent)回调中实现业务逻辑。
```ts
import StaticSubscriberExtensionAbility from '@ohos.application.StaticSubscriberExtensionAbility'
import StaticSubscriberExtensionAbility from '@ohos.application.StaticSubscriberExtensionAbility';
import commonEventManager from '@ohos.commonEventManager';
export default class StaticSubscriber extends StaticSubscriberExtensionAbility {
onReceiveEvent(event) {
onReceiveEvent(event: commonEventManager.CommonEventData) {
console.info('onReceiveEvent, event: ' + event.event);
}
}
......
......@@ -23,15 +23,16 @@
```ts
import commonEventManager from '@ohos.commonEventManager';
import Base from '@ohos.base';
```
2. 创建订阅者信息,详细的订阅者信息数据类型及包含的参数请见[CommonEventSubscribeInfo](../reference/apis/js-apis-commonEventManager.md#commoneventsubscribeinfo)文档介绍。
```ts
// 用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
let subscriber = null;
let subscriber: commonEventManager.CommonEventSubscriber | null = null;
// 订阅者信息
let subscribeInfo = {
let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = {
events: ["usual.event.SCREEN_OFF"], // 订阅灭屏公共事件
}
```
......@@ -40,7 +41,7 @@
```ts
// 创建订阅者回调
commonEventManager.createSubscriber(subscribeInfo, (err, data) => {
commonEventManager.createSubscriber(subscribeInfo, (err: Base.BusinessError, data: commonEventManager.CommonEventSubscriber) => {
if (err) {
console.error(`Failed to create subscriber. Code is ${err.code}, message is ${err.message}`);
return;
......@@ -56,7 +57,7 @@
```ts
// 订阅公共事件回调
if (subscriber !== null) {
commonEventManager.subscribe(subscriber, (err, data) => {
commonEventManager.subscribe(subscriber, (err: Base.BusinessError, data: commonEventManager.CommonEventData) => {
if (err) {
console.error(`Failed to subscribe common event. Code is ${err.code}, message is ${err.message}`);
return;
......
......@@ -19,6 +19,7 @@
```ts
import commonEventManager from '@ohos.commonEventManager';
import Base from '@ohos.base';
```
2. 根据[动态订阅公共事件](common-event-subscription.md)章节的步骤来订阅某个事件。
......@@ -28,7 +29,7 @@
```ts
// subscriber为订阅事件时创建的订阅者对象
if (subscriber !== null) {
commonEventManager.unsubscribe(subscriber, (err) => {
commonEventManager.unsubscribe(subscriber, (err: Base.BusinessError) => {
if (err) {
console.error(`[CommonEvent] UnsubscribeCallBack err=${JSON.stringify(err)}`);
} else {
......
......@@ -63,15 +63,16 @@ createFormBindingData(obj?: Object | string): FormBindingData
```ts
import formBindingData from '@ohos.app.form.formBindingData';
import fs from '@ohos.file.fs';
import Base from '@ohos.base';
try {
let fd = fs.openSync('/path/to/form.png');
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)
let createFormBindingDataParam = new Map<string, string | Object>();
let formImagesParam = new Map<string, Object>();
formImagesParam.set('image', fd);
createFormBindingDataParam.set("name", '21°');
createFormBindingDataParam.set('formImages', formImagesParam);
formBindingData.createFormBindingData(createFormBindingDataParam);
} catch (error) {
......
......@@ -51,7 +51,7 @@ import Want from '@ohos.app.ability.Want';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onAddForm(want: Want) {
console.log(`FormExtensionAbility onAddForm, want: ${want.abilityName}`);
let dataObj1 = new Map<Object, string>();
let dataObj1 = new Map<string, string>();
dataObj1.set('temperature', '11c');
dataObj1.set('time', '11:00');
......@@ -107,20 +107,19 @@ onUpdateForm(formId: string): void
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formBindingData from '@ohos.app.form.formBindingData';
import formProvider from '@ohos.app.form.formProvider';
import Base from '@ohos.base';
export default class MyFormExtensionAbility extends FormExtensionAbility {
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: Base.BusinessError) => {
console.error(`FormExtensionAbility context updateForm failed, data: ${error}`);
});
}
};
......@@ -146,6 +145,7 @@ onChangeFormVisibility(newStatus: { [key: string]: number }): void
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formBindingData from '@ohos.app.form.formBindingData';
import formProvider from '@ohos.app.form.formProvider';
import Base from '@ohos.base';
// 由于arkTs中无Object.keys,且无法使用for..in...
// 若报arkTs问题,请将此方法单独抽离至一个ts文件中并暴露,在需要用到的ets文件中引入使用
......@@ -155,23 +155,21 @@ function getObjKeys(obj: Object): string[] {
}
export default class MyFormExtensionAbility extends FormExtensionAbility {
onChangeFormVisibility(newStatus) {
onChangeFormVisibility(newStatus: Record<string, number>) {
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]}`);
formProvider.updateForm(key, obj2).then((data) => {
console.log(`FormExtensionAbility context updateForm, data: ${data}`);
}).catch((error) => {
console.error(`Operation updateForm failed. Cause: ${error}`);
let keys: string[] = getObjKeys(newStatus);
for (let i: number = 0; i < keys.length; i++) {
console.log(`FormExtensionAbility onChangeFormVisibility, key: ${keys[i]}, value= ${newStatus[keys[i]]}`);
formProvider.updateForm(keys[i], obj2).then(() => {
console.log(`FormExtensionAbility context updateForm`);
}).catch((error: Base.BusinessError) => {
console.error(`Operation updateForm failed. Cause: ${JSON.stringify(error)}`);
});
}
}
......@@ -317,9 +315,9 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onShareForm(formId: string) {
console.log(`FormExtensionAbility onShareForm, formId: ${formId}`);
let wantParams = {
let wantParams: Record<string, Object> = {
'temperature': '20',
'time': '2022-8-8 09:59',s
'time': '2022-8-8 09:59',
};
return wantParams;
}
......@@ -355,8 +353,8 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onAcquireFormData(formId: string) {
console.log('FormExtensionAbility onAcquireFormData, formId: ${formId}');
let wantParams = {
console.log(`FormExtensionAbility onAcquireFormData, formId: ${formId}`);
let wantParams: Record<string, Object> = {
'temperature': '20',
'time': '2022-8-8 09:59',
};
......
......@@ -61,7 +61,7 @@ try {
}
});
} catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -114,10 +114,10 @@ try {
formHost.deleteForm(formId).then(() => {
console.log('formHost deleteForm success');
}).catch((error: Base.BusinessError) => {
console.error('formHost deleteForm, error: ${JSON.stringify(error)}');
console.error(`formHost deleteForm, error: ${JSON.stringify(error)}`);
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -167,7 +167,7 @@ try {
}
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -218,7 +218,7 @@ try {
}
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -274,7 +274,7 @@ try {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -324,7 +324,7 @@ try {
}
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -379,7 +379,7 @@ try {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -430,7 +430,7 @@ try {
}
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -485,7 +485,7 @@ try {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -533,7 +533,7 @@ try {
}
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -586,7 +586,7 @@ try {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -634,7 +634,7 @@ try {
}
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -687,7 +687,7 @@ try {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -736,7 +736,7 @@ try {
}
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -790,7 +790,7 @@ try {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -840,7 +840,7 @@ try {
}
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -895,7 +895,7 @@ try {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -935,7 +935,7 @@ try {
}
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -974,7 +974,7 @@ try {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -1023,7 +1023,7 @@ try {
}
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -1069,7 +1069,7 @@ try {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -1120,7 +1120,7 @@ try {
}
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -1172,7 +1172,7 @@ try {
}
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -1227,7 +1227,7 @@ try {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -1277,7 +1277,7 @@ try {
}
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -1330,7 +1330,7 @@ try {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -1392,7 +1392,7 @@ try {
}
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -1457,7 +1457,7 @@ try {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -1575,7 +1575,7 @@ try {
}
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -1630,7 +1630,7 @@ try {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -1680,7 +1680,7 @@ try {
}
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -1735,7 +1735,7 @@ try {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
## shareForm
......@@ -1785,7 +1785,7 @@ try {
}
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -1841,7 +1841,7 @@ try {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -1890,7 +1890,7 @@ try {
}
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -1942,7 +1942,7 @@ try {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -1990,7 +1990,7 @@ try {
}
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -2041,6 +2041,6 @@ try {
console.error(`error, code: ${error.code}, message: ${error.message}`);
});
} catch(error) {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message}`);
}
```
......@@ -57,7 +57,7 @@ try {
console.log(`formProvider setFormNextRefreshTime success`);
});
} catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message})`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message})`);
}
```
......@@ -110,7 +110,7 @@ try {
console.error(`promise error, code: ${error.code}, message: ${error.message})`);
});
} catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message})`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message})`);
}
```
......@@ -152,15 +152,10 @@ import Base from '@ohos.base';
let formId: string = '12400633174999288';
try {
class createFormBindingDataParamType {
temperature: string
time: string
}
let createFormBindingDataParam: createFormBindingDataParamType = {
temperature:'22c',
time:'22:00'
};
let obj = formBindingData.createFormBindingData(createFormBindingDataParam);
let obj: formBindingData.FormBindingData = formBindingData.createFormBindingData({
temperature: '22c',
time: '22:00'
});
formProvider.updateForm(formId, obj, (error: Base.BusinessError) => {
if (error) {
console.error(`callback error, code: ${error.code}, message: ${error.message})`);
......@@ -169,7 +164,7 @@ try {
console.log(`formProvider updateForm success`);
});
} catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message})`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message})`);
}
```
......@@ -215,23 +210,18 @@ import formBindingData from '@ohos.app.form.formBindingData';
import Base from '@ohos.base';
let formId: string = '12400633174999288';
class createFormBindingDataParamType {
temperature: string
time: string
}
let createFormBindingDataParam: createFormBindingDataParamType = {
temperature:'22c',
time:'22:00'
};
let obj = formBindingData.createFormBindingData(createFormBindingDataParam);
let obj: formBindingData.FormBindingData = formBindingData.createFormBindingData({
temperature: '22c',
time: '22:00'
});
try {
formProvider.updateForm(formId, obj).then(() => {
console.log(`formProvider updateForm success`);
}).catch((error: Base.BusinessError) => {
console.error(`promise error, code: ${error.code}, message: ${error.message})`);
console.error(`promise error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message})`);
});
} catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message})`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message})`);
}
```
......@@ -272,7 +262,7 @@ try {
console.log(`formProvider getFormsInfo, data: ${JSON.stringify(data)}`);
});
} catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message})`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message})`);
}
```
## getFormsInfo
......@@ -319,7 +309,7 @@ try {
console.log(`formProvider getFormsInfo, data: ${JSON.stringify(data)}`);
});
} catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message})`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message})`);
}
```
......@@ -371,7 +361,7 @@ try {
console.error(`promise error, code: ${error.code}, message: ${error.message})`);
});
} catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message})`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message})`);
}
```
......@@ -421,24 +411,19 @@ let want: Want = {
}
};
try {
class createFormBindingDataParamType {
temperature: string
time: string
}
let createFormBindingDataParam: createFormBindingDataParamType = {
temperature:'22c',
time:'22:00'
};
let obj = formBindingData.createFormBindingData(createFormBindingDataParam);
let obj: formBindingData.FormBindingData = formBindingData.createFormBindingData({
temperature: '22c',
time: '22:00'
});
formProvider.requestPublishForm(want, obj, (error: Base.BusinessError, data: string) => {
if (error) {
console.error(`callback error, code: ${error.code}, message: ${error.message})`);
console.error(`callback error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message})`);
return;
}
console.log('formProvider requestPublishForm, form ID is: ${JSON.stringify(data)}');
});
} catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message})`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message})`);
}
```
......@@ -494,7 +479,7 @@ try {
console.log(`formProvider requestPublishForm, form ID is: ${JSON.stringify(data)}`);
});
} catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message})`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message})`);
}
```
......@@ -554,7 +539,7 @@ try {
console.error(`promise error, code: ${error.code}, message: ${error.message})`);
});
} catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message})`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message})`);
}
```
......@@ -614,13 +599,13 @@ try {
console.log(`formProvider requestPublishForm, form ID is: ${JSON.stringify(data)}`);
});
} catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message})`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message})`);
}
}
}
});
} catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message})`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message})`);
}
```
......@@ -674,13 +659,13 @@ try {
console.error(`promise error, code: ${error.code}, message: ${error.message})`);
});
} catch (error) {
console.error(`catch error, code: ${error.code}, message: ${error.message})`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message})`);
}
}
}).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})`);
console.error(`catch error, code: ${(error as Base.BusinessError).code}, message: ${(error as Base.BusinessError).message})`);
}
```
\ No newline at end of file
......@@ -50,6 +50,7 @@ createFormBindingData(obj?: Object | string): FormBindingData
```ts
import formBindingData from '@ohos.application.formBindingData';
import fs from '@ohos.file.fs';
import Base from '@ohos.base';
try {
let fd = fs.openSync('/path/to/form.png');
......@@ -61,6 +62,6 @@ try {
formBindingData.createFormBindingData(createFormBindingDataParam);
} catch (error) {
console.error('catch error, error: ${JSON.stringify(error)}');
console.error(`catch error, error: ${JSON.stringify(error as Base.BusinessError)}`);
}
```
......@@ -37,9 +37,9 @@ deleteForm(formId: string, callback: AsyncCallback&lt;void&gt;): void
import formHost from '@ohos.application.formHost';
let formId: string = '12400633174999288';
formHost.deleteForm(formId, (error, data) => {
formHost.deleteForm(formId, (error: Base.BusinessError) => {
if (error.code) {
console.error('formHost deleteForm, error: ${JSON.stringify(error)}');
console.error(`formHost deleteForm, error: ${JSON.stringify(error)}`);
}
});
```
......@@ -344,7 +344,7 @@ import Base from '@ohos.base';
let formId: string[] = ['12400633174999288'];
formHost.notifyVisibleForms(formId, (error: Base.BusinessError) => {
if (error.code) {
console.error('formHost notifyVisibleForms, error: ${JSON.stringify(error)}');
console.error(`formHost notifyVisibleForms, error: ${JSON.stringify(error)}`);
}
});
```
......
......@@ -97,16 +97,11 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData,call
import formBindingData from '@ohos.app.form.formBindingData';
import Base from '@ohos.base'
let formId = '12400633174999288';
class createBindingDataType {
temperature: string
time: string
};
let createBindingDataParam: createBindingDataType = {
temperature:'22c',
time:'22:00'
};
let obj = formBindingData.createFormBindingData(createBindingDataParam);
let formId: string = '12400633174999288';
let obj = formBindingData.createFormBindingData({
temperature: '22c',
time: '22:00'
});
formProvider.updateForm(formId, obj, (error: Base.BusinessError) => {
if (error.code) {
console.error(`formProvider updateForm, error: ${JSON.stringify(error)}`);
......@@ -142,15 +137,10 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Pr
import Base from '@ohos.base'
let formId: string = '12400633174999288';
class createBindingDataType {
temperature: string
time: string
};
let createBindingDataParam: createBindingDataType = {
temperature:'22c',
time:'22:00'
};
let obj = formBindingData.createFormBindingData(createBindingDataParam);
let obj = formBindingData.createFormBindingData({
temperature: '22c',
time: '22:00'
});
formProvider.updateForm(formId, obj).then(() => {
console.log('formProvider updateForm success');
}).catch((error: Base.BusinessError) => {
......
......@@ -11,8 +11,6 @@
```ts
import CommonEvent from '@ohos.commonEvent';
import CommonEventManager from '@ohos.commonEventManager';
import Base from '@ohos.base';
```
## Support
......@@ -42,6 +40,8 @@ publish(event: string, callback: AsyncCallback\<void>): void
**示例:**
```ts
import Base from '@ohos.base';
//发布公共事件回调
function publishCB(err:Base.BusinessError) {
if (err.code) {
......@@ -78,6 +78,9 @@ publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\
```ts
import Base from '@ohos.base';
import CommonEventManager from '@ohos.commonEventManager';
//公共事件相关信息
let options:CommonEventManager.CommonEventPublishData = {
code: 0, //公共事件的初始代码
......@@ -122,6 +125,8 @@ publishAsUser(event: string, userId: number, callback: AsyncCallback\<void>): vo
**示例:**
```ts
import Base from '@ohos.base';
// 发布公共事件回调
function publishCB(err:Base.BusinessError) {
if (err.code) {
......@@ -164,6 +169,9 @@ publishAsUser(event: string, userId: number, options: CommonEventPublishData, ca
```ts
import Base from '@ohos.base';
import CommonEventManager from '@ohos.commonEventManager';
// 公共事件相关信息
let options:CommonEventManager.CommonEventPublishData = {
code: 0, // 公共事件的初始代码
......@@ -208,6 +216,9 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallbac
```ts
import Base from '@ohos.base';
import CommonEventManager from '@ohos.commonEventManager';
let subscriber:CommonEventManager.CommonEventSubscriber; // 用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
// 订阅者信息
......@@ -254,6 +265,9 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise\<CommonEventS
**示例:**
```ts
import Base from '@ohos.base';
import CommonEventManager from '@ohos.commonEventManager';
let subscriber:CommonEventManager.CommonEventSubscriber; // 用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
// 订阅者信息
......@@ -291,6 +305,9 @@ subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\<CommonEven
**示例:**
```ts
import Base from '@ohos.base';
import CommonEventManager from '@ohos.commonEventManager';
let subscriber:CommonEventManager.CommonEventSubscriber;// 用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
// 订阅者信息
......@@ -344,6 +361,9 @@ unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\<void>):
**示例:**
```ts
import Base from '@ohos.base';
import CommonEventManager from '@ohos.commonEventManager';
let subscriber:CommonEventManager.CommonEventSubscriber; // 用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
// 订阅者信息
......
......@@ -10,7 +10,6 @@
```ts
import CommonEventManager from '@ohos.commonEventManager';
import Base from '@ohos.base';
```
## Support
......@@ -48,6 +47,8 @@ publish(event: string, callback: AsyncCallback\<void>): void
**示例:**
```ts
import Base from '@ohos.base';
//发布公共事件回调
function publishCB(err:Base.BusinessError) {
if (err) {
......@@ -96,6 +97,8 @@ publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\
**示例:**
```ts
import Base from '@ohos.base';
//公共事件相关信息
let options:CommonEventManager.CommonEventPublishData = {
code: 0, //公共事件的初始代码
......@@ -153,6 +156,8 @@ publishAsUser(event: string, userId: number, callback: AsyncCallback\<void>): vo
**示例:**
```ts
import Base from '@ohos.base';
//发布公共事件回调
function publishCB(err:Base.BusinessError) {
if (err) {
......@@ -208,6 +213,8 @@ publishAsUser(event: string, userId: number, options: CommonEventPublishData, ca
```ts
import Base from '@ohos.base';
//公共事件相关信息
let options:CommonEventManager.CommonEventPublishData = {
code: 0, //公共事件的初始代码
......@@ -253,6 +260,8 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallbac
**示例:**
```ts
import Base from '@ohos.base';
let subscriber:CommonEventManager.CommonEventSubscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
//订阅者信息
......@@ -301,6 +310,8 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise\<CommonEventS
**示例:**
```ts
import Base from '@ohos.base';
let subscriber:CommonEventManager.CommonEventSubscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
//订阅者信息
......@@ -340,6 +351,8 @@ createSubscriber的同步接口。
**示例:**
```ts
import Base from '@ohos.base';
let subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
//订阅者信息
......@@ -385,6 +398,8 @@ subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\<CommonEven
**示例:**
```ts
import Base from '@ohos.base';
//订阅者信息
let subscriber:CommonEventManager.CommonEventSubscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
......@@ -456,6 +471,8 @@ unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\<void>):
**示例:**
```ts
import Base from '@ohos.base';
let subscriber:CommonEventManager.CommonEventSubscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
//订阅者信息
let subscribeInfo:CommonEventManager.CommonEventSubscribeInfo = {
......@@ -543,6 +560,8 @@ removeStickyCommonEvent(event: string, callback: AsyncCallback\<void>): void
```ts
import Base from '@ohos.base';
CommonEventManager.removeStickyCommonEvent("sticky_event", (err:Base.BusinessError) => {
if (err) {
console.info(`Remove sticky event AsyncCallback failed, errCode: ${err.code}, errMes: ${err.message}`);
......@@ -590,6 +609,8 @@ removeStickyCommonEvent(event: string): Promise\<void>
```ts
import Base from '@ohos.base';
CommonEventManager.removeStickyCommonEvent("sticky_event").then(() => {
console.info(`Remove sticky event AsyncCallback success`);
}).catch ((err:Base.BusinessError) => {
......@@ -627,6 +648,8 @@ setStaticSubscriberState(enable: boolean, callback: AsyncCallback\<void>): void;
```ts
import Base from '@ohos.base';
CommonEventManager.setStaticSubscriberState(true, (err:Base.BusinessError) => {
if (!err) {
console.info(`Set static subscriber state callback failed, err is null.`);
......@@ -675,6 +698,8 @@ setStaticSubscriberState(enable: boolean): Promise\<void>;
```ts
import Base from '@ohos.base';
CommonEventManager.setStaticSubscriberState(false).then(() => {
console.info(`Set static subscriber state promise success`);
}).catch ((err:Base.BusinessError) => {
......
......@@ -10,8 +10,8 @@
## 导入模块
```javascript
import emitter from '@ohos.events.emitter'
```ts
import emitter from '@ohos.events.emitter';
```
## 权限列表
......@@ -35,16 +35,15 @@ on(event: [InnerEvent](#innerevent), callback: Callback\<[EventData](#eventdata)
**示例:**
```javascript
let innerEvent = {
```ts
let innerEvent: emitter.InnerEvent = {
eventId: 1
};
// 收到eventId为1的事件后执行回调函数
function emitterCallback() {
// 收到eventId为1的事件后执行回调函数
emitter.on(innerEvent, () => {
console.info('callback');
}
emitter.on(innerEvent, emitterCallback);
});
```
## emitter.once
......@@ -64,16 +63,15 @@ once(event: [InnerEvent](#innerevent), callback: Callback\<[EventData](#eventdat
**示例:**
```javascript
let innerEvent = {
```ts
let innerEvent: emitter.InnerEvent = {
eventId: 1
};
// 收到eventId为1的事件后执行该回调函数
function emitterCallback() {
emitter.once(innerEvent, () => {
console.info('once callback');
};
emitter.once(innerEvent, emitterCallback);
});
```
## emitter.off
......@@ -92,7 +90,7 @@ off(eventId: number): void
**示例:**
```javascript
```ts
// 取消eventID为1的所有事件回调处理函数
emitter.off(1);
```
......@@ -114,13 +112,12 @@ off(eventId: number, callback: Callback\<[EventData](#eventdata)\>): void
**示例:**
```javascript
```ts
// 取消eventID为1的事件回调处理函数 emitterCallback
// 如果该回调处理函数没有被订阅,则不做任何处理
function emitterCallback() {
emitter.off(1, () => {
console.info('callback');
}
emitter.off(1, emitterCallback);
});
```
## emitter.emit
......@@ -140,15 +137,15 @@ emit(event: [InnerEvent](#innerevent), data?: [EventData](#eventdata)): void
**示例:**
```javascript
let eventData = {
```ts
let eventData: emitter.EventData = {
data: {
"content": "c",
"id": 1,
}
};
let innerEvent = {
let innerEvent: emitter.InnerEvent = {
eventId: 1,
priority: emitter.EventPriority.HIGH
};
......
......@@ -66,7 +66,7 @@ export default class MyFormExtensionAbility extends FormExtensionAbility {
};
this.context.startAbility(want, (error: Base.BusinessError) => {
if (error) {
console.error('FormExtensionContext startAbility, error:${JSON.stringify(error)}');
console.error(`FormExtensionContext startAbility, error:${JSON.stringify(error)}`);
} else {
console.log('FormExtensionContext startAbility success');
}
......@@ -213,7 +213,7 @@ export default class MyFormExtensionAbility extends FormExtensionAbility {
connection = this.context.connectServiceExtensionAbility(want, options);
} catch (paramError) {
// 处理入参错误异常
console.error(`error.code: ${paramError.code}, error.message: ${paramError.message}`);
console.error(`error.code: ${(paramError as Base.BusinessError).code}, error.message: ${(paramError as Base.BusinessError).message}`);
}
}
};
......@@ -275,7 +275,7 @@ export default class MyFormExtensionAbility extends FormExtensionAbility {
} catch (paramError) {
commRemote = null;
// 处理入参错误异常
console.error(`error.code: ${paramError.code}, error.message: ${paramError.message}`);
console.error(`error.code: ${(paramError as Base.BusinessError).code}, error.message: ${(paramError as Base.BusinessError).message}`);
}
}
};
......@@ -343,7 +343,7 @@ export default class MyFormExtensionAbility extends FormExtensionAbility {
} catch (paramError) {
commRemote = null;
// 处理入参错误异常
console.error(`error.code: ${paramError.code}, error.message: ${paramError.message}`);
console.error(`error.code: ${(paramError as Base.BusinessError).code}, error.message: ${(paramError as Base.BusinessError).message}`);
}
}
};
......
......@@ -8,6 +8,8 @@
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
## 属性
| 名称 | 类型 | 必填 | 说明 |
| ---------------- | ---------------------- | ---- | --------------------------------- |
| soundEnabled | [NotificationFlagStatus](#notificationflagstatus) | 否 | 是否启用声音提示。 |
......
......@@ -32,8 +32,10 @@ onConsume?: (data: [SubscribeCallbackData](js-apis-notification.md#subscribecall
**示例:**
```javascript
function subscribeCallback(err) {
```ts
import Base from '@ohos.base';
let subscribeCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -41,13 +43,13 @@ function subscribeCallback(err) {
}
};
function onConsumeCallback(data) {
let onConsumeCallback = (data: notificationSubscribe.SubscribeCallbackData) => {
console.info('===> onConsume in test');
let req = data.request;
console.info('===> onConsume callback req.id:' + req.id);
};
let subscriber = {
let subscriber: notificationSubscribe.NotificationSubscriber = {
onConsume: onConsumeCallback
};
......@@ -72,8 +74,10 @@ onCancel?:(data: [SubscribeCallbackData](js-apis-notification.md#subscribecallba
**示例:**
```javascript
function subscribeCallback(err) {
```ts
import Base from '@ohos.base';
let subscribeCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -81,13 +85,13 @@ function subscribeCallback(err) {
}
};
function onCancelCallback(data) {
function onCancelCallback(data: notificationSubscribe.SubscribeCallbackData) {
console.info('===> onCancel in test');
let req = data.request;
console.info('===> onCancel callback req.id:' + req.id);
}
let subscriber = {
let subscriber: notificationSubscribe.NotificationSubscriber = {
onCancel: onCancelCallback
};
......@@ -112,8 +116,10 @@ onUpdate?:(data: [NotificationSortingMap](js-apis-notification.md#notificationso
**示例:**
```javascript
function subscribeCallback(err) {
```ts
import Base from '@ohos.base';
let subscribeCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -121,12 +127,10 @@ function subscribeCallback(err) {
}
};
function onUpdateCallback(map) {
let subscriber: notificationSubscribe.NotificationSubscriber = {
onUpdate: (map) => {
console.info('===> onUpdateCallback map:' + JSON.stringify(map));
}
let subscriber = {
onUpdate: onUpdateCallback
}
};
notificationSubscribe.subscribe(subscriber, subscribeCallback);
......@@ -144,8 +148,10 @@ onConnect?:() => void
**示例:**
```javascript
function subscribeCallback(err) {
```ts
import Base from '@ohos.base';
let subscribeCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -153,11 +159,11 @@ function subscribeCallback(err) {
}
};
function onConnectCallback() {
let onConnectCallback = () => {
console.info('===> onConnect in test');
}
let subscriber = {
let subscriber: notificationSubscribe.NotificationSubscriber = {
onConnect: onConnectCallback
};
......@@ -176,30 +182,32 @@ onDisconnect?:() => void
**示例:**
```javascript
function subscribeCallback(err) {
```ts
import Base from '@ohos.base';
let subscribeCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("subscribeCallback");
}
};
function unsubscribeCallback(err) {
if (err.code) {
let unsubscribeCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`unsubscribe failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("unsubscribeCallback");
}
};
function onConnectCallback() {
let onConnectCallback = () => {
console.info('===> onConnect in test');
}
function onDisconnectCallback() {
let onDisconnectCallback = () => {
console.info('===> onDisconnect in test');
}
let subscriber = {
let subscriber: notificationSubscribe.NotificationSubscriber = {
onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback
};
......@@ -222,8 +230,10 @@ onDestroy?:() => void
**示例:**
```javascript
function subscribeCallback(err) {
```ts
import Base from '@ohos.base';
let subscribeCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -231,11 +241,11 @@ function subscribeCallback(err) {
}
};
function onDestroyCallback() {
let onDestroyCallback = () => {
console.info('===> onDestroy in test');
}
let subscriber = {
let subscriber: notificationSubscribe.NotificationSubscriber = {
onDestroy: onDestroyCallback
};
......@@ -260,8 +270,10 @@ onDoNotDisturbDateChange?:(mode: notification.[DoNotDisturbDate](js-apis-notific
**示例:**
```javascript
function subscribeCallback(err) {
```ts
import Base from '@ohos.base';
let subscribeCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -269,11 +281,11 @@ function subscribeCallback(err) {
}
};
function onDoNotDisturbDateChangeCallback(mode) {
let onDoNotDisturbDateChangeCallback = (mode: NotificationManager.DoNotDisturbDate) => {
console.info('===> onDoNotDisturbDateChange:' + mode);
}
let subscriber = {
let subscriber: notificationSubscribe.NotificationSubscriber = {
onDoNotDisturbDateChange: onDoNotDisturbDateChangeCallback
};
......@@ -299,8 +311,10 @@ onEnabledNotificationChanged?:(callbackData: [EnabledNotificationCallbackData](j
**示例:**
```javascript
function subscribeCallback(err) {
```ts
import Base from '@ohos.base';
let subscribeCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -308,13 +322,13 @@ function subscribeCallback(err) {
}
};
function onEnabledNotificationChangedCallback(callbackData) {
let onEnabledNotificationChangedCallback = (callbackData: notificationSubscribe.EnabledNotificationCallbackData) => {
console.info("bundle: ", callbackData.bundle);
console.info("uid: ", callbackData.uid);
console.info("enable: ", callbackData.enable);
};
let subscriber = {
let subscriber: notificationSubscribe.NotificationSubscriber = {
onEnabledNotificationChanged: onEnabledNotificationChangedCallback
};
......@@ -339,8 +353,10 @@ notificationSubscribe.subscribe(subscriber, subscribeCallback);
**示例:**
```javascript
function subscribeCallback(err) {
```ts
import Base from '@ohos.base';
let subscribeCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -348,14 +364,12 @@ function subscribeCallback(err) {
}
};
function onBadgeChangedCallback(data) {
let subscriber: notificationSubscribe.NotificationSubscriber = {
onBadgeChanged: (data) => {
console.info("bundle: ", data.bundle);
console.info("uid: ", data.uid);
console.info("badgeNumber: ", data.badgeNumber);
};
let subscriber = {
onBadgeChanged: onBadgeChangedCallback
}
};
notificationSubscribe.subscribe(subscriber, subscribeCallback);
......
......@@ -10,7 +10,7 @@
## 导入模块
```js
```ts
import Notification from '@ohos.notification';
```
......@@ -31,17 +31,20 @@ publish(request: NotificationRequest, callback: AsyncCallback\<void\>): void
**示例:**
```js
```ts
import NotificationManager from '@ohos.notificationManager';
import Base from '@ohos.base';
// publish回调
function publishCallback(err) {
if (err.code) {
console.error(`publish failed, code is ${err.code}`);
let publishCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`publish failed, code is ${err}`);
} else {
console.info("publish success");
}
}
// 通知Request对象
let notificationRequest = {
let notificationRequest: NotificationManager.NotificationRequest = {
id: 1,
content: {
contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
......@@ -71,10 +74,13 @@ publish(request: NotificationRequest): Promise\<void\>
**示例:**
```js
```ts
import NotificationManager from '@ohos.notificationManager';
import Base from '@ohos.base';
// 通知Request对象
let notificationRequest = {
notificationId: 1,
let notificationRequest: NotificationManager.NotificationRequest = {
id: 1,
content: {
contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: {
......@@ -86,8 +92,9 @@ let notificationRequest = {
};
Notification.publish(notificationRequest).then(() => {
console.info("publish success");
}).catch((err: Base.BusinessError) => {
console.error(`publish failed, code is ${err}`);
});
```
## Notification.publish<sup>8+</sup>
......@@ -112,19 +119,22 @@ publish(request: NotificationRequest, userId: number, callback: AsyncCallback\<v
**示例:**
```js
```ts
import NotificationManager from '@ohos.notificationManager';
import Base from '@ohos.base';
// publish回调
function publishCallback(err) {
if (err.code) {
let publishCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`publish failed, code is ${err.code}`);
} else {
console.info("publish success");
}
}
// 用户ID
let userId = 1;
let userId: number = 1;
// 通知Request对象
let notificationRequest = {
let notificationRequest: NotificationManager.NotificationRequest = {
id: 1,
content: {
contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
......@@ -159,9 +169,12 @@ publish(request: NotificationRequest, userId: number): Promise\<void\>
**示例:**
```js
let notificationRequest = {
notificationId: 1,
```ts
import NotificationManager from '@ohos.notificationManager';
import Base from '@ohos.base';
let notificationRequest: NotificationManager.NotificationRequest = {
id: 1,
content: {
contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
normal: {
......@@ -172,10 +185,12 @@ let notificationRequest = {
}
};
let userId = 1;
let userId: number = 1;
Notification.publish(notificationRequest, userId).then(() => {
console.info("publish success");
}).catch((err: Base.BusinessError) => {
console.error(`publish failed, code is ${err}`);
});
```
......@@ -198,10 +213,12 @@ cancel(id: number, label: string, callback: AsyncCallback\<void\>): void
**示例:**
```js
```ts
import Base from '@ohos.base';
// cancel回调
function cancelCallback(err) {
if (err.code) {
let cancelCallback = (err: Base.BusinessError) => {
if (err) {
console.info("cancel failed " + JSON.stringify(err));
} else {
console.info("cancel success");
......@@ -229,9 +246,13 @@ cancel(id: number, label?: string): Promise\<void\>
**示例:**
```js
```ts
import Base from '@ohos.base';
Notification.cancel(0).then(() => {
console.info("cancel success");
}).catch((err: Base.BusinessError) => {
console.error(`cancel failed, code is ${err}`);
});
```
......@@ -254,10 +275,12 @@ cancel(id: number, callback: AsyncCallback\<void\>): void
**示例:**
```js
```ts
import Base from '@ohos.base';
// cancel回调
function cancelCallback(err) {
if (err.code) {
let cancelCallback = (err: Base.BusinessError) => {
if (err) {
console.info("cancel failed " + JSON.stringify(err));
} else {
console.info("cancel success");
......@@ -284,10 +307,12 @@ cancelAll(callback: AsyncCallback\<void\>): void
**示例:**
```js
```ts
import Base from '@ohos.base';
// cancel回调
function cancelAllCallback(err) {
if (err.code) {
let cancelAllCallback = (err: Base.BusinessError) => {
if (err) {
console.info("cancelAll failed " + JSON.stringify(err));
} else {
console.info("cancelAll success");
......@@ -306,9 +331,13 @@ cancelAll(): Promise\<void\>
**示例:**
```js
```ts
import Base from '@ohos.base';
Notification.cancelAll().then(() => {
console.info("cancelAll success");
}).catch((err: Base.BusinessError) => {
console.error(`cancelAll failed, code is ${err}`);
});
```
......@@ -333,17 +362,20 @@ addSlot(slot: NotificationSlot, callback: AsyncCallback\<void\>): void
**示例:**
```js
```ts
import NotificationManager from '@ohos.notificationManager';
import Base from '@ohos.base';
// addslot回调
function addSlotCallBack(err) {
if (err.code) {
let addSlotCallBack = (err: Base.BusinessError) => {
if (err) {
console.info("addSlot failed " + JSON.stringify(err));
} else {
console.info("addSlot success");
}
}
// 通知slot对象
let notificationSlot = {
let notificationSlot: NotificationManager.NotificationSlot = {
type: Notification.SlotType.SOCIAL_COMMUNICATION
};
Notification.addSlot(notificationSlot, addSlotCallBack);
......@@ -369,13 +401,18 @@ addSlot(slot: NotificationSlot): Promise\<void\>
**示例:**
```js
```ts
import NotificationManager from '@ohos.notificationManager';
import Base from '@ohos.base';
// 通知slot对象
let notificationSlot = {
let notificationSlot: NotificationManager.NotificationSlot = {
type: Notification.SlotType.SOCIAL_COMMUNICATION
};
Notification.addSlot(notificationSlot).then(() => {
console.info("addSlot success");
}).catch((err: Base.BusinessError) => {
console.error(`addSlot failed, code is ${err}`);
});
```
......@@ -396,10 +433,12 @@ addSlot(type: SlotType, callback: AsyncCallback\<void\>): void
**示例:**
```js
```ts
import Base from '@ohos.base';
// addslot回调
function addSlotCallBack(err) {
if (err.code) {
let addSlotCallBack = (err: Base.BusinessError) => {
if (err) {
console.info("addSlot failed " + JSON.stringify(err));
} else {
console.info("addSlot success");
......@@ -424,9 +463,13 @@ addSlot(type: SlotType): Promise\<void\>
**示例:**
```js
```ts
import NotificationManager from '@ohos.notificationManager';
Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then(() => {
console.info("addSlot success");
}).catch((err: Base.BusinessError) => {
console.error(`addSlot failed, code is ${err}`);
});
```
......@@ -451,21 +494,24 @@ addSlots(slots: Array\<NotificationSlot\>, callback: AsyncCallback\<void\>): voi
**示例:**
```js
```ts
import NotificationManager from '@ohos.notificationManager';
import Base from '@ohos.base';
// addSlots回调
function addSlotsCallBack(err) {
if (err.code) {
let addSlotsCallBack = (err: Base.BusinessError) => {
if (err) {
console.info("addSlots failed " + JSON.stringify(err));
} else {
console.info("addSlots success");
}
}
// 通知slot对象
let notificationSlot = {
let notificationSlot: NotificationManager.NotificationSlot = {
type: Notification.SlotType.SOCIAL_COMMUNICATION
};
// 通知slot array 对象
let notificationSlotArray = new Array();
let notificationSlotArray: NotificationManager.NotificationSlot[] = new Array();
notificationSlotArray[0] = notificationSlot;
Notification.addSlots(notificationSlotArray, addSlotsCallBack);
......@@ -491,17 +537,22 @@ addSlots(slots: Array\<NotificationSlot\>): Promise\<void\>
**示例:**
```js
```ts
import NotificationManager from '@ohos.notificationManager';
import Base from '@ohos.base';
// 通知slot对象
let notificationSlot = {
let notificationSlot: NotificationManager.NotificationSlot = {
type: Notification.SlotType.SOCIAL_COMMUNICATION
};
// 通知slot array 对象
let notificationSlotArray = new Array();
let notificationSlotArray: NotificationManager.NotificationSlot[] = new Array();
notificationSlotArray[0] = notificationSlot;
Notification.addSlots(notificationSlotArray).then(() => {
console.info("addSlots success");
}).catch((err: Base.BusinessError) => {
console.error(`addSlot failed, code is ${err}`);
});
```
......@@ -522,16 +573,18 @@ getSlot(slotType: SlotType, callback: AsyncCallback\<NotificationSlot\>): void
**示例:**
```js
```ts
import Base from '@ohos.base';
// getSlot回调
function getSlotCallback(err, data) {
if (err.code) {
let getSlotCallback = (err: Base.BusinessError) => {
if (err) {
console.info("getSlot failed " + JSON.stringify(err));
} else {
console.info("getSlot success");
}
}
let slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
let slotType: Notification.SlotType = Notification.SlotType.SOCIAL_COMMUNICATION;
Notification.getSlot(slotType, getSlotCallback);
```
......@@ -557,10 +610,14 @@ getSlot(slotType: SlotType): Promise\<NotificationSlot\>
**示例:**
```js
let slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
```ts
import Base from '@ohos.base';
let slotType: Notification.SlotType = Notification.SlotType.SOCIAL_COMMUNICATION;
Notification.getSlot(slotType).then((data) => {
console.info("getSlot success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`getSlot failed, code is ${err}`);
});
```
......@@ -580,10 +637,12 @@ getSlots(callback: AsyncCallback\<Array\<NotificationSlot>>): void
**示例:**
```js
```ts
import Base from '@ohos.base';
// getSlots回调
function getSlotsCallback(err, data) {
if (err.code) {
function getSlotsCallback(err: Base.BusinessError) {
if (err) {
console.info("getSlots failed " + JSON.stringify(err));
} else {
console.info("getSlots success");
......@@ -608,9 +667,13 @@ getSlots(): Promise\<Array\<NotificationSlot\>>
**示例:**
```js
```ts
import Base from '@ohos.base';
Notification.getSlots().then((data) => {
console.info("getSlots success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`getSlots failed, code is ${err}`);
});
```
......@@ -631,17 +694,19 @@ removeSlot(slotType: SlotType, callback: AsyncCallback\<void\>): void
**示例:**
```js
```ts
import Base from '@ohos.base';
// removeSlot回调
function removeSlotCallback(err) {
if (err.code) {
let removeSlotCallback = (err: Base.BusinessError) => {
if (err) {
console.info("removeSlot failed " + JSON.stringify(err));
} else {
console.info("removeSlot success");
}
}
let slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
Notification.removeSlot(slotType,removeSlotCallback);
let slotType: Notification.SlotType = Notification.SlotType.SOCIAL_COMMUNICATION;
Notification.removeSlot(slotType, removeSlotCallback);
```
## Notification.removeSlot
......@@ -660,10 +725,14 @@ removeSlot(slotType: SlotType): Promise\<void\>
**示例:**
```js
let slotType = Notification.SlotType.SOCIAL_COMMUNICATION;
```ts
import Base from '@ohos.base';
let slotType: Notification.SlotType = Notification.SlotType.SOCIAL_COMMUNICATION;
Notification.removeSlot(slotType).then(() => {
console.info("removeSlot success");
}).catch((err: Base.BusinessError) => {
console.error(`removeSlot failed, code is ${err}`);
});
```
......@@ -683,9 +752,11 @@ removeAllSlots(callback: AsyncCallback\<void\>): void
**示例:**
```js
function removeAllCallBack(err) {
if (err.code) {
```ts
import Base from '@ohos.base';
let removeAllCallBack = (err: Base.BusinessError) => {
if (err) {
console.info("removeAllSlots failed " + JSON.stringify(err));
} else {
console.info("removeAllSlots success");
......@@ -704,9 +775,13 @@ removeAllSlots(): Promise\<void\>
**示例:**
```js
```ts
import Base from '@ohos.base';
Notification.removeAllSlots().then(() => {
console.info("removeAllSlots success");
}).catch((err: Base.BusinessError) => {
console.error(`removeAllSlots failed, code is ${err}`);
});
```
......@@ -732,22 +807,25 @@ subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, c
**示例:**
```js
```ts
import Base from '@ohos.base';
import NotificationSubscribe from '@ohos.notificationSubscribe';
// subscribe回调
function subscribeCallback(err) {
if (err.code) {
let subscribeCallback = (err: Base.BusinessError) => {
if (err) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribe success");
}
}
function onConsumeCallback(data) {
let onConsumeCallback = (data: NotificationSubscribe.SubscribeCallbackData) => {
console.info("Consume callback: " + JSON.stringify(data));
}
let subscriber = {
let subscriber: NotificationSubscribe.NotificationSubscriber = {
onConsume: onConsumeCallback
};
let info = {
let info: NotificationSubscribe.NotificationSubscribeInfo = {
bundleNames: ["bundleName1", "bundleName2"]
};
Notification.subscribe(subscriber, info, subscribeCallback);
......@@ -774,18 +852,21 @@ subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>):
**示例:**
```js
function subscribeCallback(err) {
if (err.code) {
```ts
import Base from '@ohos.base';
import NotificationSubscribe from '@ohos.notificationSubscribe';
let subscribeCallback = (err: Base.BusinessError) => {
if (err) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribe success");
}
}
function onConsumeCallback(data) {
function onConsumeCallback(data: NotificationSubscribe.SubscribeCallbackData) {
console.info("Consume callback: " + JSON.stringify(data));
}
let subscriber = {
let subscriber: NotificationSubscribe.NotificationSubscriber = {
onConsume: onConsumeCallback
};
Notification.subscribe(subscriber, subscribeCallback);
......@@ -812,15 +893,20 @@ subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo):
**示例:**
```js
function onConsumeCallback(data) {
```ts
import Base from '@ohos.base';
import NotificationSubscribe from '@ohos.notificationSubscribe';
function onConsumeCallback(data: NotificationSubscribe.SubscribeCallbackData) {
console.info("Consume callback: " + JSON.stringify(data));
}
let subscriber = {
let subscriber: NotificationSubscribe.NotificationSubscriber = {
onConsume: onConsumeCallback
};
Notification.subscribe(subscriber).then(() => {
console.info("subscribe success");
}).catch((err: Base.BusinessError) => {
console.error(`subscribe failed, code is ${err}`);
});
```
......@@ -845,18 +931,21 @@ unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>)
**示例:**
```js
function unsubscribeCallback(err) {
if (err.code) {
```ts
import Base from '@ohos.base';
import NotificationSubscribe from '@ohos.notificationSubscribe';
let unsubscribeCallback = (err: Base.BusinessError) => {
if (err) {
console.info("unsubscribe failed " + JSON.stringify(err));
} else {
console.info("unsubscribe success");
}
}
function onDisconnectCallback() {
let onDisconnectCallback = () => {
console.info("subscribe disconnect");
}
let subscriber = {
let subscriber: NotificationSubscribe.NotificationSubscriber = {
onDisconnect: onDisconnectCallback
};
Notification.unsubscribe(subscriber, unsubscribeCallback);
......@@ -882,15 +971,20 @@ unsubscribe(subscriber: NotificationSubscriber): Promise\<void\>
**示例:**
```js
```ts
import Base from '@ohos.base';
import NotificationSubscribe from '@ohos.notificationSubscribe';
function onDisconnectCallback() {
console.info("subscribe disconnect");
}
let subscriber = {
let subscriber: NotificationSubscribe.NotificationSubscriber = {
onDisconnect: onDisconnectCallback
};
Notification.unsubscribe(subscriber).then(() => {
console.info("unsubscribe success");
}).catch((err: Base.BusinessError) => {
console.error(`unsubscribe failed, code is ${err}`);
});
```
......@@ -916,15 +1010,17 @@ enableNotification(bundle: BundleOption, enable: boolean, callback: AsyncCallbac
**示例:**
```js
function enableNotificationCallback(err) {
if (err.code) {
```ts
import Base from '@ohos.base';
let enableNotificationCallback = (err: Base.BusinessError) => {
if (err) {
console.info("enableNotification failed " + JSON.stringify(err));
} else {
console.info("enableNotification success");
}
}
let bundle = {
let bundle: Notification.BundleOption = {
bundle: "bundleName1",
};
Notification.enableNotification(bundle, false, enableNotificationCallback);
......@@ -951,13 +1047,18 @@ enableNotification(bundle: BundleOption, enable: boolean): Promise\<void\>
**示例:**
```js
let bundle = {
```ts
import Base from '@ohos.base';
let bundle: Notification.BundleOption = {
bundle: "bundleName1",
};
Notification.enableNotification(bundle, false).then(() => {
console.info("enableNotification success");
}).catch((err: Base.BusinessError) => {
console.error(`enableNotification failed, code is ${err}`);
});
```
## Notification.isNotificationEnabled
......@@ -981,15 +1082,17 @@ isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\<boolean\>):
**示例:**
```js
function isNotificationEnabledCallback(err, data) {
if (err.code) {
```ts
import Base from '@ohos.base';
let isNotificationEnabledCallback = (err: Base.BusinessError, data: boolean) => {
if (err) {
console.info("isNotificationEnabled failed " + JSON.stringify(err));
} else {
console.info("isNotificationEnabled success");
}
}
let bundle = {
let bundle: Notification.BundleOption = {
bundle: "bundleName1",
};
Notification.isNotificationEnabled(bundle, isNotificationEnabledCallback);
......@@ -1021,12 +1124,16 @@ isNotificationEnabled(bundle: BundleOption): Promise\<boolean\>
**示例:**
```js
let bundle = {
```ts
import Base from '@ohos.base';
let bundle: Notification.BundleOption = {
bundle: "bundleName1",
};
Notification.isNotificationEnabled(bundle).then((data) => {
console.info("isNotificationEnabled success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`isNotificationEnabled failed, code is ${err}`);
});
```
......@@ -1050,9 +1157,11 @@ isNotificationEnabled(callback: AsyncCallback\<boolean\>): void
**示例:**
```js
function isNotificationEnabledCallback(err, data) {
if (err.code) {
```ts
import Base from '@ohos.base';
let isNotificationEnabledCallback = (err: Base.BusinessError, data: boolean) => {
if (err) {
console.info("isNotificationEnabled failed " + JSON.stringify(err));
} else {
console.info("isNotificationEnabled success");
......@@ -1088,9 +1197,13 @@ isNotificationEnabled(): Promise\<boolean\>
**示例:**
```js
Notification.isNotificationEnabled().then((data) => {
```ts
import Base from '@ohos.base';
Notification.isNotificationEnabled().then((data: boolean) => {
console.info("isNotificationEnabled success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`isNotificationEnabled failed, code is ${err}`);
});
```
......@@ -1116,15 +1229,17 @@ displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<voi
**示例:**
```js
function displayBadgeCallback(err) {
if (err.code) {
```ts
import Base from '@ohos.base';
let displayBadgeCallback = (err: Base.BusinessError) => {
if (err) {
console.info("displayBadge failed " + JSON.stringify(err));
} else {
console.info("displayBadge success");
}
}
let bundle = {
let bundle: Notification.BundleOption = {
bundle: "bundleName1",
};
Notification.displayBadge(bundle, false, displayBadgeCallback);
......@@ -1151,12 +1266,16 @@ displayBadge(bundle: BundleOption, enable: boolean): Promise\<void\>
**示例:**
```js
let bundle = {
```ts
import Base from '@ohos.base';
let bundle: Notification.BundleOption = {
bundle: "bundleName1",
};
Notification.displayBadge(bundle, false).then(() => {
console.info("displayBadge success");
}).catch((err: Base.BusinessError) => {
console.error(`displayBadge failed, code is ${err}`);
});
```
......@@ -1181,15 +1300,17 @@ isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\<boolean\>): void
**示例:**
```js
function isBadgeDisplayedCallback(err, data) {
if (err.code) {
```ts
import Base from '@ohos.base';
let isBadgeDisplayedCallback = (err: Base.BusinessError, data: boolean) => {
if (err) {
console.info("isBadgeDisplayed failed " + JSON.stringify(err));
} else {
console.info("isBadgeDisplayed success");
}
}
let bundle = {
let bundle: Notification.BundleOption = {
bundle: "bundleName1",
};
Notification.isBadgeDisplayed(bundle, isBadgeDisplayedCallback);
......@@ -1221,12 +1342,16 @@ isBadgeDisplayed(bundle: BundleOption): Promise\<boolean\>
**示例:**
```js
let bundle = {
```ts
import Base from '@ohos.base';
let bundle: Notification.BundleOption = {
bundle: "bundleName1",
};
Notification.isBadgeDisplayed(bundle).then((data) => {
console.info("isBadgeDisplayed success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`isBadgeDisplayed failed, code is ${err}`);
});
```
......@@ -1252,18 +1377,21 @@ setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCal
**示例:**
```js
function setSlotByBundleCallback(err) {
if (err.code) {
```ts
import Base from '@ohos.base';
import NotificationManager from '@ohos.notificationManager';
let setSlotByBundleCallback = (err: Base.BusinessError) => {
if (err) {
console.info("setSlotByBundle failed " + JSON.stringify(err));
} else {
console.info("setSlotByBundle success");
}
}
let bundle = {
let bundle: Notification.BundleOption = {
bundle: "bundleName1",
};
let notificationSlot = {
let notificationSlot: NotificationManager.NotificationSlot = {
type: Notification.SlotType.SOCIAL_COMMUNICATION
};
Notification.setSlotByBundle(bundle, notificationSlot, setSlotByBundleCallback);
......@@ -1290,15 +1418,20 @@ setSlotByBundle(bundle: BundleOption, slot: NotificationSlot): Promise\<void\>
**示例:**
```js
let bundle = {
```ts
import Base from '@ohos.base';
import NotificationManager from '@ohos.notificationManager';
let bundle: Notification.BundleOption = {
bundle: "bundleName1",
};
let notificationSlot = {
let notificationSlot: NotificationManager.NotificationSlot = {
type: Notification.SlotType.SOCIAL_COMMUNICATION
};
Notification.setSlotByBundle(bundle, notificationSlot).then(() => {
console.info("setSlotByBundle success");
}).catch((err: Base.BusinessError) => {
console.error(`setSlotByBundle failed, code is ${err}`);
});
```
......@@ -1323,15 +1456,18 @@ getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback\<Array\<Notificat
**示例:**
```js
function getSlotsByBundleCallback(err, data) {
if (err.code) {
```ts
import Base from '@ohos.base';
import NotificationManager from '@ohos.notificationManager';
let getSlotsByBundleCallback = (err: Base.BusinessError, data: NotificationManager.NotificationSlot[]) => {
if (err) {
console.info("getSlotsByBundle failed " + JSON.stringify(err));
} else {
console.info("getSlotsByBundle success");
}
}
let bundle = {
let bundle: Notification.BundleOption = {
bundle: "bundleName1",
};
Notification.getSlotsByBundle(bundle, getSlotsByBundleCallback);
......@@ -1363,12 +1499,17 @@ getSlotsByBundle(bundle: BundleOption): Promise\<Array\<NotificationSlot>>
**示例:**
```js
let bundle = {
```ts
import Base from '@ohos.base';
import NotificationManager from '@ohos.notificationManager';
let bundle: Notification.BundleOption = {
bundle: "bundleName1",
};
Notification.getSlotsByBundle(bundle).then((data) => {
Notification.getSlotsByBundle(bundle).then((data: NotificationManager.NotificationSlot[]) => {
console.info("getSlotsByBundle success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`getSlotsByBundle failed, code is ${err}`);
});
```
......@@ -1393,15 +1534,18 @@ getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\<number\>): voi
**示例:**
```js
function getSlotNumByBundleCallback(err, data) {
if (err.code) {
```ts
import Base from '@ohos.base';
import NotificationManager from '@ohos.notificationManager';
let getSlotNumByBundleCallback = (err: Base.BusinessError, data: number) => {
if (err) {
console.info("getSlotNumByBundle failed " + JSON.stringify(err));
} else {
console.info("getSlotNumByBundle success");
}
}
let bundle = {
let bundle: Notification.BundleOption = {
bundle: "bundleName1",
};
Notification.getSlotNumByBundle(bundle, getSlotNumByBundleCallback);
......@@ -1433,12 +1577,17 @@ getSlotNumByBundle(bundle: BundleOption): Promise\<number\>
**示例:**
```js
let bundle = {
```ts
import Base from '@ohos.base';
import NotificationManager from '@ohos.notificationManager';
let bundle: Notification.BundleOption = {
bundle: "bundleName1",
};
Notification.getSlotNumByBundle(bundle).then((data) => {
Notification.getSlotNumByBundle(bundle).then((data: number) => {
console.info("getSlotNumByBundle success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`getSlotNumByBundle failed, code is ${err}`);
});
```
......@@ -1465,22 +1614,24 @@ remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveRea
**示例:**
```js
function removeCallback(err) {
if (err.code) {
```ts
import Base from '@ohos.base';
let removeCallback = (err: Base.BusinessError) => {
if (err) {
console.info("remove failed " + JSON.stringify(err));
} else {
console.info("remove success");
}
}
let bundle = {
let bundle: Notification.BundleOption = {
bundle: "bundleName1",
};
let notificationKey = {
let notificationKey: Notification.NotificationKey = {
id: 0,
label: "label",
};
let reason = Notification.RemoveReason.CLICK_REASON_REMOVE;
let reason: Notification.RemoveReason = Notification.RemoveReason.CLICK_REASON_REMOVE;
Notification.remove(bundle, notificationKey, reason, removeCallback);
```
......@@ -1506,17 +1657,21 @@ remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveRea
**示例:**
```js
let bundle = {
```ts
import Base from '@ohos.base';
let bundle: Notification.BundleOption = {
bundle: "bundleName1",
};
let notificationKey = {
let notificationKey: Notification.NotificationKey = {
id: 0,
label: "label",
};
let reason = Notification.RemoveReason.CLICK_REASON_REMOVE;
let reason: Notification.RemoveReason = Notification.RemoveReason.CLICK_REASON_REMOVE;
Notification.remove(bundle, notificationKey, reason).then(() => {
console.info("remove success");
}).catch((err: Base.BusinessError) => {
console.error(`remove failed, code is ${err}`);
});
```
......@@ -1542,17 +1697,19 @@ remove(hashCode: string, reason: RemoveReason, callback: AsyncCallback\<void\>):
**示例:**
```js
let hashCode = 'hashCode';
```ts
import Base from '@ohos.base';
let hashCode: string = 'hashCode';
function removeCallback(err) {
if (err.code) {
let removeCallback = (err: Base.BusinessError) => {
if (err) {
console.info("remove failed " + JSON.stringify(err));
} else {
console.info("remove success");
}
}
let reason = Notification.RemoveReason.CANCEL_REASON_REMOVE;
let reason: Notification.RemoveReason = Notification.RemoveReason.CANCEL_REASON_REMOVE;
Notification.remove(hashCode, reason, removeCallback);
```
......@@ -1577,11 +1734,15 @@ remove(hashCode: string, reason: RemoveReason): Promise\<void\>
**示例:**
```js
let hashCode = 'hashCode';
let reason = Notification.RemoveReason.CLICK_REASON_REMOVE;
```ts
import Base from '@ohos.base';
let hashCode: string = 'hashCode';
let reason: Notification.RemoveReason = Notification.RemoveReason.CLICK_REASON_REMOVE;
Notification.remove(hashCode, reason).then(() => {
console.info("remove success");
}).catch((err: Base.BusinessError) => {
console.error(`remove failed, code is ${err}`);
});
```
......@@ -1606,15 +1767,17 @@ removeAll(bundle: BundleOption, callback: AsyncCallback\<void\>): void
**示例:**
```js
function removeAllCallback(err) {
if (err.code) {
```ts
import Base from '@ohos.base';
let removeAllCallback = (err: Base.BusinessError) => {
if (err) {
console.info("removeAll failed " + JSON.stringify(err));
} else {
console.info("removeAll success");
}
}
let bundle = {
let bundle: Notification.BundleOption = {
bundle: "bundleName1",
};
Notification.removeAll(bundle, removeAllCallback);
......@@ -1640,9 +1803,11 @@ removeAll(callback: AsyncCallback\<void\>): void
**示例:**
```js
function removeAllCallback(err) {
if (err.code) {
```ts
import Base from '@ohos.base';
let removeAllCallback = (err: Base.BusinessError) => {
if (err) {
console.info("removeAll failed " + JSON.stringify(err));
} else {
console.info("removeAll success");
......@@ -1672,10 +1837,14 @@ removeAll(bundle?: BundleOption): Promise\<void\>
**示例:**
```js
```ts
import Base from '@ohos.base';
// 不指定应用时,删除所有通知
Notification.removeAll().then(() => {
console.info("removeAll success");
}).catch((err: Base.BusinessError) => {
console.error(`removeAll failed, code is ${err}`);
});
```
......@@ -1700,16 +1869,18 @@ removeAll(userId: number, callback: AsyncCallback\<void>): void
**示例:**
```js
function removeAllCallback(err) {
if (err.code) {
```ts
import Base from '@ohos.base';
function removeAllCallback(err: Base.BusinessError) {
if (err) {
console.info("removeAll failed " + JSON.stringify(err));
} else {
console.info("removeAll success");
}
}
let userId = 1;
let userId: number = 1;
Notification.removeAll(userId, removeAllCallback);
```
......@@ -1733,10 +1904,14 @@ removeAll(userId: number): Promise\<void>
**示例:**
```js
let userId = 1;
```ts
import Base from '@ohos.base';
let userId: number = 1;
Notification.removeAll(userId).then(() => {
console.info("removeAll success");
}).catch((err: Base.BusinessError) => {
console.error(`removeAll failed, code is ${err}`);
});
```
......@@ -1761,9 +1936,12 @@ getAllActiveNotifications(callback: AsyncCallback\<Array\<NotificationRequest>>)
**示例:**
```js
function getAllActiveNotificationsCallback(err, data) {
if (err.code) {
```ts
import Base from '@ohos.base';
import NotificationManager from '@ohos.notificationManager';
function getAllActiveNotificationsCallback(err: Base.BusinessError, data: NotificationManager.NotificationRequest[]) {
if (err) {
console.info("getAllActiveNotifications failed " + JSON.stringify(err));
} else {
console.info("getAllActiveNotifications success");
......@@ -1793,9 +1971,14 @@ getAllActiveNotifications(): Promise\<Array\<[NotificationRequest](#notification
**示例:**
```js
Notification.getAllActiveNotifications().then((data) => {
```ts
import Base from '@ohos.base';
import NotificationManager from '@ohos.notificationManager';
Notification.getAllActiveNotifications().then((data: NotificationManager.NotificationRequest[]) => {
console.info("getAllActiveNotifications success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`getAllActiveNotifications failed, code is ${err}`);
});
```
......@@ -1815,9 +1998,11 @@ getActiveNotificationCount(callback: AsyncCallback\<number\>): void
**示例:**
```js
function getActiveNotificationCountCallback(err, data) {
if (err.code) {
```ts
import Base from '@ohos.base';
let getActiveNotificationCountCallback = (err: Base.BusinessError, data: number) => {
if (err) {
console.info("getActiveNotificationCount failed " + JSON.stringify(err));
} else {
console.info("getActiveNotificationCount success");
......@@ -1843,9 +2028,13 @@ getActiveNotificationCount(): Promise\<number\>
**示例:**
```js
Notification.getActiveNotificationCount().then((data) => {
```ts
import Base from '@ohos.base';
Notification.getActiveNotificationCount().then((data: number) => {
console.info("getActiveNotificationCount success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`getAllActiveNotifications failed, code is ${err}`);
});
```
......@@ -1865,9 +2054,12 @@ getActiveNotifications(callback: AsyncCallback<Array\<NotificationRequest\>>): v
**示例:**
```js
function getActiveNotificationsCallback(err, data) {
if (err.code) {
```ts
import Base from '@ohos.base';
import NotificationManager from '@ohos.notificationManager';
let getActiveNotificationsCallback = (err: Base.BusinessError, data: NotificationManager.NotificationRequest[]) => {
if (err) {
console.info("getActiveNotifications failed " + JSON.stringify(err));
} else {
console.info("getActiveNotifications success");
......@@ -1893,9 +2085,14 @@ getActiveNotifications(): Promise\<Array\<[NotificationRequest](#notificationreq
**示例:**
```js
Notification.getActiveNotifications().then((data) => {
```ts
import Base from '@ohos.base';
import NotificationManager from '@ohos.notificationManager';
Notification.getActiveNotifications().then((data: NotificationManager.NotificationRequest[]) => {
console.info("removeGroupByBundle success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`removeGroupByBundle failed, code is ${err}`);
});
```
......@@ -1916,16 +2113,18 @@ cancelGroup(groupName: string, callback: AsyncCallback\<void\>): void
**示例:**
```js
function cancelGroupCallback(err) {
if (err.code) {
```ts
import Base from '@ohos.base';
let cancelGroupCallback = (err: Base.BusinessError) => {
if (err) {
console.info("cancelGroup failed " + JSON.stringify(err));
} else {
console.info("cancelGroup success");
}
}
let groupName = "GroupName";
let groupName: string = "GroupName";
Notification.cancelGroup(groupName, cancelGroupCallback);
```
......@@ -1946,10 +2145,14 @@ cancelGroup(groupName: string): Promise\<void\>
**示例:**
```js
let groupName = "GroupName";
```ts
import Base from '@ohos.base';
let groupName: string = "GroupName";
Notification.cancelGroup(groupName).then(() => {
console.info("cancelGroup success");
}).catch((err: Base.BusinessError) => {
console.error(`cancelGroup failed, code is ${err}`);
});
```
......@@ -1975,17 +2178,19 @@ removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCall
**示例:**
```js
function removeGroupByBundleCallback(err) {
if (err.code) {
```ts
import Base from '@ohos.base';
let removeGroupByBundleCallback = (err: Base.BusinessError) => {
if (err) {
console.info("removeGroupByBundle failed " + JSON.stringify(err));
} else {
console.info("removeGroupByBundle success");
}
}
let bundleOption = {bundle: "Bundle"};
let groupName = "GroupName";
let bundleOption: Notification.BundleOption = {bundle: "Bundle"};
let groupName: string = "GroupName";
Notification.removeGroupByBundle(bundleOption, groupName, removeGroupByBundleCallback);
```
......@@ -2011,11 +2216,15 @@ removeGroupByBundle(bundle: BundleOption, groupName: string): Promise\<void\>
**示例:**
```js
let bundleOption = {bundle: "Bundle"};
let groupName = "GroupName";
```ts
import Base from '@ohos.base';
let bundleOption: Notification.BundleOption = {bundle: "Bundle"};
let groupName: string = "GroupName";
Notification.removeGroupByBundle(bundleOption, groupName).then(() => {
console.info("removeGroupByBundle success");
}).catch((err: Base.BusinessError) => {
console.error(`removeGroupByBundle failed, code is ${err}`);
});
```
......@@ -2040,16 +2249,18 @@ setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback\<void\>): vo
**示例:**
```js
function setDoNotDisturbDateCallback(err) {
if (err.code) {
```ts
import Base from '@ohos.base';
let setDoNotDisturbDateCallback = (err: Base.BusinessError) => {
if (err) {
console.info("setDoNotDisturbDate failed " + JSON.stringify(err));
} else {
console.info("setDoNotDisturbDate success");
}
}
let doNotDisturbDate = {
let doNotDisturbDate: Notification.DoNotDisturbDate = {
type: Notification.DoNotDisturbType.TYPE_ONCE,
begin: new Date(),
end: new Date(2021, 11, 15, 18, 0)
......@@ -2078,14 +2289,18 @@ setDoNotDisturbDate(date: DoNotDisturbDate): Promise\<void\>
**示例:**
```js
let doNotDisturbDate = {
```ts
import Base from '@ohos.base';
let doNotDisturbDate: Notification.DoNotDisturbDate = {
type: Notification.DoNotDisturbType.TYPE_ONCE,
begin: new Date(),
end: new Date(2021, 11, 15, 18, 0)
};
Notification.setDoNotDisturbDate(doNotDisturbDate).then(() => {
console.info("setDoNotDisturbDate success");
}).catch((err: Base.BusinessError) => {
console.error(`setDoNotDisturbDate failed, code is ${err}`);
});
```
......@@ -2112,22 +2327,24 @@ setDoNotDisturbDate(date: DoNotDisturbDate, userId: number, callback: AsyncCallb
**示例:**
```js
function setDoNotDisturbDateCallback(err) {
if (err.code) {
```ts
import Base from '@ohos.base';
let setDoNotDisturbDateCallback = (err: Base.BusinessError) => {
if (err) {
console.info("setDoNotDisturbDate failed " + JSON.stringify(err));
} else {
console.info("setDoNotDisturbDate success");
}
}
let doNotDisturbDate = {
let doNotDisturbDate: Notification.DoNotDisturbDate = {
type: Notification.DoNotDisturbType.TYPE_ONCE,
begin: new Date(),
end: new Date(2021, 11, 15, 18, 0)
};
let userId = 1
let userId: number = 1;
Notification.setDoNotDisturbDate(doNotDisturbDate, userId, setDoNotDisturbDateCallback);
```
......@@ -2152,17 +2369,21 @@ setDoNotDisturbDate(date: DoNotDisturbDate, userId: number): Promise\<void\>
**示例:**
```js
let doNotDisturbDate = {
```ts
import Base from '@ohos.base';
let doNotDisturbDate: Notification.DoNotDisturbDate = {
type: Notification.DoNotDisturbType.TYPE_ONCE,
begin: new Date(),
end: new Date(2021, 11, 15, 18, 0)
};
let userId = 1;
let userId: number = 1;
Notification.setDoNotDisturbDate(doNotDisturbDate, userId).then(() => {
console.info("setDoNotDisturbDate success");
}).catch((err: Base.BusinessError) => {
console.error(`setDoNotDisturbDate failed, code is ${err}`);
});
```
......@@ -2187,9 +2408,11 @@ getDoNotDisturbDate(callback: AsyncCallback\<DoNotDisturbDate\>): void
**示例:**
```js
function getDoNotDisturbDateCallback(err, data) {
if (err.code) {
```ts
import Base from '@ohos.base';
let getDoNotDisturbDateCallback = (err: Base.BusinessError, data: Notification.DoNotDisturbDate) => {
if (err) {
console.info("getDoNotDisturbDate failed " + JSON.stringify(err));
} else {
console.info("getDoNotDisturbDate success");
......@@ -2219,9 +2442,13 @@ getDoNotDisturbDate(): Promise\<DoNotDisturbDate\>
**示例:**
```js
Notification.getDoNotDisturbDate().then((data) => {
```ts
import Base from '@ohos.base';
Notification.getDoNotDisturbDate().then((data: Notification.DoNotDisturbDate) => {
console.info("getDoNotDisturbDate success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`getDoNotDisturbDate failed, code is ${err}`);
});
```
......@@ -2247,16 +2474,18 @@ getDoNotDisturbDate(userId: number, callback: AsyncCallback\<DoNotDisturbDate\>)
**示例:**
```js
function getDoNotDisturbDateCallback(err,data) {
if (err.code) {
```ts
import Base from '@ohos.base';
let getDoNotDisturbDateCallback = (err: Base.BusinessError, data: Notification.DoNotDisturbDate) => {
if (err) {
console.info("getDoNotDisturbDate failed " + JSON.stringify(err));
} else {
console.info("getDoNotDisturbDate success");
}
}
let userId = 1;
let userId: number = 1;
Notification.getDoNotDisturbDate(userId, getDoNotDisturbDateCallback);
```
......@@ -2287,11 +2516,15 @@ getDoNotDisturbDate(userId: number): Promise\<DoNotDisturbDate\>
**示例:**
```js
let userId = 1;
```ts
import Base from '@ohos.base';
let userId: number = 1;
Notification.getDoNotDisturbDate(userId).then((data) => {
Notification.getDoNotDisturbDate(userId).then((data: Notification.DoNotDisturbDate) => {
console.info("getDoNotDisturbDate success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`getDoNotDisturbDate failed, code is ${err}`);
});
```
......@@ -2316,9 +2549,11 @@ supportDoNotDisturbMode(callback: AsyncCallback\<boolean\>): void
**示例:**
```js
function supportDoNotDisturbModeCallback(err,data) {
if (err.code) {
```ts
import Base from '@ohos.base';
let supportDoNotDisturbModeCallback = (err: Base.BusinessError, data: boolean) => {
if (err) {
console.info("supportDoNotDisturbMode failed " + JSON.stringify(err));
} else {
console.info("supportDoNotDisturbMode success");
......@@ -2348,9 +2583,13 @@ supportDoNotDisturbMode(): Promise\<boolean\>
**示例:**
```js
Notification.supportDoNotDisturbMode().then((data) => {
```ts
import Base from '@ohos.base';
Notification.supportDoNotDisturbMode().then((data: boolean) => {
console.info("supportDoNotDisturbMode success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`supportDoNotDisturbMode failed, code is ${err}`);
});
```
......@@ -2371,10 +2610,12 @@ isSupportTemplate(templateName: string, callback: AsyncCallback\<boolean\>): voi
**示例:**
```javascript
let templateName = 'process';
function isSupportTemplateCallback(err, data) {
if (err.code) {
```ts
import Base from '@ohos.base';
let templateName: string = 'process';
function isSupportTemplateCallback(err: Base.BusinessError, data: boolean) {
if (err) {
console.info("isSupportTemplate failed " + JSON.stringify(err));
} else {
console.info("isSupportTemplate success");
......@@ -2406,11 +2647,14 @@ isSupportTemplate(templateName: string): Promise\<boolean\>
**示例:**
```javascript
let templateName = 'process';
```ts
import Base from '@ohos.base';
Notification.isSupportTemplate(templateName).then((data) => {
let templateName: string = 'process';
Notification.isSupportTemplate(templateName).then((data: boolean) => {
console.info("isSupportTemplate success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`isSupportTemplate failed, code is ${err}`);
});
```
......@@ -2430,9 +2674,11 @@ requestEnableNotification(callback: AsyncCallback\<void\>): void
**示例:**
```javascript
function requestEnableNotificationCallback(err) {
if (err.code) {
```ts
import Base from '@ohos.base';
let requestEnableNotificationCallback = (err: Base.BusinessError) => {
if (err) {
console.info("requestEnableNotification failed " + JSON.stringify(err));
} else {
console.info("requestEnableNotification success");
......@@ -2452,9 +2698,13 @@ requestEnableNotification(): Promise\<void\>
**示例:**
```javascript
```ts
import Base from '@ohos.base';
Notification.requestEnableNotification().then(() => {
console.info("requestEnableNotification success");
}).catch((err: Base.BusinessError) => {
console.error(`requestEnableNotification failed, code is ${err}`);
});
```
......@@ -2480,16 +2730,18 @@ enableDistributed(enable: boolean, callback: AsyncCallback\<void\>): void
**示例:**
```javascript
function enabledNotificationCallback(err) {
if (err.code) {
```ts
import Base from '@ohos.base';
let enabledNotificationCallback = (err: Base.BusinessError) => {
if (err) {
console.info("enableDistributed failed " + JSON.stringify(err));
} else {
console.info("enableDistributed success");
}
};
let enable = true;
let enable: boolean = true;
Notification.enableDistributed(enable, enabledNotificationCallback);
```
......@@ -2514,10 +2766,14 @@ enableDistributed(enable: boolean): Promise\<void>
**示例:**
```javascript
let enable = true;
```ts
import Base from '@ohos.base';
let enable: boolean = true;
Notification.enableDistributed(enable).then(() => {
console.info("enableDistributed success");
}).catch((err: Base.BusinessError) => {
console.error(`enableDistributed failed, code is ${err}`);
});
```
......@@ -2538,9 +2794,11 @@ isDistributedEnabled(callback: AsyncCallback\<boolean>): void
**示例:**
```javascript
function isDistributedEnabledCallback(err, data) {
if (err.code) {
```ts
import Base from '@ohos.base';
let isDistributedEnabledCallback = (err: Base.BusinessError, data: boolean) => {
if (err) {
console.info("isDistributedEnabled failed " + JSON.stringify(err));
} else {
console.info("isDistributedEnabled success " + JSON.stringify(data));
......@@ -2566,9 +2824,13 @@ isDistributedEnabled(): Promise\<boolean>
**示例:**
```javascript
Notification.isDistributedEnabled().then((data) => {
```ts
import Base from '@ohos.base';
Notification.isDistributedEnabled().then((data: boolean) => {
console.info("isDistributedEnabled success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`isDistributedEnabled failed, code is ${err}`);
});
```
......@@ -2595,20 +2857,22 @@ enableDistributedByBundle(bundle: BundleOption, enable: boolean, callback: Async
**示例:**
```javascript
function enableDistributedByBundleCallback(err) {
if (err.code) {
```ts
import Base from '@ohos.base';
let enableDistributedByBundleCallback = (err: Base.BusinessError) => {
if (err) {
console.info("enableDistributedByBundle failed " + JSON.stringify(err));
} else {
console.info("enableDistributedByBundle success");
}
};
let bundle = {
let bundle: Notification.BundleOption = {
bundle: "bundleName1",
};
let enable = true;
let enable: boolean = true;
Notification.enableDistributedByBundle(bundle, enable, enableDistributedByBundleCallback);
```
......@@ -2634,15 +2898,21 @@ enableDistributedByBundle(bundle: BundleOption, enable: boolean): Promise\<void>
**示例:**
```javascript
let bundle = {
```ts
import Base from '@ohos.base';
let enable: boolean = true;
let bundle: Notification.BundleOption = {
bundle: "bundleName1",
};
let enable = true;
Notification.enableDistributedByBundle(bundle, enable).then(() => {
console.info("enableDistributedByBundle success");
}).catch((err: Base.BusinessError) => {
console.error(`enableDistributedByBundle failed, code is ${err}`);
});
```
## Notification.isDistributedEnabledByBundle<sup>8+</sup>
......@@ -2666,16 +2936,18 @@ isDistributedEnabledByBundle(bundle: BundleOption, callback: AsyncCallback\<bool
**示例:**
```javascript
function isDistributedEnabledByBundleCallback(err, data) {
if (err.code) {
```ts
import Base from '@ohos.base';
let isDistributedEnabledByBundleCallback = (err: Base.BusinessError, data: boolean) => {
if (err) {
console.info("isDistributedEnabledByBundle failed " + JSON.stringify(err));
} else {
console.info("isDistributedEnabledByBundle success" + JSON.stringify(data));
}
};
let bundle = {
let bundle: Notification.BundleOption = {
bundle: "bundleName1",
};
......@@ -2708,13 +2980,17 @@ isDistributedEnabledByBundle(bundle: BundleOption): Promise\<boolean>
**示例:**
```javascript
let bundle = {
```ts
import Base from '@ohos.base';
let bundle: Notification.BundleOption = {
bundle: "bundleName1",
};
Notification.isDistributedEnabledByBundle(bundle).then((data) => {
Notification.isDistributedEnabledByBundle(bundle).then((data: boolean) => {
console.info("isDistributedEnabledByBundle success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`isDistributedEnabledByBundle failed, code is ${err}`);
});
```
......@@ -2739,9 +3015,11 @@ getDeviceRemindType(callback: AsyncCallback\<DeviceRemindType\>): void
**示例:**
```javascript
function getDeviceRemindTypeCallback(err,data) {
if (err.code) {
```ts
import Base from '@ohos.base';
let getDeviceRemindTypeCallback = (err: Base.BusinessError, data: Notification.DeviceRemindType) => {
if (err) {
console.info("getDeviceRemindType failed " + JSON.stringify(err));
} else {
console.info("getDeviceRemindType success");
......@@ -2771,9 +3049,13 @@ getDeviceRemindType(): Promise\<DeviceRemindType\>
**示例:**
```javascript
Notification.getDeviceRemindType().then((data) => {
```ts
import Base from '@ohos.base';
Notification.getDeviceRemindType().then((data: Notification.DeviceRemindType) => {
console.info("getDeviceRemindType success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`getDeviceRemindType failed, code is ${err}`);
});
```
......@@ -3055,7 +3337,7 @@ Notification.getDeviceRemindType().then((data) => {
| classification | string | 是 | 是 | 通知分类。<br>**系统API**: 此接口为系统接口,三方应用不支持调用。 |
| groupName<sup>8+</sup>| string | 是 | 是 | 组通知名称。 |
| template<sup>8+</sup> | [NotificationTemplate](#notificationtemplate8) | 是 | 是 | 通知模板。 |
| isRemoveAllowed<sup>10+</sup> | boolean | 是 | 否 | 通知是否能被移除。<br>**系统API**: 此接口为系统接口,三方应用不支持调用。 |
| isRemoveAllowed<sup>8+</sup> | boolean | 是 | 否 | 通知是否能被移除。<br>**系统API**: 此接口为系统接口,三方应用不支持调用。 |
| source<sup>8+</sup> | number | 是 | 否 | 通知源。<br>**系统API**: 此接口为系统接口,三方应用不支持调用。 |
| distributedOption<sup>8+</sup> | [DistributedOptions](#distributedoptions8) | 是 | 是 | 分布式通知的选项。 |
| deviceId<sup>8+</sup> | string | 是 | 否 | 通知源的deviceId。<br>**系统API**: 此接口为系统接口,三方应用不支持调用。 |
......
......@@ -10,7 +10,6 @@
```ts
import notificationManager from '@ohos.notificationManager';
import Base from '@ohos.base';
```
## notificationManager.publish
......@@ -45,8 +44,10 @@ publish(request: NotificationRequest, callback: AsyncCallback\<void\>): void
**示例:**
```ts
import Base from '@ohos.base';
//publish回调
function publishCallback(err: Base.BusinessError) {
let publishCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`publish failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -99,6 +100,8 @@ publish(request: NotificationRequest): Promise\<void\>
**示例:**
```ts
import Base from '@ohos.base';
// 通知Request对象
let notificationRequest: notificationManager.NotificationRequest = {
id: 1,
......@@ -113,6 +116,8 @@ let notificationRequest: notificationManager.NotificationRequest = {
};
notificationManager.publish(notificationRequest).then(() => {
console.info("publish success");
}).catch((err: Base.BusinessError) => {
console.error(`publish fail: ${JSON.stringify(err)}`);
});
```
......@@ -155,8 +160,10 @@ publish(request: NotificationRequest, userId: number, callback: AsyncCallback\<v
**示例:**
```ts
import Base from '@ohos.base';
// publish回调
function publishCallback(err: Base.BusinessError) {
let publishCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`publish failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -217,6 +224,8 @@ publish(request: NotificationRequest, userId: number): Promise\<void\>
**示例:**
```ts
import Base from '@ohos.base';
let notificationRequest: notificationManager.NotificationRequest = {
id: 1,
content: {
......@@ -233,6 +242,8 @@ let userId: number = 1;
notificationManager.publish(notificationRequest, userId).then(() => {
console.info("publish success");
}).catch((err: Base.BusinessError) => {
console.error(`publish fail: ${JSON.stringify(err)}`);
});
```
......@@ -267,8 +278,10 @@ cancel(id: number, label: string, callback: AsyncCallback\<void\>): void
**示例:**
```ts
import Base from '@ohos.base';
// cancel回调
function cancelCallback(err: Base.BusinessError) {
let cancelCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`cancel failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -307,8 +320,12 @@ cancel(id: number, label?: string): Promise\<void\>
**示例:**
```ts
import Base from '@ohos.base';
notificationManager.cancel(0).then(() => {
console.info("cancel success");
}).catch((err: Base.BusinessError) => {
console.error(`cancel fail: ${JSON.stringify(err)}`);
});
```
......@@ -341,8 +358,10 @@ cancel(id: number, callback: AsyncCallback\<void\>): void
**示例:**
```ts
import Base from '@ohos.base';
// cancel回调
function cancelCallback(err: Base.BusinessError) {
let cancelCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`cancel failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -379,8 +398,10 @@ cancelAll(callback: AsyncCallback\<void\>): void
**示例:**
```ts
import Base from '@ohos.base';
// cancel回调
function cancelAllCallback(err: Base.BusinessError) {
let cancelAllCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`cancelAll failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -411,8 +432,12 @@ cancelAll(): Promise\<void\>
**示例:**
```ts
import Base from '@ohos.base';
notificationManager.cancelAll().then(() => {
console.info("cancelAll success");
}).catch((err: Base.BusinessError) => {
console.error(`cancelAll fail: ${JSON.stringify(err)}`);
});
```
......@@ -449,8 +474,10 @@ addSlot(slot: NotificationSlot, callback: AsyncCallback\<void\>): void
**示例:**
```ts
import Base from '@ohos.base';
// addslot回调
function addSlotCallBack(err: Base.BusinessError) {
let addSlotCallBack = (err: Base.BusinessError) => {
if (err) {
console.error(`addSlot failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -496,12 +523,16 @@ addSlot(slot: NotificationSlot): Promise\<void\>
**示例:**
```ts
import Base from '@ohos.base';
// 通知slot对象
let notificationSlot: notificationManager.NotificationSlot = {
type: notificationManager.SlotType.SOCIAL_COMMUNICATION
};
notificationManager.addSlot(notificationSlot).then(() => {
console.info("addSlot success");
}).catch((err: Base.BusinessError) => {
console.error(`addSlot fail: ${JSON.stringify(err)}`);
});
```
......@@ -534,8 +565,10 @@ addSlot(type: SlotType, callback: AsyncCallback\<void\>): void
**示例:**
```ts
import Base from '@ohos.base';
// addslot回调
function addSlotCallBack(err: Base.BusinessError) {
let addSlotCallBack = (err: Base.BusinessError) => {
if (err) {
console.error(`addSlot failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -573,8 +606,12 @@ addSlot(type: SlotType): Promise\<void\>
**示例:**
```ts
import Base from '@ohos.base';
notificationManager.addSlot(notificationManager.SlotType.SOCIAL_COMMUNICATION).then(() => {
console.info("addSlot success");
}).catch((err: Base.BusinessError) => {
console.error(`addSlot fail: ${JSON.stringify(err)}`);
});
```
......@@ -611,8 +648,10 @@ addSlots(slots: Array\<NotificationSlot\>, callback: AsyncCallback\<void\>): voi
**示例:**
```ts
import Base from '@ohos.base';
// addSlots回调
function addSlotsCallBack(err: Base.BusinessError) {
let addSlotsCallBack = (err: Base.BusinessError) => {
if (err) {
console.error(`addSlots failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -662,6 +701,8 @@ addSlots(slots: Array\<NotificationSlot\>): Promise\<void\>
**示例:**
```ts
import Base from '@ohos.base';
// 通知slot对象
let notificationSlot: notificationManager.NotificationSlot = {
type: notificationManager.SlotType.SOCIAL_COMMUNICATION
......@@ -672,6 +713,8 @@ notificationSlotArray[0] = notificationSlot;
notificationManager.addSlots(notificationSlotArray).then(() => {
console.info("addSlots success");
}).catch((err: Base.BusinessError) => {
console.error(`addSlot fail: ${JSON.stringify(err)}`);
});
```
......@@ -703,8 +746,10 @@ getSlot(slotType: SlotType, callback: AsyncCallback\<NotificationSlot\>): void
**示例:**
```ts
import Base from '@ohos.base';
// getSlot回调
function getSlotCallback(err: Base.BusinessError, data: notificationManager.NotificationSlot) {
let getSlotCallback = (err: Base.BusinessError, data: notificationManager.NotificationSlot) => {
if (err) {
console.error(`getSlot failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -748,10 +793,14 @@ getSlot(slotType: SlotType): Promise\<NotificationSlot\>
**示例:**
```ts
import Base from '@ohos.base';
let slotType: notificationManager.SlotType = notificationManager.SlotType.SOCIAL_COMMUNICATION;
notificationManager.getSlot(slotType).then((data: notificationManager.NotificationSlot) => {
console.info("getSlot success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`getSlot fail: ${JSON.stringify(err)}`);
});
```
......@@ -782,8 +831,10 @@ getSlots(callback: AsyncCallback\<Array\<NotificationSlot>>): void
**示例:**
```ts
import Base from '@ohos.base';
// getSlots回调
function getSlotsCallback(err: Base.BusinessError, data: Array<notificationManager.NotificationSlot>) {
let getSlotsCallback = (err: Base.BusinessError, data: Array<notificationManager.NotificationSlot>) => {
if (err) {
console.error(`getSlots failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -820,8 +871,12 @@ getSlots(): Promise\<Array\<NotificationSlot>>
**示例:**
```ts
import Base from '@ohos.base';
notificationManager.getSlots().then((data: Array<notificationManager.NotificationSlot>) => {
console.info("getSlots success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`getSlots fail: ${JSON.stringify(err)}`);
});
```
......@@ -853,8 +908,10 @@ removeSlot(slotType: SlotType, callback: AsyncCallback\<void\>): void
**示例:**
```ts
import Base from '@ohos.base';
// removeSlot回调
function removeSlotCallback(err: Base.BusinessError) {
let removeSlotCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`removeSlot failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -892,9 +949,13 @@ removeSlot(slotType: SlotType): Promise\<void\>
**示例:**
```ts
import Base from '@ohos.base';
let slotType: notificationManager.SlotType = notificationManager.SlotType.SOCIAL_COMMUNICATION;
notificationManager.removeSlot(slotType).then(() => {
console.info("removeSlot success");
}).catch((err: Base.BusinessError) => {
console.error(`removeSlot fail: ${JSON.stringify(err)}`);
});
```
......@@ -925,7 +986,9 @@ removeAllSlots(callback: AsyncCallback\<void\>): void
**示例:**
```ts
function removeAllCallBack(err: Base.BusinessError) {
import Base from '@ohos.base';
let removeAllCallBack = (err: Base.BusinessError) => {
if (err) {
console.error(`removeAllSlots failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -956,8 +1019,12 @@ removeAllSlots(): Promise\<void\>
**示例:**
```ts
import Base from '@ohos.base';
notificationManager.removeAllSlots().then(() => {
console.info("removeAllSlots success");
}).catch((err: Base.BusinessError) => {
console.error(`removeAllSlots fail: ${JSON.stringify(err)}`);
});
```
......@@ -995,7 +1062,9 @@ setNotificationEnable(bundle: BundleOption, enable: boolean, callback: AsyncCall
**示例:**
```ts
function setNotificationEnableCallback(err: Base.BusinessError) {
import Base from '@ohos.base';
let setNotificationEnableCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`setNotificationEnableCallback failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -1041,11 +1110,15 @@ setNotificationEnable(bundle: BundleOption, enable: boolean): Promise\<void\>
**示例:**
```ts
import Base from '@ohos.base';
let bundle: notificationManager.BundleOption = {
bundle: "bundleName1",
};
notificationManager.setNotificationEnable(bundle, false).then(() => {
console.info("setNotificationEnable success");
}).catch((err: Base.BusinessError) => {
console.error(`setNotificationEnable fail: ${JSON.stringify(err)}`);
});
```
......@@ -1082,7 +1155,9 @@ isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\<boolean\>):
**示例:**
```ts
function isNotificationEnabledCallback(err: Base.BusinessError, data: boolean) {
import Base from '@ohos.base';
let isNotificationEnabledCallback = (err: Base.BusinessError, data: boolean) => {
if (err) {
console.error(`isNotificationEnabled failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -1135,11 +1210,15 @@ isNotificationEnabled(bundle: BundleOption): Promise\<boolean\>
**示例:**
```ts
import Base from '@ohos.base';
let bundle: notificationManager.BundleOption = {
bundle: "bundleName1",
};
notificationManager.isNotificationEnabled(bundle).then((data: boolean) => {
console.info("isNotificationEnabled success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`isNotificationEnabled fail: ${JSON.stringify(err)}`);
});
```
......@@ -1174,7 +1253,9 @@ isNotificationEnabled(callback: AsyncCallback\<boolean\>): void
**示例:**
```ts
function isNotificationEnabledCallback(err: Base.BusinessError, data: boolean) {
import Base from '@ohos.base';
let isNotificationEnabledCallback = (err: Base.BusinessError, data: boolean) => {
if (err) {
console.error(`isNotificationEnabled failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -1216,8 +1297,12 @@ isNotificationEnabled(): Promise\<boolean\>
**示例:**
```ts
import Base from '@ohos.base';
notificationManager.isNotificationEnabled().then((data: boolean) => {
console.info("isNotificationEnabled success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`isNotificationEnabled fail: ${JSON.stringify(err)}`);
});
```
......@@ -1254,7 +1339,9 @@ isNotificationEnabled(userId: number, callback: AsyncCallback\<boolean\>): void
**示例:**
```ts
function isNotificationEnabledCallback(err: Base.BusinessError, data: boolean) {
import Base from '@ohos.base';
let isNotificationEnabledCallback = (err: Base.BusinessError, data: boolean) => {
if (err) {
console.error(`isNotificationEnabled failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -1305,10 +1392,14 @@ isNotificationEnabled(userId: number): Promise\<boolean\>
**示例:**
```ts
import Base from '@ohos.base';
let userId: number = 1;
notificationManager.isNotificationEnabled(userId).then((data: boolean) => {
console.info("isNotificationEnabled success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`isNotificationEnabled fail: ${JSON.stringify(err)}`);
});
```
......@@ -1346,7 +1437,9 @@ displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\<voi
**示例:**
```ts
function displayBadgeCallback(err: Base.BusinessError) {
import Base from '@ohos.base';
let displayBadgeCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`displayBadge failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -1392,11 +1485,15 @@ displayBadge(bundle: BundleOption, enable: boolean): Promise\<void\>
**示例:**
```ts
import Base from '@ohos.base';
let bundle: notificationManager.BundleOption = {
bundle: "bundleName1",
};
notificationManager.displayBadge(bundle, false).then(() => {
console.info("displayBadge success");
}).catch((err: Base.BusinessError) => {
console.error(`displayBadge fail: ${JSON.stringify(err)}`);
});
```
......@@ -1433,7 +1530,9 @@ isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\<boolean\>): void
**示例:**
```ts
function isBadgeDisplayedCallback(err: Base.BusinessError, data: boolean) {
import Base from '@ohos.base';
let isBadgeDisplayedCallback = (err: Base.BusinessError, data: boolean) => {
if (err) {
console.error(`isBadgeDisplayed failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -1484,12 +1583,16 @@ isBadgeDisplayed(bundle: BundleOption): Promise\<boolean\>
**示例:**
```ts
import Base from '@ohos.base';
let bundle: notificationManager.BundleOption = {
bundle: "bundleName1",
};
notificationManager.isBadgeDisplayed(bundle).then((data: boolean) => {
console.info("isBadgeDisplayed success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`isBadgeDisplayed fail: ${JSON.stringify(err)}`);
});
```
......@@ -1519,10 +1622,14 @@ setBadgeNumber(badgeNumber: number): Promise\<void\>
**示例:**
```ts
import Base from '@ohos.base';
let badgeNumber: number = 10;
notificationManager.setBadgeNumber(badgeNumber).then(() => {
console.info("displayBadge success");
}).catch((err: Base.BusinessError) => {
console.error(`displayBadge fail: ${JSON.stringify(err)}`);
});
```
......@@ -1555,7 +1662,9 @@ setBadgeNumber(badgeNumber: number, callback: AsyncCallback\<void\>): void
**示例:**
```ts
function setBadgeNumberCallback(err: Base.BusinessError) {
import Base from '@ohos.base';
let setBadgeNumberCallback = (err: Base.BusinessError) => {
if (err) {
console.info(`displayBadge failed code is ${err.code}, message is ${err.message}`);
} else {
......@@ -1601,7 +1710,9 @@ setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCal
**示例:**
```ts
function setSlotByBundleCallback(err: Base.BusinessError) {
import Base from '@ohos.base';
let setSlotByBundleCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`setSlotByBundle failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -1650,6 +1761,8 @@ setSlotByBundle(bundle: BundleOption, slot: NotificationSlot): Promise\<void\>
**示例:**
```ts
import Base from '@ohos.base';
let bundle: notificationManager.BundleOption = {
bundle: "bundleName1",
};
......@@ -1660,6 +1773,8 @@ let notificationSlot: notificationManager.NotificationSlot = {
notificationManager.setSlotByBundle(bundle, notificationSlot).then(() => {
console.info("setSlotByBundle success");
}).catch((err: Base.BusinessError) => {
console.error(`setSlotByBundle fail: ${JSON.stringify(err)}`);
});
```
......@@ -1696,7 +1811,9 @@ getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback\<Array\<Notificat
**示例:**
```ts
function getSlotsByBundleCallback(err: Base.BusinessError, data: Array<notificationManager.NotificationSlot>) {
import Base from '@ohos.base';
let getSlotsByBundleCallback = (err: Base.BusinessError, data: Array<notificationManager.NotificationSlot>) => {
if (err) {
console.error(`getSlotByBundle failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -1747,12 +1864,16 @@ getSlotsByBundle(bundle: BundleOption): Promise\<Array\<NotificationSlot>>
**示例:**
```ts
import Base from '@ohos.base';
let bundle: notificationManager.BundleOption = {
bundle: "bundleName1",
};
notificationManager.getSlotsByBundle(bundle).then((data: Array<notificationManager.NotificationSlot>) => {
console.info("getSlotsByBundle success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`getSlotsByBundle fail: ${JSON.stringify(err)}`);
});
```
......@@ -1789,7 +1910,9 @@ getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\<number\>): voi
**示例:**
```ts
function getSlotNumByBundleCallback(err: Base.BusinessError, data: number) {
import Base from '@ohos.base';
let getSlotNumByBundleCallback = (err: Base.BusinessError, data: number) => {
if (err) {
console.error(`getSlotByBundle failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -1842,12 +1965,16 @@ getSlotNumByBundle(bundle: BundleOption): Promise\<number\>
**示例:**
```ts
import Base from '@ohos.base';
let bundle: notificationManager.BundleOption = {
bundle: "bundleName1",
};
notificationManager.getSlotNumByBundle(bundle).then((data: number) => {
console.info("getSlotNumByBundle success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`getSlotsByBundle fail: ${JSON.stringify(err)}`);
});
```
......@@ -1881,7 +2008,9 @@ getAllActiveNotifications(callback: AsyncCallback\<Array\<NotificationRequest>>)
**示例:**
```ts
function getAllActiveNotificationsCallback(err: Base.BusinessError, data: Array<notificationManager.NotificationRequest>) {
import Base from '@ohos.base';
let getAllActiveNotificationsCallback = (err: Base.BusinessError, data: Array<notificationManager.NotificationRequest>) => {
if (err) {
console.error(`getAllActiveNotifications failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -1923,8 +2052,12 @@ getAllActiveNotifications(): Promise\<Array\<[NotificationRequest](js-apis-inner
**示例:**
```ts
import Base from '@ohos.base';
notificationManager.getAllActiveNotifications().then((data: Array<notificationManager.NotificationRequest>) => {
console.info("getAllActiveNotifications success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`getAllActiveNotifications fail: ${JSON.stringify(err)}`);
});
```
......@@ -1955,7 +2088,9 @@ getActiveNotificationCount(callback: AsyncCallback\<number\>): void
**示例:**
```ts
function getActiveNotificationCountCallback(err: Base.BusinessError, data: number) {
import Base from '@ohos.base';
let getActiveNotificationCountCallback = (err: Base.BusinessError, data: number) => {
if (err) {
console.error(`getActiveNotificationCount failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -1993,8 +2128,12 @@ getActiveNotificationCount(): Promise\<number\>
**示例:**
```ts
import Base from '@ohos.base';
notificationManager.getActiveNotificationCount().then((data: number) => {
console.info("getActiveNotificationCount success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`getActiveNotificationCount fail: ${JSON.stringify(err)}`);
});
```
......@@ -2025,7 +2164,9 @@ getActiveNotifications(callback: AsyncCallback\<Array\<NotificationRequest>>): v
**示例:**
```ts
function getActiveNotificationsCallback(err: Base.BusinessError, data: Array<notificationManager.NotificationRequest>) {
import Base from '@ohos.base';
let getActiveNotificationsCallback = (err: Base.BusinessError, data: Array<notificationManager.NotificationRequest>) => {
if (err) {
console.error(`getActiveNotifications failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -2063,8 +2204,12 @@ getActiveNotifications(): Promise\<Array\<[NotificationRequest](js-apis-inner-no
**示例:**
```ts
import Base from '@ohos.base';
notificationManager.getActiveNotifications().then((data: Array<notificationManager.NotificationRequest>) => {
console.info("removeGroupByBundle success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`getActiveNotificationCount fail: ${JSON.stringify(err)}`);
});
```
......@@ -2096,7 +2241,9 @@ cancelGroup(groupName: string, callback: AsyncCallback\<void\>): void
**示例:**
```ts
function cancelGroupCallback(err: Base.BusinessError) {
import Base from '@ohos.base';
let cancelGroupCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`cancelGroup failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -2136,9 +2283,13 @@ cancelGroup(groupName: string): Promise\<void\>
**示例:**
```ts
import Base from '@ohos.base';
let groupName: string = "GroupName";
notificationManager.cancelGroup(groupName).then(() => {
console.info("cancelGroup success");
}).catch((err: Base.BusinessError) => {
console.error(`cancelGroup fail: ${JSON.stringify(err)}`);
});
```
......@@ -2176,7 +2327,9 @@ removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCall
**示例:**
```ts
function removeGroupByBundleCallback(err: Base.BusinessError) {
import Base from '@ohos.base';
let removeGroupByBundleCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`removeGroupByBundle failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -2223,11 +2376,15 @@ removeGroupByBundle(bundle: BundleOption, groupName: string): Promise\<void\>
**示例:**
```ts
import Base from '@ohos.base';
let bundleOption: notificationManager.BundleOption = { bundle: "Bundle" };
let groupName: string = "GroupName";
notificationManager.removeGroupByBundle(bundleOption, groupName).then(() => {
console.info("removeGroupByBundle success");
}).catch((err: Base.BusinessError) => {
console.error(`removeGroupByBundle fail: ${JSON.stringify(err)}`);
});
```
......@@ -2264,7 +2421,9 @@ setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback\<void\>): vo
**示例:**
```ts
function setDoNotDisturbDateCallback(err: Base.BusinessError) {
import Base from '@ohos.base';
let setDoNotDisturbDateCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`setDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -2313,6 +2472,8 @@ setDoNotDisturbDate(date: DoNotDisturbDate): Promise\<void\>
**示例:**
```ts
import Base from '@ohos.base';
let doNotDisturbDate: notificationManager.DoNotDisturbDate = {
type: notificationManager.DoNotDisturbType.TYPE_ONCE,
begin: new Date(),
......@@ -2320,6 +2481,8 @@ let doNotDisturbDate: notificationManager.DoNotDisturbDate = {
};
notificationManager.setDoNotDisturbDate(doNotDisturbDate).then(() => {
console.info("setDoNotDisturbDate success");
}).catch((err: Base.BusinessError) => {
console.error(`setDoNotDisturbDate fail: ${JSON.stringify(err)}`);
});
```
......@@ -2359,7 +2522,9 @@ setDoNotDisturbDate(date: DoNotDisturbDate, userId: number, callback: AsyncCallb
**示例:**
```ts
function setDoNotDisturbDateCallback(err: Base.BusinessError) {
import Base from '@ohos.base';
let setDoNotDisturbDateCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`setDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -2412,6 +2577,8 @@ setDoNotDisturbDate(date: DoNotDisturbDate, userId: number): Promise\<void\>
**示例:**
```ts
import Base from '@ohos.base';
let doNotDisturbDate: notificationManager.DoNotDisturbDate = {
type: notificationManager.DoNotDisturbType.TYPE_ONCE,
begin: new Date(),
......@@ -2422,6 +2589,8 @@ let userId: number = 1;
notificationManager.setDoNotDisturbDate(doNotDisturbDate, userId).then(() => {
console.info("setDoNotDisturbDate success");
}).catch((err: Base.BusinessError) => {
console.error(`setDoNotDisturbDate fail: ${JSON.stringify(err)}`);
});
```
......@@ -2458,7 +2627,9 @@ getDoNotDisturbDate(callback: AsyncCallback\<DoNotDisturbDate\>): void
**示例:**
```ts
function getDoNotDisturbDateCallback(err: Base.BusinessError, data: notificationManager.DoNotDisturbDate) {
import Base from '@ohos.base';
let getDoNotDisturbDateCallback = (err: Base.BusinessError, data: notificationManager.DoNotDisturbDate) => {
if (err) {
console.error(`getDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -2501,8 +2672,12 @@ getDoNotDisturbDate(): Promise\<DoNotDisturbDate\>
**示例:**
```ts
import Base from '@ohos.base';
notificationManager.getDoNotDisturbDate().then((data: notificationManager.DoNotDisturbDate) => {
console.info("getDoNotDisturbDate success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`getDoNotDisturbDate fail: ${JSON.stringify(err)}`);
});
```
......@@ -2541,7 +2716,9 @@ getDoNotDisturbDate(userId: number, callback: AsyncCallback\<DoNotDisturbDate\>)
**示例:**
```ts
function getDoNotDisturbDateCallback(err: Base.BusinessError, data: notificationManager.DoNotDisturbDate) {
import Base from '@ohos.base';
let getDoNotDisturbDateCallback = (err: Base.BusinessError, data: notificationManager.DoNotDisturbDate) => {
if (err) {
console.error(`getDoNotDisturbDate failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -2593,10 +2770,14 @@ getDoNotDisturbDate(userId: number): Promise\<DoNotDisturbDate\>
**示例:**
```ts
import Base from '@ohos.base';
let userId: number = 1;
notificationManager.getDoNotDisturbDate(userId).then((data: notificationManager.DoNotDisturbDate) => {
console.info("getDoNotDisturbDate success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`getDoNotDisturbDate fail: ${JSON.stringify(err)}`);
});
```
......@@ -2630,7 +2811,9 @@ notificationManager.getDoNotDisturbDate(userId).then((data: notificationManager.
**示例:**
```ts
function isSupportDoNotDisturbModeCallback(err: Base.BusinessError, data: boolean) {
import Base from '@ohos.base';
let isSupportDoNotDisturbModeCallback = (err: Base.BusinessError, data: boolean) => {
if (err) {
console.error(`isSupportDoNotDisturbMode failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -2672,8 +2855,12 @@ isSupportDoNotDisturbMode(): Promise\<boolean\>
**示例:**
```ts
import Base from '@ohos.base';
notificationManager.isSupportDoNotDisturbMode().then((data: boolean) => {
console.info("supportDoNotDisturbMode success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`supportDoNotDisturbMode fail: ${JSON.stringify(err)}`);
});
```
......@@ -2704,9 +2891,11 @@ isSupportTemplate(templateName: string, callback: AsyncCallback\<boolean\>): voi
**示例:**
```javascript
```ts
import Base from '@ohos.base';
let templateName: string = 'process';
function isSupportTemplateCallback(err: Base.BusinessError, data: boolean) {
let isSupportTemplateCallback = (err: Base.BusinessError, data: boolean) => {
if (err) {
console.error(`isSupportTemplate failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -2749,11 +2938,15 @@ isSupportTemplate(templateName: string): Promise\<boolean\>
**示例:**
```javascript
```ts
import Base from '@ohos.base';
let templateName: string = 'process';
notificationManager.isSupportTemplate(templateName).then((data: boolean) => {
console.info("isSupportTemplate success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`isSupportTemplate fail: ${JSON.stringify(err)}`);
});
```
......@@ -2783,8 +2976,10 @@ requestEnableNotification(callback: AsyncCallback\<void\>): void
**示例:**
```javascript
function requestEnableNotificationCallback(err: Base.BusinessError) {
```ts
import Base from '@ohos.base';
let requestEnableNotificationCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`requestEnableNotification failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -2815,9 +3010,13 @@ requestEnableNotification(): Promise\<void\>
**示例:**
```javascript
```ts
import Base from '@ohos.base';
notificationManager.requestEnableNotification().then(() => {
console.info("requestEnableNotification success");
}).catch((err: Base.BusinessError) => {
console.error(`requestEnableNotification fail: ${JSON.stringify(err)}`);
});
```
......@@ -2848,8 +3047,10 @@ requestEnableNotification(context: UIAbilityContext, callback: AsyncCallback\<vo
**示例:**
```javascript
function requestEnableNotificationCallback(err) {
```ts
import Base from '@ohos.base';
let requestEnableNotificationCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`requestEnableNotification failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -2886,9 +3087,13 @@ requestEnableNotification(context: UIAbilityContext): Promise\<void\>
**示例:**
```javascript
```ts
import Base from '@ohos.base';
notificationManager.requestEnableNotification(globalThis.uicontext).then(() => {
console.info("requestEnableNotification success");
}).catch((err: Base.BusinessError) => {
console.error(`requestEnableNotification fail: ${JSON.stringify(err)}`);
});
```
......@@ -2924,8 +3129,10 @@ setDistributedEnable(enable: boolean, callback: AsyncCallback\<void\>): void
**示例:**
```javascript
function setDistributedEnableCallback(err: Base.BusinessError) {
```ts
import Base from '@ohos.base';
let setDistributedEnableCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`setDistributedEnable failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -2969,11 +3176,15 @@ setDistributedEnable(enable: boolean): Promise\<void>
**示例:**
```javascript
```ts
import Base from '@ohos.base';
let enable: boolean = true;
notificationManager.setDistributedEnable(enable).then(() => {
console.info("setDistributedEnable success");
}).catch((err: Base.BusinessError) => {
console.error(`requestEnableNotification fail: ${JSON.stringify(err)}`);
});
```
......@@ -3005,8 +3216,10 @@ isDistributedEnabled(callback: AsyncCallback\<boolean>): void
**示例:**
```javascript
function isDistributedEnabledCallback(err: Base.BusinessError, data: boolean) {
```ts
import Base from '@ohos.base';
let isDistributedEnabledCallback = (err: Base.BusinessError, data: boolean) => {
if (err) {
console.error(`isDistributedEnabled failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -3046,11 +3259,15 @@ isDistributedEnabled(): Promise\<boolean>
**示例:**
```javascript
```ts
import Base from '@ohos.base';
notificationManager.isDistributedEnabled()
.then((data: boolean) => {
.then((data: boolean) => {
console.info("isDistributedEnabled success, data: " + JSON.stringify(data));
});
}).catch((err: Base.BusinessError) => {
console.error(`isDistributedEnabled fail: ${JSON.stringify(err)}`);
});
```
......@@ -3088,8 +3305,10 @@ setDistributedEnableByBundle(bundle: BundleOption, enable: boolean, callback: As
**示例:**
```javascript
function setDistributedEnableByBundleCallback(err: Base.BusinessError) {
```ts
import Base from '@ohos.base';
let setDistributedEnableByBundleCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`setDistributedEnableByBundle failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -3141,7 +3360,9 @@ setDistributedEnableByBundle(bundle: BundleOption, enable: boolean): Promise\<vo
**示例:**
```javascript
```ts
import Base from '@ohos.base';
let bundle: notificationManager.BundleOption = {
bundle: "bundleName1",
};
......@@ -3150,6 +3371,8 @@ let enable: boolean = true;
notificationManager.setDistributedEnableByBundle(bundle, enable).then(() => {
console.info("setDistributedEnableByBundle success");
}).catch((err: Base.BusinessError) => {
console.error(`setDistributedEnableByBundle fail: ${JSON.stringify(err)}`);
});
```
......@@ -3186,8 +3409,10 @@ isDistributedEnabledByBundle(bundle: BundleOption, callback: AsyncCallback\<bool
**示例:**
```javascript
function isDistributedEnabledByBundleCallback(err: Base.BusinessError, data: boolean) {
```ts
import Base from '@ohos.base';
let isDistributedEnabledByBundleCallback = (err: Base.BusinessError, data: boolean) => {
if (err) {
console.error(`isDistributedEnabledByBundle failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -3240,13 +3465,17 @@ isDistributedEnabledByBundle(bundle: BundleOption): Promise\<boolean>
**示例:**
```javascript
```ts
import Base from '@ohos.base';
let bundle: notificationManager.BundleOption = {
bundle: "bundleName1",
};
notificationManager.isDistributedEnabledByBundle(bundle).then((data: boolean) => {
console.info("isDistributedEnabledByBundle success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`isDistributedEnabledByBundle fail: ${JSON.stringify(err)}`);
});
```
......@@ -3281,8 +3510,10 @@ getDeviceRemindType(callback: AsyncCallback\<DeviceRemindType\>): void
**示例:**
```javascript
function getDeviceRemindTypeCallback(err: Base.BusinessError, data: notificationManager.DeviceRemindType) {
```ts
import Base from '@ohos.base';
let getDeviceRemindTypeCallback = (err: Base.BusinessError, data: notificationManager.DeviceRemindType) => {
if (err) {
console.error(`getDeviceRemindType failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -3323,9 +3554,13 @@ getDeviceRemindType(): Promise\<DeviceRemindType\>
**示例:**
```javascript
```ts
import Base from '@ohos.base';
notificationManager.getDeviceRemindType().then((data: notificationManager.DeviceRemindType) => {
console.info("getDeviceRemindType success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`getDeviceRemindType fail: ${JSON.stringify(err)}`);
});
```
......@@ -3369,8 +3604,10 @@ publishAsBundle(request: NotificationRequest, representativeBundle: string, user
**示例:**
```ts
import Base from '@ohos.base';
//publishAsBundle回调
function callback(err: Base.BusinessError) {
let callback = (err: Base.BusinessError) => {
if (err) {
console.error(`publishAsBundle failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -3436,6 +3673,8 @@ publishAsBundle(request: NotificationRequest, representativeBundle: string, user
**示例:**
```ts
import Base from '@ohos.base';
// 被代理应用的包名
let representativeBundle: string = "com.example.demo";
// 用户ID
......@@ -3455,6 +3694,8 @@ let request: notificationManager.NotificationRequest = {
notificationManager.publishAsBundle(request, representativeBundle, userId).then(() => {
console.info("publishAsBundle success");
}).catch((err: Base.BusinessError) => {
console.error(`publishAsBundle fail: ${JSON.stringify(err)}`);
});
```
......@@ -3496,8 +3737,10 @@ cancelAsBundle(id: number, representativeBundle: string, userId: number, callbac
**示例:**
```ts
import Base from '@ohos.base';
// cancelAsBundle
function cancelAsBundleCallback(err: Base.BusinessError) {
let cancelAsBundleCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`cancelAsBundle failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -3549,6 +3792,8 @@ cancelAsBundle(id: number, representativeBundle: string, userId: number): Promis
**示例:**
```ts
import Base from '@ohos.base';
// 被代理应用的包名
let representativeBundle: string = "com.example.demo";
// 用户ID
......@@ -3556,6 +3801,8 @@ let userId: number = 100;
notificationManager.cancelAsBundle(0, representativeBundle, userId).then(() => {
console.info("cancelAsBundle success");
}).catch((err: Base.BusinessError) => {
console.error(`cancelAsBundle fail: ${JSON.stringify(err)}`);
});
```
......@@ -3594,8 +3841,10 @@ setNotificationEnableSlot(bundle: BundleOption, type: SlotType, enable: boolean,
**示例:**
```ts
import Base from '@ohos.base';
// setNotificationEnableSlot
function setNotificationEnableSlotCallback(err: Base.BusinessError) {
let setNotificationEnableSlotCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`setNotificationEnableSlot failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -3644,12 +3893,16 @@ setNotificationEnableSlot(bundle: BundleOption, type: SlotType, enable: boolean)
**示例:**
```ts
import Base from '@ohos.base';
// setNotificationEnableSlot
notificationManager.setNotificationEnableSlot(
{ bundle: "ohos.samples.notification", },
notificationManager.SlotType.SOCIAL_COMMUNICATION,
true).then(() => {
console.info("setNotificationEnableSlot success");
}).catch((err: Base.BusinessError) => {
console.error(`setNotificationEnableSlot fail: ${JSON.stringify(err)}`);
});
```
......@@ -3687,8 +3940,10 @@ isNotificationSlotEnabled(bundle: BundleOption, type: SlotType, callback: AsyncC
**示例:**
```ts
import Base from '@ohos.base';
// isNotificationSlotEnabled
function getEnableSlotCallback(err: Base.BusinessError, data: boolean) {
let getEnableSlotCallback = (err: Base.BusinessError, data: boolean) => {
if (err) {
console.error(`isNotificationSlotEnabled failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -3741,10 +3996,14 @@ isNotificationSlotEnabled(bundle: BundleOption, type: SlotType): Promise\<boolea
**示例:**
```ts
import Base from '@ohos.base';
// isNotificationSlotEnabled
notificationManager.isNotificationSlotEnabled({ bundle: "ohos.samples.notification", },
notificationManager.SlotType.SOCIAL_COMMUNICATION).then((data: boolean) => {
console.info("isNotificationSlotEnabled success, data: " + JSON.stringify(data));
}).catch((err: Base.BusinessError) => {
console.error(`isNotificationSlotEnabled fail: ${JSON.stringify(err)}`);
});
```
......@@ -3783,10 +4042,12 @@ setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean, callback:
**示例:**
```ts
import Base from '@ohos.base';
let userId: number = 100;
let enable: boolean = true;
function callback(err: Base.BusinessError) {
let callback = (err: Base.BusinessError) => {
if (err) {
console.error(`setSyncNotificationEnabledWithoutApp failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -3837,11 +4098,15 @@ setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean): Promise\<
**示例:**
```ts
import Base from '@ohos.base';
let userId: number = 100;
let enable: boolean = true;
notificationManager.setSyncNotificationEnabledWithoutApp(userId, enable).then(() => {
console.info('setSyncNotificationEnabledWithoutApp success');
}).catch((err: Base.BusinessError) => {
console.error(`setSyncNotificationEnabledWithoutApp fail: ${JSON.stringify(err)}`);
});
```
......@@ -3879,9 +4144,11 @@ getSyncNotificationEnabledWithoutApp(userId: number, callback: AsyncCallback\<bo
**示例:**
```ts
import Base from '@ohos.base';
let userId: number = 100;
function getSyncNotificationEnabledWithoutAppCallback(err: Base.BusinessError, data: boolean) {
let getSyncNotificationEnabledWithoutAppCallback = (err: Base.BusinessError, data: boolean) => {
if (err) {
console.info('getSyncNotificationEnabledWithoutAppCallback, err:' + err);
} else {
......@@ -3931,10 +4198,14 @@ getSyncNotificationEnabledWithoutApp(userId: number): Promise\<boolean>
**示例:**
```ts
import Base from '@ohos.base';
let userId: number = 100;
notificationManager.getSyncNotificationEnabledWithoutApp(userId).then((data: boolean) => {
console.info('getSyncNotificationEnabledWithoutApp, data:' + data);
}).catch((err: Base.BusinessError) => {
console.error(`getSyncNotificationEnabledWithoutApp fail: ${JSON.stringify(err)}`);
});
```
......@@ -3968,12 +4239,9 @@ on(type: 'checkNotification', callback: (checkInfo: NotificationCheckInfo) => No
**示例:**
```ts
try{
notificationManager.on("checkNotification", OnCheckNotification);
} catch (error){
console.info(`notificationManager.on error: ${JSON.stringify(error)}`);
}
function OnCheckNotification(info : notificationManager.NotificationCheckInfo) {
import Base from '@ohos.base';
let OnCheckNotification = (info : notificationManager.NotificationCheckInfo) => {
console.info(`====>OnCheckNotification info: ${JSON.stringify(info)}`);
if(info.notificationId == 1){
let result: notificationManager.NotificationCheckResult = { code: 1, message: "testMsg1"};
......@@ -3983,6 +4251,11 @@ function OnCheckNotification(info : notificationManager.NotificationCheckInfo) {
return result;
}
}
try{
notificationManager.on("checkNotification", OnCheckNotification);
} catch (error){
console.info(`notificationManager.on error: ${JSON.stringify(error)}`);
}
```
## notificationManager.off<sup>10+</sup>
......@@ -4015,6 +4288,8 @@ off(type: 'checkNotification', callback?: (checkInfo: NotificationCheckInfo) =>
**示例:**
```ts
import Base from '@ohos.base';
try{
notificationManager.off("checkNotification");
} catch (error){
......
......@@ -8,7 +8,7 @@
## 导入模块
```js
```ts
import notificationSubscribe from '@ohos.notificationSubscribe';
```
......@@ -45,22 +45,24 @@ subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, c
**示例:**
```js
```ts
import Base from '@ohos.base';
//subscribe回调
function subscribeCallback(err) {
let subscribeCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("subscribe success");
}
}
function onConsumeCallback(data) {
let onConsumeCallback = (data: notificationSubscribe.SubscribeCallbackData) => {
console.info("Consume callback: " + JSON.stringify(data));
}
let subscriber = {
let subscriber: notificationSubscribe.NotificationSubscriber = {
onConsume: onConsumeCallback
};
let info = {
let info: notificationSubscribe.NotificationSubscribeInfo = {
bundleNames: ["bundleName1","bundleName2"]
};
notificationSubscribe.subscribe(subscriber, info, subscribeCallback);
......@@ -98,18 +100,20 @@ subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>):
**示例:**
```js
function subscribeCallback(err) {
```ts
import Base from '@ohos.base';
let subscribeCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("subscribe success");
}
}
function onConsumeCallback(data) {
let onConsumeCallback = (data: notificationSubscribe.SubscribeCallbackData) => {
console.info("Consume callback: " + JSON.stringify(data));
}
let subscriber = {
let subscriber: notificationSubscribe.NotificationSubscriber = {
onConsume: onConsumeCallback
};
notificationSubscribe.subscribe(subscriber, subscribeCallback);
......@@ -149,15 +153,19 @@ subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo):
**示例:**
```js
function onConsumeCallback(data) {
```ts
import Base from '@ohos.base';
let onConsumeCallback = (data: notificationSubscribe.SubscribeCallbackData) => {
console.info("Consume callback: " + JSON.stringify(data));
}
let subscriber = {
let subscriber: notificationSubscribe.NotificationSubscriber = {
onConsume: onConsumeCallback
};
notificationSubscribe.subscribe(subscriber).then(() => {
console.info("subscribe success");
}).catch((err: Base.BusinessError) => {
console.error("subscribe fail: " + JSON.stringify(err));
});
```
......@@ -194,18 +202,20 @@ unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\<void\>)
**示例:**
```js
function unsubscribeCallback(err) {
```ts
import Base from '@ohos.base';
let unsubscribeCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`unsubscribe failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("unsubscribe success");
}
}
function onDisconnectCallback() {
let onDisconnectCallback = () => {
console.info("subscribe disconnect");
}
let subscriber = {
let subscriber: notificationSubscribe.NotificationSubscriber = {
onDisconnect: onDisconnectCallback
};
notificationSubscribe.unsubscribe(subscriber, unsubscribeCallback);
......@@ -241,15 +251,19 @@ unsubscribe(subscriber: NotificationSubscriber): Promise\<void\>
**示例:**
```js
function onDisconnectCallback() {
```ts
import Base from '@ohos.base';
let onDisconnectCallback = () => {
console.info("subscribe disconnect");
}
let subscriber = {
let subscriber: notificationSubscribe.NotificationSubscriber = {
onDisconnect: onDisconnectCallback
};
notificationSubscribe.unsubscribe(subscriber).then(() => {
console.info("unsubscribe success");
}).catch((err: Base.BusinessError) => {
console.error("unsubscribe fail: " + JSON.stringify(err));
});
```
......@@ -288,22 +302,25 @@ remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveRea
**示例:**
```js
function removeCallback(err) {
```ts
import Base from '@ohos.base';
import NotificationManager from '@ohos.notificationManager';
let removeCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`remove failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("remove success");
}
}
let bundle = {
let bundle: NotificationManager.BundleOption = {
bundle: "bundleName1",
};
let notificationKey = {
let notificationKey: notificationSubscribe.NotificationKey = {
id: 0,
label: "label",
};
let reason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE;
let reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE;
notificationSubscribe.remove(bundle, notificationKey, reason, removeCallback);
```
......@@ -343,17 +360,22 @@ remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveRea
**示例:**
```js
let bundle = {
```ts
import Base from '@ohos.base';
import NotificationManager from '@ohos.notificationManager';
let bundle: NotificationManager.BundleOption = {
bundle: "bundleName1",
};
let notificationKey = {
let notificationKey: notificationSubscribe.NotificationKey = {
id: 0,
label: "label",
};
let reason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE;
let reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE;
notificationSubscribe.remove(bundle, notificationKey, reason).then(() => {
console.info("remove success");
}).catch((err: Base.BusinessError) => {
console.error("remove fail: " + JSON.stringify(err));
});
```
......@@ -390,17 +412,19 @@ remove(hashCode: string, reason: RemoveReason, callback: AsyncCallback\<void\>):
**示例:**
```js
let hashCode = 'hashCode';
```ts
import Base from '@ohos.base';
let hashCode: string = 'hashCode';
function removeCallback(err) {
let removeCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`remove failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("remove success");
}
}
let reason = notificationSubscribe.RemoveReason.CANCEL_REASON_REMOVE;
let reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CANCEL_REASON_REMOVE;
notificationSubscribe.remove(hashCode, reason, removeCallback);
```
......@@ -436,11 +460,15 @@ remove(hashCode: string, reason: RemoveReason): Promise\<void\>
**示例:**
```js
let hashCode = 'hashCode';
let reason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE;
```ts
import Base from '@ohos.base';
let hashCode: string = 'hashCode';
let reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE;
notificationSubscribe.remove(hashCode, reason).then(() => {
console.info("remove success");
}).catch((err: Base.BusinessError) => {
console.error("remove fail: " + JSON.stringify(err));
});
```
## NotificationSubscribe.remove<sup>10+<sup>
......@@ -475,17 +503,19 @@ remove(hashCodes: Array\<String\>, reason: RemoveReason, callback: AsyncCallback
**示例:**
```js
let hashCodes = ['hashCode1', 'hashCode2'];
```ts
import Base from '@ohos.base';
let hashCodes: string[] = ['hashCode1', 'hashCode2'];
function removeCallback(err) {
let removeCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`remove failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("remove success");
}
}
let reason = notificationSubscribe.RemoveReason.CANCEL_REASON_REMOVE;
let reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CANCEL_REASON_REMOVE;
notificationSubscribe.remove(hashCodes, reason, removeCallback);
```
......@@ -520,11 +550,15 @@ remove(hashCodes: Array\<String\>, reason: RemoveReason): Promise\<void\>
**示例:**
```js
let hashCodes = ['hashCode1','hashCode2'];
let reason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE;
```ts
import Base from '@ohos.base';
let hashCodes: string[] = ['hashCode1','hashCode2'];
let reason: notificationSubscribe.RemoveReason = notificationSubscribe.RemoveReason.CLICK_REASON_REMOVE;
notificationSubscribe.remove(hashCodes, reason).then(() => {
console.info("remove success");
}).catch((err: Base.BusinessError) => {
console.error("remove fail: " + JSON.stringify(err));
});
```
......@@ -560,15 +594,17 @@ removeAll(bundle: BundleOption, callback: AsyncCallback\<void\>): void
**示例:**
```js
function removeAllCallback(err) {
```ts
import Base from '@ohos.base';
let removeAllCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`removeAll failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info("removeAll success");
}
}
let bundle = {
let bundle: notificationSubscribe.BundleOption = {
bundle: "bundleName1",
};
notificationSubscribe.removeAll(bundle, removeAllCallback);
......@@ -604,8 +640,10 @@ removeAll(callback: AsyncCallback\<void\>): void
**示例:**
```js
function removeAllCallback(err) {
```ts
import Base from '@ohos.base';
let removeAllCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`removeAll failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -647,10 +685,14 @@ removeAll(bundle?: BundleOption): Promise\<void\>
**示例:**
```js
```ts
import Base from '@ohos.base';
// 不指定应用时,删除所有通知
notificationSubscribe.removeAll().then(() => {
console.info("removeAll success");
}).catch((err: Base.BusinessError) => {
console.error("removeAll fail: " + JSON.stringify(err));
});
```
......@@ -686,8 +728,10 @@ removeAll(userId: number, callback: AsyncCallback\<void>): void
**示例:**
```js
function removeAllCallback(err) {
```ts
import Base from '@ohos.base';
let removeAllCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`removeAll failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -695,7 +739,7 @@ function removeAllCallback(err) {
}
}
let userId = 1;
let userId: number = 1;
notificationSubscribe.removeAll(userId, removeAllCallback);
```
......@@ -731,8 +775,10 @@ removeAll(userId: number): Promise\<void>
**示例:**
```js
function removeAllCallback(err) {
```ts
import Base from '@ohos.base';
let removeAllCallback = (err: Base.BusinessError) => {
if (err) {
console.error(`removeAll failed, code is ${err.code}, message is ${err.message}`);
} else {
......@@ -740,7 +786,7 @@ function removeAllCallback(err) {
}
}
let userId = 1;
let userId: number = 1;
notificationSubscribe.removeAll(userId, removeAllCallback);
```
......
......@@ -51,11 +51,7 @@ show(options?: ShowNotificationOptions): void
**示例:**
```ts
class NotificationClass {
show: Function
}
let notificationObj: NotificationClass = {
let notificationObj: notification = {
show() {
notification.show({
contentTitle: 'title info',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册