Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edit/Delete Google Calendar Events and get event Id

I am trying to edit and delete events in Google calendar using Calendar Provider. I have already Created event using Calendar Provider .

Here is my code to create an event :

    Calendar beginTime = Calendar.getInstance();
    beginTime.set(2014, 5, 19, 7, 30);
    Calendar endTime = Calendar.getInstance();
    endTime.set(2014, 5, 19, 8, 30);
    Intent intent = new Intent(Intent.ACTION_INSERT)
            .setData(Events.CONTENT_URI)
            .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginTime.getTimeInMillis())
            .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime.getTimeInMillis())
            .putExtra(Events.TITLE, "")
            .putExtra(Events.DESCRIPTION, "")
            .putExtra(Events.EVENT_LOCATION, "")
            .putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY)
            .putExtra(Intent.EXTRA_EMAIL, email);
    startActivity(intent);

event is getting created successfully. now i want to edit/delete the event. so, how can i perform this. And for edit/delete i need event id for created event how i can get that??

Please... help me guys.

like image 829
Aayushi Avatar asked May 13 '14 08:05

Aayushi


People also ask

How do I find Google Calendar event ID?

To find the event ID in gmail, you will need to click into the event you are having issues with and then edit. The ID will we be displayed in the url after https://calendar.google.com/calendar/r/eventedit/ as shown below: From the above example, this would be the ID starting "MXB.."

What happens when you remove an event from Google Calendar?

Trash. You find the events deleted from this calendar. The first time you delete an event that's moved to the trash, Google Calendar sends you an email. You can't turn off this notification, but it's the only email notification you get about trash.

Can you edit a Google Calendar event?

Edit an event you've createdOn your computer, open Google Calendar. , click it. Make changes to your event. At the top of the page, click Save.


1 Answers

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;
}
like image 196
Shini Avatar answered Sep 22 '22 17:09

Shini