如何创建重复间隔为工作日的本地通知? [英] How to create local notifications with repeat interval as weekday?

查看:83
本文介绍了如何创建重复间隔为工作日的本地通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建一个重复间隔为本地的本地通知.例如,如果我将星期一和星期五的通知设置为下午5点,那么我想在每个星期一和星期五同时(而不是在其他日子)重复此通知.

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.

我已经参考了这篇文章,但是它并不完整: https ://www.c-sharpcorner.com/article/how-to-send-local-notification-with-repeat-interval-in-xamarin-forms/

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/

推荐答案

实际上,您可以完全引用此链接,只需修改其中的notifyTimerepeateForMinute,将notifyTime更改为星期一或星期五的日期,然后将repeateForMinute更改为7天

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

例如,如果开始日期为 2019/10/18 17:00星期五.则可以在LocalNotificationService中进行更改:

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);    
    } 

您可以下载其源代码.

这篇关于如何创建重复间隔为工作日的本地通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆