Search code examples
androidandroid-contentproviderandroid-contactscalendarcontract

Android Resolver Query for CalendarContract?


I am trying to write an app to dump Calendar entries for reference and backup. To get started, I tried to dump the column names of the CalendarContract using the code below but it always fails with an exception:

try {
    Cursor cur = Resolver.query(CalendarContract.CONTENT_URI, null, null, null, null);
    // print column names...

}
catch( Exception e ) {
    Log.i( "MYAPP", "Exception on Resolver.query: "+e);  // ALWAYS HAPPENS
    return;
}

The exception is "javal.lang.IllegalArgumentException: Unknown URL content://com.android.calendar".

Autocomplete shows "CalendarContract.CONTENT_URI" is a valid member.
I also tried dumping the Contacts column names using a similar query and this works just fine:

Cursor cur = Resolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
// print column names  

Note: I am running on a Samsung S9 running Andoid V10.

What am I doing wrong?


Solution

  • This content_uri cannot be queried directly, you might want to use CalendarContract.Events.CONTENT_URI instead.

    Read the docs here: https://developer.android.com/reference/android/provider/CalendarContract

    and more specifically: https://developer.android.com/reference/android/provider/CalendarContract.Events