使用reminderAgentManager.publishReminder发布日历提醒,按照文档在module.json5中添加了ohos.permission.PUBLISH_AGENT_REMINDER权限,并且在调用方法时也请求响应权限。
问题1: 但是调试代码提示NotificationBussinessError 1700001: Notification not enable。
问题2:手动在设置页面开启了Notification后,创建提醒成功,但是在系统的日历app中无法看到我创建的提醒。
代码:
public addCalendarEvent(title:string, description:string, reminderTime:number, previousTime:number, days:Array<number>,context:Context)
{
let atManager = abilityAccessCtrl.createAtManager();
try {
atManager.requestPermissionsFromUser(context, ["ohos.permission.PUBLISH_AGENT_REMINDER","ohos.permission.WRITE_CALENDAR"], (err, data)=>{
console.info("data:" + JSON.stringify(data));
console.info("data permissions:" + data.permissions);
console.info("data authResults:" + data.authResults);
let timer:reminderAgentManager.ReminderRequestCalendar = {
reminderType: reminderAgentManager.ReminderType.REMINDER_TYPE_CALENDAR,
title:title,
content:description,
dateTime:this.timestampToLocalDateTime(reminderTime),
repeatDays:days
}
reminderAgentManager.publishReminder(timer, (err, reminderId) => {
if (err) {
console.log("callback err code:" + err.code + " message:" + err.message);
} else {
console.log("callback, reminderId = " + reminderId);
}
});
});
} catch(err) {
console.log(`catch err->${JSON.stringify(err)}`);
}
}
调用:
const now = new Date();
let reminderTime= now.getTime();
const numbers: number[] = [1, 2, 3];
new CalendarAPI().addCalendarEvent('test','this is a test description',reminderTime,0,numbers,this.context)
日程管理接口已开放,日程提醒参考文档:https://gitee.com/openharmony/docs/blob/master/zh-cn/applicat...