How to schedule an alarm so that the intent is broadcast everytime the date changes?
I want to schedule an alarm which throws an intent when the date changes.
I know that this would do this the job
alarms.setRepeating(AlarmManager.RTC_WAKEUP,triggerAtTime, interval,alarmIntent);
But what is confusing me is what to put in the triggerAtTime and the interval.It says System.currentTimeMillis() timebase.
I might be install开发者_运维问答ing the app on any day so the TriggerAtTime should be midnight of that day and the interval would be 24 hours from there on.
How can I acheive this.Can someone tell me what to put in TriggerAtTime and interval in the required format.
Thanks
They both are of type long and I think you need to set them in milliseconds...
For the triggerAtTime, this is the time of the first hit of your alarm.
The interval param is the time betwen each hit, for you 24 hours, in milliseconds : 24*60*60*1000
For exemple if you want to start updating 10 seconds after, your code should be :
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (10 * 1000),24*60*60*1000, alarmIntent);
If you want to set the first hit to be at midnight, you should calculate the time betwen midnight and now in milliseconds. I hope you understand my frenchy bad english.
Bast
You can try like this
Calendar calendar=Calendar.getInstance();
calendar.add(Calendar.DATE, 1);
calendar.set(Calendar.HOUR,0);
calendar.set(Calendar.MINUTE,0);
calendar.set(Calendar.SECOND,0);
calendar.set(Calendar.MILLISECOND,0);
mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), (24*60*60*1000), mPendingIntent);
精彩评论