dump Calendars - Android Android OS

Android examples for Android OS:Calendar Contract

Description

dump Calendars

Demo Code


import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TimeZone;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.CalendarContract;
import android.provider.CalendarContract.Attendees;
import android.provider.CalendarContract.Calendars;
import android.provider.CalendarContract.Events;
import android.util.Log;

public class Main{
    public static void dumpCalendars(Context ctx) {
        ContentResolver cr = ctx.getContentResolver();
        Cursor c = cr.query(CalendarContract.Calendars.CONTENT_URI, null,
                null, null, null);//from  ww  w .  j  a  v  a 2s .  c o  m
        Map<String, String> list = new HashMap<String, String>();
        while (c.moveToNext()) {
            list.put(Calendars._ID,
                    "" + c.getLong(c.getColumnIndex(Calendars._ID)));
            list.put(Calendars.NAME,
                    c.getString(c.getColumnIndex(Calendars.NAME)));
            /*list.put(Calendars.ACCOUNT_NAME, c.getString(c.getColumnIndex(Calendars.ACCOUNT_NAME)));
            list.put(Calendars.ACCOUNT_TYPE, c.getString(c.getColumnIndex(Calendars.ACCOUNT_TYPE)));
                    
            list.put(Calendars.NAME, c.getString(c.getColumnIndex(Calendars.NAME)));
            list.put(Calendars.CALENDAR_DISPLAY_NAME, c.getString(c.getColumnIndex(Calendars.CALENDAR_DISPLAY_NAME)));
                    
            list.put(Calendars.CALENDAR_COLOR, ""+c.getInt(c.getColumnIndex(Calendars.CALENDAR_COLOR)));
            list.put(Calendars.CALENDAR_ACCESS_LEVEL, ""+c.getInt(c.getColumnIndex(Calendars.CALENDAR_ACCESS_LEVEL)));
            list.put(Calendars.OWNER_ACCOUNT, c.getString(c.getColumnIndex(Calendars.OWNER_ACCOUNT)));
            list.put(Calendars.VISIBLE, ""+c.getInt(c.getColumnIndex(Calendars.VISIBLE)));
            list.put(Calendars.SYNC_EVENTS, ""+c.getInt(c.getColumnIndex(Calendars.SYNC_EVENTS)));
            list.put(Calendars.CALENDAR_TIME_ZONE, c.getString(c.getColumnIndex(Calendars.CALENDAR_TIME_ZONE)));
                    
            list.put(Calendars._SYNC_ID, c.getString(c.getColumnIndex(Calendars._SYNC_ID)));

            list.put(Calendars.DIRTY, ""+c.getLong(c.getColumnIndex(Calendars.DIRTY)));
            list.put(Calendars.DELETED, ""+c.getInt(c.getColumnIndex(Calendars.DELETED)));
            list.put(Calendars.MAX_REMINDERS, ""+c.getInt(c.getColumnIndex(Calendars.MAX_REMINDERS)));
                    
            list.put(Calendars.ALLOWED_REMINDERS, c.getString(c.getColumnIndex(Calendars.ALLOWED_REMINDERS)));
            list.put(Calendars.ALLOWED_AVAILABILITY, c.getString(c.getColumnIndex(Calendars.ALLOWED_AVAILABILITY)));
            list.put(Calendars.ALLOWED_ATTENDEE_TYPES, c.getString(c.getColumnIndex(Calendars.ALLOWED_ATTENDEE_TYPES)));
                    
            list.put(Calendars.CAN_MODIFY_TIME_ZONE, ""+c.getInt(c.getColumnIndex(Calendars.CAN_MODIFY_TIME_ZONE)));
            list.put(Calendars.CAN_ORGANIZER_RESPOND, ""+c.getInt(c.getColumnIndex(Calendars.CAN_ORGANIZER_RESPOND)));
            list.put(Calendars.CAN_PARTIALLY_UPDATE, ""+c.getInt(c.getColumnIndex(Calendars.CAN_PARTIALLY_UPDATE)));
                    
            list.put(Calendars.CALENDAR_LOCATION, c.getString(c.getColumnIndex(Calendars.CALENDAR_LOCATION)));

            list.put(Calendars.CAL_SYNC1, c.getString(c.getColumnIndex(Calendars.CAL_SYNC1)));
            list.put(Calendars.CAL_SYNC2, c.getString(c.getColumnIndex(Calendars.CAL_SYNC2)));
            list.put(Calendars.CAL_SYNC3,c.getString(c.getColumnIndex(Calendars.CAL_SYNC3)));
            list.put(Calendars.CAL_SYNC4,c.getString(c.getColumnIndex(Calendars.CAL_SYNC4)));
            list.put(Calendars.CAL_SYNC5,c.getString(c.getColumnIndex(Calendars.CAL_SYNC5)));
            list.put(Calendars.CAL_SYNC6,c.getString(c.getColumnIndex(Calendars.CAL_SYNC6)));
            list.put(Calendars.CAL_SYNC7,c.getString(c.getColumnIndex(Calendars.CAL_SYNC7)));
            list.put(Calendars.CAL_SYNC8,c.getString(c.getColumnIndex(Calendars.CAL_SYNC8)));
            list.put(Calendars.CAL_SYNC9,c.getString(c.getColumnIndex(Calendars.CAL_SYNC9)));
            list.put(Calendars.CAL_SYNC10,c.getString(c.getColumnIndex(Calendars.CAL_SYNC10)));*/

            StringBuilder sb = new StringBuilder("--CALENDAR DUMP--");
            for (Entry<String, String> s : list.entrySet()) {
                sb.append("(" + s.getKey() + "|" + s.getValue() + ")");
            }
            sb.append("----------");
            Log.i(C.TAG, sb.toString());
            list.clear();
        }
        c.close();
    }
}

Related Tutorials