title: How to read google calendar events in android?
body: <p>I am reading all the android calendar events and it is working fine by using this below code but, I want to fetch all the google calendar events from user mail accounts .How can I do that? Any suggestions or sample program will be really helpfull!</p>
  
  <p>For example: I want to get the events for xxxxxxxxx@gmail.com (the mail account which I opened in android mobile)</p>
  
  <pre><code>public static void readCalendarEvent(Context context) throws ParseException {
          ContentResolver contentResolver = context.getContentResolver();
          Calendar calendar = Calendar.getInstance();
          String dtstart = "dtstart";
          String dtend = "dtend";
  
  
          SimpleDateFormat    displayFormatter = new SimpleDateFormat("MMMM dd, yyyy (EEEE)");
  
           stime=displayFormatter.format(calendar.getTime());     
  
          SimpleDateFormat startFormatter = new SimpleDateFormat("MM/dd/yy");
          String dateString = startFormatter.format(calendar.getTime());
  
          long after = calendar.getTimeInMillis();
          SimpleDateFormat formatterr = new SimpleDateFormat("hh:mm:ss MM/dd/yy");
          Calendar endOfDay = Calendar.getInstance();
          Date dateCCC = formatterr.parse("47:59:59 " + dateString);
          endOfDay.setTime(dateCCC);
  
  
  
          cursor = contentResolver.query(Uri.parse("content://com.android.calendar/calendars"), (new String[] { "calendar_id", "title", "description", "dtstart", "dtend","eventTimezone", "eventLocation" }), "(" + dtstart + "&gt;" + after + " and " + dtend + "&lt;" + endOfDay.getTimeInMillis() + ")", null, "dtstart ASC");
          gCalendar = new ArrayList&lt;GoogleCalendar&gt;();
          try {
  
  
              if (cursor.getCount() &gt; 0) {
  
  
                  while (cursor.moveToNext()) {
                      GoogleCalendar googleCalendar = new GoogleCalendar();
                      gCalendar.add(googleCalendar);
                      int calendar_id = cursor.getInt(0);
                      googleCalendar.setCalendar_id(calendar_id);
                      String title = cursor.getString(1);
                      googleCalendar.setTitle(title);
                      String description = cursor.getString(2);
                      googleCalendar.setDescription(description);
                      String dtstart1 = cursor.getString(3);
                       dt=convertDate(dtstart1,"hh:mm:ss");
  
                      googleCalendar.setDtstart(dt);                  
  
                  String dtend1 = cursor.getString(4);
                      googleCalendar.setDtend(dtend1);
  
  
                      String eventTimeZone=cursor.getString(5);
                      googleCalendar.setEventTimeZone(eventTimeZone);
                      String eventlocation = cursor.getString(6);
  
                      googleCalendar.setEventlocation(eventlocation);
  
  
  
                  }
              }
          } catch (AssertionError ex) {
              ex.printStackTrace();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>