zonte
zonte

Reputation: 33

Android open any calendar app with intent (4.2.2 and up)

I'm trying to do 3 things. Depending on a selection within the preferences, I want to either open up an installed calendar app, show the event details within an installed calendar or create a new event using a desired installed calendar app. The user should be able to decide what app to use with the decision dialog from the android framework.

For testing purposes I installed aCalendar and Jorte besides the stock google calendar app. At the moment only the "create new event" lists all 3 apps to perform this action.

Intent intent = null;
intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");

When using the action to open up just calendar or calendar details, only aCalendar and google calendar are shown within the selection dialog. Both working fine.

this is the complete method I use to create the intent :

private Intent createCalendarIntent()
{
    long startMillis = System.currentTimeMillis();
    Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
    builder.appendPath("time");
    ContentUris.appendId(builder, startMillis);
    Intent intent = null;

    Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, 
                                         calHandle.getEventID(0));          

    switch(getPreferenceIntentAction())
    {
        case 1: intent = new Intent(Intent.ACTION_VIEW);
                            intent.setType("vnd.android.cursor.item/event");
                            intent.setData(builder.build());
            break;
        case 2: intent = new Intent(Intent.ACTION_VIEW);
                            intent.setType("vnd.android.cursor.item/event");
                            intent.setData(uri);
            break;
        case 3: intent = new Intent(Intent.ACTION_EDIT);
                            intent.setType("vnd.android.cursor.item/event");
            break;
            default:
                break;
    }

where case 1 is just to open up the calendar at the actual week, case 2 is to show event details and case 3 is to create a new event.

I don't have any clue, why Jorte isn't showing up. I think this will happen to other calendar apps too.

How is it possible to show op Jorte (and others too) too, without reading out all installed apps on the device and filter on calendar apps to let the user decide within the preferences but on the built-in dialog.

Thanks in advance!

Upvotes: 3

Views: 1902

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006724

I don't have any clue, why Jorte isn't showing up.

Because it is a calendar app, not a Google Calendar front-end. Your other two Intent configurations should only be honored by an application that uses CalendarContract to store its events. Jorte probably does not, as its Play Store description indicates that "it can synchronize with Google Calendar" (emphasis mine), indicating that it does not store its events in Google Calendar all of the time. There is no requirement that all calendar apps store their data in CalendarContract.

I think this will happen to other calendar apps too.

Any calendar app that uses its own data store should behave the way Jorte behaves.

How is it possible to show op Jorte (and others too) too

By definition, it will not be possible for you to have arbitrary calendar apps support your second Intent configuration. That is for viewing a specific Google Calendar entry, and not every calendar app will store its events in Google Calendar.

Upvotes: 1

Related Questions