I trigger the creation of a calendar event through the following piece of code:
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setData(CalendarContract.Events.CONTENT_URI);
startActivity(intent);
But I would like to specifiy which calendar should be used for the event creation (i.e set the initial value of the calendar dropdown in the event creation screen).
I've tried to provide ACCOUNT_TYPE
, ACCOUNT_NAME
and CALENDAR_ID
intent.putExtra(CalendarContract.Events.ACCOUNT_TYPE, accountType);
intent.putExtra(CalendarContract.Events.ACCOUNT_NAME, accountName);
intent.putExtra(CalendarContract.Events.CALENDAR_ID, calendarId);
but it has no effect on the calendar dropdown initial value.
Is it possible to specify a calendar in the event creation intent?
I believe, there is no reliable way to achieve this with just an
Intent
. You may come across all sorts of calendar apps that may or may not support this.If you don't mind if the user can not change the calendar you can achieve this with a simple trick:
Just create a "placeholder" event in the calendar you want to (like outlined in the Android Developer Guide) and fire an
Intent.ACTION_EDIT
Intent
for this event instead.Here is some (untested) code to show how this could work:
The edit
Intent
probably doesn't return a status that tells you if the event has been saved or if the user dismissed the editor without saving. So you should read back the event and check if it has been modified by the user and delete it if it has not been changed.Its's Simple to add Event Using this simple Method.
Use the following code snippet to invoke the default calendar event.
The following code bundle can be used to pass the information to calendar intent.
May it will help you :) Thanks.
Source: How to Add an Event to Device Calendar in Android
You can check this one too. Adding Events to the User’s Calendar