0

I am trying to get the calendar events, I used the code below,

 public static  ArrayList<CalendarEvents>calendarEvents;
 calendarEvents = new ArrayList<CalendarEvents>();

 String[] projection = new String[] { "calendar_id", "title", "description","dtstart", "dtend","organizer", "eventLocation"};
Cursor cursor = context.getContentResolver()
                .query(
                        Uri.parse("content://com.android.calendar/events"),projection
                        , null,
                        null, null);

The result getting all the evnets including birthdays, hloydays,etc... I want to filter user created events.

Vineesh TP
  • 7,755
  • 12
  • 66
  • 130

1 Answers1

1

To filter your events. You must have some unique constraint. Let say in my case, my title contains some significant letters. So i had compared it by title. You can also compare by Events.EVENT_COLOR

  Uri eventUri =  Events.CONTENT_URI;
  int result = 0;
  String projection[] = {Events._ID, Events.TITLE};
  Cursor cursor = mContext.getApplicationContext()
            .getContentResolver().query(eventUri,
                    projection,
                    Events.TITLE + " = ? ",
                    new String[]{title},
                    null);
Beena
  • 2,334
  • 24
  • 50
  • I am new to Android dvelopem I dont want all the calendar events. Needed only the user created events.There there any way to get this. – Vineesh TP Jan 27 '16 at 07:15
  • Yes. You can add your filter like this which i have suggested. ` Events.TITLE + " = ? "` and applying value ` new String[]{title}`. You can add as many as filters here. You can refer http://stackoverflow.com/a/2158589/3817374 to check how filters can be added – Beena Jan 27 '16 at 07:20