Question

The Code

I have implemented the Calendar Intent on an Android Application as follows:

Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setData(Events.CONTENT_URI);
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, parsedStartTime.toMillis(false))
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, parsedEndTime.toMillis(false))
intent.putExtra(Events.TITLE, eventInfo.getName())
intent.putExtra(Events.DESCRIPTION, eventInfo.getText())
intent.putExtra(Events.EVENT_LOCATION, eventInfo.getWhere())
intent.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY);
startActivity(intent);

The Problem

I´ve used ACTION_EDIT, since ACTION_INSERT as it is on the official developer guide seems to generate problems on some devices.

Now, this code works OK on the devices i've tested. Those include a Motorola Defy+ with an Android 4.1.2 custom rom and a Samsung Galaxy SIII Mini with Android 4.1.2 from Samsung.

But i have reports that on a Samsung Galaxy SII with Android 4.0.4 the app is crashing. Specifically with the error:

android.content.ActivityNotFoundException

Sadly, this is all the information I've got, since i don't have access to the phone itself (it's from a user). I've got the error from Analytics.


The question

As I've seen on this post, there is some sort of problem with Samsung and the calendar provider. Is there a way to use Calendar Intents on this phone? or i will have to use getContentResolver()?

I believe in this case i will have to add the Calendar permissions to the app, but the user won't be able to choose the calendar on which to save the Event.

Any help would be appreciated!

Was it helpful?

Solution

Ok, so i've found the problem: the client didn't have any Calendar app installed to handle the Calendar Intent. I didn't think this was possible.

In this case the option will be to add a test to check if there is an app that can handle the intent.

To check if an intent is available we can use:

public static boolean isAvailable(Context ctx, Intent intent) {
        final PackageManager mgr = ctx.getPackageManager();
        List<ResolveInfo> list = mgr.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        return list.size() > 0;
}

And pass the intent as argument to this function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top