4

I made this code:

long eventID = 208;
Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID);
Intent intent = new Intent(Intent.ACTION_VIEW)
   .setData(uri);
startActivity(intent);

I made sure the EventID was correct, and the event-title showed in the view was correct.

THE PROBLEM is the event time was incorrect, like: 1970-1-1 8:00.

Why? Anyone can Help? Thanks.

William J H
  • 43
  • 1
  • 3

3 Answers3

4

You have to add the event begin & end time to intent's extra data :

intent.putExtra("beginTime", beginMilliTS);
intent.putExtra("endTime", endMilliTS);

I got this working by using the values from "begin" and "end" field of an event instance. This should work too with "dtstart" and "dtend" field from an event.

GeH
  • 155
  • 1
  • 10
  • +1 for this great answer. However, this code seems to crash when trying to view events that are recurring. Do you know of a way to get around this? – John Roberts Nov 23 '12 at 15:50
  • 1
    Never see a crash. To edit a reccuring event, you have to get real events associated to it. Use the instance DB, not the event DB; then use the event_id, begin, end (these are the field's name in instance DB) to setup the intent. – GeH Nov 24 '12 at 07:12
  • Thanks a lot man. If you'd like, submit your answer here and I'll accept it: http://stackoverflow.com/questions/13532549/android-calendar-recurring-events-have-wrong-end-date-time – John Roberts Nov 24 '12 at 18:07
  • Nice one. This also solved my problem with freezing of the app on HTC Sense when trying to view event detail. Thanks! – Erveron Jan 21 '13 at 18:42
1

on Android 4.2.2, seems still having the same problem. Is it the correct behavior, or some thing missing here?

  1. got the event id through Instances.query(Globals.sContext.getContentResolver(), proj, begin, end); proj= String[]{Instances.EVENT_ID, Instances.BEGIN, Instances.END...};

  2. use the even id to view the event in calendar app.

tried with code (from http://developer.android.com/guide/topics/providers/calendar-provider.html), it still shows December 31 1969 on the 'Detail view' opened by the 'intent'; and shows current date in the 'Edit event' form if clicking on the the event on the 'Detail view' of the calendar.

...

Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID);

Intent intent = new Intent(Intent.ACTION_VIEW)

   .setData(uri);

startActivity(intent);

and still does not work even with the:

intent.putExtra("beginTime", from);
intent.putExtra("endTime", till);  //'from', 'till' is the mills got from the Instances.BEGIN/END fields from the query

EDIT: the following code works. only difference is using the define CalendarContract.EXTRA_EVENT_BEGIN_TIME

Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, eventId);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, from);
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, till);
startActivity(intent);
Mohsin Naeem
  • 12,542
  • 3
  • 39
  • 53
lannyf
  • 9,865
  • 12
  • 70
  • 152
1

This may help you!!! http://developer.android.com/guide/topics/providers/calendar-provider.html

JKV
  • 271
  • 3
  • 12