Condition : User selects a active time period (from and to) for a day within which the alarm should be active with user specified interval. User selects a inactive time period (from and to) for a day within which the alarm should be inactive or silent. User selects the days on which the alarm should be fired.
eg: a user selects the active period of the alarm to be 9:00 am to 6:00pm with an interval of 20 minutes. and he don't want the alarm to notify during his break time.say lunch break time is from 1:00 pm to 2:00 pm.He wasnts the alarm to be active only on Tuesday,Thursday and Sunday. So during Tuesday, Thursday and Sunday ,the alarm should fire at 9:00am and fire with an interval of 20 minutes till 6:00pm. In between the alarm should be silent for 1:00pm to 2:00pm.
The user sets the timings in the main activity and the alarm for those timings is set in another activity where the alarm can be set and canceled.
Variables:
Active from time(in millisec) : int AFrom
Active to time (in millisec) : int ATo
Break from time (in millisec) : int BFrom
Break to time (in millisec) : int Bto
Alarm firing Interval (in millisec) : int interval
To select no: of days using a Android Alert Dialog with Multiple checkboxes:
String days[] = {"MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY","SUNDAY"} ;
Boolean checkedDays[] = {false,true,false,true,false,true,false};
final ArrayList DaysSelected = new ArrayList();
(this is just for information. Actual working Dialog box is created already. Just want to use the selected day's index for checking with the calendar day)
days[] is referenced with checkedDays[] to identify the selected days in setMultiChoiceItems().
Inside setMultiChioceItems():
builder.setMultiChoiceItems(days, checkedDays,
new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int selectedItemId,
boolean isSelected) {
if (isSelected) {
DaysSelected .add(selectedItemId);
} else if (DaysSelected .contains(selectedItemId)) {
DaysSelected .remove(Integer.valueOf(selectedItemId));
}
}
})
Alarm has to be set for the days whose checkedDays[] values are true
Note :All the variables all set static to use across all activities.
with the above variables how do I fire the below alarm for my above required condition?
Intent intent = new Intent(this,Notifier.class);
PendingIntent pendingIntent = PendingIntent.getActivitythis.getApplicationContext(),
12345, intent, FLAG_CANCEL_CURRENT );
AlarmManager am =(AlarmManager)getSystemService(Activity.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, AT_from , interval, pendingIntent);