public String getTaskEventUri(Task task) { String uri; if (!TextUtils.isEmpty(task.getCalendarURI())) { uri = task.getCalendarURI(); } else { task = taskService.fetchById(task.getId(), Task.CALENDAR_URI); if (task == null) { return null; } uri = task.getCalendarURI(); } return uri; }
public boolean deleteTaskEvent(Task task) { boolean eventDeleted = false; String uri; if (task.containsNonNullValue(Task.CALENDAR_URI)) { uri = task.getCalendarURI(); } else { task = taskService.fetchById(task.getId(), Task.CALENDAR_URI); if (task == null) { return false; } uri = task.getCalendarURI(); } if (!TextUtils.isEmpty(uri)) { try { Uri calendarUri = Uri.parse(uri); // try to load calendar ContentResolver cr = context.getContentResolver(); Cursor cursor = cr.query(calendarUri, new String[] {"dtstart"}, null, null, null); // $NON-NLS-1$ try { boolean alreadydeleted = cursor.getCount() == 0; if (!alreadydeleted) { cr.delete(calendarUri, null, null); eventDeleted = true; } } finally { cursor.close(); } task.setCalendarUri(""); } catch (Exception e) { log.error(e.getMessage(), e); } } return eventDeleted; }