Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6215735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:06:34+00:00 2026-05-24T07:06:34+00:00

What I want to do is to delete only the content that is saved

  • 0

What I want to do is to delete only the content that is saved by me in the calendar instead of all the content which is already present in the calendar. For that, I use the following code. But it will delete all the content of the calendar. So can anyone tell me how that can be prevented?

Uri CALENDAR_URI = Uri.parse("content://calendar/events");
ContentResolver cr = getContentResolver();
cr.delete(CALENDAR_URI, null, null); // Delete all



ContentValues values = new ContentValues();
values.put("calendar_id", 1);
values.put("title", this.title);
values.put("allDay", this.allDay);
values.put("dtstart", this.dtstart.toMillis(false));
values.put("dtend", this.dtend.toMillis(false));
values.put("description", this.description);
values.put("eventLocation", this.eventLocation);
values.put("visibility", this.visibility);
values.put("hasAlarm", this.hasAlarm);

cr.insert(CALENDAR_URI, values);

So what I want is to delete only that entry that is put by me.

Deleting the event

Uri EVENTS_URI = Uri.parse("content://com.android.calendar/" + "events");
            
ContentResolver cr = c.getContentResolver();
deleteEvent(cr, EVENTS_URI, 1);

private void deleteEvent(ContentResolver resolver, Uri eventsUri, int calendarId) {
        Cursor cursor;     
        cursor = resolver.query(eventsUri, new String[]{ "_id" },     "calendar_id=" + calendarId, null, null);
        while(cursor.moveToNext()) {
            long eventId = cursor.getLong(cursor.getColumnIndex("_id"));
            resolver.delete(ContentUris.withAppendedId(eventsUri, eventId), null, null);
        }
        cursor.close();
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:06:35+00:00Added an answer on May 24, 2026 at 7:06 am

    After reading the data from the Calendar just try this out..

    Adding a Single-Occurrence Event to a Calendar

    To add an entry to a specific calendar, we need to configure a calendar entry to insert using the ContentValues as follows:

    ContentValues event = new ContentValues();
    

    Each event needs to be tied to a specific Calendar, so the first thing you’re going to want to set is the identifier of the Calendar to insert this event into:

    event.put("calendar_id", calId);
    

    We then set some of the basic information about the event, including String fields such as the event title, description and location.

    event.put("title", "Event Title");
    event.put("description", "Event Desc");
    event.put("eventLocation", "Event Location");
    

    There are a number of different options for configuring the time and date of an event.

    We can set the event start and end information as follows:

    long startTime = START_TIME_MS;
    long endTime = END_TIME_MS;
    event.put("dtstart", startTime);
    event.put("dtend", endTime);
    

    If we are adding a birthday or holiday, we would set the entry to be an all day event:

    event.put("allDay", 1);   // 0 for false, 1 for true
    

    This information is sufficient for most entries. However, there are a number of other useful calendar entry attributes.

    For example, you can set the event status to tentative (0), confirmed (1) or canceled (2):

    event.put("eventStatus", 1);
    

    You can control who can see this event by setting its visibility to default (0), confidential (1), private (2), or public (3):

    event.put("visibility", 0);
    

    You can control whether an event consumes time (can have schedule conflicts) on the calendar by setting its transparency to opaque (0) or transparent (1).

    event.put("transparency", 0);
    

    You can control whether an event triggers a reminder alarm as follows:

    event.put(“hasAlarm”, 1); // 0 for false, 1 for true

    Once the calendar event is configured correctly, we’re ready to use the ContentResolver to insert the new calendar entry into the appropriate Uri for calendar events:

     Uri eventsUri = Uri.parse("content://calendar/events");
      Uri url = getContentResolver().insert(eventsUri, event);
    

    The call to the insert() method contacts the Calendar content provider and attempts to insert the entry into the appropriate user Calendar. If you navigate to the Calendar application and launch it, you should see your calendar entry in the appropriate Calendar. Since the Calendar syncs, you will also see the Calendar entry online, if you’re using the Google Calendar on the web.

    Delete the event

     private int DeleteCalendarEntry(int entryID) {
            int iNumRowsDeleted = 0;
    
            Uri eventsUri = Uri.parse(getCalendarUriBase()+"events");
            Uri eventUri = ContentUris.withAppendedId(eventsUri, entryID);
            iNumRowsDeleted = getContentResolver().delete(eventUri, null, null);
    
            Log.i(DEBUG_TAG, "Deleted " + iNumRowsDeleted + " calendar entry.");
    
            return iNumRowsDeleted;
        }
    

    Also go through this link for deleting

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to delete all rows in a datatable. I use something like this:
I'm working in PHP to allow users to delete content and I want delete
I want to delete all files in a directory with a given name, except
I want to delete a file into recycle bin. I using this code. SHFILEOPSTRUCT
In a mini blog app, I want to create a delete function, so that
I want to delete rows in GlassesColor table that associated with GlassesID in Glasses
Let's say I have a rails app with content that's read-only to the public,
So I have this 2d dynamic array which content I want to free when
I have a CSV document that is of the following structure Headers Path,Publish,Hashlist,Package Content
I want to delete DataRows from a DataTable. The rows to be deleted are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.