重复问题(AlarmManager)
我正在构建一个应用程序,它必须在一段时间后显示通知,因为我使用了 AlarmManager。 要每 15 分钟收到一次通知,我们必须这样做:
mgr.setRepeating(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime(), 900000, pi);
一天的值是 86400000
。我的想法是每周(86400000 乘以 7)和每月(86400000 乘以 28)也发出通知。问题在于月份常数,我有:
The literal 2419200000 of type int is out of range
不可能使用 AlarmManager 发出长时间通知?有解决办法吗? 谢谢。 编辑:
if (Integer.valueOf(choix_notif) == 0)
{
mgr.setRepeating(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime(), 86400000, pi);
Log.d("DAY_REPEATING","OK");
}
else if (Integer.valueOf(choix_notif) == 1) {
mgr.setRepeating(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime(), 604800000, pi);
Log.d("WEEK_REPEATING","OK");
}
else if (Integer.valueOf(choix_notif) == 2) {
mgr.setRepeating(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime(), 2419200000L, pi);
Log.d("MONTH_REPEATING","OK");
I'm building an app that has to show a notifcation after some period, for that i used AlarmManager.
To have a notification every 15 minutes we have to do this:
mgr.setRepeating(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime(), 900000, pi);
For a day we have 86400000
as value. My idea is to make also a notification every week( multiply 86400000 with 7) and every month(multiply 86400000 with 28). The problem is in month constant, i have:
The literal 2419200000 of type int is out of range
It's not possible to make a long period notifications with AlarmManager? Is there a solution ?
Thank you.
EDIT:
if (Integer.valueOf(choix_notif) == 0)
{
mgr.setRepeating(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime(), 86400000, pi);
Log.d("DAY_REPEATING","OK");
}
else if (Integer.valueOf(choix_notif) == 1) {
mgr.setRepeating(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime(), 604800000, pi);
Log.d("WEEK_REPEATING","OK");
}
else if (Integer.valueOf(choix_notif) == 2) {
mgr.setRepeating(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime(), 2419200000L, pi);
Log.d("MONTH_REPEATING","OK");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是可能的(如
setRepeating()
接收 long 作为参数),但您应该代替2419200000
写2419200000L
因为 2419200000 对于 int 来说太大了,任何整数常量都会被视为int
,所以你需要添加L
来指示这一点号码很长。It is possible (as
setRepeating()
receives long as parameter), but instead of2419200000
, you should write2419200000L
since 2419200000 is too big for int, and any integer constant is treated asint
, so you need to add theL
to indicate this number is long.