Divyesh
Divyesh

Reputation: 2415

How to create local notifications with repeat interval as weekday?

I want to create a local notification with repeat interval as a weekday. For example, if I set notification for Monday and Friday for 5 pm, I want to repeat this notification every Monday and Friday at the same time, not on other days.

I have referred to this article but it's not complete: https://www.c-sharpcorner.com/article/how-to-send-local-notification-with-repeat-interval-in-xamarin-forms/

Upvotes: 0

Views: 713

Answers (1)

Leo Zhu
Leo Zhu

Reputation: 15021

In fact, you can refer to this link completely, just modify the notifyTime and repeateForMinute inside,change the notifyTime to the date of Monday or Friday ,then change the repeateForMinute to seven days

for example,if the begin date is 2019/10/18 17:00 Friday.you could change in the LocalNotificationService :

  public void LocalNotification(string title, string body, int id, DateTime notifyTime){    

        notifyTime = new DateTime(2019, 10, 18, 17, 0, 0, DateTimeKind.Utc);   
        long repeate7Days = 1000 * 60 * 60 * 24 * 7;    
        long totalMilliSeconds = (long)(notifyTime.ToUniversalTime() - _jan1st1970).TotalMilliseconds;    
        if (totalMilliSeconds < JavaSystem.CurrentTimeMillis()){    
            totalMilliSeconds = totalMilliSeconds + repeate7Days;    
        }    

         ...

        var alarmManager = GetAlarmManager();    
        alarmManager.SetRepeating(AlarmType.RtcWakeup, totalMilliSeconds, repeate7Days, pendingIntent);    
    } 

you could download its Source codes.

Upvotes: 1

Related Questions