gpt4 book ai didi

java - 设置日期时,警报管理器不会触发通知

转载 作者:行者123 更新时间:2023-12-03 17:50:33 24 4
gpt4 key购买 nike

我正在尝试在特定的日期和时间设置通知。

通知仅在我将小时和分钟设置为日历值而不是日期时才起作用。
这是我的代码示例

    Calendar cal1 = Calendar.getInstance();

cal1.set(Calendar.YEAR, 2019);
cal1.set(Calendar.MONTH, 10);
cal1.set(Calendar.DAY_OF_MONTH, 24);

cal1.set(Calendar.HOUR_OF_DAY, 10);
cal1.set(Calendar.MINUTE, 30);
cal1.set(Calendar.SECOND, 0);
long time = cal1.getTimeInMillis();

AlarmManager alarmManager =(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);

Intent notificationIntent = new Intent(context, AlarmReceiver.class);
notificationIntent.putExtra(AddReminder.REMINDER_ID, Integer.toString(ID));
PendingIntent broadcast = PendingIntent.getBroadcast(context, 100, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);


alarmManager.setExact(AlarmManager.RTC_WAKEUP, time, broadcast);


我究竟做错了什么?

最佳答案

Java日历月份从0开始,因此如果您希望10月成为月份,则它将是9 note 10

cal1.set(Calendar.MONTH, 9);

关于java - 设置日期时,警报管理器不会触发通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58546982/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com