android - issue while setting time for alarm Manager -
hey guys facing weird problem when setting time alarm manager notification not giving me notification tying :
notification = new notificationcompat.builder(this); notification.setautocancel(true); counter = (textview) findviewbyid(r.id.textview); alarmmanager alarmmanager = (alarmmanager) getsystemservice(context.alarm_service); intent notificationintent = new intent("android.media.action.display_notification"); notificationintent.addcategory("android.intent.category.default"); pendingintent broadcast = pendingintent.getbroadcast(this, 5000, notificationintent, pendingintent.flag_update_current); calendar cal = calendar.getinstance(); cal.add(calendar.hour_of_day, 22); cal.add(calendar.minute, 43); cal.add(calendar.second, 0); cal.add(calendar.millisecond, 0); // cal.add(calendar.second, 20); alarmmanager.setexact(alarmmanager.rtc_wakeup, cal.gettimeinmillis(), broadcast);
but when setting alarm while using cal.add(calendar.second, 20)
giving me notification (working fine) 1 can tell me why not working when using hours, minutes , why working when use seconds
??/ appreciated , :)
as @indra notes in answer, incorrectly using cal.gettimeinmillis()
both alarm trigger time and interval. value not valid interval. presumably, want alarm fire every hour, day, or other reasonable interval. i'm guessing because interval requesting huge value, , alarm requesting inexact, never see fire once because of behavior explained in documentation: "your alarm's first trigger not before requested time, might not occur full interval after time". in case "full interval" 46 years.
Comments
Post a Comment