Android Calendar Specific Event Deletion

2019-02-18 10:48发布

问题:

I have created an application that easily puts the values that I want to the the device's calendar but when I want to delete it from the calendar programmatically I can't find a way how to.

I've searched the net, mostly other stackoverflow questions, to find an answer (links here):

Delete Calendar Entry,

Events from Calendar not Deleted,

Delete Specific Event.

I found a way to delete all event entries on the calendar:

public void onClick(View v) {
    Uri eventsUri = Uri.parse("content://com.android.calendar/events");
    ContentResolver cr = getContentResolver();
    Cursor cursor;
    cursor = cr.query(eventsUri, new String[]{ "_id" },"calendar_id=" + 1, null, null);
    while(cursor.moveToNext()) {
        long eventId = cursor.getLong(cursor.getColumnIndex("_id"));
        cr.delete(ContentUris.withAppendedId(eventsUri, eventId), null, null);
    }
    cursor.close();
    // Show message
    Toast.makeText(getApplicationContext(), "Calendar Cleared!",Toast.LENGTH_LONG).show();
}

It works but what I do want is to delete just one specific event entry. So my questions are:

1.) Can you give me a link or code snippet on how to delete a specific event on Android's calendar?

2.) Is it possible to delete a calendar entry by just finding its title ?