Calendar ContentProvider URL on Android phones with Sense UI
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 On开发者_Python百科e 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?
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;
}
精彩评论