Android notifications don't work if set to next day - android

I've made a program, which uses broadcastreceiver to create an alarm (which is activated after several days).
When the time comes, it is supposed to play a notification.
I've tried setting the time to few minutes, hours and the notification always plays.
However in real life testing when the time was over one day the notification doesn't work.
Is there a limit to which Broadcast receivers can be set to in the future?
Here is my code: [http://pastebin.com/JnxVExtK]
Let's say today is Sunday 5:00.
If I set the alarm at Sunday 7:09 - It will ring.
But if I set the alarm for Wednesday at 3:00 - it won't work.
And obviously I cannot set the emulator for such long period.
I've been trying the program on my tablet and there too the notification fails to show up if the alarm is set to ring after few days.

fallow the two steps and schedule the task perfectly
1.create date object
Date dateobj=new Date(year-1900,month,day,hour,min);
year - scheduling Year month-scheduling month(0-11) day-scheduling
day (1-30) hour scheduling hour (24 hrs format )(0-24) min
scheduling min 0-59
2. set the alarm to dateobj.getTime() its returns milli seconds
alarmManager.set(AlarmManager.RTC_WAKEUP, dateobj.getTime(),
pendingIntent);

Related

Android notifications on different days of the week

I want to build notifications that are showed recurrently in specific days of the week, for example, I want X notification every monday and friday of each week. I know how to set intervals with alarms, but not how to select specific days
You can set repeating alarm for every day and show notification only those days that are needed on onReceive() function of the alarm BroadcastReceiver.
The logical way to control push notification timing is from server side but if you want to do it on your phone you must work with android os date and time and Java CALENDAR class.

Stratagy to set repeat days alarm in android

I'm really confused about which technique I should use to set and cancel the repeat days alarm.
I have two conditions in my mind.
First is that I set all the repeating days alarm at once when alarm is added.
Second is that I should check at the time when alarm is triggered that is there any alarm for next day or not.
Problems with my conditions.
If i set the repeating days at once and if the user changed the repeating days like user added alarm at 8:30 AM for Monday , Wednesday and Friday and then the user changed the days to Monday and Friday only then how can i keep check on it and cancel it for Wednesday.
In second condition if I check at the time when alarm goes-off for the next day and what if user did not set that alarm for next day and set that same alarm for day after tomorrow? Like user set alarm at Monday 8:30 AM and the same alarm is also set for Wednesday not Tuesday then how can i check this ?
It would be great pleasure if anybody can give me some kind of solution to keep check on it.
You can start from Clock app of AOSP https://android.googlesource.com/platform/packages/apps/DeskClock/+/master
In the specific check how the alarms are implemented in the Alarm class.
In any case you have to schedule the alarm for the "first next day" that is setted, then when the alarm is fired, you need a method that tell you when is the next occurrence.
If an user need to modify the alarm you have to unschedule the existing alarm and reschedule it.
You should also save your alarm to a database because if the device is rebooted all scheduled alarms are lost. So you have to register a boot receiver and re-schedule all the alarms

how to set alarm which will ring when the date changes in system

i am making a app which is using alarm facility for user almost i have done all the parts but there is a problem in my alarm system i explaining this
-- according to app alarm has to ring when the date changes not without depending on the time user set
ex-- let the current time is 4 pm and date is 4 june user wants to set the alarm for 5 june
so my alarm will ring on 5 june when date changes in my system.
currently what is happening alarm is ringing on 5 june but on 4pm when the 24 hrs is completed

alarm triggers even after finish time in android

I am creating small Alarm project which has week days option. (I am using alarm manager).
The alarm triggers perfectly on given time and day but the problem is that it also triggers any previous alarm if I change the day or time after to the given alarm time.
For eg.
If the alarm is set to ring at 5:00 AM Monday Wednesday Friday. - And the current time is 6:00PM Sunday.
And another alarm set for for 4:00PM Monday Wednesday Friday - The current time is 6:30PM Sunday.
For testing I changed the day to Tuesday 6:00PM - Immediately the two alarm triggers one by one for Monday's schedule.
How do I stop this specific alarm and trigger only next Monday rather immediately? Do I need to check the dates also???
Let me know!
You can't really. The alarm manager bases everything off of the system time. If you change the system time manually it is going to act just as if all the time had passed between now and whenever you set it for.
Edit: You can find the source code for the stock alarm application. Here is a link to one of the relavent objects Alarms.
I didn't test it any to ensure but from what I can tell they are storing the time the event is supposed to fire, and if it suddenly finds that it is in the past it ignores the alarm instead of letting it trigger. Some other relavent classes to check out are SetAlarm and AlarmClock, search for them on grepcode if you want to follow the way they set and react to the alarms in the stock app.
But it is still important to point out that manually changing the system time can still be used to manipulate the alarms. If for instance you set an alarm for 10:00pm tomorrow, then manually jump the time to 9:59pm tomorrow. The alarm will fire after 1 minute.
compare your alarm time with System.currentTimeMillis()
if your alarm time is smaller then the current time, than no need to set the alarm

Setting alarm at different timings using AlarmManager

I am currently developing an application that will set off a alarm at some timings. Now I have managed to set it off after 10 seconds however I don't know how to set alarm in the format that is same as the built-in alarm system where they set like 10 minutes before the event or 1 day before the event, etc.

Categories

Resources