Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

How to use ContentResolver to execute a query to find an existing calendar event in android.

$
0
0

I have used the dependency service to add an event in android calendar. How can I check any particular event exist on particular date and time or not?

My code :

var calendarsUri = CalendarContract.Calendars.ContentUri;

            string[] calendarsProjection = {
                        CalendarContract.Calendars.InterfaceConsts.Id,
                        CalendarContract.Events.InterfaceConsts.Title,
                        CalendarContract.Events.InterfaceConsts.Dtstart,
                        CalendarContract.Events.InterfaceConsts.Dtend
                };

            string start = GetDateTimeMS(2016, 8, 26, 10, 10, 0).ToString();
            string end = GetDateTimeMS(2016, 8, 27, 11, 11, 0).ToString();

 var selection = "((_id = ?) AND (title = ?) AND (dtstart <= ?) AND (dtend >= ?))";
            var selectionArgs = new string[] {"1", "Test Event", ""+ GetDateTimeMS(2016, 8, 26, 10, 10, 0), ""+ GetDateTimeMS(2016, 8, 27, 11, 11, 0)};

            var ctx = Forms.Context;
            var cursor = ctx.ApplicationContext.ContentResolver.Query(calendarsUri, calendarsProjection, selection, selectionArgs, null);

Suppose I want to check if an event with title as "Test Event" and given start date and end date time as written above.

Can anyone write the correct query to do this.


Viewing all articles
Browse latest Browse all 91519

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>