delete Calendar Event With ID - Android Android OS

Android examples for Android OS:Calendar Event

Description

delete Calendar Event With ID

Demo Code


//package com.java2s;

import android.content.ContentResolver;
import android.content.ContentUris;

import android.content.Context;

import android.database.Cursor;

import android.net.Uri;

public class Main {
    public static void deleteEventWithID(Context curActivity, Long id) {

        ContentResolver cr = curActivity.getContentResolver();
        Uri EVENTS_URI = Uri.parse("content://com.android.calendar/events");
        Cursor cursor = cr.query(EVENTS_URI, new String[] { "calendar_id",
                "title", "description", "dtstart", "dtend",
                "eventLocation", "deleted", "_id" }, null, null, null);
        cursor.moveToFirst();/*from ww  w  .  j  av a 2s .  c  o  m*/
        // fetching calendars name
        String CNames[] = new String[cursor.getCount()];

        // fetching calendars id
        int cont = 0;

        for (int i = 0; i < CNames.length; i++) {
            String titleL = cursor.getString(1);
            long eventId = cursor.getLong(cursor.getColumnIndex("_id"));
            if (id == (eventId)) {
                cr.delete(ContentUris.withAppendedId(EVENTS_URI, eventId),
                        null, null);
                break;
            }

            CNames[i] = cursor.getString(1);
            cursor.moveToNext();
        }
    }
}

Related Tutorials