Add event and reminder not working in 6.0 marshmallow
<p>I am facing on weird issue.
I am trying to add events in <code>calendar</code> and also <code>reminder</code>. It's working fine in all devices except the one having <code>Marshmallow - 6.0</code></p>

<p>When i try to add events, it also returns me event id here. And even though i am getting event id here, <code>I can not see events added in my calendar</code></p>

<pre><code>   ContentValues event = new ContentValues();
        event.put("calendar_id", 1);
        event.put("title", "Match");
        event.put("description",PTGConstantMethod.validateString(match.getMatch_name()));
        event.put("eventLocation", match.getVenue());
        event.put("eventTimezone", TimeZone.getDefault().getID());
        event.put("dtstart", startDate.getTime());
        event.put("dtend", endDate);

        event.put("allDay", 0); // 0 for false, 1 for true
        event.put("eventStatus", 1);
        event.put("hasAlarm", 1); // 0 for false, 1 for true

        Uri eventUri = context.getApplicationContext()
                .getContentResolver()
                .insert(Events.CONTENT_URI, event);
        long eventID = Long.parseLong(eventUri.getLastPathSegment());
</code></pre>

<p>I am adding reminder here,</p>

<pre><code>        ContentValues reminders = new ContentValues();
            reminders.put("event_id", eventID);
            reminders.put("method", CalendarContract.Reminders.METHOD_ALERT);
            reminders.put("minutes", minutes);

            context.getApplicationContext().getContentResolver()
                    .insert(Reminders.CONTENT_URI, reminders);
</code></pre>

<p>But app crashes while adding reminder. Here are my logs.</p>

<blockquote>
  <p>android.database.sqlite.SQLiteException
  at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:179)
  at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
  at android.content.ContentProviderProxy.insert(ContentProviderNative.java:476)
  at android.content.ContentResolver.insert(ContentResolver.java:1231)</p>
</blockquote>

<p>In my build.gradle</p>

<pre><code>  minSdkVersion 14
  targetSdkVersion 22
</code></pre>

<p>I finally found that there isn't any calendar with    <code>event.put("calendar_id", 1);</code>. So how could i get app default calendar?</p>

<p>I tried by adding new calendar and add events to that. </p>

<pre><code>        ContentValues calendar = new ContentValues();
    calendar.put(CalendarContract.Calendars.NAME, context.getResources().getString(R.string.app_name));
    calendar.put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, context.getResources().getString(R.string.app_name)+" Calendar");
    calendar.put(CalendarContract.Calendars.VISIBLE, true);

    Uri uri = context.getApplicationContext()
            .getContentResolver()
            .insert(CalendarContract.Calendars.CONTENT_URI, calendar);
    long calendarId = Long.parseLong(uri.getLastPathSegment());
</code></pre>

<p>But i am not able to see this calendar in my calendar app. When i try to add events using this new calendar. Events get display but on click of event, my default calendar app gets crashed. What i am doing wrong while adding new calendar to default calendar app? Thanks.</p>