Only allow push notifications during certain time of the day in xamarin.forms app

Wei Wen 1,126 Reputation points
2021-05-31T04:05:28.02+00:00

In my app, I need to give the users the options to not allow push notifications during certain time of the day that they prefer. For example, the users may want push notifications to be turned from 12:00am to 7:00am. How can I turn off the notifications during that time?

Developer technologies .NET Xamarin
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Kyle Wang 5,531 Reputation points Microsoft External Staff
    2021-06-01T05:32:34.26+00:00

    Hi WeiWen-3421,

    Welcome to our Microsoft Q&A platform!

    To allow users to choose a certain period of time to disable notification, you can add two TimePickers in you page.

    <TimePicker x:Name="startTime"/>  
    <TimePicker x:Name="endTime"/>  
    

    You can get the demo of notification from this document.

    You only need to add the following code into method OnSendClick.

    void OnSendClick(object sender, EventArgs e)  
    {  
        TimeSpan current = DateTime.Now.TimeOfDay;  
        TimeSpan start = startTime.Time;  
        TimeSpan end = endTime.Time;  
        if (current < start || end < current)  
            notificationManager.SendNotification(title, message);  
    }  
    

    Regards,
    Kyle


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Wei Wen 1,126 Reputation points
    2021-06-01T17:49:48.49+00:00

    Hi KyleWang-MSFT,

    Sorry about the mixed IDs. I think there is an issue about who logged in. I used my own email address, but somehow it got mixed with another account. I posted the previous comment. I think your solution does not work for remote push notification.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.