Search code examples
delphifiremonkeydelphi-xe8

Custom notification interval


I am building an app in FireMonkey under Rad Studio XE8.

I would like to have custom intervals on my notifications (FMX.Notification).

However notification repeats can only be set to certain intervals.

TRepeatInterval = (None, Second, Minute, Hour, Day, Week, Weekday, Month, Quarter, Year, Era);

If i whant to fire each 15 minutes, would I really need to create four notification (at 0 , 15, 30, 45 minutes) and repeat them every hour with TRepeatInterval(4)?


Solution

  • The documentation for FMX.Notification.TNotification.RepeatInterval says, with my emphasis:

    If you want to set a custom interval, like for example 30 minutes, you need to create two notifications setting a scheduled difference of 30 minutes with FireDate and set the repeat interval of both notifications to an hour.

    You're guessing right. You would need to create four notification and repeat them every hour.


    OP told in the comments, that he used following code, in the end. I included it in my answer to improve readability of his given information.

    //Repeat very 5 minutes
    //Create 12 notifications fireing every hour with 5 minute intervals Notification.RepeatInterval := TRepeatInterval.Hour;
    for I := 0 to 11 do
    begin
      Notification.FireDate := Notification.FireDate + EncodeTime(0,(I*5),0,0);
      ANotificationcenter.ScheduleNotification(Notification);
    end;