5
votes

I am using Google calendar API. I have added reminder to an event from this code

ContentValues values1 = new ContentValues();

values1.put("event_id", eventId);

values1.put("method", 1);

values1.put( "minutes", reminderValue );

Uri reminder = Uri.parse("content://com.android.calendar/reminders");

this.getContentResolver().insert(reminder, values1);

My issue is this I know how to add reminder.. I need query for update the Reminders. By this code it added multiple reminders for an event.

Please help me.

thanks

1

1 Answers

4
votes

I think you cannot update the already set reminders directly.First you should get the id of the reminder you need to update by using the following code:

String[] projection = new String[] {
        CalendarContract.Reminders._ID,
        CalendarContract.Reminders.METHOD,
        CalendarContract.Reminders.MINUTES
};

Cursor cursor = CalendarContract.Reminders.query(
    contentResolver, eventId, projection);
while (cursor.moveToNext()) {
    long reminderId = cursor.getLong(0);
    int method = cursor.getInt(1);
    int minutes = cursor.getInt(2);

    // etc.

}
cursor.close();

then using this reminderid you have to delete the already set reminder using this code:

Uri reminderUri = ContentUris.withAppendedId(
CalendarContract.Reminders.CONTENT_URI, reminderId);
int rows = contentResolver.delete(reminderUri, null, null);

then use your code to insert the reminder again.Hope this helps...