-1

Using Broadcast receiver, how can i make the alarmmanager repeat evrey given day/days/time ?

public void startAlert(String time, String title) {
    long timeInMillis = Long.decode(time);
    intent = new Intent(this, AlarmReceiver.class);
    intent.putExtra("myTitle", title);
    alarmmanager = (AlarmManager) getSystemService(ALARM_SERVICE);
    pendingIntent = PendingIntent.getBroadcast(this, (int) Long.parseLong(time), intent, PendingIntent.FLAG_UPDATE_CURRENT);
    alarmmanager.set(AlarmManager.RTC_WAKEUP, timeInMillis, pendingIntent);
}

2 Answers2

0

Use setRepeating instead of set.
Here is the proper syntax -

alarmmanager.setRepeating(AlarmManager.RTC_WAKEUP,
        startUpTime, AlarmManager.INTERVAL_DAY, pendingIntent);
Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49
  • i know the command, but what i do next ? how i tell it to work in any given day ? not every day, not every sunday, but any given day that the user chose. – Tal Brodkin Nov 05 '17 at 16:40
  • in that case you have to develop logic like whatever day was chosen by user, you have calculate interval between now and that day and use that interval, hope it help, if not i will have to write complete code and show you. – Prakash Meghani Nov 06 '17 at 17:36
0

I think you can use setRepeating with customized Date like this another question.

alarmmanager.setRepeating(AlarmManager.RTC_WAKEUP, startUpTime, AlarmManager.INTERVAL_DAY, pendingIntent);

Ênio Abrantes
  • 302
  • 2
  • 11