Search code examples
androidalarmmanagerandroid-alarms

Repeating inexact alarms once a week


I need to do a task every week in my app and it doesn't really care the precision, so I'm thinking to use setInexactRepeating() but I can't find any constant for a week delay. From documentation it seems that you can use only defined constants. I could use a simpler setRepeating() but I don't want to set exact alarm for api < 19. How can I do? Can I only set the timer to INTERVAL_DAY?


Solution

  • If you look at the INTERVAL_DAY constant you'll see:

    public static final long INTERVAL_DAY = 86400000L;
    

    It is 86,400,000 milliseconds which is equal to 1 day. It means, that you can use your own value in milliseconds in the setInexactRepeating method. A week would be INTERVAL_DAY * 7.