1

This is my code to view an event selected from a ListActivity (events is the ArrayList containing all those events):

Uri viewUri = Uri.parse("content://com.android.calendar/events/" + events.get(position).id);
Intent l_intent = new Intent(Intent.ACTION_VIEW);
l_intent.putExtra("beginTime", Long.parseLong(events.get(position).startTime));
l_intent.putExtra("endTime", Long.parseLong(events.get(position).endTime));
startActivity(l_intent);

This code works perfectly for all events except recurring events. For any event that is recurring, endTime returns as null, causing the program to crash. Anyone know how to get around this? Are there other extras I should be passing?

John Roberts
  • 5,885
  • 21
  • 70
  • 124

3 Answers3

4

beginTime and endTime can be 0/null because you got them from a wrong database, certainly from events database. You should use the instances database instead (ex: "content://com.android.calendar/instances/when/" on SDK 8).

In the instances DB, you'll get all "real" events : There, each recurring event has as many instances as needed, with correct begin and end timestamps; and the other events are visible too. You only have to read these fields - event_id, begin, end - and use them to open your Intent.

GeH
  • 155
  • 1
  • 10
2

While working with calendar events, I found out that the events table in the calendar.db stores information of normal events as you have used. (I guess you are using startTime for Dtstart and endTime as Dtend)

But in case of Recurrence events, Dtend will be null. So instead use lastDate column for the same since this column is never null. It will work well both in the case of recurrence events as well as for normal events.

But if you require more info on the recurrence events, use Instances table (like the exact start and end time for each of the occurrences) as suggested by @GeH.

Garrett Hyde
  • 5,409
  • 8
  • 49
  • 55
Abhi..
  • 21
  • 1
0

I think you may want to put a null check before parsing:

long endTime = 0L;//use some default value
if( events.get(position).endTime != null)
     endTime = Long.parseLong(events.get(position).endTime);
}
l_intent.putExtra("endTime", endTime );
Pang
  • 9,564
  • 146
  • 81
  • 122
Yogendra Singh
  • 33,927
  • 6
  • 63
  • 73
  • That will avoid the null error, but it still won't get me the accurate end time of the recurring event. – John Roberts Nov 23 '12 at 17:14
  • @JohnRoberts: I believe recurring events don't have the end time as they are recurring? No? – Yogendra Singh Nov 23 '12 at 17:32
  • Well, suppose you have a one hour meeting every Friday. That has an end time and is recurring. You can also confirm this through your Android calendar. – John Roberts Nov 23 '12 at 21:50
  • @JohnRoberts: Did you check this: http://stackoverflow.com/questions/7130025/cannot-read-recurring-events-from-android-calendar-programmatically? – Yogendra Singh Nov 23 '12 at 21:57
  • I checked that out earlier. That seems to be in regards to not being able to pull recurring events from the calendar - I am available to pull them into my ListActivity. My problem instead arises when I select a specific recurrent event for viewing. – John Roberts Nov 24 '12 at 01:53
  • recurring events are not coming in my application can you tell me how can i do it i have don like – koteswara D K Jul 26 '17 at 10:15