Julius Babies
Julius Babies

Reputation: 1861

Event added using content provider isn't saved

I tried adding a calendar event to the Android calendar using this code:

fun insertEvent(event: CalendarEvent): Uri? {
    val contentResolver = context.contentResolver
    val values = ContentValues()
    values.put(CalendarContract.Events.DTSTART, event.startTimeStamp)
    values.put(CalendarContract.Events.DTEND, event.endTimeStamp)
    values.put(CalendarContract.Events.TITLE, event.title)
    values.put(CalendarContract.Events.DESCRIPTION, event.location)
    values.put(CalendarContract.Events.CALENDAR_ID, event.calendarId)
    values.put(CalendarContract.Events.EVENT_TIMEZONE, event.timeZone.id)
        
    return contentResolver.insert(CalendarContract.Events.CONTENT_URI, values)
}

When I use it, I get a URI returned but cannot see it in a calendar app like Google Calendar or aCalendar. Using the debugger verified that the contentValues all had the correct data.

My app requests these permissions:

<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="android.permission.READ_CALENDAR" />

They are enabled in app info.

Upvotes: 2

Views: 138

Answers (1)

Julius Babies
Julius Babies

Reputation: 1861

Problem was, that I used unix-Timestamps instead of milliseconds, so the events were to old for Android.

Upvotes: 0

Related Questions