谷歌日历API:更新事件提醒

5

我正在使用Google日历API。我已经通过以下代码向事件添加了提醒:

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);

我的问题是,我知道如何添加提醒,但我需要查询更新提醒。使用这段代码会为一个事件添加多个提醒。
请帮助我。
谢谢。
1个回答

4

我认为您无法直接更新已设置的提醒。首先,您应该使用以下代码获取需要更新的提醒的ID:

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();

然后,使用此提醒ID,您需要使用以下代码删除已设置的提醒:
Uri reminderUri = ContentUris.withAppendedId(
CalendarContract.Reminders.CONTENT_URI, reminderId);
int rows = contentResolver.delete(reminderUri, null, null);

然后使用你的代码再次插入提醒。希望这有所帮助...

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接