Android set repeating alarm for certain time of day

后端 未结 1 1854
悲哀的现实
悲哀的现实 2021-01-24 16:42

I am trying to set a repeating alarm that will will download a file every minute but only between 8:00 and 22:00. I feel like I\'m really close but I can\'t see the error I\'m m

相关标签:
1条回答
  • 2021-01-24 17:02

    You should set your alarm reapeating when it is between 8:00 and 22:00 like you mentioned:

    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+10000, 60000,pendingIntent); 
    

    This will repeat every minute. But you must explicitly cancel the alarm. You can cancel it after download is completed, by checking if its already 22:00. Or by another alarm that will be triggered when it is 22:00. Otherwise it will not stop.

    use alarmManager.cancel (pendingIntent)

    described here: http://developer.android.com/reference/android/app/AlarmManager.html#cancel(android.app.PendingIntent

    Hope this helps.

    0 讨论(0)
提交回复
热议问题