开发者

Problem with repeating(AlarmManager)

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 t开发者_运维问答o 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");


It is possible (as setRepeating() receives long as parameter), but instead of 2419200000 , you should write 2419200000L since 2419200000 is too big for int, and any integer constant is treated as int, so you need to add the L to indicate this number is long.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜