Check this url
Update and delete calendar events in android through my application
Hope it helps :)
Get Event Id :
private int ListSelectedCalendars(String eventtitle) {
Uri eventUri;
if (android.os.Build.VERSION.SDK_INT <= 7) {
// the old way
eventUri = Uri.parse("content://calendar/events");
} else {
// the new way
eventUri = Uri.parse("content://com.android.calendar/events");
}
int result = 0;
String projection[] = { "_id", "title" };
Cursor cursor = getContentResolver().query(eventUri, null, null, null,
null);
if (cursor.moveToFirst()) {
String calName;
String calID;
int nameCol = cursor.getColumnIndex(projection[1]);
int idCol = cursor.getColumnIndex(projection[0]);
do {
calName = cursor.getString(nameCol);
calID = cursor.getString(idCol);
if (calName != null && calName.contains(eventtitle)) {
result = Integer.parseInt(calID);
}
} while (cursor.moveToNext());
cursor.close();
}
return result;
}
Update Event :
@SuppressLint("InlinedApi")
private int UpdateCalendarEntry(int entryID) {
int iNumRowsUpdated = 0;
Uri eventUri;
if (android.os.Build.VERSION.SDK_INT <= 7) {
// the old way
eventUri = Uri.parse("content://calendar/events");
} else {
// the new way
eventUri = Uri.parse("content://com.android.calendar/events");
}
ContentValues values = new ContentValues();
values.put(Events.TITLE, "test");
values.put(Events.EVENT_LOCATION, "Chennai");
Uri updateUri = ContentUris.withAppendedId(eventUri, entryID);
iNumRowsUpdated = getContentResolver().update(updateUri, values, null,
null);
return iNumRowsUpdated;
}
Delete Event :
private int DeleteCalendarEntry(int entryID) {
int iNumRowsDeleted = 0;
Uri eventUri = ContentUris
.withAppendedId(getCalendarUriBase(), entryID);
iNumRowsDeleted = getContentResolver().delete(eventUri, null, null);
return iNumRowsDeleted;
}
private Uri getCalendarUriBase() {
Uri eventUri;
if (android.os.Build.VERSION.SDK_INT <= 7) {
// the old way
eventUri = Uri.parse("content://calendar/events");
} else {
// the new way
eventUri = Uri.parse("content://com.android.calendar/events");
}
return eventUri;
}