1 page.title= 2 @jd:body 3 4 <div id="qv-wrapper"> 5 <div id="qv"> 6 <h2></h2> 7 <ol> 8 <li><a href="#overview"></a></li> 9 <li><a href="#manifest"> </a></li> 10 <li><a href="#calendar">Calendars </a> 11 <ol> 12 <li><a href="#query"></a></li> 13 <li><a href="#modify-calendar"></a></li> 14 <li><a href="#insert-calendar"></a></li> 15 </ol> 16 </li> 17 <li><a href="#events">Events </a> 18 <ol> 19 <li><a href="#add-event"></a></li> 20 <li><a href="#update-event"></a></li> 21 <li><a href="#delete-event"></a></li> 22 </ol> 23 </li> 24 <li><a href="#attendees">Attendees </a> 25 <ol> 26 <li><a href="#add-attendees"></a></li> 27 </ol> 28 </li> 29 <li><a href="#reminders">Reminders </a> 30 <ol> 31 <li><a href="#add-reminders"></a></li> 32 </ol> 33 </li> 34 <li><a href="#instances">Instances </a> 35 <ol> 36 <li><a href="#query-instances">Instances </a></li> 37 </ol></li> 38 <li><a href="#intents"></a> 39 <ol> 40 <li><a href="#intent-insert"></a></li> 41 <li><a href="#intent-edit"></a></li> 42 <li><a href="#intent-view"> </a></li> 43 </ol> 44 </li> 45 46 <li><a href="#sync-adapter"></a></li> 47 </ol> 48 49 <h2></h2> 50 <ol> 51 <li>{@link android.provider.CalendarContract.Calendars}</li> 52 <li>{@link android.provider.CalendarContract.Events}</li> 53 <li>{@link android.provider.CalendarContract.Attendees}</li> 54 <li>{@link android.provider.CalendarContract.Reminders}</li> 55 </ol> 56 </div> 57 </div> 58 59 <p> API 60 61 </p> 62 63 64 <p> API 65 API 66 <a href="#sync-adapter"></a> 67 68 </p> 69 70 71 <p> <a href="#manifest"> </a> 72 73 <a href="#intents"></a> 74 75 76 77 78 </p> 79 80 <h2 id="overview"></h2> 81 82 <p><a href="{@docRoot}guide/topics/providers/content-providers.html"> </a> 83 Android 84 85 API 86 87 </p> 88 89 <p> URI{@link android.net.Uri} 90 91 URI 92 URI content:// 93 94 URI 95 URI <code><em><class></em>.CONTENT_URI</code> 96 {@link android.provider.CalendarContract.Events#CONTENT_URI Events.CONTENT_URI} 97 </p> 98 99 <p> 1 100 </p> 101 102 <img src="{@docRoot}images/providers/datamodel.png" alt="Calendar Provider Data Model" /> 103 <p class="img-caption"><strong> 1.</strong> </p> 104 105 <p>Google Exchange </p> 106 107 <p>{@link android.provider.CalendarContract} </p> 108 109 <table> 110 <tr> 111 <th></th> 112 <th></th> 113 </tr> 114 <tr> 115 <td><p>{@link android.provider.CalendarContract.Calendars}</p></td> 116 117 <td> 118 1 119 </td> 120 </tr> 121 <tr> 122 <td>{@link android.provider.CalendarContract.Events}</td> 123 124 <td> 125 1 — 126 127 128 Events {@link android.provider.BaseColumns#_ID} {@link android.provider.CalendarContract.AttendeesColumns#EVENT_ID} 129 130 </td> 131 132 </tr> 133 <tr> 134 <td>{@link android.provider.CalendarContract.Instances}</td> 135 136 <td> 137 1 138 1 1 139 140 </td> 141 </tr> 142 <tr> 143 <td>{@link android.provider.CalendarContract.Attendees}</td> 144 145 <td> 146 1 1 147 148 </td> 149 </tr> 150 <tr> 151 <td>{@link android.provider.CalendarContract.Reminders}</td> 152 153 <td> 154 1 1 1 155 1 {@link android.provider.CalendarContract.CalendarColumns#MAX_REMINDERS} 156 157 158 159 160 </td> 161 </tr> 162 163 </table> 164 165 <p> API 166 167 API 168 </p> 169 170 <ul> 171 172 <li><strong> </strong> <a href="#manifest"></a> Android 173 174 175 176 <a href="#intents"></a> 177 </p> 178 179 180 <li><strong></strong> 181 {@link android.provider.CalendarContract.Calendars} {@link android.provider.CalendarContract.Events} 182 183 184 185 186 <a href="#sync-adapter"></a> 187 </li> 188 189 </ul> 190 191 192 <h2 id="manifest"> </h2> 193 194 <p> {@link android.Manifest.permission#READ_CALENDAR} 195 {@link android.Manifest.permission#WRITE_CALENDAR} 196 197 </p> 198 199 <pre> 200 <?xml version="1.0" encoding="utf-8"?> 201 <manifest xmlns:android="http://schemas.android.com/apk/res/android"...> 202 <uses-sdk android:minSdkVersion="14" /> 203 <uses-permission android:name="android.permission.READ_CALENDAR" /> 204 <uses-permission android:name="android.permission.WRITE_CALENDAR" /> 205 ... 206 </manifest> 207 </pre> 208 209 210 <h2 id="calendar">Calendars </h2> 211 212 <p>{@link android.provider.CalendarContract.Calendars} 213 Calendars <a href="#sync-adapter"></a> 214 {@link android.provider.CalendarContract.Calendars} 215 216 </p> 217 <table> 218 <tr> 219 <th></th> 220 <th></th> 221 </tr> 222 <tr> 223 <td>{@link android.provider.CalendarContract.Calendars#NAME}</td> 224 <td></td> 225 </tr> 226 <tr> 227 <td>{@link android.provider.CalendarContract.Calendars#CALENDAR_DISPLAY_NAME}</td> 228 <td></td> 229 </tr> 230 <tr> 231 <td>{@link android.provider.CalendarContract.Calendars#VISIBLE}</td> 232 233 <td> 0 234 235 1 236 {@link android.provider.CalendarContract.Instances} 237 </td> 238 239 240 </tr> 241 <tr> 242 <td>{@link android.provider.CalendarContract.CalendarColumns#SYNC_EVENTS}</td> 243 244 <td> 245 0 246 1 247 </td> 248 </tr> 249 </table> 250 251 <h3 id="query"></h3> 252 253 <p> 254 255 256 <a href="{@docRoot}guide/components/loaders.html"></a> 257 {@link android.content.AsyncQueryHandler} 258 259 </p> 260 261 262 <pre> 263 // Projection array. Creating indices for this array instead of doing 264 // dynamic lookups improves performance. 265 public static final String[] EVENT_PROJECTION = new String[] { 266 Calendars._ID, // 0 267 Calendars.ACCOUNT_NAME, // 1 268 Calendars.CALENDAR_DISPLAY_NAME, // 2 269 Calendars.OWNER_ACCOUNT // 3 270 }; 271 272 // The indices for the projection array above. 273 private static final int PROJECTION_ID_INDEX = 0; 274 private static final int PROJECTION_ACCOUNT_NAME_INDEX = 1; 275 private static final int PROJECTION_DISPLAY_NAME_INDEX = 2; 276 private static final int PROJECTION_OWNER_ACCOUNT_INDEX = 3;</pre> 277 278 279 <div class="sidebox-wrapper"> <div class="sidebox"> <h3>ACCOUNT_TYPE 280 </h3> <p>{@link android.provider.CalendarContract.Calendars#ACCOUNT_NAME Calendars.ACCOUNT_NAME} {@link android.provider.CalendarContract.Calendars#ACCOUNT_TYPE Calendars.ACCOUNT_TYPE} 281 282 283 284 <code>ACCOUNT_NAME</code> <code>ACCOUNT_TYPE</code> 285 286 <code>ACCOUNT_TYPE</code> {@link android.accounts.AccountManager} 287 288 {@link android.provider.CalendarContract#ACCOUNT_TYPE_LOCAL} {@link android.provider.CalendarContract#ACCOUNT_TYPE_LOCAL} 289 290 291 292 </p> </div> </div> 293 294 295 <p> selection 296 <code>ACCOUNT_NAME</code> sampleuser (a] google.com<code>ACCOUNT_TYPE</code> com.google<code>OWNER_ACCOUNT</code> sampleuser (a] google.com 297 298 299 300 <code>OWNER_ACCOUNT</code> {@link android.database.Cursor} 301 302 303 304 <a href="{@docRoot}guide/topics/providers/content-providers.html"> </a> 305 </p> 306 307 308 <pre>// Run query 309 Cursor cur = null; 310 ContentResolver cr = getContentResolver(); 311 Uri uri = Calendars.CONTENT_URI; 312 String selection = "((" + Calendars.ACCOUNT_NAME + " = ?) AND (" 313 + Calendars.ACCOUNT_TYPE + " = ?) AND (" 314 + Calendars.OWNER_ACCOUNT + " = ?))"; 315 String[] selectionArgs = new String[] {"sampleuser (a] gmail.com", "com.google", 316 "sampleuser (a] gmail.com"}; 317 // Submit the query and get a Cursor object back. 318 cur = cr.query(uri, EVENT_PROJECTION, selection, selectionArgs, null);</pre> 319 320 <p> 321 322 </p> 323 324 <pre>// Use the cursor to step through the returned records 325 while (cur.moveToNext()) { 326 long calID = 0; 327 String displayName = null; 328 String accountName = null; 329 String ownerName = null; 330 331 // Get the field values 332 calID = cur.getLong(PROJECTION_ID_INDEX); 333 displayName = cur.getString(PROJECTION_DISPLAY_NAME_INDEX); 334 accountName = cur.getString(PROJECTION_ACCOUNT_NAME_INDEX); 335 ownerName = cur.getString(PROJECTION_OWNER_ACCOUNT_INDEX); 336 337 // Do something with the values... 338 339 ... 340 } 341 </pre> 342 343 <h3 id="modify-calendar"></h3> 344 345 <p> {@link android.provider.BaseColumns#_ID} URI{@link android.content.ContentUris#withAppendedId(android.net.Uri,long) withAppendedId()} ID selection 346 347 348 349 350 selection <code>"_id=?"</code> <code>selectionArg</code> {@link android.provider.BaseColumns#_ID} 351 352 353 URL ID {@link android.content.ContentUris#withAppendedId(android.net.Uri,long) withAppendedId()} 354 355 356 357 </p> 358 359 <pre>private static final String DEBUG_TAG = "MyActivity"; 360 ... 361 long calID = 2; 362 ContentValues values = new ContentValues(); 363 // The new display name for the calendar 364 values.put(Calendars.CALENDAR_DISPLAY_NAME, "Trevor's Calendar"); 365 Uri updateUri = ContentUris.withAppendedId(Calendars.CONTENT_URI, calID); 366 int rows = getContentResolver().update(updateUri, values, null, null); 367 Log.i(DEBUG_TAG, "Rows updated: " + rows);</pre> 368 369 <h3 id="insert-calendar"></h2> 370 371 <p> 372 373 {@link android.provider.CalendarContract.SyncColumns#ACCOUNT_TYPE} {@link android.provider.CalendarContract#ACCOUNT_TYPE_LOCAL} {@link android.provider.CalendarContract#ACCOUNT_TYPE_LOCAL} 374 375 376 377 378 379 380 <a href="#sync-adapter"></a> 381 </p> 382 383 <h2 id="events">Events </h2> 384 385 <p>{@link android.provider.CalendarContract.Events} 386 387 <a href="#manifest"> </a> {@link android.Manifest.permission#WRITE_CALENDAR} 388 </p> 389 390 <p> Events 391 {@link android.provider.CalendarContract.Events} 392 </p> 393 394 <table> 395 <tr> 396 <th></th> 397 <th></th> 398 </tr> 399 <tr> 400 <td>{@link android.provider.CalendarContract.EventsColumns#CALENDAR_ID}</td> 401 <td> {@link android.provider.BaseColumns#_ID}</td> 402 </tr> 403 <tr> 404 <td>{@link android.provider.CalendarContract.EventsColumns#ORGANIZER}</td> 405 <td></td> 406 </tr> 407 <tr> 408 <td>{@link android.provider.CalendarContract.EventsColumns#TITLE}</td> 409 <td></td> 410 </tr> 411 <tr> 412 <td>{@link android.provider.CalendarContract.EventsColumns#EVENT_LOCATION}</td> 413 <td> </td> 414 </tr> 415 <tr> 416 <td>{@link android.provider.CalendarContract.EventsColumns#DESCRIPTION}</td> 417 <td></td> 418 </tr> 419 <tr> 420 <td>{@link android.provider.CalendarContract.EventsColumns#DTSTART}</td> 421 <td> UTC </td> 422 </tr> 423 <tr> 424 <td>{@link android.provider.CalendarContract.EventsColumns#DTEND}</td> 425 <td> UTC </td> 426 </tr> 427 <tr> 428 <td>{@link android.provider.CalendarContract.EventsColumns#EVENT_TIMEZONE}</td> 429 <td></td> 430 </tr> 431 <tr> 432 <td>{@link android.provider.CalendarContract.EventsColumns#EVENT_END_TIMEZONE}</td> 433 <td></td> 434 </tr> 435 <tr> 436 <td>{@link android.provider.CalendarContract.EventsColumns#DURATION}</td> 437 438 <td><a href="http://tools.ietf.org/html/rfc5545#section-3.8.2.5">RFC5545</a> <code>"PT1H"</code> 1 <code>"P2W"</code> 2 439 440 441 </td> 442 443 444 </tr> 445 <tr> 446 <td>{@link android.provider.CalendarContract.EventsColumns#ALL_DAY}</td> 447 448 <td> 1 449 0 1 450 </td> 451 452 453 </tr> 454 455 456 <tr> 457 <td>{@link android.provider.CalendarContract.EventsColumns#RRULE}</td> 458 459 <td><code>"FREQ=WEEKLY;COUNT=10;WKST=SU"</code> 460 <a href="http://tools.ietf.org/html/rfc5545#section-3.8.5.3"></a> 461 </td> 462 463 </tr> 464 465 <tr> 466 <td>{@link android.provider.CalendarContract.EventsColumns#RDATE}</td> 467 <td>{@link android.provider.CalendarContract.EventsColumns#RDATE} {@link android.provider.CalendarContract.EventsColumns#RRULE} 468 469 470 471 <a href="http://tools.ietf.org/html/rfc5545#section-3.8.5.2">RFC5545 </a></td> 472 </tr> 473 474 <tr> 475 <td>{@link android.provider.CalendarContract.EventsColumns#AVAILABILITY}</td> 476 477 <td> 478 </td> 479 480 </tr> 481 <tr> 482 <td>{@link android.provider.CalendarContract.EventsColumns#GUESTS_CAN_MODIFY}</td> 483 <td> </td> 484 </tr> 485 <tr> 486 <td>{@link android.provider.CalendarContract.EventsColumns#GUESTS_CAN_INVITE_OTHERS}</td> 487 <td> </td> 488 </tr> 489 <tr> 490 <td>{@link android.provider.CalendarContract.EventsColumns#GUESTS_CAN_SEE_GUESTS}</td> 491 <td></td> 492 </tr> 493 </table> 494 495 <h3 id="add-event"></h3> 496 497 <p>{@link android.content.Intent#ACTION_INSERT INSERT} <a href="#intent-insert"></a> 498 499 500 </p> 501 502 503 <p> </p> 504 <ul> 505 506 <li>{@link android.provider.CalendarContract.EventsColumns#CALENDAR_ID} {@link android.provider.CalendarContract.EventsColumns#DTSTART} 507 508 </li> 509 510 <li>{@link android.provider.CalendarContract.EventsColumns#EVENT_TIMEZONE} 511 ID {@link java.util.TimeZone#getAvailableIDs()} 512 513 <a href="#intent-insert"></a>{@link android.content.Intent#ACTION_INSERT INSERT} — 514 515 516 </li> 517 518 <li>{@link android.provider.CalendarContract.EventsColumns#DTEND} 519 </li> 520 521 522 <li>{@link android.provider.CalendarContract.EventsColumns#RRULE} {@link android.provider.CalendarContract.EventsColumns#RDATE} {@link android.provider.CalendarContract.EventsColumns#DURATION} 523 524 525 <a href="#intent-insert"></a>{@link android.content.Intent#ACTION_INSERT INSERT} —{@link android.provider.CalendarContract.EventsColumns#RRULE} {@link android.provider.CalendarContract.EventsColumns#DTEND} {@link android.provider.CalendarContract.EventsColumns#DTSTART} 526 527 528 529 530 </li> 531 532 </ul> 533 534 <p> UI 535 536 {@link android.content.AsyncQueryHandler} 537 </p> 538 539 540 <pre> 541 long calID = 3; 542 long startMillis = 0; 543 long endMillis = 0; 544 Calendar beginTime = Calendar.getInstance(); 545 beginTime.set(2012, 9, 14, 7, 30); 546 startMillis = beginTime.getTimeInMillis(); 547 Calendar endTime = Calendar.getInstance(); 548 endTime.set(2012, 9, 14, 8, 45); 549 endMillis = endTime.getTimeInMillis(); 550 ... 551 552 ContentResolver cr = getContentResolver(); 553 ContentValues values = new ContentValues(); 554 values.put(Events.DTSTART, startMillis); 555 values.put(Events.DTEND, endMillis); 556 values.put(Events.TITLE, "Jazzercise"); 557 values.put(Events.DESCRIPTION, "Group workout"); 558 values.put(Events.CALENDAR_ID, calID); 559 values.put(Events.EVENT_TIMEZONE, "America/Los_Angeles"); 560 Uri uri = cr.insert(Events.CONTENT_URI, values); 561 562 // get the event ID that is the last element in the Uri 563 long eventID = Long.parseLong(uri.getLastPathSegment()); 564 // 565 // ... do something with event ID 566 // 567 //</pre> 568 569 <p class="note"><strong>:</strong> ID 570 ID ID — 571 572 </p> 573 574 575 <h3 id="update-event"></h3> 576 577 <p>{@link android.content.Intent#ACTION_EDIT EDIT} <a href="#intent-edit"></a> 578 579 580 <code>_ID</code> URI{@link android.content.ContentUris#withAppendedId(android.net.Uri,long) withAppendedId()} ID selection 581 582 583 584 selection <code>"_id=?"</code> <code>selectionArg</code> <code>_ID</code> 585 586 ID selection 587 588 {@link android.content.ContentUris#withAppendedId(android.net.Uri,long) withAppendedId()} 589 590 </p> 591 592 593 <pre>private static final String DEBUG_TAG = "MyActivity"; 594 ... 595 long eventID = 188; 596 ... 597 ContentResolver cr = getContentResolver(); 598 ContentValues values = new ContentValues(); 599 Uri updateUri = null; 600 // The new title for the event 601 values.put(Events.TITLE, "Kickboxing"); 602 updateUri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID); 603 int rows = getContentResolver().update(updateUri, values, null, null); 604 Log.i(DEBUG_TAG, "Rows updated: " + rows); </pre> 605 606 <h3 id="delete-event"></h3> 607 608 <p> {@link android.provider.BaseColumns#_ID} URI ID 609 610 ID 2 611 <em></em> 1 612 613 614 615 {@link android.provider.BaseColumns#_ID} 616 </p> 617 618 619 <pre>private static final String DEBUG_TAG = "MyActivity"; 620 ... 621 long eventID = 201; 622 ... 623 ContentResolver cr = getContentResolver(); 624 ContentValues values = new ContentValues(); 625 Uri deleteUri = null; 626 deleteUri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID); 627 int rows = getContentResolver().delete(deleteUri, null, null); 628 Log.i(DEBUG_TAG, "Rows deleted: " + rows); 629 </pre> 630 631 <h2 id="attendees">Attendees </h2> 632 633 <p>{@link android.provider.CalendarContract.Attendees} 1 634 {@link android.provider.CalendarContract.Reminders#query(android.content.ContentResolver, long, java.lang.String[]) query()} {@link android.provider.CalendarContract.AttendeesColumns#EVENT_ID} 635 636 637 {@link android.provider.CalendarContract.AttendeesColumns#EVENT_ID} {@link android.provider.BaseColumns#_ID} 638 639 640 </p> 641 642 <p> 643 <code>ATTENDEE_NAME</code> 644 645 </p> 646 647 648 <table> 649 <tr> 650 <th></th> 651 <th></th> 652 </tr> 653 <tr> 654 <td>{@link android.provider.CalendarContract.AttendeesColumns#EVENT_ID}</td> 655 <td> ID</td> 656 </tr> 657 <tr> 658 <td>{@link android.provider.CalendarContract.AttendeesColumns#ATTENDEE_NAME}</td> 659 <td></td> 660 </tr> 661 <tr> 662 <td>{@link android.provider.CalendarContract.AttendeesColumns#ATTENDEE_EMAIL}</td> 663 <td></td> 664 </tr> 665 <tr> 666 <td>{@link android.provider.CalendarContract.AttendeesColumns#ATTENDEE_RELATIONSHIP}</td> 667 <td><p></p> 668 <ul> 669 <li>{@link android.provider.CalendarContract.AttendeesColumns#RELATIONSHIP_ATTENDEE}</li> 670 <li>{@link android.provider.CalendarContract.AttendeesColumns#RELATIONSHIP_NONE}</li> 671 <li>{@link android.provider.CalendarContract.AttendeesColumns#RELATIONSHIP_ORGANIZER}</li> 672 <li>{@link android.provider.CalendarContract.AttendeesColumns#RELATIONSHIP_PERFORMER}</li> 673 <li>{@link android.provider.CalendarContract.AttendeesColumns#RELATIONSHIP_SPEAKER}</li> 674 </ul> 675 </td> 676 </tr> 677 <tr> 678 <td>{@link android.provider.CalendarContract.AttendeesColumns#ATTENDEE_TYPE}</td> 679 <td><p> </p> 680 <ul> 681 <li>{@link android.provider.CalendarContract.AttendeesColumns#TYPE_REQUIRED}</li> 682 <li>{@link android.provider.CalendarContract.AttendeesColumns#TYPE_OPTIONAL}</li> 683 </ul></td> 684 </tr> 685 <tr> 686 <td>{@link android.provider.CalendarContract.AttendeesColumns#ATTENDEE_STATUS}</td> 687 <td><p></p> 688 <ul> 689 <li>{@link android.provider.CalendarContract.AttendeesColumns#ATTENDEE_STATUS_ACCEPTED}</li> 690 <li>{@link android.provider.CalendarContract.AttendeesColumns#ATTENDEE_STATUS_DECLINED}</li> 691 <li>{@link android.provider.CalendarContract.AttendeesColumns#ATTENDEE_STATUS_INVITED}</li> 692 <li>{@link android.provider.CalendarContract.AttendeesColumns#ATTENDEE_STATUS_NONE}</li> 693 <li>{@link android.provider.CalendarContract.AttendeesColumns#ATTENDEE_STATUS_TENTATIVE}</li> 694 </ul></td> 695 </tr> 696 </table> 697 698 <h3 id="add-attendees"></h3> 699 700 <p> 1 {@link android.provider.CalendarContract.AttendeesColumns#EVENT_ID} 701 702 </p> 703 704 <pre> 705 long eventID = 202; 706 ... 707 ContentResolver cr = getContentResolver(); 708 ContentValues values = new ContentValues(); 709 values.put(Attendees.ATTENDEE_NAME, "Trevor"); 710 values.put(Attendees.ATTENDEE_EMAIL, "trevor (a] example.com"); 711 values.put(Attendees.ATTENDEE_RELATIONSHIP, Attendees.RELATIONSHIP_ATTENDEE); 712 values.put(Attendees.ATTENDEE_TYPE, Attendees.TYPE_OPTIONAL); 713 values.put(Attendees.ATTENDEE_STATUS, Attendees.ATTENDEE_STATUS_INVITED); 714 values.put(Attendees.EVENT_ID, eventID); 715 Uri uri = cr.insert(Attendees.CONTENT_URI, values); 716 </pre> 717 718 <h2 id="reminders">Reminders </h2> 719 720 <p>{@link android.provider.CalendarContract.Reminders} 1 721 {@link android.provider.CalendarContract.Reminders#query(android.content.ContentResolver, long, java.lang.String[]) query()} {@link android.provider.CalendarContract.AttendeesColumns#EVENT_ID} 722 723 724 </p> 725 726 727 <p> 728 {@link android.provider.CalendarContract.Calendars} 729 730 {@link android.provider.CalendarContract.CalendarColumns#ALLOWED_REMINDERS} 731 732 </p> 733 734 735 <table> 736 <tr> 737 <th></th> 738 <th></th> 739 </tr> 740 <tr> 741 <td>{@link android.provider.CalendarContract.RemindersColumns#EVENT_ID}</td> 742 <td> ID</td> 743 </tr> 744 <tr> 745 <td>{@link android.provider.CalendarContract.RemindersColumns#MINUTES}</td> 746 <td></td> 747 </tr> 748 <tr> 749 <td>{@link android.provider.CalendarContract.RemindersColumns#METHOD}</td> 750 <td><p></p> 751 <ul> 752 <li>{@link android.provider.CalendarContract.RemindersColumns#METHOD_ALERT}</li> 753 <li>{@link android.provider.CalendarContract.RemindersColumns#METHOD_DEFAULT}</li> 754 <li>{@link android.provider.CalendarContract.RemindersColumns#METHOD_EMAIL}</li> 755 <li>{@link android.provider.CalendarContract.RemindersColumns#METHOD_SMS}</li> 756 </ul></td> 757 </tr> 758 </table> 759 760 <h3 id="add-reminders"></h3> 761 762 <p> 15 763 </p> 764 <pre> 765 long eventID = 221; 766 ... 767 ContentResolver cr = getContentResolver(); 768 ContentValues values = new ContentValues(); 769 values.put(Reminders.MINUTES, 15); 770 values.put(Reminders.EVENT_ID, eventID); 771 values.put(Reminders.METHOD, Reminders.METHOD_ALERT); 772 Uri uri = cr.insert(Reminders.CONTENT_URI, values);</pre> 773 774 <h2 id="instances">Instances </h2> 775 776 <p>{@link android.provider.CalendarContract.Instances} 777 778 1 779 Instances 780 </p> 781 782 <p> {@link android.provider.CalendarContract.CalendarCache#KEY_TIMEZONE_TYPE} {@link android.provider.CalendarContract.CalendarCache#KEY_TIMEZONE_INSTANCES} 783 784 785 786 </p> 787 788 789 <table> 790 <tr> 791 <th></th> 792 <th></th> 793 </tr> 794 <tr> 795 <td>{@link android.provider.CalendarContract.Instances#BEGIN}</td> 796 <td>UTC </td> 797 </tr> 798 <tr> 799 <td>{@link android.provider.CalendarContract.Instances#END}</td> 800 <td>UTC </td> 801 </tr> 802 <tr> 803 <td>{@link android.provider.CalendarContract.Instances#END_DAY}</td> 804 805 <td> 806 807 808 </td> 809 </tr> 810 <tr> 811 <td>{@link android.provider.CalendarContract.Instances#END_MINUTE}</td> 812 813 <td> 814 </td> 815 816 </tr> 817 <tr> 818 <td>{@link android.provider.CalendarContract.Instances#EVENT_ID}</td> 819 <td> <code>_ID</code></td> 820 </tr> 821 <tr> 822 <td>{@link android.provider.CalendarContract.Instances#START_DAY}</td> 823 <td> 824 </td> 825 </tr> 826 <tr> 827 <td>{@link android.provider.CalendarContract.Instances#START_MINUTE}</td> 828 829 <td> 830 831 </td> 832 833 </tr> 834 835 </table> 836 837 <h3 id="query-instances">Instances </h3> 838 839 <p>Instances URI {@link android.provider.CalendarContract.Instances} {@link android.provider.CalendarContract.EventsColumns} {@link android.provider.CalendarContract.EventsColumns#TITLE} 840 841 842 843 {@link android.provider.CalendarContract.EventsColumns#TITLE} {@link android.provider.CalendarContract.Instances} 844 845 846 847 </p> 848 849 <pre> 850 private static final String DEBUG_TAG = "MyActivity"; 851 public static final String[] INSTANCE_PROJECTION = new String[] { 852 Instances.EVENT_ID, // 0 853 Instances.BEGIN, // 1 854 Instances.TITLE // 2 855 }; 856 857 // The indices for the projection array above. 858 private static final int PROJECTION_ID_INDEX = 0; 859 private static final int PROJECTION_BEGIN_INDEX = 1; 860 private static final int PROJECTION_TITLE_INDEX = 2; 861 ... 862 863 // Specify the date range you want to search for recurring 864 // event instances 865 Calendar beginTime = Calendar.getInstance(); 866 beginTime.set(2011, 9, 23, 8, 0); 867 long startMillis = beginTime.getTimeInMillis(); 868 Calendar endTime = Calendar.getInstance(); 869 endTime.set(2011, 10, 24, 8, 0); 870 long endMillis = endTime.getTimeInMillis(); 871 872 Cursor cur = null; 873 ContentResolver cr = getContentResolver(); 874 875 // The ID of the recurring event whose instances you are searching 876 // for in the Instances table 877 String selection = Instances.EVENT_ID + " = ?"; 878 String[] selectionArgs = new String[] {"207"}; 879 880 // Construct the query with the desired date range. 881 Uri.Builder builder = Instances.CONTENT_URI.buildUpon(); 882 ContentUris.appendId(builder, startMillis); 883 ContentUris.appendId(builder, endMillis); 884 885 // Submit the query 886 cur = cr.query(builder.build(), 887 INSTANCE_PROJECTION, 888 selection, 889 selectionArgs, 890 null); 891 892 while (cur.moveToNext()) { 893 String title = null; 894 long eventID = 0; 895 long beginVal = 0; 896 897 // Get the field values 898 eventID = cur.getLong(PROJECTION_ID_INDEX); 899 beginVal = cur.getLong(PROJECTION_BEGIN_INDEX); 900 title = cur.getString(PROJECTION_TITLE_INDEX); 901 902 // Do something with the values. 903 Log.i(DEBUG_TAG, "Event: " + title); 904 Calendar calendar = Calendar.getInstance(); 905 calendar.setTimeInMillis(beginVal); 906 DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy"); 907 Log.i(DEBUG_TAG, "Date: " + formatter.format(calendar.getTime())); 908 } 909 }</pre> 910 911 <h2 id="intents"></h2> 912 <p> <a href="#manifest"></a>Android </p> 913 <table> 914 <tr> 915 <th></th> 916 <th>URI</th> 917 918 <th></th> 919 <th></th> 920 </tr> 921 <tr> 922 <td><br> 923 {@link android.content.Intent#ACTION_VIEW VIEW} <br></td> 924 <td><p><code>content://com.android.calendar/time/<ms_since_epoch></code></p> 925 URI {@link android.provider.CalendarContract#CONTENT_URI CalendarContract.CONTENT_URI} 926 <a href="{@docRoot}guide/topics/providers/calendar-provider.html#intent-view"> </a> 927 928 929 </td> 930 <td><code><ms_since_epoch></code> </td> 931 <td></td> 932 </tr> 933 <tr> 934 <td><p>{@link android.content.Intent#ACTION_VIEW VIEW} </p> 935 936 </td> 937 <td><p><code>content://com.android.calendar/events/<event_id></code></p> 938 939 URI {@link android.provider.CalendarContract.Events#CONTENT_URI Events.CONTENT_URI} 940 <a href="{@docRoot}guide/topics/providers/calendar-provider.html#intent-view"> </a> 941 942 943 </td> 944 <td><code><event_id></code> </td> 945 946 <td>{@link android.provider.CalendarContract#EXTRA_EVENT_BEGIN_TIME CalendarContract.EXTRA_EVENT_BEGIN_TIME}<br> 947 <br> 948 <br> 949 {@link android.provider.CalendarContract#EXTRA_EVENT_END_TIME CalendarContract.EXTRA_EVENT_END_TIME}</td> 950 </tr> 951 952 <tr> 953 <td>{@link android.content.Intent#ACTION_EDIT EDIT} </td> 954 <td><p><code>content://com.android.calendar/events/<event_id></code></p> 955 956 URI {@link android.provider.CalendarContract.Events#CONTENT_URI Events.CONTENT_URI} 957 <a href="{@docRoot}guide/topics/providers/calendar-provider.html#intent-edit"> </a> 958 959 960 961 </td> 962 <td><code><event_id></code> </td> 963 964 <td>{@link android.provider.CalendarContract#EXTRA_EVENT_BEGIN_TIME CalendarContract.EXTRA_EVENT_BEGIN_TIME}<br> 965 <br> 966 <br> 967 {@link android.provider.CalendarContract#EXTRA_EVENT_END_TIME CalendarContract.EXTRA_EVENT_END_TIME}</td> 968 </tr> 969 970 <tr> 971 <td>{@link android.content.Intent#ACTION_EDIT EDIT} <br> 972 <br> 973 {@link android.content.Intent#ACTION_INSERT INSERT} </td> 974 <td><p><code>content://com.android.calendar/events</code></p> 975 976 URI {@link android.provider.CalendarContract.Events#CONTENT_URI Events.CONTENT_URI} 977 <a href="{@docRoot}guide/topics/providers/calendar-provider.html#intent-insert"> </a> 978 979 980 </td> 981 982 <td></td> 983 <td></td> 984 </tr> 985 </table> 986 987 <p> 988 </p> 989 <table> 990 <tr> 991 <th> </th> 992 <th></th> 993 </tr> 994 <tr> 995 <td>{@link android.provider.CalendarContract.EventsColumns#TITLE Events.TITLE}</td> 996 <td></td> 997 </tr> 998 <tr> 999 1000 <td>{@link android.provider.CalendarContract#EXTRA_EVENT_BEGIN_TIME CalendarContract.EXTRA_EVENT_BEGIN_TIME} 1001 </td> 1002 <td></td> 1003 </tr> 1004 <tr> 1005 <td>{@link android.provider.CalendarContract#EXTRA_EVENT_END_TIME CalendarContract.EXTRA_EVENT_END_TIME} 1006 </td> 1007 1008 <td></td> 1009 </tr> 1010 <tr> 1011 <td>{@link android.provider.CalendarContract#EXTRA_EVENT_ALL_DAY CalendarContract.EXTRA_EVENT_ALL_DAY} 1012 </td> 1013 1014 <td> <code>true</code> <code>false</code> 1015 </td> </tr> 1016 <tr> 1017 <td>{@link android.provider.CalendarContract.EventsColumns#EVENT_LOCATION Events.EVENT_LOCATION} 1018 </td> 1019 1020 <td></td> 1021 </tr> 1022 <tr> 1023 <td>{@link android.provider.CalendarContract.EventsColumns#DESCRIPTION Events.DESCRIPTION} 1024 </td> 1025 1026 <td></td> 1027 </tr> 1028 <tr> 1029 <td> 1030 {@link android.content.Intent#EXTRA_EMAIL Intent.EXTRA_EMAIL}</td> 1031 <td></td> 1032 </tr> 1033 <tr> 1034 <td> 1035 {@link android.provider.CalendarContract.EventsColumns#RRULE Events.RRULE}</td> 1036 <td></td> 1037 </tr> 1038 <tr> 1039 <td> 1040 {@link android.provider.CalendarContract.EventsColumns#ACCESS_LEVEL Events.ACCESS_LEVEL} 1041 </td> 1042 1043 <td></td> 1044 </tr> 1045 <tr> 1046 <td>{@link android.provider.CalendarContract.EventsColumns#AVAILABILITY Events.AVAILABILITY} 1047 </td> 1048 1049 <td></td> 1050 1051 </table> 1052 <p></p> 1053 1054 1055 <h3 id="intent-insert"></h3> 1056 1057 <p>{@link android.content.Intent#ACTION_INSERT INSERT} {@link android.Manifest.permission#WRITE_CALENDAR} <a href="#manifest"> </a> 1058 1059 1060 </p> 1061 1062 1063 <p> 1064 {@link android.content.Intent#ACTION_INSERT INSERT} 1065 1066 1067 1068 </p> 1069 1070 1071 1072 <p>2012 1 19 7:30 8:30 1073 </p> 1074 1075 <ul> 1076 <li>URI {@link android.provider.CalendarContract.Events#CONTENT_URI Events.CONTENT_URI} 1077 </li> 1078 1079 <li>{@link android.provider.CalendarContract#EXTRA_EVENT_BEGIN_TIME CalendarContract.EXTRA_EVENT_BEGIN_TIME} {@link android.provider.CalendarContract#EXTRA_EVENT_END_TIME CalendarContract.EXTRA_EVENT_END_TIME} 1080 1081 1082 1083 1084 UTC 1085 </li> 1086 1087 <li>{@link android.content.Intent#EXTRA_EMAIL Intent.EXTRA_EMAIL} 1088 </li> 1089 1090 </ul> 1091 <pre> 1092 Calendar beginTime = Calendar.getInstance(); 1093 beginTime.set(2012, 0, 19, 7, 30); 1094 Calendar endTime = Calendar.getInstance(); 1095 endTime.set(2012, 0, 19, 8, 30); 1096 Intent intent = new Intent(Intent.ACTION_INSERT) 1097 .setData(Events.CONTENT_URI) 1098 .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginTime.getTimeInMillis()) 1099 .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime.getTimeInMillis()) 1100 .putExtra(Events.TITLE, "Yoga") 1101 .putExtra(Events.DESCRIPTION, "Group class") 1102 .putExtra(Events.EVENT_LOCATION, "The gym") 1103 .putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY) 1104 .putExtra(Intent.EXTRA_EMAIL, "rowan (a] example.com,trevor (a] example.com"); 1105 startActivity(intent); 1106 </pre> 1107 1108 <h3 id="intent-edit"></h3> 1109 1110 <p><a href="#update-event"></a>{@link android.content.Intent#ACTION_EDIT EDIT} 1111 1112 1113 1114 </p> <p> 1115 </p> 1116 1117 1118 <pre>long eventID = 208; 1119 Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID); 1120 Intent intent = new Intent(Intent.ACTION_EDIT) 1121 .setData(uri) 1122 .putExtra(Events.TITLE, "My New Title"); 1123 startActivity(intent);</pre> 1124 1125 <h3 id="intent-view"> </h3> 1126 <p> {@link android.content.Intent#ACTION_VIEW VIEW} 2 </p> 1127 <ul> 1128 <li></li> 1129 <li></li> 1130 1131 </ul> 1132 <p></p> 1133 <pre>// A date-time specified in milliseconds since the epoch. 1134 long startMillis; 1135 ... 1136 Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon(); 1137 builder.appendPath("time"); 1138 ContentUris.appendId(builder, startMillis); 1139 Intent intent = new Intent(Intent.ACTION_VIEW) 1140 .setData(builder.build()); 1141 startActivity(intent);</pre> 1142 1143 <p></p> 1144 <pre>long eventID = 208; 1145 ... 1146 Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID); 1147 Intent intent = new Intent(Intent.ACTION_VIEW) 1148 .setData(uri); 1149 startActivity(intent); 1150 </pre> 1151 1152 1153 <h2 id="sync-adapter"></h2> 1154 1155 1156 <p> 1157 </p> 1158 1159 <ul> 1160 <li>{@link android.provider.CalendarContract#CALLER_IS_SYNCADAPTER} <code>true</code> </li> 1161 1162 1163 <li>{@link android.provider.CalendarContract.SyncColumns#ACCOUNT_NAME} {@link android.provider.CalendarContract.SyncColumns#ACCOUNT_TYPE} URI 1164 1165 </li> 1166 1167 <li> 1168 1169 1170 <code>ACCOUNT_NAME</code> <code>ACCOUNT_TYPE</code> 1171 1172 1173 </li> </ul> 1174 1175 <p> URI </p> 1176 <pre> static Uri asSyncAdapter(Uri uri, String account, String accountType) { 1177 return uri.buildUpon() 1178 .appendQueryParameter(android.provider.CalendarContract.CALLER_IS_SYNCADAPTER,"true") 1179 .appendQueryParameter(Calendars.ACCOUNT_NAME, account) 1180 .appendQueryParameter(Calendars.ACCOUNT_TYPE, accountType).build(); 1181 } 1182 </pre> 1183 <p><a href="{@docRoot}resources/samples/SampleSyncAdapter/index.html">SampleSyncAdapter</a> 1184 1185