Esempio n. 1
0
  public static Event getEvent(Context context, long eventId) {
    Event event = null;

    Uri uri = CalendarContract.Events.CONTENT_URI;
    Builder builder = uri.buildUpon();
    ContentUris.appendId(builder, eventId);
    uri = builder.build();

    // Run query
    ContentResolver cr = context.getContentResolver();
    Cursor cur = cr.query(uri, EVENT_PROJECTION, null, null, null);
    EntityIterator it = CalendarContract.EventsEntity.newEntityIterator(cur, cr);
    if (it.hasNext()) {
      event = new Event(it.next());
    }
    cur.close();

    return event;
  }
Esempio n. 2
0
  public static ArrayList<Event> getEvents(Context context, long calId) {
    ArrayList<Event> events = new ArrayList<Event>();

    // Run query
    ContentResolver cr = context.getContentResolver();

    String selection = "(" + CalendarContract.Events.CALENDAR_ID + " = ?)";
    String[] selectionArgs = new String[] {calId + ""};
    // Submit the query and get a Cursor object back.
    Cursor cur =
        cr.query(
            CalendarContract.Events.CONTENT_URI, EVENT_PROJECTION, selection, selectionArgs, null);

    EntityIterator it = CalendarContract.EventsEntity.newEntityIterator(cur, cr);
    while (it.hasNext()) {
      Entity entity = it.next();
      events.add(new Event(entity));
    }
    cur.close();

    return events;
  }