Android daily alarm development

I have this piece of code that starts the alarm once, setting the time and date using TimePicker and DatePicker in another action. I want to change it so that every time I set the time and date, it works every day every day. In other words, I want the alarm to work daily.

public class M_ReminderManager {

    private Context mContext; 
    private AlarmManager mAlarmManager;

    public M_ReminderManager(Context context) {
        mContext = context; 
        mAlarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
    }

    public void setReminder(Long reminderId, Calendar when) {

        Intent i = new Intent(mContext, Medicines_OnAlarmReceiver.class);
        i.putExtra(RemindersDbAdapter.KEY_ROWID_MEDS, (long)reminderId); 

        PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, i, PendingIntent.FLAG_ONE_SHOT); 
        mAlarmManager.set(AlarmManager.RTC_WAKEUP, when.getTimeInMillis(), pi);
      }
}

I tried to use the setRepeating function, but I don’t know how exactly I should set the attributes. I used this line instead of the set function in the code, but it did not work:

mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, when.getTimeInMillis() ,AlarmManager.INTERVAL_DAY , pi);

Can someone help me?

+5
source share
2 answers

Just change the code

alarmManager.set(AlarmManager.RTC_WAKEUP,
    calendar.getTimeInMillis(), pendingIntent)

in class AndroidAlarmServicefor

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
    calendar.getTimeInMillis(), 5*1000, pendingIntent)

: http://android-er.blogspot.com/2010/10/schedule-repeating-alarm.html

+4

: reset , .

+1

All Articles