Sunday, March 18, 2012

How to get list of calendars in android 4.0?


 // Get list of Calendars 


        ContentResolver contentResolver = ctx.getContentResolver();
        Log.d(MainActivity.TAG, "URI = " + CalendarContract.Calendars.CONTENT_URI);
        final Cursor cursor = contentResolver.query(CalendarContract.Calendars.CONTENT_URI,
        CALENDAR_QUERY_COLUMNS, null, null, null);
        Log.d(MainActivity.TAG, "cursor = " + cursor);
        while (cursor.moveToNext()) {
        final String _id = cursor.getString(0);
        final String displayName = cursor.getString(1);
        final Boolean selected = !cursor.getString(2).equals("0");
        final String accountName = cursor.getString(3);
        Log.d(MainActivity.TAG, "Found calendar " + accountName);
        calendarList.append(
        "Calendar: Id: " + _id + " Display Name: " + displayName + " Selected: " + selected + " Name " + accountName);
        }

No comments:

Post a Comment