Bhavesh Hirpara
Bhavesh Hirpara

Reputation: 22536

Can not insert calendar event through intent in android

I am getting this error in HTC(v2.3.3) and works in Galaxy s3(v4.1)

Intent intent = new Intent(Intent.ACTION_EDIT)
            .setData(Uri.parse(EventUtils.EVENT_URI))
            .putExtra(Event.EXTRA_EVENT_BEGIN_TIME,
                    beginTime.getTimeInMillis())
            .putExtra(Event.EXTRA_EVENT_END_TIME, endTime.getTimeInMillis())
            .putExtra(
                    Event.TITLE,
                    Utils.getPref(getApplicationContext(),
                            Constant.PREF_EVENT_TAG,
                            Constant.CONST_EVENT_TAG)
                            + "Meeting")
            .putExtra(Event.DESCRIPTION, "important meeting")
            .putExtra(Event.AVAILABILITY, Events.AVAILABILITY_BUSY);
    // .putExtra(Event.EVENT_LOCATION, "The gym")
    // .putExtra(Intent.EXTRA_EMAIL,
    // "[email protected],[email protected]");

    if (calID != -1) {
        intent.putExtra(Event.CALENDAR_ID, calID);
    }

    startActivity(intent);

Exception

01-13 18:58:59.417: E/AndroidRuntime(31730): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.EDIT dat=content://com.android.calendar/events (has extras) }

How can it be resolved?

Upvotes: 1

Views: 544

Answers (2)

Ridcully
Ridcully

Reputation: 23655

What Android Version do you have on HTC? -- I think the Calendar Indent is only around since Android 4.

Edit:

What you use and what also How to set a reminder in Android? uses, is sort of a non-offical way to add calendar events, and this will work or not work depending on the various Android implementations and devices.

Starting with Android 4 (API Level 14) there is an official way to do it, using the CalendarProvider.

Upvotes: 1

BamsBamx
BamsBamx

Reputation: 4256

Most Probably you have set wrong data for your intent... Check your Uri parameter in Intent.setData() method....

Also you should surround that with try/catch, because some users that have calendar app disabled/uninstalled may get a force close when launching that intent

Upvotes: 0

Related Questions