开发者

How to set a static alarm to go off at a set time every day?

开发者 https://www.devze.com 2023-04-03 04:25 出处:网络
I am using this to set a alarm to go off every 24 for hours from the time the application was opened.

I am using this to set a alarm to go off every 24 for hours from the time the application was opened.

Instead of 24 hours from the time it was opened. i want to set a static time like at 8:00am every morning according to device the alarm goes off.

Here is what i have so far.

 String alarm = Context.ALARM_SERVICE;
                Calendar calendar = Calendar.getInstance();
                AlarmManager am = (AlarmManager)getActivity().getSystemService(alarm);
                    Intent intent = new Intent("NEW_ITEM");
                    PendingIntent sender = PendingIntent.getBroadcast(getActivity(),开发者_如何学Python 0, intent, 0);
                     calendar.setTimeInMillis(System.currentTimeMillis());
                     calendar.add(Calendar.MINUTE, 1);
                    am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + AlarmManager.INTERVAL_DAY, AlarmManager.INTERVAL_DAY, sender);


Instead of passing System.currentTimeMillis() + AlarmManager.INTERVAL_DAY as your second argument, just calculate 8am of the next day and pass that in.

0

精彩评论

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

关注公众号