IllegalArgumentException: Unknown URL content://co

2019-07-02 05:59发布

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.

1条回答
\"骚年 ilove
2楼-- · 2019-07-02 06:43

Try something like that, instead of :

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

use :

Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, values);
查看更多
登录 后发表回答