add Calendar Event by Intent - Android Intent

Android examples for Intent:Calendar

Description

add Calendar Event by Intent

Demo Code


//package com.java2s;
import java.util.GregorianCalendar;

import android.content.Intent;

import android.provider.CalendarContract;
import android.provider.CalendarContract.Events;

public class Main {
    public static Intent addCalendarEventbyIntent() {
        Intent intent = new Intent(Intent.ACTION_INSERT);
        intent.setType("vnd.android.cursor.item/event");
        intent.putExtra(Events.TITLE, "Learn Android");
        intent.putExtra(Events.EVENT_LOCATION, "Home suit home");
        intent.putExtra(Events.DESCRIPTION, "Download Examples");
        intent.putExtra(Events.ACCOUNT_NAME, "rbarnes23@gmail.com");
        //Setting dates
        GregorianCalendar calDate = new GregorianCalendar(2014, 03, 13);
        intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,
                calDate.getTimeInMillis());
        intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
                calDate.getTimeInMillis());

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

        //Make it a recurring Event
        intent.putExtra(Events.RRULE,/*from   ww  w. j ava  2  s . co  m*/
                "FREQ=WEEKLY;COUNT=1;WKST=SU;BYDAY=TU,TH");

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

        //intent.setData(CalendarContract.Events.CONTENT_URI);
        //startActivity(intent);
        return intent;
    }
}

Related Tutorials