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

Xamarin Forms Android Calendar Event Time not setting properly

$
0
0

Hi,

i am creating an event in my calendar. The event is setting correctly in the device calendar. but the Time ( hour and minute ) is 00:00.

any body faced similar issue before.

my code is as below,

can some one can help me please ?

```ContentValues eventValues = new ContentValues();
eventValues.Put(CalendarContract.Events.InterfaceConsts.CalendarId, 1);
eventValues.Put(CalendarContract.Events.InterfaceConsts.AllDay, 1);
eventValues.Put(CalendarContract.Events.InterfaceConsts.HasAlarm, 1);
eventValues.Put(CalendarContract.Events.InterfaceConsts.Title, title);
eventValues.Put(CalendarContract.Events.InterfaceConsts.Description, message);
eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtstart, GetDateTimeMS(startDate.Year, startDate.Month, startDate.Day, startDate.Hour, startDate.Minute));
eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtend, GetDateTimeMS(endtDate.Year, endtDate.Month, endtDate.Day, endtDate.Hour, endtDate.Minute));
eventValues.Put(CalendarContract.Events.InterfaceConsts.EventTimezone, "GMT");
eventValues.Put(CalendarContract.Events.InterfaceConsts.EventEndTimezone, "GMT");
var uri = Forms.Context.ContentResolver.Insert(CalendarContract.Events.ContentUri, eventValues);

            long eventID = long.Parse(uri.LastPathSegment);
            // reminder insert
            Uri REMINDERS_URI = new Uri(CalendarContract.Reminders.ContentUri + "reminders");
            ContentValues remindervalues = new ContentValues();
            // remindervalues.Put(CalendarContract.Reminders.InterfaceConsts.AllDay, 1);
            remindervalues.Put(CalendarContract.Reminders.InterfaceConsts.Minutes, 30);
            remindervalues.Put(CalendarContract.Reminders.InterfaceConsts.EventId, eventID);
            remindervalues.Put(CalendarContract.Reminders.InterfaceConsts.Method, (int)Android.Provider.RemindersMethod.Alert);
            var reminderURI = Forms.Context.ContentResolver.Insert(CalendarContract.Reminders.ContentUri, remindervalues);'```

and

` long GetDateTimeMS(int yr, int month, int day, int hr, int min)
{
Calendar c = Calendar.GetInstance(Java.Util.TimeZone.GetTimeZone("GMT"));

        c.Set(Calendar.DayOfMonth, day);
        c.Set(Calendar.HourOfDay, hr);
        c.Set(Calendar.Minute, min);
        c.Set(Calendar.Month, Calendar.December);
        c.Set(Calendar.Year, yr);

        return c.TimeInMillis;
    }`

Viewing all articles
Browse latest Browse all 91519

Trending Articles



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