Error Inserting Event into Calendar with Intent
Asked Answered
E

6

4

I'm trying to insert events to the calendar from a fragment, but I keep getting an error that no activity is found to handle Intent.

Here's the error -

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.INSERT cat=[android.intent.category.APP_CALENDAR] typ=vnd.android.cursor.item/event (has extras) }

Here's my code:

Intent intent = new Intent(Intent.ACTION_INSERT);
intent.addCategory(Intent.CATEGORY_APP_CALENDAR);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra(Events.TITLE, "Phototherapy Treatment");
intent.putExtra(Events.EVENT_LOCATION, "");
intent.putExtra(Events.DESCRIPTION, "Phototherapy Treatment");

// Setting dates
Calendar calDate = Calendar.getInstance();
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,calDate.getTimeInMillis());
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
calDate.getTimeInMillis()+60*60*1000);

// Make it a full day event
intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, false);

// Make it a recurring Event                    
intent.putExtra(Events.RRULE, "FREQ=WEEKLY;COUNT="+Integer.valueOf(No.getText().toString())+";"
+"WKST=SU;BYDAY="+days);

// Making it private and shown as busy
 intent.putExtra(Events.ACCESS_LEVEL, Events.ACCESS_PRIVATE);
 intent.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY);

startActivity(intent);

Intent Filter

<intent-filter> 
<action android:name="android.intent.action.MAIN" /> 
<action android:name="android.intent.action.INSERT" /> 
<category android:name="android.intent.category.APP_CALENDAR" /> 
<data android:mimeType="vnd.android.cursor.item/event" /> 
</intent-filter>
Envelop answered 29/3, 2012 at 13:55 Comment(0)
E
13

I used Intent intent = new Intent(Intent.ACTION_EDIT); and it seemed to resolve the issue

Envelop answered 26/7, 2012 at 14:5 Comment(2)
Had the same problem with a HTC Sense Android 4.0. Its annoying because the official way of doing this is with ACTION_INSERT (ref: developer.android.com/guide/topics/providers/…Disrespect
I'm using am HTC EVO with Android 4.0.3 and both INSERT and EDIT give me the ActivityNotFoundException.Publicist
L
1

Calender App may not be installed in some devices. So enclose within try catch block to check.

Calendar startTymVar = Calendar.getInstance();
startTymVar.set(2015, 12, 31, 11, 30);

Intent calendarIntentVar = new Intent(Intent.ACTION_INSERT)
            .setData(CalendarContract.Events.CONTENT_URI)
            .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, startTymVar.getTimeInMillis())
            .putExtra(CalendarContract.Events.TITLE, "New Year")
            .putExtra(CalendarContract.Events.DESCRIPTION, "Hav ful fun");

try
{
    startActivity(calendarIntentVar);
}
catch (ActivityNotFoundException ErrVar)
{
    Toast.makeText(this, "Install Calender App", Toast.LENGTH_LONG).show();
}
Landonlandor answered 18/7, 2017 at 10:11 Comment(0)
S
0

if you already know the information which it looks like you do you do not need to launch the calendar app, simply just insert the event into the database see adding events

Also looking at the docs APP_CALENDAR is only used with ACTION_MAIN not ACTION_INSERT

Stray answered 29/3, 2012 at 14:45 Comment(0)
W
0

Check if there is any activity that resolves this intent

if (intent.resolveActivity(getPackageManager()) == null) {
}
Workingwoman answered 17/12, 2018 at 8:36 Comment(0)
T
0

This is relevant for Android 11 and above devices, that on the top of steps mentioned in Common Intents - Add Event, we have to add the intent in the <queries> block in the Android Manifest file.

Do note that adding an <intent-filter> on Activity which launches the calendar intent won't work as it adds that Activity as a receiver of such intents, but rather adding following snippet in manifest file does the trick:

<queries>
    <intent>
        <action android:name="android.intent.action.INSERT" />
        <data android:mimeType="vnd.android.cursor.dir/event" />
    </intent>
</queries>

For me this trick worked for my Android 11 device, and it was already working fine for devices before that!

Torrence answered 13/4, 2022 at 15:55 Comment(0)
W
0

There is not App to handle this Intent. But it's not possible. Android phone will be carry a Calendar app.

Maybe something wrong with that app. Maybe update it will fix this. (I updated it. Then the problem is gone.)

Woolgrower answered 15/7, 2023 at 5:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.