I would like to launch the phones stock Calendar App and view the single calendar event using that App. Does anyone know what the correct Intent options are to do this?
Asked
Active
Viewed 4,473 times
1 Answers
6
I finally found the solution:
Intent intent = new Intent(Intent.ACTION_VIEW);
//Android 2.2+
intent.setData(Uri.parse("content://com.android.calendar/events/" + String.valueOf(calendarEventID)));
//Android 2.1 and below.
//intent.setData(Uri.parse("content://calendar/events/" + String.valueOf(calendarEventID)));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
I hope that some of you find this usefull.
I have also added a few other calendar Intents below:
/**
* Add a calendar event.
*/
private void addCalendarEvent(){
Context context = getContext();
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
/**
* Edit a calendar event.
*/
private void editCalendarEvent(){
Context context = getContext();
long calendarEventID = .....
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setData(Uri.parse("content://com.android.calendar/events/" + String.valueOf(calendarEventID)));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
Let me know if anyone has any questions or has a better way to accomplish the same task.

Camille Sévigny
- 5,104
- 4
- 38
- 61
-
The correct way to generate the URI is: Uri event = ContentUris.withAppendedId(Events.CONTENT_URI, eventID); – Robert Massaioli Apr 08 '12 at 10:35
-
@Camille Sévigny , the code you gave and it is working , in calendar event view it shows 1 Jan 1970 , can you tell what could be the reason – Avi Kumar Apr 25 '12 at 13:19
-
This was incredibly helpful https://github.com/roman10/roman10-android-tutorial/blob/master/CalendarOps/src/roman10/tutorial/calendarops/Main.java – user788511 Nov 09 '12 at 10:48
-
Great answer man. However, when I run the code to view an event, my dates always seem to come back as December 1969. Do you have any idea what might be causing this? – John Roberts Nov 22 '12 at 22:18
-
@AviKumarManku I think we have the same problem. Were you able to figure it out? – John Roberts Nov 22 '12 at 22:18
-
1@JohnRoberts i found solution from this answer http://stackoverflow.com/questions/9798997/how-to-using-intents-to-view-calendar-data/9799145#9799145 – Avi Kumar Nov 23 '12 at 07:39
-
@AviKumarManku Thank you for your reply, but that tutorial seems to only deal with inserting a new calendar event. I thought your issue was with viewing a specific one? – John Roberts Nov 23 '12 at 13:40
-
@JohnRoberts not my answer buddy the solution is the selected answer – Avi Kumar Nov 23 '12 at 13:47
-
1like startT = begdate.getTime(); endT = enddate.getTime(); intent.setData(Uri.parse("content://com.android.calendar/events/" + String.valueOf(eventid[pos]))); System.out.println(startT); System.out.println(endT); intent.putExtra("beginTime", startT); intent.putExtra("endTime", endT); startActivity(intent); – Avi Kumar Nov 23 '12 at 13:48
-
@AviKumarManku Yeah, I just realized that - thanks. It works great for normal events, but this viewing method seems to crash with a NumberFormatException when you're trying to view a Recurring event. Have you encountered this issue as well? Perhaps there is another extra that needs to be passed in this case? – John Roberts Nov 23 '12 at 14:04
-
@JohnRoberts sorry buddy i don't know about this – Avi Kumar Nov 24 '12 at 15:09
-
In case of multiple accounts on the phone will the implementation change? – Navjacinth Mathew Jun 25 '18 at 10:48