How can I access calendar and reminder items on .net MAUI?

Sacha B 116 Reputation points
2022-12-24T03:26:32.363+00:00

I have made a .net MAUI app, and I would like to access the calendars on phones and also be able to create reminders.
Is there a native .net MAUI way to do this?

Thanks

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
4,120 questions
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2022-12-27T07:02:53.66+00:00

    Hello,

    For problems related to calling native functions, you can first create new static classes and static functions on the corresponding platform to call in MAUI.

    You could refer to the following renferences to get the details about how to access system calendar on native Android and iOS, and how to invoke platform codes on MAUI:

    For instance, you could refer to the following steps to implement this part: Add reminders.

    Step 1: Create a static helper class in your Platforms/Android folder:

    Step 2: Create a static MainActivity variable named Instance, and implement this function:

       public class MainActivity : MauiAppCompatActivity  
       {  
           public static MainActivity Instance { get; private set; }  
           protected override void OnCreate(Bundle savedInstanceState)  
           {  
               base.OnCreate(savedInstanceState);  
               Instance = this;  
                 
           }  
           public void calendarHelper()  
           {  
               long eventID = 221;  
               ContentResolver cr = ContentResolver;  
               ContentValues values = new ContentValues();  
               values.Put(Reminders.InterfaceConsts.Minutes, 1);  
               values.Put(Reminders.InterfaceConsts.EventId, eventID);  
               values.Put(Reminders.InterfaceConsts.Method, (int)RemindersMethod.Alert);  
               Android.Net.Uri uri = cr.Insert(Reminders.ContentUri, values);  
           }  
       }  
    

    Step 3: Implement the static method:

       public static class MyHelper  
           {  
               public static void calendarHelper()  
               {  
                   MainActivity.Instance.calendarHelper();  
               }  
           }  
    

    Step 4: Call this Android method on MAUI button click event:

       private async void OnCounterClicked(object sender, EventArgs e)  
           {  
       #if ANDROID  
               MauiApp5.Platforms.Android.MyHelper.calendarHelper();  
       #endif  
           }  
    

    You could follow the above process to implement other calendar events in MAUI.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.


1 additional answer

Sort by: Most helpful
  1. michot jean-louis 0 Reputation points
    2024-03-22T16:48:20.7933333+00:00

    hello what calendar are you targeting with this code?

    my Android emulator displays only the google calendar and to develop apps with Google calendar you would have to pay? Maybe I am wrong?

    0 comments No comments

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.