0

I am developing an android application that trigger alarm for one/ two weeks or for long life. Also, this alarm will be repeated per day according to the number of pills. For example, if the user has to take the pill for only two weeks and on every day he needs to take three pills. So, the alarm will be repeated for only Two weeks. and on every day will be repeated after 8 hours, suppose he takes the pill on the noon 12pm then the second pill should be at 8pm,4am and so on. (I want the alarm to trigger on these period of time)

This is my code, I used Spinner as dropdown list to select the duration time for the pill

if(deuTime.equals("Two week")) {
calendar.set(Calendar.DAY_OF_WEEK_IN_MONTH, 14);
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minute);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
calendar.set(Calendar.DAY_OF_WEEK, dayOfWeek);

long alarm_time = calendar.getTimeInMillis();
if (calendar.before(Calendar.getInstance()))
    alarm_time += AlarmManager.INTERVAL_DAY * 7;

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, alarm_time,
        1000*60*60*8, alarmIntent);
 }

thank you for your help :)

Fatimah Mohmmed
  • 147
  • 2
  • 18

0 Answers0