c# - Xamarin CalendarContract -
i'm creating calendar in xamarin forms using dependencyservice , creating events code:
contentresolver cr = ((activity)forms.context).contentresolver; contentvalues values = new contentvalues(); var uri = calendarcontract.calendars.contenturi; values.put(calendarcontract.events.interfaceconsts.calendarid, id); values.put(calendarcontract.events.interfaceconsts.title, title); values.put(calendarcontract.events.interfaceconsts.description, description); values.put(calendarcontract.events.interfaceconsts.dtstart, getdatetimems(year, month, day, hour, minute)); values.put(calendarcontract.events.interfaceconsts.dtend, getdatetimems(year, month, day, hour, minute)); values.put(calendarcontract.events.interfaceconsts.allday, allday ? "1" : "0"); values.put(calendarcontract.events.interfaceconsts.hasalarm, hasalarm ? "1" : "0"); values.put(calendarcontract.events.interfaceconsts.eventtimezone, "gmt+" + zone + ":00"); values.put(calendarcontract.events.interfaceconsts.eventendtimezone, "gmt+" + zone + ":00"); cr.insert(calendarcontract.events.contenturi, values);
what want add events self-created calendar. how create calendar first , add above events it?
here's example of creating new calendar on device, taken source:
var uri = calendarcontract.calendars.contenturi; contentvalues val = new contentvalues(); val.put(calendarcontract.calendars.interfaceconsts.accountname, accountname); val.put(calendarcontract.calendars.interfaceconsts.accounttype, calendarcontract.accounttypelocal); val.put(calendarcontract.calendars.name, "my calendar"); val.put(calendarcontract.calendars.interfaceconsts.calendardisplayname, "silverspot"); val.put(calendarcontract.calendars.interfaceconsts.calendarcolor, android.graphics.color.red); val.put(calendarcontract.calendars.interfaceconsts.owneraccount, accountname); val.put(calendarcontract.calendars.interfaceconsts.visible, true); val.put(calendarcontract.calendars.interfaceconsts.syncevents, true); uri = uri.buildupon() .appendqueryparameter(calendarcontract.callerissyncadapter, "true") .appendqueryparameter(calendarcontract.calendars.interfaceconsts.accountname, accountname) .appendqueryparameter(calendarcontract.calendars.interfaceconsts.accounttype, calendarcontract.accounttypelocal) .build(); var calresult = contentresolver.insert(uri, val);
Comments
Post a Comment