开发者

broadcast Intent when date changes?

I would like to know whether there is an android intent to check for change in the system date.I want to an intent that is broadcasted when time changes from 23:59 to 00:00 (the next date).I searched the net and found about android.intent.action.DATE_CHANGED but it seems like this intent is broadcast only if the date is changed manually.

If there is no intent like this let me know if an alternative exists.One alternative i can think of is using an AlarmManger and broadcast a pending intent.开发者_JAVA技巧Is there anything simpler than this?


Use AlarmManager and schedule an alarm for midnight.

LINK: A small tutorial to AlarmManager.

btw, I was trying to find this answer ! Thanks.


This should not be hard to implement using AlarmManager. You just need the following few statements to trigger your app by setting a pending intent on the alarm manager.

Context.getSystemService(Context.ALARM_SERVICE);

Remove any alarms with a matching Intent. Do this first.

cancel(PendingIntent operation);

Schedule an alarm. Just add 24 hrs or whatever makes sense for your need.

set(int type, long triggerAtTime, PendingIntent operation);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜