How to set a static alarm to go off at a set time every day?
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.
精彩评论