alarm and notification not triggered at specified time

后端 未结 2 1756
有刺的猬
有刺的猬 2021-01-17 03:31

I am trying to trigger a notification and an alarm at a specified time. I have put log information to console to see if the correct time is being set and it is fine. However

2条回答
  •  臣服心动
    2021-01-17 03:43

    Inside btn_add_task listener, set the alarm as below -

    Intent notifyMessage = new Intent(getApplicationContext(),NotificationMessage.class);
    PendingIntent pi = PendingIntent.getBroadcast(getApplicationContext(), 0, notifyMessage, PendingIntent.FLAG_UPDATE_CURRENT);    
    AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
    am.setRepeating(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(),AlarmManager.INTERVAL_DAY,pi);
    

    Now, put a log inside onReceive of NotificationMessage class to be sure that the alarm is fired on time. Hope, now your program will run.

提交回复
热议问题