I'm trying to set notifications at specific date and time.
Notifications are working only when I set to calendar values for hour and minute, but not date. here is example from my code
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);
What am I doing wrong?
Java calender month starts from 0, so if you want October to be the month, it will be 9 not 10
cal1.set(Calendar.MONTH, 9);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.