在HarmonyOS中使用reminderAgentManager.publishReminder发布日历提醒,无法在日历上看到?

使用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)
阅读 674
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题