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:
- Calendar provider overview on Android
- Reading and Writing Calendar Events on iOS
- Invoke platform code
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.