Titanium Local Notification to trigger daily at specified time

You must Login before you can answer or comment on any questions.

Hi all,

Is there a way I can generate local notifications in Android each day at lets say 9:00am?

using Android 2.3.3; Ti SDK 2.0.2

1 Answer

Simply sen the when property when you create your Notification. Simply set the time to the specified time you want it to appear.

As for the each day, this might prove a little tricky.

— answered 8 months ago by Christian Brousseau
answer permalink
5 Comments
  • Hey Christiian, Thanks for your reply. what sould i specify in intent.putExtra('interval', ???);

    — commented 8 months ago by Aadil Farooq

  • I think this answer is not quite accurate. I've been struggling with this issue for days, so I feel your pain, Aadil.

    From the docs for Notification:

    "when" has nothing to do with when the actual notification will happen. It is only a timestamp that will show on the notification and can be set to any date you wish.

    The notification will fire as soon as you call NotificationManager.notify().

    So you have to use a background service, which at the appropriate time will create and fire the notification.

    However, once the device goes to sleep, I don't think your service will get any cycles. It might run for a little while, but I don't know if it will run until 9:00 a.m. the next day.

    Android has the concept of wake locks that prevent the device from going to sleep, but I think it would be a bad idea to hold such a lock for hours at a time, as you will probably kill the battery.

    Ben Bahrenburg generously built and shared a module for interfacing with Titanium's AlarmManager. Get it here. I've had some success with this. Unfortunately for my purposes, his module does not support setting multiple alarms. I may end up reworking it a bit.

    One last problem I've encountered is that I can't figure out how to get the screen to come on when the Notification (or the Alarm) fires. I want my app to behave like the alarm clock that's built into my android device.

    This problem should be simple. It's very difficult with the current Titanium API. If I can come up with a working solution, I will definitely be sharing it here in the Q&A.

    — commented 8 months ago by Jason Priebe

  • Thanks Jason for replying and thanks for understanding the problem. I had a problem. Lets say if the user sets a notification of 9am and the current time is 8:30am. What should the interval be in intent.putExtra('interval', ???);?? I think you cant change it once you set it.

    What I have done till now is that I am using two services. One with "x" interval(i.e x=9am-Current Time) and other with interval of 24hrs. So when the first service triggers I generate notification and stop the first service and make a new service with new interval of 24hrs....

    I thought I had some success... But you just told me about the problem of missing cycles when android goes sleep. I think some more experienced people should also shed a light on it.

    — commented 8 months ago by Aadil Farooq

  • Show 2 more comments

Your Answer

Think you can help? Login to answer this question!