Permanently deletes our calendar from database (along with all events) - Android android.provider

Android examples for android.provider:CalendarContract

Description

Permanently deletes our calendar from database (along with all events)

Demo Code


import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.provider.CalendarContract;
import android.provider.CalendarContract.Attendees;
import android.provider.CalendarContract.Calendars;
import android.provider.CalendarContract.Events;
import android.provider.CalendarContract.Reminders;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;

public class Main{
    /** The main/basic URI for the android calendars table */
    private static final Uri CAL_URI = CalendarContract.Calendars.CONTENT_URI;
    static final String LOG = "CalendarUtil";
    /** Permanently deletes our calendar from database (along with all events) */
    public static int deleteCalendar(CalendarRequest crx) throws Exception {
        ContentResolver cr = crx.getContext().getContentResolver();
        Uri calUri = ContentUris.withAppendedId(
                buildCalUri(crx.getAccountName()), crx.getCalendarID());
        Log.w(LOG, "about to delete this calendar: " + calUri.toString());
        int x = cr.delete(calUri, null, null);
        return x;
    }/* www  .  ja  v  a2s . c om*/
    /** Builds the Uri for your Calendar in android database (as a Sync Adapter) */

    private static Uri buildCalUri(String accountName) {
        return CAL_URI
                .buildUpon()
                .appendQueryParameter(
                        CalendarContract.CALLER_IS_SYNCADAPTER, "true")
                .appendQueryParameter(Calendars.ACCOUNT_NAME, accountName)
                .appendQueryParameter(Calendars.ACCOUNT_TYPE,
                        CalendarContract.ACCOUNT_TYPE_LOCAL).build();
    }
}

Related Tutorials