3

I worked on an app that lets users create appointments and then inserts them into the Android calendar. I see a crash report from a user running Android version 4.0.4

Caused by: java.lang.IllegalArgumentException: Unknown URL content://com.android.calendar/events
at android.content.ContentResolver.insert(ContentResolver.java:726)

This works fine when I test it on my Android Phone, but I'm wondering what's wrong in this case?

edit: here's my code-

        ContentResolver cr = getContentResolver();
        ContentValues values = new ContentValues();
        values.put(Events.DTSTART, startMillis);
        values.put(Events.DTEND, endMillis);
        values.put(Events.TITLE, title);
        values.put(Events.DESCRIPTION, location);
        values.put(Events.CALENDAR_ID, calID);
        values.put(Events.EVENT_TIMEZONE, TimeZone.getDefault().getDisplayName());
        Uri uri = cr.insert(Events.CONTENT_URI, values);

It's crashing on cr.insert(Events.CONTENT_URI, values) but only intermittently. So far only one crash report for this problem has been submitted.

Andy
  • 1,815
  • 2
  • 22
  • 49

1 Answers1

2

Try something like that, instead of :

Uri uri = cr.insert(Events.CONTENT_URI, values);

use :

Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, values);
Bibu
  • 1,249
  • 2
  • 17
  • 40
  • I'm not sure if this will fix this crash, but I'll accept the answer anyway. Thanks for your help. – Andy Apr 17 '13 at 14:54
  • 4
    You should accept the answer if you tested the solution, IMHO. By the way, there is no difference in these 2 sentences, they refer to the same field – Jose_GD Apr 17 '14 at 23:12
  • 1
    This accepted answer does not work on Android 5.1 (API 22) – droida Sep 06 '17 at 04:04