create Event Calendar With Name - Android Android OS

Android examples for Android OS:Calendar Event

Description

create Event Calendar With Name

Demo Code


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

import java.util.TimeZone;

import android.content.ContentValues;
import android.content.Context;

import android.net.Uri;
import android.provider.CalendarContract;

import android.provider.CalendarContract.Events;

public class Main {
    public static Uri createEventWithName(Context ctx, Uri calendar,
            String name, Date at) {
        long id = Long.parseLong(calendar.getLastPathSegment());
        ContentValues cv = new ContentValues();
        cv.put(Events.TITLE, name);/*from  w  ww.jav a 2 s .com*/
        cv.put(Events.DTSTART, at.getTime());
        cv.put(Events.DTEND, at.getTime() + 1000000);
        cv.put(Events.CALENDAR_ID, id);
        cv.put(Events.EVENT_TIMEZONE, TimeZone.getDefault().toString());
        //cv.put(Events.RRULE, "FREQ=DAILY;INTERVAL=2");

        Uri newEvent = ctx.getContentResolver().insert(
                CalendarContract.Events.CONTENT_URI, cv);
        return newEvent;
    }
}

Related Tutorials