如何限制Android中的特定天数后再次发生警报?
我是一名 Android 开发人员,我以前问过这个问题,但可能我无法解释更多,我想设置以天为间隔的重复闹钟。我如何限制它在几天后重复出现,例如 15 天,任何人都可以帮助我。 以下是我的第一个问题,请检查一下 如何在 Android 中创建重复闹钟接受用户输入后?
I am an android developer I have asked this question before But may be I was not able to explain it more I want set repeating alarm with day interval .How can i restrict it from recurring after some days for example 15days can any body help me .
following was my first question please check it
How to create Recurring of Alarm in Android After taking user input?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道如何很好地捕捉到这个,但是让我给你一个提示,创建一个具有
startimg
警报静态方法的类,并使用set()
方法alarmManager
设置间隔等。并在广播接收器的 onRecieve() 方法中再次调用静态方法。但在这些类中的任何一个中都声明一个静态字段,每次调用 onRecieve() 方法时该字段都会递增。在设置闹钟之前,放置一个 if() 条件来检查其是否不是 15
。对于pendingIntent,请使用此标志PendingIntent.FLAG_CANCEL_CURRENT
。当用户输入他的日子时执行此操作
i don't know how well catch this, but let me give you a tip, make a class which has static method for
startimg
alarm, and useset()
method ofalarmManager
to set interval and so on. and inBroadcaste reciever
in itsonRecieve()
method call the static method again. but in any of these classes declare a static field which isincremented each time onRecieve()
method is called. and beforesetting the alarm put an if() condition to check its not 15
. and for pendingIntent use this flagPendingIntent.FLAG_CANCEL_CURRENT
.when user enters his days do this
不使用“setRepeating”方法来设置重复警报,而是使用“set”方法在每次警报触发时重新安排警报。
使用 Calendar.DAY_OF_MONTH - “首次安排闹钟的月份日期”来查找已过去的天数。
如果满足您的条件,请使用alarm.cancel(pendingIntent)方法取消警报。
device a repeating alarm not by using the 'setRepeating' method but by rescheduling the alarm every time the alarm fires by using the 'set' method.
Use Calendar.DAY_OF_MONTH - 'day of month the alarm was first scheduled' to find out the number of days elapsed.
if your condition is satisfied, use alarm.cancel(pendingIntent) method to cancel the alarm.