Dhiraj
Dhiraj

Reputation: 910

How to set Alarm to multiple dates at same time once

I am having following code to set the alarm.It is working for single date.But in my application user can select multiple dates and and when he/she selects the multiple date i have to set the alarm on each selected date on selected time.eg- if user selects three dates 11,12,13 and selects time 8am then the alarm should ring on 11,12,13 on 8am following is my code where i am setting alarm for single date

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MONTH, 0);
calendar.set(Calendar.YEAR, 2016);
calendar.set(Calendar.DAY_OF_MONTH, 11);

calendar.set(Calendar.HOUR_OF_DAY, alarmTimePicker.getCurrentHour());
calendar.set(Calendar.MINUTE, alarmTimePicker.getCurrentMinute());

Intent myIntent = new Intent(MainActivity.this, AlarmReceiver.class);
pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, myIntent, 0);
alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(), pendingIntent);

Upvotes: 0

Views: 611

Answers (1)

Rohit5k2
Rohit5k2

Reputation: 18112

Use different request code for each PendingIntent like this

final int requestId = (int) System.currentTimeMillis();
pendingIntent = PendingIntent.getBroadcast(MainActivity.this, requestId, myIntent, 0);

Upvotes: 1

Related Questions