Вопрос

I'm using the calendar contract to pull events from the DB.
First I get a list of the calendars and then I pull all the events in specific time for each calendar, it all works fine.
I use _id column name to get the event ID.
But when I try to get a pending event to open the calendar on that specific event, the calendar is opened on another event.
I've ran some tests to see if the ID is unique and it seems correct.
Here is the creating of the pendingIntent :

public static PendingIntent getEventPendingIntent(Context c, int eventID) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri.Builder uri = Events.CONTENT_URI.buildUpon();
    uri.appendPath(Long.toString(eventID));
    intent.setData(uri.build());
    return PendingIntent.getActivity(c, 0, intent, 0);
}

This is the method to get the events for a given CalendarID :

private static Cursor getEvents(String calendarID, ContentResolver contentResolver, long    timeFromNow) {
    // Create a builder to define the time span
    Uri.Builder builder = Uri.parse("content://com.android.calendar/instances/when").buildUpon();

    long now = new Date().getTime();
    ContentUris.appendId(builder, now);
    if (timeFromNow == -1) {
        timeFromNow = DateUtils.DAY_IN_MILLIS * 10000;
    }
    ContentUris.appendId(builder, now + timeFromNow);

    Cursor eventCursor = null;
    // Create an event cursor to find all events in the calendar
    String[] queryFields = {"title", "dtstart", "begin", "end", "allDay", "eventLocation","description", "_id" };
    try {
        eventCursor = contentResolver.query(builder.build(),
                queryFields , "calendar_id=" + calendarID, null, "startDay ASC, startMinute ASC");
    } catch (Exception e) {
        Log.w(TAG, "ERROR: "+e.toString());
        Log.w(TAG, "Didn't find calender for ID="+calendarID);
        eventCursor = null;
    }
    return eventCursor;
}
Это было полезно?

Решение

The problem was with the ID columns, I used _id instead of event_id
After changing this, the correct events were shown.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top