Android alarm setting with specific date

前端 未结 4 2274
刺人心
刺人心 2020-12-11 09:17

I wan to set alarm with notification at specific date. Then I am using AmarmManager with NotificationManager currently. When I set selected date from dateDialog, the alarm i

4条回答
  •  星月不相逢
    2020-12-11 10:11

    You should call public void setRepeating (int type, long triggerAtTime, long interval, PendingIntent operation)(see here) to repeat the alarm. For example, you want to fire the alarm on 9:00 am every day, you can do :

    Calendar c=Calendar.getInstance();
    c.set(Calendar.HOUR_OF_DAY, 9);
    c.set(Calendar.MINUTE, 0);
    setRepeating(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), AlarmManager.INTERVAL_DAY,pendingIntent);
    

    Also,set the last parameter to 0 when initilazing the PendingIntent.

    PendingIntent pendingIntent = PendingIntent.getBroadcast(fridgeDetails.this, 
                            0, myIntent, 0);
    

提交回复
热议问题