insert event to calendar using intent

You caught ActivityNotFoundException because any activity can't handle your action.

Instead using Intent.ACTION_INSERT try to do like this :

Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra(Events.TITLE, strTitle);
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,
                    startDateMillis);
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
                    endDateMillis);
intent.putExtra(Events.ALL_DAY, false);// periodicity
            intent.putExtra(Events.DESCRIPTION,strDescription));

You can check in developer documentation for other attributes.


Insert an Event like this


    Calendar beginTime = Calendar.getInstance();
    beginTime.set(2012, 0, 19, 7, 30);

    Calendar endTime = Calendar.getInstance();
    endTime.set(2012, 0, 19, 8, 30);

    Intent intent = new Intent(Intent.ACTION_INSERT)
     .setData(Events.CONTENT_URI)
     .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, 
         beginTime.getTimeInMillis())
     .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, 
         endTime.getTimeInMillis())
     .putExtra(Events.TITLE, "Yoga")
     .putExtra(Events.DESCRIPTION, "Group class")
     .putExtra(Events.EVENT_LOCATION, "The gym")
     .putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY)
     .putExtra(Intent.EXTRA_EMAIL, "[email protected],[email protected]");

    startActivity(intent);

Tags:

Android