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
I used Intent intent = new Intent(Intent.ACTION_EDIT); and it seemed to resolve the issue
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();
}
Check if there is any activity that resolves this intent
if (intent.resolveActivity(getPackageManager()) == null) {
}
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