3

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?

Rohit
  • 1,710
  • 5
  • 20
  • 29
  • 1
    This is one of those 'I told you so' moments. Since the calendar API is undocumented its best to just leave it alone. Granted I too want this functionality and am interested in the responses you will hopefully get. – smith324 Aug 26 '10 at 04:13
  • I know, but the gdata api library is 13 Mb. Hardly a good idea to include in an application of few kb. – Rohit Aug 26 '10 at 04:28
  • 1
    Then roll your own library. GData is just Atom over HTTP -- you do not need to use their client JAR AFAIK. The Calendar application is not part of the Android SDK and should not be directly used by developers, for the reasons you are discovering. – CommonsWare Aug 26 '10 at 04:30

1 Answers1

3

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;
        }
Dinesh Prajapati
  • 9,274
  • 5
  • 30
  • 47