我已經使用caledarcontract API以編程方式添加了日曆活動並獲得了eventId。同樣,我爲這個事件添加了提醒,並保存了提醒ID。現在我不想提醒這個事件(或者我想關閉提醒),所以我試圖刪除提醒使用reminderId,但我無法刪除。我嘗試使用eventId刪除提醒,但它不起作用。無法從Android中的日曆中刪除提醒
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意味着沒有行被更改。提醒恰好在適當的時候出現。如何從日曆中刪除提醒而不刪除事件?
任何異常或錯誤,同時刪除? – Sameer 2012-02-08 10:03:30
沒有。沒有錯誤或例外。只有被更改的行的數量是0 – Vansi 2012-02-08 10:48:19
通過我的答案.. – Sameer 2012-02-08 10:49:07