简体   繁体   中英

How to remove reminder from event in android?

When I set a reminder for an event can not remove it! I've already test this code:

Uri reminderUri = ContentUris.withAppendedId(CalendarContract.Reminders.CONTENT_URI, reminder.id);
context.getContentResolver().update(reminderUri, getEmptyReminderContentValues(reminder), null, null);
context.getContentResolver().delete(reminderUri, null, null);

I seen some calendars include google calendar do this but some of them do not. Anyone can help me?

You can use following method to delete the reminder set on event

public static void deleteReminderOnEvent(Long reminderId) {
    Uri reminderUri = ContentUris.withAppendedId(CalendarContract.Reminders.CONTENT_URI, reminderId);
    int rows = contentResolver.delete(reminderUri, null, null);
}

You need to use following method before above method to get the reminderId for the event and then pass it to above method.

private static Long checkIfReminderExist(ContentResolver contentResolver, long eventId) {
    Long reminderId = null;

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

    Cursor cursor = CalendarContract.Reminders.query(contentResolver, eventId, projection);

    while (cursor != null && cursor.moveToNext()) {
        reminderId = cursor.getLong(0);
    }

    cursor.close();

    return reminderId;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM