0

Ok so i am making an app which extracts the scynced calendars from the phone and displays them, i have read through many tutorials but i am still unsure how to do this. I want to extract a calendar with the ACCOUNT_TYPE "ca.ryerson" (it is powered by google apps for education), then i wanna get all events from that particular database and only display them when someone clicks on the date provided.

So when someone clicks on Sept 5, it shows all the events on sept 5 from the ca.ryerson account, i am fairly new to android development and have almost 0 experience with database handling, i would really like your help with this one. I have read many tutorials and read through the documentation but i still cannot figure out how to do this.

Thanks :)

TanmayP
  • 706
  • 1
  • 6
  • 12

1 Answers1

1

i was able to determine how to do this here is my code

ContentResolver contentResolver = getContentResolver();
        final Cursor cursor = contentResolver.query(CalendarContract.Calendars.CONTENT_URI,
                (new String[]{CalendarContract.Calendars._ID, CalendarContract.Calendars.CALENDAR_DISPLAY_NAME}), null, null, null);

        while (cursor.moveToNext()) {
            final String _id = cursor.getString(0);
            final String displayName = cursor.getString(1);


            int stringLength = displayName.length();
            String output = displayName.substring(stringLength - 10);
            //Log.d("Cursor", output);

            if (output.equals("ryerson.ca")) {
                //Log.d("Cursor", "true");
                calendarID = new String[]{_id};
            }

            Uri.Builder builder = CalendarContract.Instances.CONTENT_URI.buildUpon();

            Calendar beginTime = Calendar.getInstance();
            beginTime.set(2014, Calendar.SEPTEMBER, 2, 8, 0);
            long startMills = beginTime.getTimeInMillis();

            Calendar endTime = Calendar.getInstance();
            endTime.set(2014, Calendar.SEPTEMBER, 2, 20, 0);
            long endMills = endTime.getTimeInMillis();

            ContentUris.appendId(builder, startMills);
            ContentUris.appendId(builder, endMills);

            Cursor eventCursor = contentResolver.query(builder.build(), new String[]{CalendarContract.Instances.TITLE,
                            CalendarContract.Instances.BEGIN, CalendarContract.Instances.END, CalendarContract.Instances.DESCRIPTION},
                    CalendarContract.Instances.CALENDAR_ID + " = ?", calendarID, null);

            while (eventCursor.moveToNext()) {
                final String title = eventCursor.getString(0);
                final Date begin = new Date(eventCursor.getLong(1));
                final Date end = new Date(eventCursor.getLong(2));
                final String description = eventCursor.getString(3);

                Log.d("Cursor", "Title: " + title + "\tDescription: " + description + "\tBegin: " + begin + "\tEnd: " + end);
            }
TanmayP
  • 706
  • 1
  • 6
  • 12