Android ежедневно повторяет уведомление в определенное время суток с помощью AlarmManager

Мне нужно приложение для Android, чтобы отправлять уведомления, чтобы напомнить пользователям в 8 утра, 3 вечера и 8 вечера каждый день. Поэтому я использую следующие три строки в onCreate () MainActivity, когда приложение запускается. Однако, когда я запускаю приложение, все три уведомления приходят сразу, а не в нужное время.

    setRepeatedNotification(1,8,0,0); 
    setRepeatedNotification(2,15,0,0); 
    setRepeatedNotification(3,20,0,0);    

Это почему? Я также прикрепляю функцию setRepeatedNotification здесь. Спасибо!

private void setRepeatedNotification(int ID, int hh, int mm, int ss) {
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    Intent alarmIntent = new Intent(MainActivity.this, AlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, ID, alarmIntent, 0);

    Calendar calendar = Calendar.getInstance();
   // calendar.set();
    calendar.set(Calendar.HOUR_OF_DAY, hh);
    calendar.set(Calendar.MINUTE, mm);
    calendar.set(Calendar.SECOND, ss);

    // Clear previous everyday pending intent if exists.
    if (null != mEverydayPendingIntent) {
        alarmManager.cancel(mEverydayPendingIntent);
    }
    mEverydayPendingIntent = pendingIntent;
    alarmManager.setRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, mEverydayPendingIntent);
}

Ответы на вопрос(0)

Ваш ответ на вопрос