Create calendar Intent - Android Intent

Android examples for Intent:Calendar

Description

Create calendar Intent

Demo Code


import android.content.Intent;
import android.provider.CalendarContract;
import java.util.Calendar;
import java.util.GregorianCalendar;
import android.app.Activity;

public class Main{
    public static Intent calendarIntent(Event e) {

        Intent calIntent = new Intent(Intent.ACTION_INSERT);

        calIntent.setType("vnd.android.cursor.item/event");
        calIntent.putExtra(CalendarContract.Events.TITLE, e.getTitle());

        if (e.getLocation() != null)
            calIntent.putExtra(CalendarContract.Events.EVENT_LOCATION,
                    e.getLocation());/*from   ww  w .  j  a va 2  s.c  o  m*/

        calIntent.putExtra(CalendarContract.Events.DESCRIPTION,
                e.getDescription());

        /* GregorianCalendar eventDate = new GregorianCalendar(2012, 7, 15);

         calIntent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);
         calIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,
                 eventDate.getTimeInMillis());
         calIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
                 eventDate.getTimeInMillis());   */

        GregorianCalendar eventDate = new GregorianCalendar(e.getDeadline()
                .get(Calendar.YEAR), e.getDeadline().get(Calendar.MONTH), e
                .getDeadline().get(Calendar.DAY_OF_MONTH));

        calIntent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);
        calIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,
                eventDate.getTimeInMillis());
        calIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
                eventDate.getTimeInMillis());

        return calIntent;
    }
}

Related Tutorials