Reputation: 4968
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
Upvotes: 1
Views: 2097
Reputation: 4968
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);
Upvotes: 1
Reputation: 7635
there might not be any calendar configured in your calendar application. try creating an event in native calendar app which was shipped with device. if that generate any error while creating an event.
if yes, absence of configured calendar might be the issue.
if no, that is if you could successfully create an event in you native app then probably there is a problem in your code.
But one thing i noticed in your code is that you have not specified calendar_id, this event supposed to be created in.
Calendar_id is mandatory field while creating an event in calendar. try putting this thing in your code.
Upvotes: 0