init Calendars - Android Android OS

Android examples for Android OS:Calendar Contract

Description

init Calendars

Demo Code


//package com.java2s;

import java.util.TimeZone;

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

import android.graphics.Color;
import android.net.Uri;
import android.provider.CalendarContract;
import android.provider.CalendarContract.Calendars;

public class Main {
    private static final String CALENDAR_NAME = "VoiceCard";

    private static void initCalendars(Context activity) {
        TimeZone timeZone = TimeZone.getDefault();
        ContentValues value = new ContentValues();
        value.put(Calendars.OWNER_ACCOUNT, CALENDAR_NAME);
        value.put(Calendars.NAME, CALENDAR_NAME);
        value.put(Calendars.ACCOUNT_NAME, CALENDAR_NAME);
        value.put(Calendars.ACCOUNT_TYPE,
                CalendarContract.ACCOUNT_TYPE_LOCAL);
        value.put(Calendars.CALENDAR_DISPLAY_NAME, CALENDAR_NAME);
        value.put(Calendars.VISIBLE, 1);
        value.put(Calendars.CALENDAR_COLOR, Color.RED);
        value.put(Calendars.CALENDAR_ACCESS_LEVEL,
                Calendars.CAL_ACCESS_OWNER);
        value.put(Calendars.SYNC_EVENTS, 1);
        value.put(Calendars.CALENDAR_TIME_ZONE, timeZone.getID());
        value.put(Calendars.OWNER_ACCOUNT, CALENDAR_NAME);
        value.put(Calendars.CAN_ORGANIZER_RESPOND, 0);
        Uri calendarUri = Calendars.CONTENT_URI;
        calendarUri = calendarUri/*from  w w w  .j  a  va2  s .  c om*/
                .buildUpon()
                .appendQueryParameter(
                        CalendarContract.CALLER_IS_SYNCADAPTER, "true")
                .appendQueryParameter(Calendars.ACCOUNT_NAME, CALENDAR_NAME)
                .appendQueryParameter(Calendars.ACCOUNT_TYPE,
                        CalendarContract.ACCOUNT_TYPE_LOCAL).build();
        activity.getContentResolver().insert(calendarUri, value);
    }
}

Related Tutorials