Calendar ContentProvider URL on Android phones with Sense UI

1.5k Views Asked by At

I have an application that adds an event to the calendar on the device. I have the following URLs for the Calendar ContentProvider:

Pre Froyo: content://calendar/calendars
Froyo: content://com.android.calendar/calendars

These urls work fine for Nexus One but do not return any calendars on HTC Desire/Incredible/Hero. Probably all phones with a Sense UI. This happens on 2.1 and 2.2.

Has anybody run into this problem before and has any workarounds?

1

There are 1 best solutions below

1
On

use this code to get the URI for your platform

private String getCalendarUriBase() {

            String calendarUriBase = null;
            Uri calendars = Uri.parse("content://calendar/calendars");
            Cursor managedCursor = null;
            try {
                managedCursor = managedQuery(calendars, null, null, null, null);
            } catch (Exception e) {
            }
            if (managedCursor != null) {
                calendarUriBase = "content://calendar/";
            } else {
                calendars = Uri.parse("content://com.android.calendar/calendars");
                try {
                    managedCursor = managedQuery(calendars, null, null, null, null);
                } catch (Exception e) {
                }
                if (managedCursor != null) {
                    calendarUriBase = "content://com.android.calendar/";
                }
            }
            return calendarUriBase;
        }