无法在Android中从日历中删除提醒

无法在Android中从日历中删除提醒,android,google-calendar-api,android-calendar,Android,Google Calendar Api,Android Calendar,我使用caledarcontract api以编程方式添加了一个日历事件,并获得了一个eventId。同样,我为这个事件添加了一个提醒,并保存了提醒ID。现在我不想要此事件的提醒(或者我想关闭提醒),因此我尝试使用提醒ID删除提醒,但无法删除。我也尝试使用eventId删除提醒,但它不起作用 public int AddEventToCalendar(String calendarId, Entity entity) { // TODO Auto-generated method stu

我使用caledarcontract api以编程方式添加了一个日历事件,并获得了一个eventId。同样,我为这个事件添加了一个提醒,并保存了提醒ID。现在我不想要此事件的提醒(或者我想关闭提醒),因此我尝试使用提醒ID删除提醒,但无法删除。我也尝试使用eventId删除提醒,但它不起作用

public int AddEventToCalendar(String calendarId, Entity entity) {
    // TODO Auto-generated method stub
    ContentValues event = new ContentValues();
    event.put("calendar_id", calendarId);
    event.put("title", entity.description);
    event.put("dtstart", System.currentTimeMillis());
    event.put("dtend", System.currentTimeMillis() + 3600*1000);
    event.put("allDay", 0);
    //status: 0~ tentative; 1~ confirmed; 2~ canceled
    event.put("eventStatus", 1);
    //0~ default; 1~ confidential; 2~ private; 3~ public
    event.put("visibility", 0);
    //0~ opaque, no timing conflict is allowed; 1~ transparency, allow overlap of scheduling
    event.put("transparency", 0);
    //0~ false; 1~ true
    event.put("hasAlarm", 1);
    Uri add_eventUri;
    if (Build.VERSION.SDK_INT >= 8) {
        add_eventUri = Uri.parse("content://com.android.calendar/events");
    } else {
        add_eventUri = Uri.parse("content://calendar/events");
    }
    Uri l_uri = context.getContentResolver().insert(add_eventUri, event);
    if(l_uri != null)
    {
        long eventID = Long.parseLong(l_uri.getLastPathSegment());
        return (int) eventID;
    }
    else
        return 0;
}

public int AddReminderOnEvent(Entity entity)
{
    if(entity.eventId != 0)
    {
        ContentValues reminderValues = new ContentValues();
        reminderValues.put("event_id", entity.eventId);
        reminderValues.put("method", 1);// will alert the user with a reminder notification
        reminderValues.put("minutes", 0);// number of minutes before the start time of the event to fire a reminder
        Uri reminder_eventUri;
        if (Build.VERSION.SDK_INT >= 8) {
            reminder_eventUri = Uri.parse("content://com.android.calendar/reminders");
        } else {
            reminder_eventUri = Uri.parse("content://calendar/reminders");
        }
        Uri r_uri = context.getContentResolver().insert(reminder_eventUri, reminderValues); 
        if(r_uri != null)
        {
            long reminderID = Long.parseLong(r_uri.getLastPathSegment());
            return (int) reminderID;
//          Toast.makeText(getApplicationContext(), "Event Created Successfully", Toast.LENGTH_LONG).show();
        }
        else
            return 0;
    }
    else
    {
        return 0;
    }
}

    public boolean DeleteReminderOnTask(int eventId, int reminderId) {
    // TODO Auto-generated method stub

    Uri delete_reminderUri;
    if (Build.VERSION.SDK_INT >= 8) {
        delete_reminderUri = Uri.parse("content://com.android.calendar/reminders");
    } else {
        delete_reminderUri = Uri.parse("content://calendar/reminders");
    }
    delete_reminderUri = ContentUris.withAppendedId(delete_reminderUri, reminderId);
    int rows = context.getContentResolver().delete(delete_reminderUri,null , null);

    if(rows > 0)
        return true;
    else
        return false;

}

每次执行此代码后,行返回0,表示没有任何行被更改。提醒会在适当的时候出现。如何在不删除事件的情况下从日历中删除提醒?

这可能不是唯一或最好的方法,但我所能想到的是如何删除事件的所有提醒。我不知道如何删除一个提醒

//What we want to update
ContentValues values = new ContentValues();
values.put(Events.HAS_ALARM, 0);

//We're setting the event to have no alarms
int result = getContentResolver().update(
    Events.CONTENT_URI,
    values,
    Events._ID + " = ?",
    new String[]{"44"}
);
不幸的是,这会删除所有提醒,但我不确定Android 14+或大多数日历提供商(如Exchange)是否真的支持多个提醒。ICS中的日历应用程序只允许添加一个提醒(尽管会说“添加提醒”)


如果我使用另一个应用程序(如Business Calendar)添加多个提醒,当我签入Exchange时,它只显示一个提醒。它在日历应用程序中显示多个提醒,但仅在该设备上显示,而不在其他设备上显示,因此多个提醒似乎仅在本地显示。

我不确定失败时运行的SDK版本,但此代码(基本上与您的相同,不包括版本检查)适用于我:

Uri reminderUri = ContentUris.withAppendedId(
    CalendarContract.Reminders.CONTENT_URI, reminderId);
int rows = contentResolver.delete(reminderUri, null, null);
通过查询事件的提醒,我获得了
提醒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();

删除时有任何异常或错误吗?没有。没有错误或异常。当0i浏览您的链接时,只有更改的行数出现。您正在尝试引用事件的插入、更新和删除。在发生事件时,这些功能对我来说非常有效。在提醒的情况下,插入有效,但删除无效。请提出解决办法。谢谢有人帮我找到解决这个问题的办法。谢谢,我也有同样的问题。。我想更新我的提醒值或删除我事件的提醒。但是没有成功。你找到解决办法了吗??