title: Android read calendar events
body: <p>I'm trying to create a interface to choose calenar events but I have run into some issues. On my devices I get the correct events but many of my users have reported the functionality isn't working and some shows events that aren't even in the calendar. On a 4.1 Samsung device I tested on the app crashed so what I'm wondering is; what is the correct way to display a list of all calendar events? Here's the  code I'm using right now:</p>
  
  <pre><code> Cursor cursor = getActivity().getContentResolver().query(Uri.parse
  ("content://com.android.calendar/events"),
   new String[]{"calendar_id", "title", "description",
  "dtstart", "dtend", "eventLocation"}, "calendar_id=1", null, null);
  
          cursor.moveToFirst();
  
          int length = cursor.getCount();
  
          for (int i = 0; i &lt; length; i++) {
  
                  CalendarEvent ce = new CalendarEvent();
  
                  ce.setTitle(cursor.getString(1));
                  ce.setNote(cursor.getString(2));
                  ce.setDate(cursor.getLong(3));
  
                  if (cursor.getString(1).length() &gt; 0) {
                      mItems.add(ce);
                  }
  
                  cursor.moveToNext();
          }
  
          cursor.close();
  </code></pre>