I am developing an alarm based application, in which i have to repeat the alarm for every weekday like (every monday, tuesday, wednesday) based on user input. I used this sn
here is my code to set alarm to repeat every month in 4th
public void init(Context context) {
Intent intent = new Intent(context, AlarmReceiver.class);
pendingIntent = PendingIntent.getBroadcast(context, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
// Get the AlarmManager service
alarmManager = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
}
public void createAlarmControler(Context context) {
init(context);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH, 4);
cal.set(Calendar.HOUR_OF_DAY, 10);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
Date now = new Date(System.currentTimeMillis());
if (cal.getTime().before(now)) {
cal.add(Calendar.MONTH, 1);
}
long firstTime = cal.getTime().getTime();
alarmManager.cancel(pendingIntent);
Log.e("", "firstTime: " + firstTime);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, firstTime, 1000 * 60
* 60 * 24 * 30, pendingIntent);
}
public void cancelAlarmControler(Context context) {
init(context);
alarmManager.cancel(pendingIntent);
}