1921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickpage.title=Calendar Provider
2921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick@jd:body
3921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
4921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<div id="qv-wrapper">
5921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<div id="qv">
6921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <h2>In this document</h2>
7921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <ol>
8921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <li><a href="#overview">Basics</a></li>
9921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <li><a href="#manifest">User Permissions</a></li>
10921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <li><a href="#calendar">Calendars table</a>
11921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<ol>
12921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      <li><a href="#query">Querying a calendar</a></li>
13921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      <li><a href="#modify-calendar">Modifying a calendar</a></li>
14921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      <li><a href="#insert-calendar">Inserting a calendar</a></li>
15921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    </ol>
16921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </li>
17921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <li><a href="#events">Events table</a>
18921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<ol>
19921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      <li><a href="#add-event">Adding Events</a></li>
20921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      <li><a href="#update-event">Updating Events</a></li>
21921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      <li><a href="#delete-event">Deleting Events</a></li>
22921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    </ol>
23921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </li>
24921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <li><a href="#attendees">Attendees table</a>
25921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<ol>
26921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      <li><a href="#add-attendees">Adding Attendees</a></li>
27921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    </ol>
28921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </li>
29921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <li><a href="#reminders">Reminders table</a>
30921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<ol>
31921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      <li><a href="#add-reminders">Adding Reminders</a></li>
32921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    </ol>
33921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </li>
34921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <li><a href="#instances">Instances table</a>
35921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <ol>
36921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      <li><a href="#query-instances">Querying the Instances table</a></li>
37921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </ol></li>
38921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <li><a href="#intents">Calendar Intents</a>
39921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <ol>
40921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      <li><a href="#intent-insert">Using an intent to insert an event</a></li>
41921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      <li><a href="#intent-edit">Using an intent to edit an event</a></li>
42921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      <li><a href="#intent-view">Using intents to view calendar data</a></li>
43921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    </ol>
44921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </li>
45921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  
46921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <li><a href="#sync-adapter">Sync Adapters</a></li>
47921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</ol>
48921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
49921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <h2>Key classes</h2>
50921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <ol>
51921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      <li>{@link android.provider.CalendarContract.Calendars}</li>
52921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      <li>{@link android.provider.CalendarContract.Events}</li>
53921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      <li>{@link android.provider.CalendarContract.Attendees}</li>
54921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      <li>{@link android.provider.CalendarContract.Reminders}</li>
55921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    </ol>
56921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</div>
57921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</div>
58921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
59921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>The Calendar Provider is a repository for a user's calendar events. The
60921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickCalendar Provider API allows you to perform query, insert, update, and delete
61921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickoperations on calendars, events, attendees, reminders, and so on.</p>
62921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
63921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
64921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>The Calender Provider API can be used by applications and sync adapters. The
65921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickrules vary depending on what type of program is making the calls. This document
66921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickfocuses primarily on using the Calendar Provider API as an application. For 
67921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormicka discussion of how sync adapters are different, see 
68921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<a href="#sync-adapter">Sync Adapters</a>.</p>
69921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
70921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
71921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>Normally, to read or write calendar data, an application's manifest must
72921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickinclude the proper permissions, described in <a href="#manifest">User
73921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickPermissions</a>. To make performing common operations easier, the Calendar
74921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickProvider offers a set of intents, as described in <a href="#intents">Calendar
75921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickIntents</a>. These intents take users to the Calendar application to insert, view,
76921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickand edit events. The user interacts with the Calendar application and then
77921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickreturns to the original application. Thus your application doesn't need to request permissions,
78921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormicknor does it need to provide a user interface to view or create events.</p>
79921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
80921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<h2 id="overview">Basics</h2>
81921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
82921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p><a href="{@docRoot}guide/topics/providers/content-providers.html">Content providers</a> store data and make it accessible to 
83921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickapplications. The content providers offered by the Android platform (including the Calendar Provider) typically expose data as a set of tables based on a
84921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickrelational database model, where each row is a record and each column is data of
85921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormicka particular type and meaning. Through the Calendar Provider API, applications
86921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickand sync adapters can get read/write access to the database tables that hold a
87921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickuser's calendar data.</p>
88921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
89921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>Every content provider exposes a public URI (wrapped as a 
90921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick{@link android.net.Uri} 
91921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickobject) that uniquely identifies its data set.  A content provider that controls
92921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick multiple data sets (multiple tables) exposes a separate URI for each one.  All 
93921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickURIs for providers begin with the string &quot;content://&quot;.  This
94921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickidentifies the data as being controlled by a content provider. The Calendar
95921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickProvider defines constants for the URIs for each of its classes (tables). These
96921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickURIs have the format <code><em>&lt;class&gt;</em>.CONTENT_URI</code>. For
97921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickexample, {@link android.provider.CalendarContract.Events#CONTENT_URI Events.CONTENT_URI}.</p>
98921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
99921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>Figure 1 shows a graphical representation of the Calendar Provider data model. It shows the
100921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickmain tables and the fields that link them to each other.</p>
101921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
102921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<img src="{@docRoot}images/providers/datamodel.png" alt="Calendar Provider Data Model"/>
103921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p class="img-caption"><strong>Figure 1.</strong> Calendar Provider data model.</p>
104921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
105921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>A user can have multiple calendars, and different calendars can be associated with different types of accounts (Google Calendar, Exchange, and so on).</p>
106921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
107921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>The {@link android.provider.CalendarContract} defines the data model of calendar and event related information. This data is stored in a number of tables, listed below.</p>
108921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
109921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<table>
110921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
111921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <th>Table (Class)</th>
112921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <th>Description</th>
113921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
114921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
115921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td><p>{@link android.provider.CalendarContract.Calendars}</p></td>
116921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
117921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>This table holds 
118921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickthe calendar-specific information. Each  row in this table contains the details for
119921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormicka single calendar, such as the  name, color, sync information, and so on.</td>
120921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
121921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
122921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.Events}</td>
123921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
124921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>This table holds the
125921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickevent-specific information. Each row  in this table has the information for a single
126921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickevent&mdash;for example, event title, location, start time, end
127921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormicktime, and so on. The event can occur one-time or can recur multiple times. Attendees,
128921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickreminders, and extended  properties are stored in separate tables. 
129921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickThey each have an {@link android.provider.CalendarContract.AttendeesColumns#EVENT_ID} 
130921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickthat references the {@link android.provider.BaseColumns#_ID} in the Events table.</td>
131921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
132921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
133921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
134921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.Instances}</td>
135921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
136921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>This table holds the
137921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickstart and end time for each occurrence of an event. Each row in this table
138921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickrepresents a single event occurrence. For one-time events there is a 1:1 mapping
139921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickof instances to events. For recurring events, multiple rows are automatically
140921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick generated that correspond to multiple occurrences of that event.</td>
141921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
142921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
143921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.Attendees}</td>
144921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
145921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>This table holds the
146921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickevent attendee (guest) information. Each row represents a single guest of an
147921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickevent. It specifies the type of guest and the guest's attendance response
148921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickfor the event.</td>
149921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
150921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
151921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.Reminders}</td>
152921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
153921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>This table holds the
154921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickalert/notification data. Each row represents a single alert for an event. An
155921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickevent can have multiple reminders. The maximum number of reminders per event is
156921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickspecified in 
157921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick{@link android.provider.CalendarContract.CalendarColumns#MAX_REMINDERS}, 
158921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickwhich is set by the sync adapter that
159921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickowns  the given calendar. Reminders are specified in minutes before the event
160921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickand have a method that determines how the user will be alerted.</td>
161921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
162921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  
163921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</table>
164921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
165921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>The Calendar Provider API is designed to be flexible and powerful. At the
166921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormicksame time, it's important to provide a good end user experience and
167921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickprotect the integrity of the calendar and its data. To this end, here are
168921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormicksome things to keep in mind when using the API:</p>
169921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
170921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<ul>
171921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
172921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<li><strong>Inserting, updating, and viewing calendar events.</strong> To directly insert, modify, and read events from the Calendar Provider, you need the appropriate <a href="#manifest">permissions</a>. However, if you're not building a full-fledged calendar application or sync adapter, requesting these permissions isn't necessary. You can instead use intents supported by Android's Calendar application to hand off read and write operations to that application. When you use the intents, your application sends users to the Calendar application to perform the desired operation
173921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickin a pre-filled form. After they're done, they're returned to your application.
174921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickBy designing your application to perform common operations through the Calendar,
175921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickyou provide users with a consistent, robust user interface. This is the
176921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickrecommended approach. For more information, see <a href="#intents">Calendar
177921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickIntents</a>.</p>
178921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
179921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
180921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<li><strong>Sync adapters.</strong> A sync adapter synchronizes the calendar data
181921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickon a user's device with another server or data source. In the 
182921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick{@link android.provider.CalendarContract.Calendars} and
183921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick{@link android.provider.CalendarContract.Events} tables, 
184921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickthere are columns that are reserved for the sync adapters to use.
185921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickThe provider and applications should not modify them. In fact, they are not
186921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickvisible unless they are accessed as a sync adapter. For more information about
187921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormicksync adapters, see <a href="#sync-adapter">Sync Adapters</a>.</li>
188921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
189921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</ul>
190921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
191921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
192921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<h2 id="manifest">User Permissions</h2>
193921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
194921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>To read calendar data, an application must include the {@link
195921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.Manifest.permission#READ_CALENDAR} permission in its manifest file. It
196921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickmust include the {@link android.Manifest.permission#WRITE_CALENDAR} permission
197921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickto delete, insert or update calendar data:</p>
198921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
199921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<pre>
200921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
201921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android"...>;
202921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    &lt;uses-sdk android:minSdkVersion=&quot;14&quot; /&gt;
203921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    &lt;uses-permission android:name=&quot;android.permission.READ_CALENDAR&quot; /&gt;
204921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    &lt;uses-permission android:name=&quot;android.permission.WRITE_CALENDAR&quot; /&gt;
205921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    ...
206921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick&lt;/manifest&gt;
207921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</pre>
208921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
209921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
210921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<h2 id="calendar">Calendars Table</h2>
211921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
212921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>The {@link android.provider.CalendarContract.Calendars} table contains details 
213921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickfor individual calendars. The following
214921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickCalendars columns are writable by both an application and a <a href="#sync-adapter">sync adapter</a>. 
215921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickFor a full list of supported fields, see the
216921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick{@link android.provider.CalendarContract.Calendars} reference.</p>
217921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<table>
218921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
219921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <th>Constant</th>
220921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <th>Description</th>
221921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
222921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
223921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.Calendars#NAME}</td>
224921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The name of the calendar.</td>
225921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
226921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
227921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.Calendars#CALENDAR_DISPLAY_NAME}</td>
228921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The name of this calendar that is displayed to the user.</td>
229921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
230921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
231921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.Calendars#VISIBLE}</td>
232921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
233921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>A boolean indicating whether the calendar is selected to be displayed. A
234921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickvalue of 0 indicates that events associated with this calendar should not be
235921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickshown.  A value of 1 indicates that events associated with this calendar should
236921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickbe shown. This value affects the generation of rows in the {@link
237921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.CalendarContract.Instances} table.</td>
238921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
239921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
240921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
241921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
242921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.CalendarColumns#SYNC_EVENTS}</td>
243921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
244921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>A boolean indicating whether the calendar should be synced and have its
245921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickevents stored on the device. A value of 0 says do not sync this calendar or
246921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickstore its events on the device.  A value of 1 says sync events for this calendar
247921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickand store its events on the device.</td>
248921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
249921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</table>
250921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
251921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<h3 id="query">Querying a calendar</h3>
252921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
25350e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main<p>Here is an example that shows how to get the calendars that are owned by a particular
254921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickuser. For simplicity's sake, in this example the query operation is shown in the
255921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickuser interface thread ("main thread"). In practice, this should be done in an asynchronous
256921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickthread instead of on the main thread. For more discussion, see 
25750e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main<a href="{@docRoot}guide/components/loaders.html">Loaders</a>. If you are not just 
25850e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainreading data but modifying it, see {@link android.content.AsyncQueryHandler}.
259921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</p>
260921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
261921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
262921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<pre>
26350e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main// Projection array. Creating indices for this array instead of doing
26450e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main// dynamic lookups improves performance.
26550e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainpublic static final String[] EVENT_PROJECTION = new String[] {
266921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    Calendars._ID,                           // 0
267921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    Calendars.ACCOUNT_NAME,                  // 1
26850e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main    Calendars.CALENDAR_DISPLAY_NAME,         // 2
26950e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main    Calendars.OWNER_ACCOUNT                  // 3
27050e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main};
271921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  
27250e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main// The indices for the projection array above.
27350e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainprivate static final int PROJECTION_ID_INDEX = 0;
27450e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainprivate static final int PROJECTION_ACCOUNT_NAME_INDEX = 1;
27550e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainprivate static final int PROJECTION_DISPLAY_NAME_INDEX = 2;
27650e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainprivate static final int PROJECTION_OWNER_ACCOUNT_INDEX = 3;</pre>
277921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  
278921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
279921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<div class="sidebox-wrapper"> <div class="sidebox"> <h3>Why must you include
280921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickACCOUNT_TYPE?</h3> <p>If you query on a {@link
281921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.CalendarContract.Calendars#ACCOUNT_NAME
282921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickCalendars.ACCOUNT_NAME}, you must also include 
283921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick{@link android.provider.CalendarContract.Calendars#ACCOUNT_TYPE Calendars.ACCOUNT_TYPE}
284921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickin the selection. That is because a given account is
285921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickonly considered unique given both its <code>ACCOUNT_NAME</code> and its
28620bfe4e68dbdbdb3d726c260b9223f03a3c5df75Michael Chan<code>ACCOUNT_TYPE</code>. The <code>ACCOUNT_TYPE</code> is the string corresponding to the
28720bfe4e68dbdbdb3d726c260b9223f03a3c5df75Michael Chanaccount authenticator that was used when the account was registered with the
28820bfe4e68dbdbdb3d726c260b9223f03a3c5df75Michael Chan{@link android.accounts.AccountManager}. There is also a special type of account called {@link
289921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.CalendarContract#ACCOUNT_TYPE_LOCAL} for calendars not
290921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickassociated with a device account. {@link
291921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.CalendarContract#ACCOUNT_TYPE_LOCAL} accounts do not get
292921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormicksynced.</p> </div> </div> 
293921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
294921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
295921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p> In the next part of the example, you construct your query. The selection
296921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickspecifies the criteria for the query. In this example the query is looking for
29750e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Maincalendars that have the <code>ACCOUNT_NAME</code>
29850e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main"sampleuser@google.com", the <code>ACCOUNT_TYPE</code>
29950e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main"com.google", and the <code>OWNER_ACCOUNT</code>
30050e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main"sampleuser@google.com". If you want to see all calendars that a user
30150e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainhas viewed, not just calendars the user owns, omit the <code>OWNER_ACCOUNT</code>.
30250e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott MainThe query returns a {@link android.database.Cursor}
303921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickobject that you can use to traverse the result set returned by the database
30450e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainquery. For more discussion of using queries in content providers, 
30550e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainsee <a href="{@docRoot}guide/topics/providers/content-providers.html">Content Providers</a>.</p>
306921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
307921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
308921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<pre>// Run query
309921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickCursor cur = null;
310921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickContentResolver cr = getContentResolver();
311921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickUri uri = Calendars.CONTENT_URI;   
312921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickString selection = "((" + Calendars.ACCOUNT_NAME + " = ?) AND (" 
31350e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main                        + Calendars.ACCOUNT_TYPE + " = ?) AND ("
31450e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main                        + Calendars.OWNER_ACCOUNT + " = ?))";
31550e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott MainString[] selectionArgs = new String[] {"sampleuser@gmail.com", "com.google",
31650e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main        "sampleuser@gmail.com"}; 
317921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick// Submit the query and get a Cursor object back. 
318921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickcur = cr.query(uri, EVENT_PROJECTION, selection, selectionArgs, null);</pre>
319921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
320921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>This next section uses the cursor to step through the result set. It uses the
321921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickconstants that were set up at the beginning of the example to return the values
322921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickfor each field.</p>
323921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
324921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<pre>// Use the cursor to step through the returned records
325921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickwhile (cur.moveToNext()) {
326921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    long calID = 0;
327921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    String displayName = null;
32850e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main    String accountName = null;
32950e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main    String ownerName = null;
330921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      
331921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    // Get the field values
332921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    calID = cur.getLong(PROJECTION_ID_INDEX);
333921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    displayName = cur.getString(PROJECTION_DISPLAY_NAME_INDEX);
334921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    accountName = cur.getString(PROJECTION_ACCOUNT_NAME_INDEX);
33550e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main    ownerName = cur.getString(PROJECTION_OWNER_ACCOUNT_INDEX);
336921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick              
337921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    // Do something with the values...
338921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
339921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick   ...
340921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick}
341921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</pre>
342921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  
343921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<h3 id="modify-calendar">Modifying a calendar</h3>
344921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
345921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>To perform an update of an calendar, you can provide the {@link
346921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.BaseColumns#_ID} of the calendar either as an appended ID to
347921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickthe Uri 
348921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
349921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick({@link android.content.ContentUris#withAppendedId(android.net.Uri,long) withAppendedId()}) 
350921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickor as the first selection item. The  selection
351921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickshould start with <code>&quot;_id=?&quot;</code>, and the first
352921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<code>selectionArg</code> should be  the {@link
353921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.BaseColumns#_ID} of the calendar. 
354921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickYou can also do updates by encoding the ID in the URI. This example changes a
355921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickcalendar's display name using the 
356921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick({@link android.content.ContentUris#withAppendedId(android.net.Uri,long) withAppendedId()}) 
357921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickapproach:</p>
358921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
359921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<pre>private static final String DEBUG_TAG = "MyActivity";
360921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick...
361921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormicklong calID = 2;
362921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickContentValues values = new ContentValues();
363921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick// The new display name for the calendar
364921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickvalues.put(Calendars.CALENDAR_DISPLAY_NAME, &quot;Trevor's Calendar&quot;);
365921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickUri updateUri = ContentUris.withAppendedId(Calendars.CONTENT_URI, calID);
366921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickint rows = getContentResolver().update(updateUri, values, null, null);
367921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickLog.i(DEBUG_TAG, &quot;Rows updated: &quot; + rows);</pre>
368921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
369921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<h3 id="insert-calendar">Inserting a calendar</h2>
370921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
371921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>Calendars are  designed to be primarily managed by a sync adapter, so you
372921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickshould only insert new calendars as a sync adapter. For the most part,
373921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickapplications can only make superficial changes to calendars, such as changing the display name. If
374921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickan application needs to create a local calendar, it can do this by performing
375921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickthe calendar insertion as a sync adapter, using an {@link
376921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.CalendarContract.SyncColumns#ACCOUNT_TYPE} of {@link
377921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.CalendarContract#ACCOUNT_TYPE_LOCAL}.
378921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick{@link android.provider.CalendarContract#ACCOUNT_TYPE_LOCAL} 
379921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickis a special account type for calendars that are not
380921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickassociated with a device account. Calendars of this type are not synced to a server. For a
381921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickdiscussion of sync adapters, see <a href="#sync-adapter">Sync Adapters</a>.</p>
382921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
383921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<h2 id="events">Events Table</h2>
384921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
385921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>The {@link android.provider.CalendarContract.Events} table contains details
386921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickfor individual events. To add, update, or delete  events, an application must
387921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickinclude the {@link android.Manifest.permission#WRITE_CALENDAR} permission in its
388921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<a href="#manifest">manifest file</a>.</p>
389921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
390921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>The following Events columns are writable by both an application and a sync
391921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickadapter. For a full list of supported fields, see the {@link
392921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.CalendarContract.Events} reference.</p>
393921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
394921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<table>
395921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
396921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <th>Constant</th>
397921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <th>Description</th>
398921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
399921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
400921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.EventsColumns#CALENDAR_ID}</td>
401921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The {@link android.provider.BaseColumns#_ID} of the calendar the event belongs to.</td>
402921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
403921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
404921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.EventsColumns#ORGANIZER}</td>
405921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>Email of the organizer (owner) of the event.</td>
406921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
407921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
408921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.EventsColumns#TITLE}</td>
409921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The title of the event.</td>
410921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
411921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
412921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.EventsColumns#EVENT_LOCATION}</td>
413921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>Where the event takes place. </td>
414921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
415921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
416921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.EventsColumns#DESCRIPTION}</td>
417921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The description of the event.</td>
418921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
419921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
420921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.EventsColumns#DTSTART}</td>
421921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The time the event starts in UTC milliseconds since the epoch. </td>
422921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
423921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
424921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.EventsColumns#DTEND}</td>
425921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The time the event ends in UTC milliseconds since the epoch. </td>
426921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
427921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
428921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.EventsColumns#EVENT_TIMEZONE}</td>
429921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The time zone for the event.</td>
430921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
431921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
432921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.EventsColumns#EVENT_END_TIMEZONE}</td>
433921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The time zone for the end time of the event.</td>
434921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
435921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
436921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.EventsColumns#DURATION}</td>
437921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
438921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The duration of the event in <a
439921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickhref="http://tools.ietf.org/html/rfc5545#section-3.8.2.5">RFC5545</a> format.
440921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickFor example, a value of <code>&quot;PT1H&quot;</code> states that the event
441921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickshould last one hour, and a value of <code>&quot;P2W&quot;</code> indicates a
442921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickduration of 2 weeks. </td>
443921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
444921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
445921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
446921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
447921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.EventsColumns#ALL_DAY}</td>
448921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
449921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>A value of 1 indicates this event occupies the entire day, as defined by
450921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickthe local time zone. A value of 0 indicates it is a regular event that may start
451921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickand end at any time during a day.</td>
452921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
453921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
454921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
455921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  
456921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  
457921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
458921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.EventsColumns#RRULE}</td>
459921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
460921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The recurrence rule for the event format. For
461921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickexample, <code>&quot;FREQ=WEEKLY;COUNT=10;WKST=SU&quot;</code>. You can find
462921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickmore examples <a
463921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickhref="http://tools.ietf.org/html/rfc5545#section-3.8.5.3">here</a>.</td>
464921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
465921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
466921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  
467921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
468921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.EventsColumns#RDATE}</td>
469921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The recurrence dates for the event. 
470921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    You typically use {@link android.provider.CalendarContract.EventsColumns#RDATE} 
471921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    in conjunction with {@link android.provider.CalendarContract.EventsColumns#RRULE} 
472921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    to define an aggregate set of
473921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickrepeating occurrences. For more discussion, see the <a
474921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickhref="http://tools.ietf.org/html/rfc5545#section-3.8.5.2">RFC5545 spec</a>.</td>
475921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</tr>
476921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick 
477921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
478921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.EventsColumns#AVAILABILITY}</td>
479921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
480921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>If this event counts as busy time or is free time that can be 
481921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickscheduled over. </td>
482921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
483921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
484921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
485921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.EventsColumns#GUESTS_CAN_MODIFY}</td>
486921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>Whether guests can modify the event. </td>
487921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
488921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
489921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.EventsColumns#GUESTS_CAN_INVITE_OTHERS}</td>
490921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>Whether guests can invite other guests. </td>
491921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
492921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
493921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.EventsColumns#GUESTS_CAN_SEE_GUESTS}</td>
494921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>Whether guests can see the list of attendees.</td>
495921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
496921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</table>
497921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
498921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<h3 id="add-event">Adding Events</h3>
499921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
500921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>When your application inserts a new event, we recommend that you use an
501921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick{@link android.content.Intent#ACTION_INSERT INSERT} Intent, as described in <a
502921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickhref="#intent-insert">Using an intent to insert an event</a>. However, if you
503921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickneed to, you can insert events directly. This section describes how to do
504921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickthis.</p>
505921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
506921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
507921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>Here are the rules for inserting a new event: </p>
508921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<ul>
509921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
510921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <li>You must include  {@link
511921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.CalendarContract.EventsColumns#CALENDAR_ID} and {@link
512921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.CalendarContract.EventsColumns#DTSTART}.</li>
513921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
514921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<li>You must include an {@link
515921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.CalendarContract.EventsColumns#EVENT_TIMEZONE}. To get a list
516921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickof the system's installed time zone IDs, use {@link
517921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickjava.util.TimeZone#getAvailableIDs()}. Note that this rule does not apply if
518921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickyou're inserting an event through the {@link
519921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.content.Intent#ACTION_INSERT INSERT} Intent, described in <a
520921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickhref="#intent-insert">Using an intent to insert an event</a>&mdash;in that
521921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickscenario, a default time zone is supplied.</li>
522921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  
523921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <li>For non-recurring events, you must include {@link
524921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.CalendarContract.EventsColumns#DTEND}. </li>
525921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  
526921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  
527921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <li>For recurring events, you must include a {@link
528921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.CalendarContract.EventsColumns#DURATION} in addition to  {@link
529921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.CalendarContract.EventsColumns#RRULE} or {@link
530921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.CalendarContract.EventsColumns#RDATE}. Note that this rule does not apply if
531921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickyou're inserting an event through the {@link
532921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.content.Intent#ACTION_INSERT INSERT} Intent, described in <a
533921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickhref="#intent-insert">Using an intent to insert an event</a>&mdash;in that
534921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickscenario, you can use an {@link
535921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.CalendarContract.EventsColumns#RRULE} in conjunction with {@link android.provider.CalendarContract.EventsColumns#DTSTART} and {@link android.provider.CalendarContract.EventsColumns#DTEND}, and the Calendar application 
536921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickconverts it to a duration automatically.</li>
537921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  
538921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</ul>
539921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
540921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>Here is an example of inserting an event. This is being performed in the UI
541921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickthread for simplicity. In practice, inserts and updates should be done in an
542921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickasynchronous thread to move the action into a background thread. For more
543921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickinformation, see {@link android.content.AsyncQueryHandler}.</p>
544921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
545921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
546921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<pre>
547921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormicklong calID = 3;
548921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormicklong startMillis = 0; 
549921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormicklong endMillis = 0;     
550921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickCalendar beginTime = Calendar.getInstance();
551921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickbeginTime.set(2012, 9, 14, 7, 30);
552921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickstartMillis = beginTime.getTimeInMillis();
553921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickCalendar endTime = Calendar.getInstance();
554921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickendTime.set(2012, 9, 14, 8, 45);
555921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickendMillis = endTime.getTimeInMillis();
556921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick...
557921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
558921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickContentResolver cr = getContentResolver();
559921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickContentValues values = new ContentValues();
560921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickvalues.put(Events.DTSTART, startMillis);
561921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickvalues.put(Events.DTEND, endMillis);
562921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickvalues.put(Events.TITLE, &quot;Jazzercise&quot;);
563921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickvalues.put(Events.DESCRIPTION, &quot;Group workout&quot;);
564921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickvalues.put(Events.CALENDAR_ID, calID);
565921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickvalues.put(Events.EVENT_TIMEZONE, "America/Los_Angeles");
566921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickUri uri = cr.insert(Events.CONTENT_URI, values);
567921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
568921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick// get the event ID that is the last element in the Uri
569921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormicklong eventID = Long.parseLong(uri.getLastPathSegment());
570921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick// 
571921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick// ... do something with event ID
572921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick//
573921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick//</pre>
574921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
575921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p class="note"><strong>Note:</strong> See how this example captures the event
576921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickID after the event is created. This is the easiest way to get an event ID. You often
577921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickneed the event ID to perform other calendar operations&mdash;for example, to add
578921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickattendees or reminders to an event.</p>
579921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
580921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
581921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<h3 id="update-event">Updating Events</h3>
582921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
583921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>When your application wants to allow the user to edit an event, we recommend
584921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickthat you use an {@link android.content.Intent#ACTION_EDIT EDIT} Intent, as
585921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickdescribed in <a href="#intent-edit">Using an intent to edit an  event</a>.
586921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickHowever, if you need to, you can edit events directly. To perform an update of
587921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickan Event, you can provide the <code>_ID</code> of the 
588921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickevent either as an appended ID to the Uri ({@link
589921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.content.ContentUris#withAppendedId(android.net.Uri,long) withAppendedId()}) 
590921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickor as the first selection item. 
591921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickThe selection should start with <code>&quot;_id=?&quot;</code>, and the first
592921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<code>selectionArg</code> should be  the <code>_ID</code> of the event. You can
593921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickalso do updates using a selection with no ID. Here is an example of updating an
594921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickevent. It changes the title of the event using the 
595921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick{@link android.content.ContentUris#withAppendedId(android.net.Uri,long) withAppendedId()}
596921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickapproach:</p>
597921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
598921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
599921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<pre>private static final String DEBUG_TAG = "MyActivity";
600921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick...
601921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormicklong eventID = 188;
602921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick...
603921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickContentResolver cr = getContentResolver();
604921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickContentValues values = new ContentValues();
605921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickUri updateUri = null;
606921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick// The new title for the event
607921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickvalues.put(Events.TITLE, &quot;Kickboxing&quot;); 
608921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickmyUri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID);
609921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickint rows = getContentResolver().update(updateUri, values, null, null);
610921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickLog.i(DEBUG_TAG, &quot;Rows updated: &quot; + rows);  </pre>
611921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
612921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<h3 id="delete-event">Deleting Events</h3>
613921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
614921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>You can delete an event either by its {@link
615921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.BaseColumns#_ID} as an appended  ID on the URI, or by using
616921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickstandard selection. If you use an appended ID, you can't also do a selection.
617921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickThere are two versions of delete: as an application and as a sync adapter. An
618921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickapplication delete sets the <em>deleted</em> column to 1. This flag that tells
619921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickthe sync adapter that the row was deleted and that this deletion should be
620921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickpropagated to the server. A sync adapter delete removes the event from the
621921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickdatabase along with all its associated data. Here is an example of application
622921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickdeleting an event through its {@link android.provider.BaseColumns#_ID}:</p>
623921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
624921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
625921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<pre>private static final String DEBUG_TAG = "MyActivity";
626921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick...
627921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormicklong eventID = 201;
628921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick...
629921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickContentResolver cr = getContentResolver();
630921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickContentValues values = new ContentValues();
631921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickUri deleteUri = null;
632921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickdeleteUri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID);
633921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickint rows = getContentResolver().delete(deleteUri, null, null);
634921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickLog.i(DEBUG_TAG, &quot;Rows deleted: &quot; + rows);  
635921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</pre>
636921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
637921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<h2 id="attendees">Attendees Table</h2>
638921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
639921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>Each row of the {@link android.provider.CalendarContract.Attendees} table
640921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickrepresents a single attendee or guest of an event. Calling 
641921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick{@link android.provider.CalendarContract.Reminders#query(android.content.ContentResolver, long, java.lang.String[]) query()} 
642921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickreturns a list of attendees for  the
643921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickevent with the given {@link android.provider.CalendarContract.AttendeesColumns#EVENT_ID}. 
644921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickThis  {@link android.provider.CalendarContract.AttendeesColumns#EVENT_ID} 
645921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickmust match the {@link
646921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.BaseColumns#_ID} of a particular event.</p> 
647921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
648921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>The following table lists the
649921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickwritable fields. When inserting a new attendee, you must include all of them 
650921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickexcept <code>ATTENDEE_NAME</code>.
651921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</p>
652921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
653921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
654921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<table>
655921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
656921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <th>Constant</th>
657921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <th>Description</th>
658921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
659921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
660921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.AttendeesColumns#EVENT_ID}</td>
661921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The ID of the event.</td>
662921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
663921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
664921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.AttendeesColumns#ATTENDEE_NAME}</td>
665921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The name of the attendee.</td>
666921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
667921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
668921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.AttendeesColumns#ATTENDEE_EMAIL}</td>
669921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The email address of the attendee.</td>
670921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
671921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
672921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.AttendeesColumns#ATTENDEE_RELATIONSHIP}</td>
673921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td><p>The relationship of the attendee to the event. One of:</p>
674921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      <ul>
675921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        <li>{@link android.provider.CalendarContract.AttendeesColumns#RELATIONSHIP_ATTENDEE}</li>
676921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        <li>{@link android.provider.CalendarContract.AttendeesColumns#RELATIONSHIP_NONE}</li>
677921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        <li>{@link android.provider.CalendarContract.AttendeesColumns#RELATIONSHIP_ORGANIZER}</li>
678921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        <li>{@link android.provider.CalendarContract.AttendeesColumns#RELATIONSHIP_PERFORMER}</li>
679921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        <li>{@link android.provider.CalendarContract.AttendeesColumns#RELATIONSHIP_SPEAKER}</li>
680921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    </ul>
681921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    </td>
682921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
683921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
684921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.AttendeesColumns#ATTENDEE_TYPE}</td>
685921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td><p>The type of attendee. One of: </p>
686921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      <ul>
687921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        <li>{@link android.provider.CalendarContract.AttendeesColumns#TYPE_REQUIRED}</li>
688921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        <li>{@link android.provider.CalendarContract.AttendeesColumns#TYPE_OPTIONAL}</li>
689921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    </ul></td>
690921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
691921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
692921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.AttendeesColumns#ATTENDEE_STATUS}</td>
693921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td><p>The attendance status of the attendee. One of:</p>
694921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      <ul>
695921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        <li>{@link android.provider.CalendarContract.AttendeesColumns#ATTENDEE_STATUS_ACCEPTED}</li>
696921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        <li>{@link android.provider.CalendarContract.AttendeesColumns#ATTENDEE_STATUS_DECLINED}</li>
697921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        <li>{@link android.provider.CalendarContract.AttendeesColumns#ATTENDEE_STATUS_INVITED}</li>
698921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        <li>{@link android.provider.CalendarContract.AttendeesColumns#ATTENDEE_STATUS_NONE}</li>
699921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        <li>{@link android.provider.CalendarContract.AttendeesColumns#ATTENDEE_STATUS_TENTATIVE}</li>
700921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    </ul></td>
701921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
702921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</table>
703921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
704921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<h3 id="add-attendees">Adding Attendees</h3>
705921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
706921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>Here is an example that adds a single attendee to an event. Note that the
707921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick{@link android.provider.CalendarContract.AttendeesColumns#EVENT_ID} 
708921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickis required:</p>
709921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
710921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<pre>
711921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormicklong eventID = 202;
712921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick...
713921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickContentResolver cr = getContentResolver();
714921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickContentValues values = new ContentValues();
715921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickvalues.put(Attendees.ATTENDEE_NAME, &quot;Trevor&quot;);
716921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickvalues.put(Attendees.ATTENDEE_EMAIL, &quot;trevor@example.com&quot;);
717921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickvalues.put(Attendees.ATTENDEE_RELATIONSHIP, Attendees.RELATIONSHIP_ATTENDEE);
718921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickvalues.put(Attendees.ATTENDEE_TYPE, Attendees.TYPE_OPTIONAL);
719921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickvalues.put(Attendees.ATTENDEE_STATUS, Attendees.ATTENDEE_STATUS_INVITED);
720921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickvalues.put(Attendees.EVENT_ID, eventID);
721921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickUri uri = cr.insert(Attendees.CONTENT_URI, values);
722921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</pre>
723921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
724921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<h2 id="reminders">Reminders Table</h2>
725921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
726921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>Each row of the {@link android.provider.CalendarContract.Reminders} table
727921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickrepresents a single reminder for an event. Calling 
728921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick{@link android.provider.CalendarContract.Reminders#query(android.content.ContentResolver, long, java.lang.String[]) query()}  returns a list of reminders for the
729921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickevent with the given 
730921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick{@link android.provider.CalendarContract.AttendeesColumns#EVENT_ID}.</p>
731921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
732921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
733921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>The following table lists the writable fields for reminders. All of them must
734921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickbe included when inserting a new reminder. Note that sync adapters specify the
735921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormicktypes of reminders they support in the {@link
736921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.CalendarContract.Calendars} table. See 
737921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick{@link android.provider.CalendarContract.CalendarColumns#ALLOWED_REMINDERS} 
738921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickfor details.</p>
739921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
740921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
741921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<table>
742921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
743921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <th>Constant</th>
744921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <th>Description</th>
745921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
746921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
747921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.RemindersColumns#EVENT_ID}</td>
748921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The ID of the event.</td>
749921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
750921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
751921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.RemindersColumns#MINUTES}</td>
752921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The minutes prior to the event that the reminder should fire.</td>
753921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
754921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
755921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.RemindersColumns#METHOD}</td>
756921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td><p>The alarm method, as set on the server. One of:</p>
757921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      <ul>
758921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        <li>{@link android.provider.CalendarContract.RemindersColumns#METHOD_ALERT}</li>
759921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        <li>{@link android.provider.CalendarContract.RemindersColumns#METHOD_DEFAULT}</li>
760921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        <li>{@link android.provider.CalendarContract.RemindersColumns#METHOD_EMAIL}</li>
761921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        <li>{@link android.provider.CalendarContract.RemindersColumns#METHOD_SMS}</li>
762921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    </ul></td>
763921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
764921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</table>
765921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
766921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<h3 id="add-reminders">Adding Reminders</h3>
767921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
768921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>This example adds a reminder to an event. The reminder fires 15
769921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickminutes before the event.</p>
770921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<pre>
771921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormicklong eventID = 221;
772921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick...
773921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickContentResolver cr = getContentResolver();
774921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickContentValues values = new ContentValues();
775921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickvalues.put(Reminders.MINUTES, 15);
776921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickvalues.put(Reminders.EVENT_ID, eventID);
777921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickvalues.put(Reminders.METHOD, Reminders.METHOD_ALERT);
778921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickUri uri = cr.insert(Reminders.CONTENT_URI, values);</pre>
779921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
780921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<h2 id="instances">Instances Table</h2>
781921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
782921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>The 
783921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick{@link android.provider.CalendarContract.Instances} table holds the
784921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickstart and end time for occurrences of an event. Each row in this table
785921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickrepresents a single event occurrence. The instances table is not writable and only
786921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickprovides a  way to query event occurrences. </p>
787921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
788921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>The following table lists some of the fields you can query on for an instance. Note 
789921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickthat time zone is defined by 
790921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick{@link android.provider.CalendarContract.CalendarCache#KEY_TIMEZONE_TYPE} 
791921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickand 
792921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick{@link android.provider.CalendarContract.CalendarCache#KEY_TIMEZONE_INSTANCES}.</p>
793921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
794921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
795921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<table>
796921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
797921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <th>Constant</th>
798921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <th>Description</th>
799921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
800921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
801921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.Instances#BEGIN}</td>
802921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The beginning time of the instance, in UTC milliseconds.</td>
803921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
804921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
805921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.Instances#END}</td>
806921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The ending time of the instance, in UTC milliseconds.</td>
807921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
808921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
809921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.Instances#END_DAY}</td>
810921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
811921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The Julian end day of the instance, relative to the Calendar's time
812921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickzone. 
813921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
814921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</td>
815921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
816921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
817921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.Instances#END_MINUTE}</td>
818921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
819921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The end minute of the instance measured from midnight in the the
820921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickCalendar's time zone.</td>
821921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
822921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
823921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
824921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.Instances#EVENT_ID}</td>
825921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The <code>_ID</code> of the event for this instance.</td>
826921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
827921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <tr>
828921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.Instances#START_DAY}</td>
829921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The Julian start day of the instance, relative to the Calendar's time zone. 
830921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick </td>
831921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
832921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
833921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.Instances#START_MINUTE}</td>
834921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
835921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The start minute of the instance measured from midnight, relative to the
836921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickCalendar's time zone. 
837921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</td>
838921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
839921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
840921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
841921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</table>
842921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
843921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<h3 id="query-instances">Querying the Instances table</h3>
844921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
845921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>To query the Instances table, you need to specify a range time for the query
846921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickin the URI. In this example, {@link android.provider.CalendarContract.Instances}
847921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickgets access to the {@link
848921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.CalendarContract.EventsColumns#TITLE} field through its
849921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickimplementation of the {@link android.provider.CalendarContract.EventsColumns} interface. 
850921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickIn other words, {@link
851921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.CalendarContract.EventsColumns#TITLE} is returned through a
852921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickdatabase view, not through querying the raw {@link
853921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.CalendarContract.Instances} table.</p>
854921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
855921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<pre>
856921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickprivate static final String DEBUG_TAG = "MyActivity";
857921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickpublic static final String[] INSTANCE_PROJECTION = new String[] {
858921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    Instances.EVENT_ID,      // 0
859921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    Instances.BEGIN,         // 1
860921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    Instances.TITLE          // 2
861921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  };
862921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  
863921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick// The indices for the projection array above.
864921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickprivate static final int PROJECTION_ID_INDEX = 0;
865921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickprivate static final int PROJECTION_BEGIN_INDEX = 1;
866921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickprivate static final int PROJECTION_TITLE_INDEX = 2;
867921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick...
868921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
869921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick// Specify the date range you want to search for recurring
870921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick// event instances
871921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickCalendar beginTime = Calendar.getInstance();
872921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickbeginTime.set(2011, 9, 23, 8, 0);
873921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormicklong startMillis = beginTime.getTimeInMillis();
874921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickCalendar endTime = Calendar.getInstance();
875921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickendTime.set(2011, 10, 24, 8, 0);
876921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormicklong endMillis = endTime.getTimeInMillis();
877921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  
878921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickCursor cur = null;
879921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickContentResolver cr = getContentResolver();
880921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
881921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick// The ID of the recurring event whose instances you are searching
882921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick// for in the Instances table
883921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickString selection = Instances.EVENT_ID + " = ?";
884921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickString[] selectionArgs = new String[] {"207"};
885921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
886921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick// Construct the query with the desired date range.
887921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickUri.Builder builder = Instances.CONTENT_URI.buildUpon();
888921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickContentUris.appendId(builder, startMillis);
889921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickContentUris.appendId(builder, endMillis);
890921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
891921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick// Submit the query
892921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickcur =  cr.query(builder.build(), 
893921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    INSTANCE_PROJECTION, 
894921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    selection, 
895921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    selectionArgs, 
896921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    null);
897921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick   
898921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickwhile (cur.moveToNext()) {
899921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    String title = null;
900921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    long eventID = 0;
901921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    long beginVal = 0;    
902921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
903921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    // Get the field values
904921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    eventID = cur.getLong(PROJECTION_ID_INDEX);
905921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    beginVal = cur.getLong(PROJECTION_BEGIN_INDEX);
906921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    title = cur.getString(PROJECTION_TITLE_INDEX);
907921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick              
908921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    // Do something with the values. 
909921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    Log.i(DEBUG_TAG, "Event:  " + title); 
910921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    Calendar calendar = Calendar.getInstance();
911921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    calendar.setTimeInMillis(beginVal);  
912921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
913921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    Log.i(DEBUG_TAG, "Date: " + formatter.format(calendar.getTime()));    
914921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    }
915921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick }</pre>
916921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
917921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<h2 id="intents">Calendar Intents</h2>
918921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>Your application doesn't need <a href="#manifest">permissions</a> to read and write calendar data. It can instead use intents supported by Android's Calendar application to hand off read and write operations to that application. The following table lists the intents supported by the Calendar Provider:</p>
919921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<table>
920921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
921921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <th>Action</th>
922921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <th>URI</th>
923921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
924921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <th>Description</th>
925921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <th>Extras</th>
926921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
927921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
928921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td><br>
929921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    {@link android.content.Intent#ACTION_VIEW VIEW} <br></td>
930921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td><p><code>content://com.android.calendar/time/&lt;ms_since_epoch&gt;</code></p>
931921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    You can also refer to the URI with 
932921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick{@link android.provider.CalendarContract#CONTENT_URI CalendarContract.CONTENT_URI}. 
933921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickFor an example of using this intent, see <a href="{@docRoot}guide/topics/providers/calendar-provider.html#intent-view">Using intents to view calendar data</a>. 
934921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
935921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    </td>
936921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>Open calendar to the time specified by <code>&lt;ms_since_epoch&gt;</code>.</td>
937921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>None.</td>
938921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
939921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
940921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td><p>{@link android.content.Intent#ACTION_VIEW VIEW} </p>
941921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
942921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick     </td>
943921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td><p><code>content://com.android.calendar/events/&lt;event_id&gt;</code></p>
944921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
945921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    You can also refer to the URI with 
946921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick{@link android.provider.CalendarContract.Events#CONTENT_URI Events.CONTENT_URI}. 
947921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickFor an example of using this intent, see <a href="{@docRoot}guide/topics/providers/calendar-provider.html#intent-view">Using intents to view calendar data</a>.
948921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
949921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    </td>
950921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>View the event specified by <code>&lt;event_id&gt;</code>.</td>
951921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
952921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract#EXTRA_EVENT_BEGIN_TIME CalendarContract.EXTRA_EVENT_BEGIN_TIME}<br>
953921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      <br>
954921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      <br>
955921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    {@link android.provider.CalendarContract#EXTRA_EVENT_END_TIME CalendarContract.EXTRA_EVENT_END_TIME}</td>
956921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
957921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
958921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
959921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.content.Intent#ACTION_EDIT EDIT} </td>
960921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td><p><code>content://com.android.calendar/events/&lt;event_id&gt;</code></p>
961921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
962921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  You can also refer to the URI with 
963921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick{@link android.provider.CalendarContract.Events#CONTENT_URI Events.CONTENT_URI}. 
964921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickFor an example of using this intent, see <a href="{@docRoot}guide/topics/providers/calendar-provider.html#intent-edit">Using an intent to edit an event</a>.
965921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
966921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
967921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    </td>
968921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>Edit the event specified by <code>&lt;event_id&gt;</code>.</td>
969921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
970921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract#EXTRA_EVENT_BEGIN_TIME CalendarContract.EXTRA_EVENT_BEGIN_TIME}<br>
971921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      <br>
972921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick      <br>
973921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    {@link android.provider.CalendarContract#EXTRA_EVENT_END_TIME CalendarContract.EXTRA_EVENT_END_TIME}</td>
974921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
975921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
976921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
977921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.content.Intent#ACTION_EDIT EDIT} <br>
978921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <br>
979921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    {@link android.content.Intent#ACTION_INSERT INSERT} </td>
980921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td><p><code>content://com.android.calendar/events</code></p>
981921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
982921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick   You can also refer to the URI with 
983921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick{@link android.provider.CalendarContract.Events#CONTENT_URI Events.CONTENT_URI}. 
984921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickFor an example of using this intent, see <a href="{@docRoot}guide/topics/providers/calendar-provider.html#intent-insert">Using an intent to insert an event</a>.
985921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
986921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    </td>
987921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
988921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>Create an event.</td>
989921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>Any of the extras listed in the table below.</td>
990921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
991921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</table>
992921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
993921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>The following table lists the intent extras supported by the Calendar Provider:
994921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</p>
995921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<table>
996921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
997921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <th>Intent Extra</th>
998921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <th>Description</th>
999921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
1000921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
1001921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.EventsColumns#TITLE Events.TITLE}</td>
1002921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>Name for the event.</td>
1003921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
1004921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
1005921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  
1006921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract#EXTRA_EVENT_BEGIN_TIME
1007921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickCalendarContract.EXTRA_EVENT_BEGIN_TIME}</td>
1008921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>Event begin time in milliseconds from the epoch.</td>
1009921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
1010921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
1011921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract#EXTRA_EVENT_END_TIME
1012921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickCalendarContract.EXTRA_EVENT_END_TIME}</td>
1013921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
1014921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>Event end time in milliseconds from the epoch.</td>
1015921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
1016921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
1017921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract#EXTRA_EVENT_ALL_DAY
1018921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickCalendarContract.EXTRA_EVENT_ALL_DAY}</td>
1019921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
1020921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>A boolean that indicates that an event is all day. Value can be
1021921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<code>true</code> or <code>false</code>.</td> </tr>
1022921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
1023921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.EventsColumns#EVENT_LOCATION
1024921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickEvents.EVENT_LOCATION}</td>
1025921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
1026921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>Location of the event.</td>
1027921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
1028921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
1029921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.EventsColumns#DESCRIPTION
1030921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickEvents.DESCRIPTION}</td>
1031921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
1032921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>Event description.</td>
1033921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
1034921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
1035921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>
1036921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    {@link android.content.Intent#EXTRA_EMAIL Intent.EXTRA_EMAIL}</td>
1037921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>Email addresses of those to invite as a comma-separated list.</td>
1038921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
1039921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
1040921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>
1041921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    {@link android.provider.CalendarContract.EventsColumns#RRULE Events.RRULE}</td>
1042921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>The recurrence rule for the event.</td>
1043921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
1044921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
1045921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>
1046921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    {@link android.provider.CalendarContract.EventsColumns#ACCESS_LEVEL
1047921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickEvents.ACCESS_LEVEL}</td>
1048921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
1049921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>Whether the event is private or public.</td>
1050921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  </tr>
1051921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <tr>
1052921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>{@link android.provider.CalendarContract.EventsColumns#AVAILABILITY
1053921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickEvents.AVAILABILITY}</td>
1054921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
1055921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    <td>If this event counts as busy time or is free time that can be scheduled over.</td>
1056921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    
1057921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</table> 
1058921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>The following sections describe how to use these intents.</p>
1059921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
1060921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
1061921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<h3 id="intent-insert">Using an intent to insert an event</h3>
1062921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
1063921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>Using the {@link android.content.Intent#ACTION_INSERT INSERT} Intent
1064921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormicklets your application hand off the event insertion task to the Calendar itself.
1065921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickWith this approach, your application doesn't even need to have the {@link
1066921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.Manifest.permission#WRITE_CALENDAR} permission included in its <a
1067921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickhref="#manifest">manifest file</a>.</p>
1068921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
1069921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  
1070921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>When users run an application that uses this approach, the application sends
1071921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickthem to the Calendar to finish adding the event. The {@link
1072921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.content.Intent#ACTION_INSERT INSERT} Intent uses extra fields to
1073921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickpre-populate a form with the details of the event in the Calendar. Users can
1074921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickthen cancel the event, edit the form as needed, or save the event to their
1075921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickcalendars.</p>
1076921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  
1077921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
1078921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
1079921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>Here is a code snippet that schedules an event on January 19, 2012, that runs
1080921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickfrom 7:30 a.m. to 8:30 a.m. Note the following about this code snippet:</p>
1081921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
1082921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<ul>
1083921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <li>It specifies {@link android.provider.CalendarContract.Events#CONTENT_URI Events.CONTENT_URI} 
1084921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  as the Uri.</li>
1085921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  
1086921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <li>It uses the {@link
1087921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.CalendarContract#EXTRA_EVENT_BEGIN_TIME
1088921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickCalendarContract.EXTRA_EVENT_BEGIN_TIME} and {@link
1089921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.CalendarContract#EXTRA_EVENT_END_TIME
1090921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickCalendarContract.EXTRA_EVENT_END_TIME} extra fields to pre-populate the form
1091921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickwith the time of the event. The values  for these times must be in UTC milliseconds
1092921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickfrom the epoch.</li>
1093921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  
1094921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <li>It uses the {@link android.content.Intent#EXTRA_EMAIL Intent.EXTRA_EMAIL}
1095921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickextra field to provide a comma-separated list of invitees, specified by email address.</li>
1096921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  
1097921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</ul>
1098921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<pre>
1099921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickCalendar beginTime = Calendar.getInstance();
1100921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickbeginTime.set(2012, 0, 19, 7, 30);
1101921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickCalendar endTime = Calendar.getInstance();
1102921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickendTime.set(2012, 0, 19, 8, 30);
1103921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickIntent intent = new Intent(Intent.ACTION_INSERT)
1104921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        .setData(Events.CONTENT_URI)
1105921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginTime.getTimeInMillis())
1106921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime.getTimeInMillis())
1107921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        .putExtra(Events.TITLE, &quot;Yoga&quot;)
1108921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        .putExtra(Events.DESCRIPTION, &quot;Group class&quot;)
1109921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        .putExtra(Events.EVENT_LOCATION, &quot;The gym&quot;)
1110921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        .putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY)
1111921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        .putExtra(Intent.EXTRA_EMAIL, &quot;rowan@example.com,trevor@example.com&quot;);
1112921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickstartActivity(intent);
1113921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</pre>
1114921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
1115921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<h3 id="intent-edit">Using an intent to edit an event</h3>
1116921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
1117921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>You can update an event directly, as described in <a
1118921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickhref="#update-event">Updating events</a>. But using the {@link
1119921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.content.Intent#ACTION_EDIT EDIT} Intent allows an application that
1120921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickdoesn't have permission to hand off event editing to the Calendar application.
1121921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickWhen users finish editing their event in Calendar, they're returned to the
1122921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickoriginal application.</p> <p>Here is an example of an intent that sets a new
1123921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormicktitle for a specified event and lets users edit the event in the Calendar.</p>
1124921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
1125921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
1126921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<pre>long eventID = 208;
1127921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickUri uri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID);
1128921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickIntent intent = new Intent(Intent.ACTION_EDIT)
1129921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    .setData(uri)
1130921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    .putExtra(Events.TITLE, &quot;My New Title&quot;);
1131921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickstartActivity(intent);</pre>
1132921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
1133921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<h3 id="intent-view">Using  intents to view calendar data</h3>
1134921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>Calender Provider offers two different ways to use the {@link android.content.Intent#ACTION_VIEW VIEW} Intent:</p>
1135921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<ul>
1136921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <li>To open the Calendar to a particular date.</li>
1137921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <li>To view an event.</li>
1138921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
1139921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</ul>
1140921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>Here is an example that shows how to open the Calendar to a particular date:</p>
1141921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<pre>// A date-time specified in milliseconds since the epoch.
1142921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormicklong startMillis;
1143921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick...
1144921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickUri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
1145921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickbuilder.appendPath(&quot;time&quot;);
1146921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickContentUris.appendId(builder, startMillis);
1147921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickIntent intent = new Intent(Intent.ACTION_VIEW)
1148921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    .setData(builder.build());
1149921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickstartActivity(intent);</pre>
1150921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
1151921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>Here is an example that shows how to open an event for viewing:</p>
1152921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<pre>long eventID = 208;
1153921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick...
1154921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickUri uri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID);
1155921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickIntent intent = new Intent(Intent.ACTION_VIEW)
1156921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick   .setData(uri);
1157921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickstartActivity(intent);
1158921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</pre>
1159921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
1160921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
1161921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<h2 id="sync-adapter">Sync Adapters</h2>
1162921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
1163921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
1164921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>There are only minor differences in how an application and a sync adapter
1165921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickaccess the Calendar Provider:</p>
1166921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
1167921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<ul>
1168921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <li>A sync adapter needs to specify that it's a sync adapter by setting {@link android.provider.CalendarContract#CALLER_IS_SYNCADAPTER} to <code>true</code>.</li>
1169921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  
1170921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  
1171921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <li>A sync adapter needs to provide an {@link
1172921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.CalendarContract.SyncColumns#ACCOUNT_NAME} and an {@link
1173921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickandroid.provider.CalendarContract.SyncColumns#ACCOUNT_TYPE} as query parameters in the URI. </li>
1174921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  
1175921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  <li>A sync adapter has write access to more columns than an application or widget.
1176921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  For example, an application can only modify a few characteristics of a calendar, 
1177921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  such as its name, display name, visibility setting, and whether the calendar is
1178921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  synced. By comparison, a sync adapter can access not only those columns, but many others,
1179921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick  such as calendar color, time zone, access level, location, and so on.
1180921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormickHowever, a sync adapter is restricted to the <code>ACCOUNT_NAME</code> and 
1181921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<code>ACCOUNT_TYPE</code> it specified.</li> </ul>
1182921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick
1183921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>Here is a helper method you can use to return a URI for use with a sync adapter:</p>
1184921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<pre> static Uri asSyncAdapter(Uri uri, String account, String accountType) {
1185921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick    return uri.buildUpon()
1186921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        .appendQueryParameter(android.provider.CalendarContract.CALLER_IS_SYNCADAPTER,&quot;true&quot;)
1187921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        .appendQueryParameter(Calendars.ACCOUNT_NAME, account)
1188921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick        .appendQueryParameter(Calendars.ACCOUNT_TYPE, accountType).build();
1189921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick }
1190921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick</pre>
1191921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<p>For a sample implementation of a sync adapter (not specifically related to Calendar), see 
1192921afe39d6041b06c6a002b08f9dcd1561a9ae99Katie McCormick<a href="{@docRoot}resources/samples/SampleSyncAdapter/index.html">SampleSyncAdapter</a>.
1193