Following is the code which i am using to add events in my android app
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra(Events.TITLE, summary);
intent.putExtra(Events.DESCRIPTION, summary);
intent.putExtra(Events.EVENT_LOCATION, "");
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginCal.getTimeInMillis());
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endCal.getTimeInMillis());
intent.putExtra(Events.ALL_DAY, allDayFlag);
intent.putExtra(Events.STATUS, 1);
intent.putExtra(Events.VISIBLE, 0);
intent.putExtra(Events.HAS_ALARM, 1);
startActivity(intent);
This code works good in android 4.0 emulator but when i checked in Samsung Galaxy S II of andriod 4.0 it gets crashed and the error log seems to be as follows
Error ( 4489): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.INSERT typ=vnd.android.cursor.item/event (has extras) }
how to rectify this error
I tried in the following way and its working fine
ContentResolver cr = getContentResolver();
ContentValues values = new ContentValues();
values.put(Events.DTSTART, startTime);
values.put(Events.DTEND, endTime);
values.put(Events.TITLE, summary);
values.put(Events.DESCRIPTION, summary);
values.put(Events.CALENDAR_ID, calID);
values.put(Events.EVENT_TIMEZONE, "America/Los_Angeles");
values.put(Events.EVENT_LOCATION, "");
values.put(Events.ALL_DAY, allDayFlag);
values.put(Events.STATUS, 1);
values.put(Events.HAS_ALARM, 1);
Uri uri = cr.insert(Events.CONTENT_URI, values);