0

I am making a medicine reminder app which reminds people to take their medicine on a scheduled date-time.

For example, if my start-date is 08-APR-2013 and the end-date is 12-APR-2013 and time is 11.30 am then the alarm should fire till 12-APR-2013 at 11.30 am. Please help with how I can achieve this. I know how to set an alarm manager and the normal alarm is fired. But when I have a start-date and end-date at that time I become confused about how I should use the alarmManager.setRepeating() method.

JDJ
  • 4,298
  • 3
  • 25
  • 44
Riddhi Shah
  • 477
  • 7
  • 26
  • I think you have to use 'set()' if you want to set it for an exact date instead of 'setRepeating()' http://developer.android.com/reference/android/app/AlarmManager.html#set%28int,%20long,%20android.app.PendingIntent%29 – luanjot Apr 08 '13 at 09:58
  • hey i will try the code the way you suggest. i hope i'll get the things the way i want..!! – Riddhi Shah Apr 08 '13 at 10:17
  • hey thanks for suggestion its almost done..!! – Riddhi Shah Apr 08 '13 at 16:48

2 Answers2

0

this code for repeating alarm for every day

Date dateobj=new Date(Year,month,day,hour,min);             
setRepeating(AlarmManager.RTC_WAKEUP, dateobj.getTime(), (24*60*60*1000), pendingIntent);
Deepak Bala
  • 11,095
  • 2
  • 38
  • 49
srinivas
  • 163
  • 9
  • i want to repeat the alarm till my end-date came. above code will work on my requirements? – Riddhi Shah Apr 08 '13 at 10:03
  • if you want to schedule only four days setrepeting concept doesn't work.use different request code with different timings – srinivas Apr 08 '13 at 10:12
  • then how should i set my alarm? – Riddhi Shah Apr 08 '13 at 10:14
  • 1
    Date dateobj=new Date(Year,month,day,hour,min); // increment by day Intent intent1= new Intent(CurrentClass.this,service.class);//service or broadcast pendingIntent =PendingIntent.getService(ScheduleManagement.this,1, intent1,3);//change the request code every time set(AlarmManager.RTC_WAKEUP, dateobj.getTime(), pendingIntent); – srinivas Apr 08 '13 at 10:20
0

you can do this by setting the alarm at the time you want by using the setReapting() method.

1.Use a table to insert your entries.
2.query the table for every minute or for the time interval you want using a broadcast receiver.
3.In the onReceive() callback compare the current time with the insert time and fire the alarm.
4.if there is no record then cancel the pending intent.

if you have any doubt in this go through this link

.

Community
  • 1
  • 1
vinoth
  • 485
  • 4
  • 16