Friday, May 28, 2010

New calendar API

The Calendar API (used by Call Log Calendar) has been changed on Froyo.

I've received many emails asking how I had this issue solved. Actually this is only a small change to the content provider URI.

URI past Froyo: content://calendar/
URI after Froyo: content://com.android.calendar/

You'll need something like this on your code to handle older devices as well:

private static Uri CALENDAR_CALENDARS_URI = Uri.parse("content://calendar/calendars");
private static Uri CALENDAR_CALENDARS_URI_8_PLUS = Uri.parse("content://com.android.calendar/calendars");

private Uri getCalendarUri() {
    if(Integer.parseInt(Build.VERSION.SDK) <= 7) {
        return CALENDAR_CALENDARS_URI;
    } else {
        return CALENDAR_CALENDARS_URI_8_PLUS;
    }
}

There is also Build.VERSION.SDK_INT avaiable since API level 4. But to make my application compatible with api level 3 I had to use Build.VERSION.SDK.

1 comment:

Anonymous said...

Useful for me. Thanks a lot.