如何实现年度和月度重复报警? [英] How to implement yearly and monthly repeating alarms?

查看:111
本文介绍了如何实现年度和月度重复报警?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置每月和每年的报警器在我app.I这样做是为每周一次。 AlarmManager.INTERVAL_DAY帮我that.But我找不到实行每月和每年的重复好办法。

I want to set monthly and yearly alarm in my app.I did this for weekly. AlarmManager.INTERVAL_DAY helped me for that.But i could not find good way to implement monthly and yearly repeat.

到目前为止搜索:

<一个href="http://www.satyakomatineni.com/akc/display?url=displaynoteimpurl&ownerUserId=satya&reportId=3503">http://www.satyakomatineni.com/akc/display?url=displaynoteimpurl&ownerUserId=satya&reportId=3503

<一个href="http://groups.google.com/group/android-developers/browse_thread/thread/9f946e40307073c4?pli=1">http://groups.google.com/group/android-developers/browse_thread/thread/9f946e40307073c4?pli=1

时可用任何其他方式做到这一点?任何帮助AP preciated。

Is any other way available to do this? Any help appreciated.

推荐答案

我解决了这个问题。在我的应用程序,multipal报警分别设置不同的重复时间intervals.So在我的广播接收器,报警器,我重新安排的基础上的报警什么时候它被定为repeated.I使用日历对象添加月份和年份accordinly并再次将其设置为下alarm.i使用code这样的(调度它下个月) -

I solved the issue. In my app,multipal alarms were set with different repeating time intervals.So in my broadcast receiver for alarm,i re-scheduled the alarm based on for what time it was scheduled to be repeated.I used calendar object to add month and year accordinly and again set it for next alarm.i used code like this(for scheduling it for next month)-

PendingIntent sender = PendingIntent.getBroadcast(context,Integer.parseInt(Long.toString(id)), intent1, 0);                             

Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(calendar.getTimeInMillis());
calendar.add(Calendar.SECOND, 30);

AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);

calendar.add(Calendar.MONTH, 1);

am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);

这篇关于如何实现年度和月度重复报警?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆