我正在尝试在特定日期和时间设置通知。
仅当我将小时和分钟设置为日历值(而不是日期)时,通知才起作用。这是我的代码的示例
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);
我究竟做错了什么?
一只斗牛犬
相关分类