1 page.title= 2 @jd:body 3 <div id="qv-wrapper"> 4 <div id="qv"> 5 <h2> </h2> 6 <ul> 7 <li> Android .</li> 8 <li> 9 . 10 </li> 11 <li> 12 . 13 </li> 14 </ul> 15 <h2> </h2> 16 <ol> 17 <li> 18 <a href="#InformationTypes"> </a> 19 </li> 20 <li> 21 <a href="#RawContactBasics"> </a> 22 </li> 23 <li> 24 <a href="#DataBasics"></a> 25 </li> 26 <li> 27 <a href="#ContactBasics"></a> 28 </li> 29 <li> 30 <a href="#Sources"> </a> 31 </li> 32 <li> 33 <a href="#Permissions"> </a> 34 </li> 35 <li> 36 <a href="#UserProfile"> </a> 37 </li> 38 <li> 39 <a href="#ContactsProviderMetadata"> </a> 40 </li> 41 <li> 42 <a href="#Access"> </a> 43 <li> 44 </li> 45 <li> 46 <a href="#SyncAdapters"> </a> 47 </li> 48 <li> 49 <a href="#SocialStream"> </a> 50 </li> 51 <li> 52 <a href="#AdditionalFeatures"> </a> 53 </li> 54 </ol> 55 <h2>Key </h2> 56 <ol> 57 <li>{@link android.provider.ContactsContract.Contacts}</li> 58 <li>{@link android.provider.ContactsContract.RawContacts}</li> 59 <li>{@link android.provider.ContactsContract.Data}</li> 60 <li>{@code android.provider.ContactsContract.StreamItems}</li> 61 </ol> 62 <h2> </h2> 63 <ol> 64 <li> 65 <a href="{@docRoot}resources/samples/ContactManager/index.html"> 66 67 </a> 68 </li> 69 <li> 70 <a href="{@docRoot}resources/samples/SampleSyncAdapter/index.html"> 71 </a> 72 </li> 73 </ol> 74 <h2> </h2> 75 <ol> 76 <li> 77 <a href="{@docRoot}guide/topics/providers/content-provider-basics.html"> 78 79 </a> 80 </li> 81 </ol> 82 </div> 83 </div> 84 <p> 85 86 Android . 87 . 88 . 89 , 90 . API 91 92 . 93 </p> 94 <p> 95 . 96 </p> 97 <ul> 98 <li> 99 . 100 </li> 101 <li> 102 . 103 </li> 104 <li> 105 . 106 </li> 107 <li> 108 109 . 110 </li> 111 </ul> 112 <p> 113 Android . Android 114 115 <a href="{@docRoot}guide/topics/providers/content-provider-basics.html"> 116 </a> . 117 <a href="{@docRoot}resources/samples/SampleSyncAdapter/index.html"> </a> 118 Google Web Services 119 . 120 </p> 121 <h2 id="InformationTypes"> </h2> 122 <p> 123 Android . 124 . 1 125 . 126 </p> 127 <img src="{@docRoot}images/providers/contacts_structure.png" alt="" height="364" id="figure1" /> 128 <p class="img-caption"> 129 <strong> 1.</strong> . 130 </p> 131 <p> 132 . 133 URI, . 134 </p> 135 <dl> 136 <dt> 137 {@link android.provider.ContactsContract.Contacts} 138 </dt> 139 <dd> 140 . 141 </dd> 142 <dt> 143 {@link android.provider.ContactsContract.RawContacts} 144 </dt> 145 <dd> 146 , . 147 </dd> 148 <dt> 149 {@link android.provider.ContactsContract.Data} 150 </dt> 151 <dd> 152 . 153 </dd> 154 </dl> 155 <p> 156 {@link android.provider.ContactsContract} 157 , 158 . 159 </p> 160 <h2 id="RawContactBasics"> </h2> 161 <p> 162 163 . , 164 . 165 166 . 167 </p> 168 <p> 169 170 {@link android.provider.ContactsContract.RawContacts} . , 171 {@link android.provider.ContactsContract.Data} . 172 {@link android.provider.ContactsContract.RawContacts} {@code android.provider.BaseColumns#_ID RawContacts._ID} 173 {@link android.provider.ContactsContract.DataColumns#RAW_CONTACT_ID Data.RAW_CONTACT_ID} 174 . 175 </p> 176 <h3 id="RawContactsColumns"> </h3> 177 <p> 178 {@link android.provider.ContactsContract.RawContacts} 179 1 . . 180 </p> 181 <p class="table-caption" id="table1"> 182 <strong> 1.</strong> . 183 </p> 184 <table> 185 <tr> 186 <th scope="col"> </th> 187 <th scope="col"></th> 188 <th scope="col"></th> 189 </tr> 190 <tr> 191 <td> 192 {@link android.provider.ContactsContract.SyncColumns#ACCOUNT_NAME} 193 </td> 194 <td> 195 . 196 , Google 197 Gmail . 198 {@link android.provider.ContactsContract.SyncColumns#ACCOUNT_TYPE} 199 . 200 </td> 201 <td> 202 . 203 . 204 </td> 205 </tr> 206 <tr> 207 <td> 208 {@link android.provider.ContactsContract.SyncColumns#ACCOUNT_TYPE} 209 </td> 210 <td> 211 . , Google 212 <code>com.google</code>. 213 . 214 . 215 </td> 216 <td> 217 218 . 219 </tr> 220 <tr> 221 <td> 222 {@link android.provider.ContactsContract.RawContactsColumns#DELETED} 223 </td> 224 <td> 225 "" . 226 </td> 227 <td> 228 . 229 230 . 231 </td> 232 </tr> 233 </table> 234 <h4></h4> 235 <p> 236 237 {@link android.provider.ContactsContract.RawContacts} . 238 </p> 239 <ul> 240 <li> 241 242 {@link android.provider.ContactsContract.RawContacts} . , 243 {@link android.provider.ContactsContract.CommonDataKinds.StructuredName} 244 {@link android.provider.ContactsContract.Data} . 245 {@link android.provider.ContactsContract.Data} . 246 </li> 247 <li> 248 <strong>:</strong> 249 {@link android.accounts.AccountManager} . , 250 . , 251 . 252 <p> 253 , {@code com.example.dataservice} 254 255 {@code becky.sharp (a] dataservice.example.com}, 256 ""({@code com.example.dataservice}) "" 257 ({@code becky.smart (a] dataservice.example.com}) . 258 , 259 . 260 . 261 </li> 262 </ul> 263 <h3 id="RawContactsExample"> </h3> 264 <p> 265 , "Emily Dickinson" 266 . 267 </p> 268 <ul> 269 <li><code>emily.dickinson (a] gmail.com</code></li> 270 <li><code>emilyd (a] gmail.com</code></li> 271 <li>Twitter "belle_of_amherst"</li> 272 </ul> 273 <p> 274 <em></em> <em> </em> 275 . 276 </p> 277 <p> 278 Emily Dickinson , 279 Gmail <code>emily.dickinson (a] gmail.com</code> , 280 "Thomas Higginson" . Gmail 281 <code>emilyd (a] gmail.com</code> "Thomas Higginson" . 282 . Emily Twitter "colonel_tom"(Thomas Higginson Twitter ID) 283 . 284 </p> 285 <p> 286 . 287 </p> 288 <ol> 289 <li> 290 <code>emily.dickinson (a] gmail.com</code> "Thomas Higginson" . 291 Google. 292 </li> 293 <li> 294 <code>emilyd (a] gmail.com</code> "Thomas Higginson" . 295 Google. 296 . 297 . 298 </li> 299 <li> 300 "belle_of_amherst" "Thomas Higginson" . 301 Twitter. 302 </li> 303 </ol> 304 <h2 id="DataBasics"></h2> 305 <p> 306 , 307 <code>_ID</code> {@link android.provider.ContactsContract.Data} 308 . . 309 . , 310 {@code emilyd (a] gmail.com} "Thomas Higginson"(Google <code>emilyd (a] gmail.com</code> Thomas Higginson 311 ) 312 <code>thigg (a] gmail.com</code> 313 <code>thomas.higginson (a] gmail.com</code> , 314 . 315 </p> 316 <p> 317 . , 318 , , , 319 {@link android.provider.ContactsContract.Data} . 320 {@link android.provider.ContactsContract.Data} 321 . , 322 323 . 324 </p> 325 <h3 id="DescriptiveColumns"> </h3> 326 <p> 327 . 328 </p> 329 <dl> 330 <dt> 331 {@link android.provider.ContactsContract.Data#RAW_CONTACT_ID} 332 </dt> 333 <dd> 334 <code>_ID</code> . 335 </dd> 336 <dt> 337 {@link android.provider.ContactsContract.Data#MIMETYPE} 338 </dt> 339 <dd> 340 , MIME . 341 {@link android.provider.ContactsContract.CommonDataKinds} 342 MIME . MIME , 343 . 344 </dd> 345 <dt> 346 {@link android.provider.ContactsContract.DataColumns#IS_PRIMARY} 347 </dt> 348 <dd> 349 , 350 {@link android.provider.ContactsContract.DataColumns#IS_PRIMARY} 351 . , 352 <strong> </strong> 353 {@link android.provider.ContactsContract.Data} 354 {@link android.provider.ContactsContract.DataColumns#IS_PRIMARY} 355 0 . 356 </dd> 357 </dl> 358 <h3 id="GenericColumns"> </h3> 359 <p> 360 15 <code>DATA1</code> 361 <code>DATA15</code> 362 , <code>SYNC1</code> <code>SYNC4</code> 363 . 364 . 365 </p> 366 <p> 367 <code>DATA1</code> . 368 . 369 , . 370 </p> 371 <p> 372 <code>DATA15</code> BLOB(Binary Large Object) 373 . 374 </p> 375 <h3 id="TypeSpecificNames"> </h3> 376 <p> 377 , 378 . 379 {@link android.provider.ContactsContract.CommonDataKinds} . 380 , 381 . 382 </p> 383 <p> 384 , {@link android.provider.ContactsContract.CommonDataKinds.Email} 385 MIME {@link android.provider.ContactsContract.CommonDataKinds.Email#CONTENT_ITEM_TYPE 386 Email.CONTENT_ITEM_TYPE} 387 {@link android.provider.ContactsContract.Data} 388 . 389 {@link android.provider.ContactsContract.CommonDataKinds.Email#ADDRESS} 390 . 391 {@link android.provider.ContactsContract.CommonDataKinds.Email#ADDRESS} 392 "data1", . 393 </p> 394 <p class="caution"> 395 <strong>:</strong> 396 {@link android.provider.ContactsContract.Data} 397 MIME . 398 . , MIME 399 {@link android.provider.ContactsContract.CommonDataKinds.Email#CONTENT_ITEM_TYPE 400 Email.CONTENT_ITEM_TYPE} 401 <code>DATA1</code> . MIME 402 . 403 </p> 404 <p> 405 2 406 {@link android.provider.ContactsContract.Data} 407 "" . 408 </p> 409 <img src="{@docRoot}images/providers/data_columns.png" alt="How type-specific column names map to generic column names" height="311" id="figure2" /> 410 <p class="img-caption"> 411 <strong> 2.</strong> . 412 </p> 413 <h3 id="ColumnMaps"> </h3> 414 <p> 415 2 . 416 </p> 417 <p class="table-caption" id="table2"> 418 <strong> 2.</strong> </p> 419 <table> 420 <tr> 421 <th scope="col"> </th> 422 <th scope="col"> </th> 423 <th scope="col"></th> 424 </tr> 425 <tr> 426 <td>{@link android.provider.ContactsContract.CommonDataKinds.StructuredName}</td> 427 <td> .</td> 428 <td> .</td> 429 </tr> 430 <tr> 431 <td>{@link android.provider.ContactsContract.CommonDataKinds.Photo}</td> 432 <td> .</td> 433 <td> .</td> 434 </tr> 435 <tr> 436 <td>{@link android.provider.ContactsContract.CommonDataKinds.Email}</td> 437 <td> .</td> 438 <td> .</td> 439 </tr> 440 <tr> 441 <td>{@link android.provider.ContactsContract.CommonDataKinds.StructuredPostal}</td> 442 <td> .</td> 443 <td> .</td> 444 </tr> 445 <tr> 446 <td>{@link android.provider.ContactsContract.CommonDataKinds.GroupMembership}</td> 447 <td> .</td> 448 <td> 449 . 450 <a href="#Groups"> </a> . 451 </td> 452 </tr> 453 </table> 454 <h3 id="ContactBasics"></h3> 455 <p> 456 457 <strong></strong> . 458 . 459 . 460 , . 461 </p> 462 <p class="note"> 463 <strong>:</strong> 464 {@link android.content.ContentResolver#insert(Uri,ContentValues) insert()} , 465 {@link java.lang.UnsupportedOperationException} . " " 466 . 467 </p> 468 <p> 469 470 . 471 472 . 473 <em></em> , 474 . 475 </p> 476 <p> 477 478 {@link android.provider.ContactsContract.Contacts Contacts} <code>_ID</code> 479 . {@link android.provider.ContactsContract.RawContacts} <code>CONTACT_ID</code> 480 <code>_ID</code> 481 . 482 </p> 483 <p> 484 {@link android.provider.ContactsContract.Contacts} "" 485 {@code android.provider.ContactsContract.ContactsColumns#LOOKUP_KEY} 486 . , 487 {@code android.provider.BaseColumns#_ID} 488 . URI 489 {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI} 490 {@code android.provider.ContactsContract.ContactsColumns#LOOKUP_KEY} 491 , 492 {@code android.provider.ContactsContract.ContactsColumns#LOOKUP_KEY} 493 "" . 494 {@code android.provider.BaseColumns#_ID} . 495 </p> 496 <p> 497 3 . 498 </p> 499 <img src="{@docRoot}images/providers/contacts_tables.png" alt="Contacts provider main tables" height="514" id="figure4" /> 500 <p class="img-caption"> 501 <strong> 3.</strong> , . 502 </p> 503 <h2 id="Sources"> </h2> 504 <p> 505 , 506 <strong> </strong> . 507 . 508 , {@link android.content.ContentResolver} 509 . 510 </p> 511 <p> 512 Android . 513 , 514 . 515 <a href="#RawContactsExample"> </a> . , 516 . 517 </p> 518 <dl> 519 <dt> 520 521 </dt> 522 <dd> 523 . , 524 . , Google , 525 <code>google.com</code> . 526 {@link android.accounts.AccountManager} . 527 </dd> 528 <dt> 529 530 </dt> 531 <dd> 532 . Google 533 Google , . 534 ID . 535 </dd> 536 </dl> 537 <p> 538 . Google 539 . 540 , . 541 . 542 . 543 </p> 544 <p> 545 , 546 . 547 <a href="#SyncAdapters"> </a> . 548 </p> 549 <p> 550 4 551 . " " , . 552 </p> 553 <img src="{@docRoot}images/providers/ContactsDataFlow.png" alt="Flow of data about people" height="252" id="figure5" /> 554 <p class="img-caption"> 555 <strong> 4.</strong> . 556 </p> 557 <h2 id="Permissions"> </h2> 558 <p> 559 560 . 561 </p> 562 <dl> 563 <dt> </dt> 564 <dd> 565 {@link android.Manifest.permission#READ_CONTACTS}, 566 <code>AndroidManifest.xml</code> 567 <code><a href="{@docRoot}guide/topics/manifest/uses-permission-element.html"> 568 <uses-permission></a></code> 569 <code><uses-permission android:name="android.permission.READ_CONTACTS"></code> . 570 </dd> 571 <dt> </dt> 572 <dd> 573 {@link android.Manifest.permission#WRITE_CONTACTS}, 574 <code>AndroidManifest.xml</code> 575 <code><a href="{@docRoot}guide/topics/manifest/uses-permission-element.html"> 576 <uses-permission></a></code> 577 <code><uses-permission android:name="android.permission.WRITE_CONTACTS"></code> . 578 </dd> 579 </dl> 580 <p> 581 . 582 583 <a href="#UserProfile"> </a> . 584 </p> 585 <p> 586 . 587 . 588 589 . 590 </p> 591 <h2 id="UserProfile"> </h2> 592 <p> 593 {@link android.provider.ContactsContract.Contacts} 594 . <code>user</code> 595 . 596 . 597 . 598 {@link android.provider.ContactsContract.Profile} . 599 </p> 600 <p> 601 . 602 {@link android.Manifest.permission#READ_CONTACTS} 603 {@link android.Manifest.permission#WRITE_CONTACTS} , 604 {@code android.Manifest.permission#READ_PROFILE} 605 {@code android.Manifest.permission#WRITE_PROFILE} 606 . 607 </p> 608 <p> 609 . 610 {@code android.Manifest.permission#READ_PROFILE} 611 . 612 . 613 </p> 614 <p> 615 , 616 {@link android.content.ContentResolver#query(Uri,String[], String, String[], String) 617 ContentResolver.query()} . URI 618 {@link android.provider.ContactsContract.Profile#CONTENT_URI} 619 . URI 620 URI . , . 621 </p> 622 <pre> 623 // Sets the columns to retrieve for the user profile 624 mProjection = new String[] 625 { 626 Profile._ID, 627 Profile.DISPLAY_NAME_PRIMARY, 628 Profile.LOOKUP_KEY, 629 Profile.PHOTO_THUMBNAIL_URI 630 }; 631 632 // Retrieves the profile from the Contacts Provider 633 mProfileCursor = 634 getContentResolver().query( 635 Profile.CONTENT_URI, 636 mProjection , 637 null, 638 null, 639 null); 640 </pre> 641 <p class="note"> 642 <strong>:</strong> 643 , 644 {@link android.provider.ContactsContract.ContactsColumns#IS_USER_PROFILE} . 645 "1" . 646 </p> 647 <h2 id="ContactsProviderMetadata"> </h2> 648 <p> 649 650 . 651 , , 652 {@link android.provider.ContactsContract.Settings} 653 {@link android.provider.ContactsContract.SyncState} . 654 . 655 </p> 656 <p class="table-caption" id="table3"> 657 <strong> 3.</strong> </p> 658 <table> 659 <tr> 660 <th scope="col"></th> 661 <th scope="col"></th> 662 <th scope="col"></th> 663 <th scope="col"></th> 664 </tr> 665 <tr> 666 <td rowspan="2">{@link android.provider.ContactsContract.RawContacts}</td> 667 <td rowspan="2">{@link android.provider.ContactsContract.SyncColumns#DIRTY}</td> 668 <td>"0" - .</td> 669 <td rowspan="2"> 670 671 . Android 672 . 673 <p> 674 675 {@link android.provider.ContactsContract#CALLER_IS_SYNCADAPTER} 676 URI . (dirty) . 677 , 678 . 679 </p> 680 </td> 681 </tr> 682 <tr> 683 <td>"1" - , .</td> 684 </tr> 685 <tr> 686 <td>{@link android.provider.ContactsContract.RawContacts}</td> 687 <td>{@link android.provider.ContactsContract.SyncColumns#VERSION}</td> 688 <td> .</td> 689 <td> 690 691 . 692 </td> 693 </tr> 694 <tr> 695 <td>{@link android.provider.ContactsContract.Data}</td> 696 <td>{@link android.provider.ContactsContract.DataColumns#DATA_VERSION}</td> 697 <td> .</td> 698 <td> 699 700 . 701 </td> 702 </tr> 703 <tr> 704 <td>{@link android.provider.ContactsContract.RawContacts}</td> 705 <td>{@link android.provider.ContactsContract.SyncColumns#SOURCE_ID}</td> 706 <td> 707 708 . 709 </td> 710 <td> 711 , 712 ID . Android , 713 . 714 , 715 {@link android.provider.ContactsContract.SyncColumns#SOURCE_ID} . 716 <p> 717 , ID <strong></strong> 718 . 719 </p> 720 <ul> 721 <li> 722 : ID . 723 . 724 <em></em> ID 725 . , 726 {@code emily.dickinson (a] gmail.com} "Thomas Higginson" 727 {@code emilyd (a] gmail.com} 728 "Thomas Higginson" ID . 729 </li> 730 <li> 731 : ID 732 . , 733 ID 734 . 735 . 736 </li> 737 </ul> 738 </td> 739 </tr> 740 <tr> 741 <td rowspan="2">{@link android.provider.ContactsContract.Groups}</td> 742 <td rowspan="2">{@link android.provider.ContactsContract.GroupsColumns#GROUP_VISIBLE}</td> 743 <td>"0" - Android UI .</td> 744 <td> 745 746 . 747 </td> 748 </tr> 749 <tr> 750 <td>"1" - UI .</td> 751 </tr> 752 <tr> 753 <td rowspan="2">{@link android.provider.ContactsContract.Settings}</td> 754 <td rowspan="2"> 755 {@link android.provider.ContactsContract.SettingsColumns#UNGROUPED_VISIBLE}</td> 756 <td> 757 "0" - , Android UI 758 . 759 </td> 760 <td rowspan="2"> 761 , ( 762 {@link android.provider.ContactsContract.Data} 763 {@link android.provider.ContactsContract.CommonDataKinds.GroupMembership} 764 ). 765 {@link android.provider.ContactsContract.Settings} 766 . 767 . 768 </td> 769 </tr> 770 <tr> 771 <td> 772 "1" - , UI 773 . 774 </td> 775 776 </tr> 777 <tr> 778 <td>{@link android.provider.ContactsContract.SyncState}</td> 779 <td>()</td> 780 <td> 781 . 782 </td> 783 <td> 784 785 . 786 </td> 787 </tr> 788 </table> 789 <h2 id="Access"> </h2> 790 <p> 791 , 792 . 793 </p> 794 <ul> 795 <li> 796 . 797 </li> 798 <li> 799 . 800 </li> 801 <li> 802 . 803 </li> 804 <li> 805 . 806 </li> 807 </ul> 808 <p> 809 810 <a href="#SyncAdapters"> </a> . 811 </p> 812 <h3 id="Entities"> </h3> 813 <p> 814 , 815 "" . , 816 817 {@link android.provider.ContactsContract.Contacts} 818 {@link android.provider.ContactsContract.RawContacts} 819 {@link android.provider.ContactsContract.RawContacts} 820 {@link android.provider.ContactsContract.CommonDataKinds.Email} . , 821 <strong></strong> 822 . 823 </p> 824 <p> 825 . 826 , 827 . {@link android.database.Cursor}, 828 . 829 {@link android.provider.ContactsContract.Contacts.Entity} 830 {@link android.provider.ContactsContract.CommonDataKinds.Email} 831 {@link android.database.Cursor} 832 {@link android.provider.ContactsContract.CommonDataKinds.Email} . 833 </p> 834 <p> 835 . 836 . ID , 837 ID . , 838 , 839 . 840 </p> 841 <p class="note"> 842 <strong>:</strong> 843 . , 844 {@link java.lang.Exception} . 845 </p> 846 <p> 847 . 848 , "" "" . 849 . , ID 850 . {@link android.provider.ContactsContract.Contacts.Entity} 851 852 . 853 </p> 854 <p> 855 "" . 856 </p> 857 <pre> 858 ... 859 /* 860 * Appends the entity path to the URI. In the case of the Contacts Provider, the 861 * expected URI is content://com.google.contacts/#/entity (# is the ID value). 862 */ 863 mContactUri = Uri.withAppendedPath( 864 mContactUri, 865 ContactsContract.Contacts.Entity.CONTENT_DIRECTORY); 866 867 // Initializes the loader identified by LOADER_ID. 868 getLoaderManager().initLoader( 869 LOADER_ID, // The identifier of the loader to initialize 870 null, // Arguments for the loader (in this case, none) 871 this); // The context of the activity 872 873 // Creates a new cursor adapter to attach to the list view 874 mCursorAdapter = new SimpleCursorAdapter( 875 this, // the context of the activity 876 R.layout.detail_list_item, // the view item containing the detail widgets 877 mCursor, // the backing cursor 878 mFromColumns, // the columns in the cursor that provide the data 879 mToViews, // the views in the view item that display the data 880 0); // flags 881 882 // Sets the ListView's backing adapter. 883 mRawContactList.setAdapter(mCursorAdapter); 884 ... 885 @Override 886 public Loader<Cursor> onCreateLoader(int id, Bundle args) { 887 888 /* 889 * Sets the columns to retrieve. 890 * RAW_CONTACT_ID is included to identify the raw contact associated with the data row. 891 * DATA1 contains the first column in the data row (usually the most important one). 892 * MIMETYPE indicates the type of data in the data row. 893 */ 894 String[] projection = 895 { 896 ContactsContract.Contacts.Entity.RAW_CONTACT_ID, 897 ContactsContract.Contacts.Entity.DATA1, 898 ContactsContract.Contacts.Entity.MIMETYPE 899 }; 900 901 /* 902 * Sorts the retrieved cursor by raw contact id, to keep all data rows for a single raw 903 * contact collated together. 904 */ 905 String sortOrder = 906 ContactsContract.Contacts.Entity.RAW_CONTACT_ID + 907 " ASC"; 908 909 /* 910 * Returns a new CursorLoader. The arguments are similar to 911 * ContentResolver.query(), except for the Context argument, which supplies the location of 912 * the ContentResolver to use. 913 */ 914 return new CursorLoader( 915 getApplicationContext(), // The activity's context 916 mContactUri, // The entity content URI for a single contact 917 projection, // The columns to retrieve 918 null, // Retrieve all the raw contacts and their data rows. 919 null, // 920 sortOrder); // Sort by the raw contact ID. 921 } 922 </pre> 923 <p> 924 , {@link android.app.LoaderManager} 925 {@link android.app.LoaderManager.LoaderCallbacks#onLoadFinished(Loader, D) 926 onLoadFinished()} . 927 {@link android.database.Cursor}, . , 928 {@link android.database.Cursor} . 929 </p> 930 <h3 id="Transactions"> </h3> 931 <p> 932 , 933 " " . 934 {@link android.content.ContentProviderOperation} {@link java.util.ArrayList} 935 {@link android.content.ContentResolver#applyBatch(String, ArrayList) applyBatch()} . 936 937 {@link android.content.ContentResolver#applyBatch(String, ArrayList) applyBatch()} 938 , 939 . 940 . 941 </p> 942 <p class="note"> 943 <strong>:</strong> <em></em> 944 . 945 946 <a href="#Intents"> </a> . 947 </p> 948 <h4> </h4> 949 <p> 950 , 951 . 952 953 <strong> </strong> . 954 {@link android.content.ContentProviderOperation#isYieldAllowed()} <code>true</code> {@link android.content.ContentProviderOperation} . 955 956 957 . , 958 {@link java.util.ArrayList} 959 . 960 </p> 961 <p> 962 963 {@link android.content.ContentResolver#applyBatch(String, ArrayList) applyBatch()} . , 964 . 965 , 966 , 967 . 968 </p> 969 <p> 970 . 971 . , 972 . , 973 974 . 975 </p> 976 <h4> </h4> 977 <p> 978 979 {@link android.content.ContentProviderOperation} , 980 981 {@code android.provider.BaseColumns#_ID} 982 {@link android.provider.ContactsContract.DataColumns#RAW_CONTACT_ID} . , 983 {@link android.content.ContentProviderOperation} 984 . {@link android.content.ContentProviderOperation} 985 . 986 {@link android.content.ContentProviderOperation.Builder} 987 {@link android.content.ContentProviderOperation.Builder#withValueBackReference(String, int) withValueBackReference()} . 988 989 . 990 </p> 991 <p> 992 {@link android.content.ContentProviderOperation.Builder#withValueBackReference(String, int) withValueBackReference()} 993 . 994 </p> 995 <dl> 996 <dt> 997 <code>key</code> 998 </dt> 999 <dd> 1000 - . 1001 . 1002 </dd> 1003 <dt> 1004 <code>previousResult</code> 1005 </dt> 1006 <dd> 1007 1008 {@link android.content.ContentResolver#applyBatch(String, ArrayList) applyBatch()} {@link android.content.ContentProviderResult} 1009 0 . 1010 1011 . <code>previousResult</code> 1012 , <code>key</code> 1013 . 1014 {@code android.provider.BaseColumns#_ID} , 1015 {@link android.provider.ContactsContract.Data} "" . 1016 <p> 1017 1018 {@link android.content.ContentResolver#applyBatch(String, ArrayList) applyBatch()} , 1019 {@link android.content.ContentProviderOperation} {@link java.util.ArrayList} 1020 . 1021 <code>null</code> , 1022 1023 {@link android.content.ContentProviderOperation.Builder#withValueBackReference(String, int) withValueBackReference()} 1024 {@link java.lang.Exception} . 1025 1026 </p> 1027 </dd> 1028 </dl> 1029 <p> 1030 . 1031 . 1032 <code>createContacEntry()</code> , 1033 <code><a href="{@docRoot}resources/samples/ContactManager/index.html"> 1034 Contact Manager</a></code> <code>ContactAdder</code> 1035 . 1036 </p> 1037 <p> 1038 UI . 1039 . 1040 </p> 1041 <pre> 1042 // Creates a contact entry from the current UI values, using the currently-selected account. 1043 protected void createContactEntry() { 1044 /* 1045 * Gets values from the UI 1046 */ 1047 String name = mContactNameEditText.getText().toString(); 1048 String phone = mContactPhoneEditText.getText().toString(); 1049 String email = mContactEmailEditText.getText().toString(); 1050 1051 int phoneType = mContactPhoneTypes.get( 1052 mContactPhoneTypeSpinner.getSelectedItemPosition()); 1053 1054 int emailType = mContactEmailTypes.get( 1055 mContactEmailTypeSpinner.getSelectedItemPosition()); 1056 </pre> 1057 <p> 1058 1059 {@link android.provider.ContactsContract.RawContacts} . 1060 </p> 1061 <pre> 1062 /* 1063 * Prepares the batch operation for inserting a new raw contact and its data. Even if 1064 * the Contacts Provider does not have any data for this person, you can't add a Contact, 1065 * only a raw contact. The Contacts Provider will then add a Contact automatically. 1066 */ 1067 1068 // Creates a new array of ContentProviderOperation objects. 1069 ArrayList<ContentProviderOperation> ops = 1070 new ArrayList<ContentProviderOperation>(); 1071 1072 /* 1073 * Creates a new raw contact with its account type (server type) and account name 1074 * (user's account). Remember that the display name is not stored in this row, but in a 1075 * StructuredName data row. No other data is required. 1076 */ 1077 ContentProviderOperation.Builder op = 1078 ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI) 1079 .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, mSelectedAccount.getType()) 1080 .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, mSelectedAccount.getName()); 1081 1082 // Builds the operation and adds it to the array of operations 1083 ops.add(op.build()); 1084 </pre> 1085 <p> 1086 , , . 1087 </p> 1088 <p> 1089 1090 {@link android.content.ContentProviderOperation.Builder#withValueBackReference(String, int) withValueBackReference()} 1091 1092 {@link android.provider.ContactsContract.DataColumns#RAW_CONTACT_ID} . 1093 {@link android.content.ContentProviderResult} , 1094 {@code android.provider.BaseColumns#_ID} 1095 . , 1096 {@link android.provider.ContactsContract.DataColumns#RAW_CONTACT_ID} 1097 {@link android.provider.ContactsContract.RawContacts} . 1098 </p> 1099 <p> 1100 {@link android.content.ContentProviderOperation.Builder} 1101 {@link android.content.ContentProviderOperation.Builder#withYieldAllowed(boolean) 1102 withYieldAllowed()} . 1103 </p> 1104 <pre> 1105 // Creates the display name for the new raw contact, as a StructuredName data row. 1106 op = 1107 ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) 1108 /* 1109 * withValueBackReference sets the value of the first argument to the value of 1110 * the ContentProviderResult indexed by the second argument. In this particular 1111 * call, the raw contact ID column of the StructuredName data row is set to the 1112 * value of the result returned by the first operation, which is the one that 1113 * actually adds the raw contact row. 1114 */ 1115 .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) 1116 1117 // Sets the data row's MIME type to StructuredName 1118 .withValue(ContactsContract.Data.MIMETYPE, 1119 ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE) 1120 1121 // Sets the data row's display name to the name in the UI. 1122 .withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name); 1123 1124 // Builds the operation and adds it to the array of operations 1125 ops.add(op.build()); 1126 1127 // Inserts the specified phone number and type as a Phone data row 1128 op = 1129 ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) 1130 /* 1131 * Sets the value of the raw contact id column to the new raw contact ID returned 1132 * by the first operation in the batch. 1133 */ 1134 .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) 1135 1136 // Sets the data row's MIME type to Phone 1137 .withValue(ContactsContract.Data.MIMETYPE, 1138 ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE) 1139 1140 // Sets the phone number and type 1141 .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, phone) 1142 .withValue(ContactsContract.CommonDataKinds.Phone.TYPE, phoneType); 1143 1144 // Builds the operation and adds it to the array of operations 1145 ops.add(op.build()); 1146 1147 // Inserts the specified email and type as a Phone data row 1148 op = 1149 ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) 1150 /* 1151 * Sets the value of the raw contact id column to the new raw contact ID returned 1152 * by the first operation in the batch. 1153 */ 1154 .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) 1155 1156 // Sets the data row's MIME type to Email 1157 .withValue(ContactsContract.Data.MIMETYPE, 1158 ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE) 1159 1160 // Sets the email address and type 1161 .withValue(ContactsContract.CommonDataKinds.Email.ADDRESS, email) 1162 .withValue(ContactsContract.CommonDataKinds.Email.TYPE, emailType); 1163 1164 /* 1165 * Demonstrates a yield point. At the end of this insert, the batch operation's thread 1166 * will yield priority to other threads. Use after every set of operations that affect a 1167 * single contact, to avoid degrading performance. 1168 */ 1169 op.withYieldAllowed(true); 1170 1171 // Builds the operation and adds it to the array of operations 1172 ops.add(op.build()); 1173 </pre> 1174 <p> 1175 1176 {@link android.content.ContentResolver#applyBatch(String, ArrayList) applyBatch()} 1177 . 1178 </p> 1179 <pre> 1180 // Ask the Contacts Provider to create a new contact 1181 Log.d(TAG,"Selected account: " + mSelectedAccount.getName() + " (" + 1182 mSelectedAccount.getType() + ")"); 1183 Log.d(TAG,"Creating contact: " + name); 1184 1185 /* 1186 * Applies the array of ContentProviderOperation objects in batch. The results are 1187 * discarded. 1188 */ 1189 try { 1190 1191 getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); 1192 } catch (Exception e) { 1193 1194 // Display a warning 1195 Context ctx = getApplicationContext(); 1196 1197 CharSequence txt = getString(R.string.contactCreationFailure); 1198 int duration = Toast.LENGTH_SHORT; 1199 Toast toast = Toast.makeText(ctx, txt, duration); 1200 toast.show(); 1201 1202 // Log exception 1203 Log.e(TAG, "Exception encountered while inserting contact: " + e); 1204 } 1205 } 1206 </pre> 1207 <p> 1208 <strong> </strong> . 1209 . 1210 1211 . 1212 . 1213 </p> 1214 <p> 1215 1216 . 1217 . 1218 </p> 1219 <p> 1220 1221 {@link android.provider.ContactsContract.RawContacts} , . 1222 </p> 1223 <ol> 1224 <li> 1225 {@link android.provider.ContactsContract.SyncColumns#VERSION} 1226 . 1227 </li> 1228 <li> 1229 1230 {@link android.content.ContentProviderOperation.Builder} 1231 {@link android.content.ContentProviderOperation#newAssertQuery(Uri)} . URI , 1232 {@link android.provider.ContactsContract.RawContacts#CONTENT_URI 1233 RawContacts.CONTENT_URI} 1234 {@code android.provider.BaseColumns#_ID} . 1235 </li> 1236 <li> 1237 {@link android.content.ContentProviderOperation.Builder} , 1238 {@link android.content.ContentProviderOperation.Builder#withValue(String, Object) 1239 withValue()} {@link android.provider.ContactsContract.SyncColumns#VERSION} 1240 . 1241 </li> 1242 <li> 1243 {@link android.content.ContentProviderOperation.Builder} , 1244 {@link android.content.ContentProviderOperation.Builder#withExpectedCount(int) 1245 withExpectedCount()} . 1246 </li> 1247 <li> 1248 {@link android.content.ContentProviderOperation.Builder#build()} 1249 {@link android.content.ContentProviderOperation} , 1250 {@link android.content.ContentResolver#applyBatch(String, ArrayList) applyBatch()} {@link java.util.ArrayList} . 1251 1252 </li> 1253 <li> 1254 . 1255 </li> 1256 </ol> 1257 <p> 1258 , 1259 "" {@link android.content.ContentProviderOperation} 1260 . 1261 . 1262 </p> 1263 <p> 1264 {@link android.content.CursorLoader} 1265 "" {@link android.content.ContentProviderOperation} 1266 . 1267 </p> 1268 <pre> 1269 /* 1270 * The application uses CursorLoader to query the raw contacts table. The system calls this method 1271 * when the load is finished. 1272 */ 1273 public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { 1274 1275 // Gets the raw contact's _ID and VERSION values 1276 mRawContactID = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID)); 1277 mVersion = cursor.getInt(cursor.getColumnIndex(SyncColumns.VERSION)); 1278 } 1279 1280 ... 1281 1282 // Sets up a Uri for the assert operation 1283 Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, mRawContactID); 1284 1285 // Creates a builder for the assert operation 1286 ContentProviderOperation.Builder assertOp = ContentProviderOperation.netAssertQuery(rawContactUri); 1287 1288 // Adds the assertions to the assert operation: checks the version and count of rows tested 1289 assertOp.withValue(SyncColumns.VERSION, mVersion); 1290 assertOp.withExpectedCount(1); 1291 1292 // Creates an ArrayList to hold the ContentProviderOperation objects 1293 ArrayList ops = new ArrayList<ContentProviderOperationg>; 1294 1295 ops.add(assertOp.build()); 1296 1297 // You would add the rest of your batch operations to "ops" here 1298 1299 ... 1300 1301 // Applies the batch. If the assert fails, an Exception is thrown 1302 try 1303 { 1304 ContentProviderResult[] results = 1305 getContentResolver().applyBatch(AUTHORITY, ops); 1306 1307 } catch (OperationApplicationException e) { 1308 1309 // Actions you want to take if the assert operation fails go here 1310 } 1311 </pre> 1312 <h3 id="Intents"> </h3> 1313 <p> 1314 1315 . UI , 1316 . . 1317 <ul> 1318 <li> .</li> 1319 <li> .</li> 1320 <li> .</li> 1321 <li> .</li> 1322 </ul> 1323 <p> 1324 , 1325 . 1326 </p> 1327 <p> 1328 1329 UI . 1330 . 1331 , 1332 . 1333 </p> 1334 <p> 1335 1336 " " <a href="{@docRoot}guide/topics/providers/content-provider-basics.html"> 1337 </a> . , 1338 MIME 4 , 1339 1340 {@link android.content.Intent#putExtra(String, String) putExtra()} 1341 {@link android.provider.ContactsContract.Intents.Insert} . 1342 </p> 1343 <p class="table-caption" id="table4"> 1344 <strong> 4.</strong> 1345 </p> 1346 <table style="width:75%"> 1347 <tr> 1348 <th scope="col" style="width:10%"></th> 1349 <th scope="col" style="width:5%"></th> 1350 <th scope="col" style="width:10%"></th> 1351 <th scope="col" style="width:10%">MIME </th> 1352 <th scope="col" style="width:25%"></th> 1353 </tr> 1354 <tr> 1355 <td><strong> </strong></td> 1356 <td>{@link android.content.Intent#ACTION_PICK}</td> 1357 <td> 1358 . 1359 <ul> 1360 <li> 1361 {@link android.provider.ContactsContract.Contacts#CONTENT_URI Contacts.CONTENT_URI}, 1362 . 1363 </li> 1364 <li> 1365 {@link android.provider.ContactsContract.CommonDataKinds.Phone#CONTENT_URI Phone.CONTENT_URI}, 1366 . 1367 </li> 1368 <li> 1369 {@link android.provider.ContactsContract.CommonDataKinds.StructuredPostal#CONTENT_URI 1370 StructuredPostal.CONTENT_URI}, 1371 . 1372 </li> 1373 <li> 1374 {@link android.provider.ContactsContract.CommonDataKinds.Email#CONTENT_URI Email.CONTENT_URI}, 1375 . 1376 </li> 1377 </ul> 1378 </td> 1379 <td> 1380 1381 </td> 1382 <td> 1383 URI 1384 . 1385 <p> 1386 1387 {@link android.app.Activity#startActivityForResult(Intent, int) startActivityForResult()} , 1388 URI . URI 1389 URI <code>LOOKUP_ID</code> . 1390 URI 1391 . 1392 <a href="{@docRoot}guide/topics/providers/content-provider-basics.html"> 1393 </a> . 1394 </p> 1395 </td> 1396 </tr> 1397 <tr> 1398 <td><strong> </strong></td> 1399 <td>{@link android.provider.ContactsContract.Intents.Insert#ACTION Insert.ACTION}</td> 1400 <td>N/A</td> 1401 <td> 1402 {@link android.provider.ContactsContract.RawContacts#CONTENT_TYPE 1403 RawContacts.CONTENT_TYPE}, MIME . 1404 </td> 1405 <td> 1406 <strong> </strong> . 1407 . 1408 {@link android.app.Activity#startActivityForResult(Intent, int) startActivityForResult()} , 1409 URI 1410 "" {@link android.content.Intent} {@link android.app.Activity#onActivityResult(int, int, Intent) onActivityResult()} 1411 1412 . , {@link android.content.Intent#getData()} . 1413 </td> 1414 </tr> 1415 <tr> 1416 <td><strong> </strong></td> 1417 <td>{@link android.content.Intent#ACTION_EDIT}</td> 1418 <td> 1419 1420 {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}. 1421 . 1422 </td> 1423 <td> 1424 {@link android.provider.ContactsContract.Contacts#CONTENT_ITEM_TYPE 1425 Contacts.CONTENT_ITEM_TYPE}, .</td> 1426 <td> 1427 . 1428 . <strong></strong> , 1429 . 1430 </td> 1431 </tr> 1432 <tr> 1433 <td><strong> .</strong></td> 1434 <td>{@link android.content.Intent#ACTION_INSERT_OR_EDIT}</td> 1435 <td> 1436 N/A 1437 </td> 1438 <td> 1439 {@link android.provider.ContactsContract.Contacts#CONTENT_ITEM_TYPE} 1440 </td> 1441 <td> 1442 . 1443 . 1444 1445 . , 1446 1447 . 1448 <p class="note"> 1449 <strong>:</strong> . 1450 . , 1451 1452 . 1453 . 1454 </p> 1455 </td> 1456 </tr> 1457 </table> 1458 <p> 1459 1460 . , 1461 {@link android.content.ContentResolver#delete(Uri, String, String[]) ContentResolver.delete()} 1462 {@link android.content.ContentProviderOperation#newDelete(Uri) 1463 ContentProviderOperation.newDelete()} . 1464 </p> 1465 <p> 1466 1467 , . 1468 </p> 1469 <pre> 1470 // Gets values from the UI 1471 String name = mContactNameEditText.getText().toString(); 1472 String phone = mContactPhoneEditText.getText().toString(); 1473 String email = mContactEmailEditText.getText().toString(); 1474 1475 String company = mCompanyName.getText().toString(); 1476 String jobtitle = mJobTitle.getText().toString(); 1477 1478 // Creates a new intent for sending to the device's contacts application 1479 Intent insertIntent = new Intent(ContactsContract.Intents.Insert.ACTION); 1480 1481 // Sets the MIME type to the one expected by the insertion activity 1482 insertIntent.setType(ContactsContract.RawContacts.CONTENT_TYPE); 1483 1484 // Sets the new contact name 1485 insertIntent.putExtra(ContactsContract.Intents.Insert.NAME, name); 1486 1487 // Sets the new company and job title 1488 insertIntent.putExtra(ContactsContract.Intents.Insert.COMPANY, company); 1489 insertIntent.putExtra(ContactsContract.Intents.Insert.JOB_TITLE, jobtitle); 1490 1491 /* 1492 * Demonstrates adding data rows as an array list associated with the DATA key 1493 */ 1494 1495 // Defines an array list to contain the ContentValues objects for each row 1496 ArrayList<ContentValues> contactData = new ArrayList<ContentValues>(); 1497 1498 1499 /* 1500 * Defines the raw contact row 1501 */ 1502 1503 // Sets up the row as a ContentValues object 1504 ContentValues rawContactRow = new ContentValues(); 1505 1506 // Adds the account type and name to the row 1507 rawContactRow.put(ContactsContract.RawContacts.ACCOUNT_TYPE, mSelectedAccount.getType()); 1508 rawContactRow.put(ContactsContract.RawContacts.ACCOUNT_NAME, mSelectedAccount.getName()); 1509 1510 // Adds the row to the array 1511 contactData.add(rawContactRow); 1512 1513 /* 1514 * Sets up the phone number data row 1515 */ 1516 1517 // Sets up the row as a ContentValues object 1518 ContentValues phoneRow = new ContentValues(); 1519 1520 // Specifies the MIME type for this data row (all data rows must be marked by their type) 1521 phoneRow.put( 1522 ContactsContract.Data.MIMETYPE, 1523 ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE 1524 ); 1525 1526 // Adds the phone number and its type to the row 1527 phoneRow.put(ContactsContract.CommonDataKinds.Phone.NUMBER, phone); 1528 1529 // Adds the row to the array 1530 contactData.add(phoneRow); 1531 1532 /* 1533 * Sets up the email data row 1534 */ 1535 1536 // Sets up the row as a ContentValues object 1537 ContentValues emailRow = new ContentValues(); 1538 1539 // Specifies the MIME type for this data row (all data rows must be marked by their type) 1540 emailRow.put( 1541 ContactsContract.Data.MIMETYPE, 1542 ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE 1543 ); 1544 1545 // Adds the email address and its type to the row 1546 emailRow.put(ContactsContract.CommonDataKinds.Email.ADDRESS, email); 1547 1548 // Adds the row to the array 1549 contactData.add(emailRow); 1550 1551 /* 1552 * Adds the array to the intent's extras. It must be a parcelable object in order to 1553 * travel between processes. The device's contacts app expects its key to be 1554 * Intents.Insert.DATA 1555 */ 1556 insertIntent.putParcelableArrayListExtra(ContactsContract.Intents.Insert.DATA, contactData); 1557 1558 // Send out the intent to start the device's contacts app in its add contact activity. 1559 startActivity(insertIntent); 1560 </pre> 1561 <h3 id="DataIntegrity"> </h3> 1562 <p> 1563 1564 . 1565 . 1566 . 1567 </p> 1568 <dl> 1569 <dt> 1570 {@link android.provider.ContactsContract.RawContacts} 1571 {@link android.provider.ContactsContract.CommonDataKinds.StructuredName} . 1572 </dt> 1573 <dd> 1574 {@link android.provider.ContactsContract.Data} {@link android.provider.ContactsContract.CommonDataKinds.StructuredName} {@link android.provider.ContactsContract.RawContacts} 1575 1576 . 1577 1578 </dd> 1579 <dt> 1580 {@link android.provider.ContactsContract.Data} 1581 {@link android.provider.ContactsContract.RawContacts} . 1582 </dt> 1583 <dd> 1584 {@link android.provider.ContactsContract.RawContacts} {@link android.provider.ContactsContract.Data} 1585 , 1586 . 1587 </dd> 1588 <dt> 1589 . 1590 </dt> 1591 <dd> 1592 / 1593 . 1594 , 1595 . 1596 </dd> 1597 <dt> 1598 , URI, URI , , MIME 1599 {@link android.provider.ContactsContract.CommonDataKinds.CommonColumns#TYPE} 1600 {@link android.provider.ContactsContract} . 1601 </dt> 1602 <dd> 1603 . 1604 . 1605 </dd> 1606 </dl> 1607 <h3 id="CustomData"> </h3> 1608 <p> 1609 MIME , 1610 {@link android.provider.ContactsContract.Data} , , . 1611 {@link android.provider.ContactsContract.DataColumns} 1612 . 1613 . 1614 , 1615 . , 1616 . 1617 </p> 1618 <p> 1619 , <code><ContactsAccountType></code> <code><ContactsDataKind></code> <code>contacts.xml</code> 1620 . 1621 1622 <a href="#SocialStreamDataKind"><code><ContactsDataKind> element</code></a> . 1623 </p> 1624 <p> 1625 MIME , 1626 <a href="{@docRoot}guide/topics/providers/content-provider-creating.html"> 1627 </a> . 1628 </p> 1629 <h2 id="SyncAdapters"> </h2> 1630 <p> 1631 <strong></strong> 1632 . 1633 , . 1634 1635 . 1636 . 1637 </p> 1638 <p> 1639 , Android 1640 . 1641 <ul> 1642 1643 <li> 1644 . 1645 </li> 1646 <li> 1647 . 1648 </li> 1649 <li> 1650 . 1651 </li> 1652 </ul> 1653 <p> 1654 . 1655 , . 1656 . 1657 </p> 1658 <h3 id="SyncClassesFiles"> </h3> 1659 <p> 1660 1661 {@link android.content.AbstractThreadedSyncAdapter} 1662 Android . 1663 XML . XML 1664 , 1665 . 1666 1667 . , , 1668 . 1669 </p> 1670 <p class="note"> 1671 <strong>:</strong> 1672 1673 . , Google 1674 <code>com.google</code> . Google , 1675 Google . 1676 . 1677 </p> 1678 <p> 1679 1680 ID Android 1681 . 1682 {@link android.accounts.AbstractAccountAuthenticator} 1683 . 1684 ID . 1685 <ol> 1686 <li> 1687 , ( 1688 <strong> </strong>) . 1689 </li> 1690 <li> 1691 . 1692 </li> 1693 <li> 1694 . 1695 </li> 1696 </ol> 1697 <p> 1698 1699 . , 1700 {@link android.accounts.AccountManager} Oauth2 authToken authToken 1701 . 1702 </p> 1703 <p> 1704 , . 1705 , Android . 1706 </p> 1707 <h3 id="SyncAdapterImplementing"> </h3> 1708 <p> 1709 , 1710 Android . 1711 </p> 1712 <dl> 1713 <dt> 1714 {@link android.app.Service} 1715 . 1716 </dt> 1717 <dd> 1718 , 1719 {@link android.app.Service#onBind(Intent) onBind()} 1720 {@link android.os.IBinder} . 1721 . 1722 <p> 1723 <a href="{@docRoot}resources/samples/SampleSyncAdapter/index.html"> 1724 </a> 1725 <code>com.example.android.samplesync.syncadapter.SyncService</code>. 1726 </p> 1727 </dd> 1728 <dt> 1729 {@link android.content.AbstractThreadedSyncAdapter} 1730 . 1731 </dt> 1732 <dd> 1733 , , 1734 . 1735 {@link android.content.AbstractThreadedSyncAdapter#onPerformSync( 1736 Account, Bundle, String, ContentProviderClient, SyncResult) 1737 onPerformSync()} . . 1738 <p> 1739 <a href="{@docRoot}resources/samples/SampleSyncAdapter/index.html"> 1740 </a> 1741 <code>com.example.android.samplesync.syncadapter.SyncAdapter</code> . 1742 </p> 1743 </dd> 1744 <dt> 1745 {@link android.app.Application} . 1746 </dt> 1747 <dd> 1748 . 1749 {@link android.app.Application#onCreate()} 1750 , 1751 {@link android.app.Service#onBind(Intent) onBind()} "getter" 1752 . 1753 </dd> 1754 <dt> 1755 <strong> :</strong> {@link android.app.Service} 1756 . 1757 </dt> 1758 <dd> 1759 {@link android.accounts.AccountManager} 1760 . {@link android.app.Service#onCreate()} 1761 . , 1762 1763 {@link android.app.Service#onBind(Intent) onBind()} 1764 {@link android.os.IBinder} . 1765 . 1766 <p> 1767 <a href="{@docRoot}resources/samples/SampleSyncAdapter/index.html"> 1768 </a> 1769 <code>com.example.android.samplesync.authenticator.AuthenticationService</code>. 1770 </p> 1771 </dd> 1772 <dt> 1773 <strong> :</strong> 1774 {@link android.accounts.AbstractAccountAuthenticator} 1775 . 1776 </dt> 1777 <dd> 1778 {@link android.accounts.AccountManager} 1779 . 1780 . 1781 . 1782 <p> 1783 <a href="{@docRoot}resources/samples/SampleSyncAdapter/index.html"> 1784 </a> 1785 <code>com.example.android.samplesync.authenticator.Authenticator</code> . 1786 </p> 1787 </dd> 1788 <dt> 1789 XML . 1790 </dt> 1791 <dd> 1792 1793 1794 <code><<a href="{@docRoot}guide/topics/manifest/service-element.html">service</a>></code> 1795 . 1796 1797 <code><<a href="{@docRoot}guide/topics/manifest/meta-data-element.html">meta-data</a>></code> 1798 1799 . 1800 <ul> 1801 <li> 1802 1803 <code><<a href="{@docRoot}guide/topics/manifest/meta-data-element.html">meta-data</a>></code> 1804 1805 XML <code>res/xml/syncadapter.xml</code> . 1806 URI 1807 . 1808 </li> 1809 <li> 1810 <strong> :</strong> 1811 <code><<a href="{@docRoot}guide/topics/manifest/meta-data-element.html">meta-data</a>></code> 1812 XML 1813 <code>res/xml/authenticator.xml</code> . 1814 , UI 1815 . 1816 1817 . 1818 </li> 1819 </ul> 1820 </dd> 1821 </dl> 1822 <h2 id="SocialStream"> </h2> 1823 <p> 1824 {@code android.provider.ContactsContract.StreamItems} 1825 {@code android.provider.ContactsContract.StreamItemPhotos} 1826 . 1827 , 1828 . 1829 Android . 1830 </p> 1831 <h3 id="StreamText"> </h3> 1832 <p> 1833 . 1834 {@code android.provider.ContactsContract.StreamItemsColumns#RAW_CONTACT_ID} 1835 <code>_ID</code> . 1836 . 1837 </p> 1838 <p> 1839 . 1840 </p> 1841 <dl> 1842 <dt> 1843 {@code android.provider.ContactsContract.StreamItemsColumns#ACCOUNT_TYPE} 1844 </dt> 1845 <dd> 1846 <strong>.</strong> 1847 . . 1848 </dd> 1849 <dt> 1850 {@code android.provider.ContactsContract.StreamItemsColumns#ACCOUNT_NAME} 1851 </dt> 1852 <dd> 1853 <strong>.</strong> 1854 . . 1855 </dd> 1856 <dt> 1857 1858 </dt> 1859 <dd> 1860 <strong>.</strong> 1861 . 1862 <ul> 1863 <li> 1864 {@code android.provider.ContactsContract.StreamItemsColumns#CONTACT_ID}: 1865 {@code android.provider.BaseColumns#_ID} 1866 . 1867 </li> 1868 <li> 1869 {@code android.provider.ContactsContract.StreamItemsColumns#CONTACT_LOOKUP_KEY}: 1870 {@code android.provider.ContactsContract.ContactsColumns#LOOKUP_KEY} 1871 . 1872 </li> 1873 <li> 1874 {@code android.provider.ContactsContract.StreamItemsColumns#RAW_CONTACT_ID}: 1875 {@code android.provider.BaseColumns#_ID} 1876 . 1877 </li> 1878 </ul> 1879 </dd> 1880 <dt> 1881 {@code android.provider.ContactsContract.StreamItemsColumns#COMMENTS} 1882 </dt> 1883 <dd> 1884 . . 1885 </dd> 1886 <dt> 1887 {@code android.provider.ContactsContract.StreamItemsColumns#TEXT} 1888 </dt> 1889 <dd> 1890 , 1891 . 1892 {@link android.text.Html#fromHtml(String) fromHtml()} 1893 . 1894 , . 1895 </dd> 1896 <dt> 1897 {@code android.provider.ContactsContract.StreamItemsColumns#TIMESTAMP} 1898 </dt> 1899 <dd> 1900 , 1901 epoch <em></em> . 1902 , 1903 . 1904 </dd> 1905 </dl> 1906 <p> 1907 1908 {@code android.provider.ContactsContract.StreamItemsColumns#RES_ICON}, 1909 {@code android.provider.ContactsContract.StreamItemsColumns#RES_LABEL}, 1910 {@code android.provider.ContactsContract.StreamItemsColumns#RES_PACKAGE} 1911 . 1912 </p> 1913 <p> 1914 {@code android.provider.ContactsContract.StreamItems} 1915 {@code android.provider.ContactsContract.StreamItemsColumns#SYNC1} 1916 {@code android.provider.ContactsContract.StreamItemsColumns#SYNC4} 1917 . 1918 </p> 1919 <h3 id="StreamPhotos"> </h3> 1920 <p> 1921 {@code android.provider.ContactsContract.StreamItemPhotos} 1922 . 1923 {@code android.provider.ContactsContract.StreamItemPhotosColumns#STREAM_ITEM_ID} 1924 {@code android.provider.ContactsContract.StreamItems} {@code android.provider.BaseColumns#_ID} 1925 . 1926 . 1927 </p> 1928 <dl> 1929 <dt> 1930 {@code android.provider.ContactsContract.StreamItemPhotos#PHOTO} (BLOB). 1931 </dt> 1932 <dd> 1933 , . 1934 1935 . 1936 . , 1937 {@code android.provider.ContactsContract.StreamItemPhotosColumns#PHOTO_FILE_ID} 1938 {@code android.provider.ContactsContract.StreamItemPhotosColumns#PHOTO_URI}( 1939 ) . 1940 . 1941 </dd> 1942 <dt> 1943 {@code android.provider.ContactsContract.StreamItemPhotosColumns#PHOTO_FILE_ID} 1944 </dt> 1945 <dd> 1946 . 1947 {@link android.provider.ContactsContract.DisplayPhoto#CONTENT_URI DisplayPhoto.CONTENT_URI} 1948 URI , 1949 {@link android.content.ContentResolver#openAssetFileDescriptor(Uri, String) 1950 openAssetFileDescriptor()} . 1951 </dd> 1952 <dt> 1953 {@code android.provider.ContactsContract.StreamItemPhotosColumns#PHOTO_URI} 1954 </dt> 1955 <dd> 1956 URI. 1957 URI {@link android.content.ContentResolver#openAssetFileDescriptor(Uri, String) 1958 openAssetFileDescriptor()} . 1959 </dd> 1960 </dl> 1961 <h3 id="SocialStreamTables"> </h3> 1962 <p> 1963 , . 1964 </p> 1965 <ul> 1966 <li> 1967 . 1968 {@code android.Manifest.permission#READ_SOCIAL_STREAM} . 1969 1970 {@code android.Manifest.permission#WRITE_SOCIAL_STREAM} . 1971 </li> 1972 <li> 1973 {@code android.provider.ContactsContract.StreamItems} , 1974 . , 1975 . 1976 {@code android.provider.ContactsContract.StreamItemsColumns#TIMESTAMP} 1977 . 1978 , URI 1979 {@code android.provider.ContactsContract.StreamItems#CONTENT_LIMIT_URI} . 1980 URI <code>null</code> . 1981 , 1982 {@code android.provider.ContactsContract.StreamItems#MAX_ITEMS} . 1983 </li> 1984 </ul> 1985 1986 <p> 1987 {@code android.provider.ContactsContract.StreamItems.StreamItemPhotos} 1988 {@code android.provider.ContactsContract.StreamItemPhotos} 1989 . 1990 </p> 1991 <h3 id="SocialStreamInteraction"> </h3> 1992 <p> 1993 1994 1995 . . 1996 </p> 1997 <ul> 1998 <li> 1999 , 2000 2001 {@code android.provider.ContactsContract.StreamItems} 2002 {@code android.provider.ContactsContract.StreamItemPhotos} . 2003 </li> 2004 <li> 2005 2006 . 2007 . 2008 </li> 2009 <li> 2010 , 2011 <em></em>, 2012 . 2013 . 2014 </li> 2015 <li> 2016 2017 . " " . 2018 2019 XML , 2020 . 2021 </li> 2022 </ul> 2023 <p> 2024 2025 . 2026 <a href="#SyncAdapters"> </a> . 2027 . 2028 </p> 2029 <h4> </h4> 2030 <p> 2031 2032 : 2033 </p> 2034 <ol> 2035 <li> 2036 <code>res/xml/</code> <code>contacts.xml</code> 2037 . . 2038 </li> 2039 <li> 2040 , 2041 <code><ContactsAccountType xmlns:android="http://schemas.android.com/apk/res/android"></code> . 2042 . 2043 </li> 2044 <li> 2045 2046 , 2047 <code>viewContactNotifyService="<em>serviceclass</em>"</code> . 2048 <code><em>serviceclass</em></code> 2049 . , 2050 {@link android.app.IntentService} 2051 . 2052 URI . 2053 . 2054 </li> 2055 </ol> 2056 <p> 2057 , : 2058 </p> 2059 <ol> 2060 <li> 2061 <code>res/xml/</code> <code>contacts.xml</code> 2062 . . 2063 </li> 2064 <li> 2065 , 2066 <code><ContactsAccountType xmlns:android="http://schemas.android.com/apk/res/android"></code> . 2067 . 2068 </li> 2069 <li> 2070 2071 , 2072 <code>viewStreamItemActivity="<em>activityclass</em>"</code> . 2073 <code><em>activityclass</em></code> 2074 . 2075 </li> 2076 <li> 2077 2078 , 2079 <code>viewStreamItemPhotoActivity="<em>activityclass</em>"</code> . 2080 <code><em>activityclass</em></code> 2081 . 2082 </li> 2083 </ol> 2084 <p> 2085 <code><ContactsAccountType></code> 2086 <a href="#SocialStreamAcctType"><ContactsAccountType> </a> . 2087 </p> 2088 <p> 2089 URI . 2090 , . 2091 </p> 2092 <h4> </h4> 2093 <p> 2094 2095 . , 2096 . . 2097 </p> 2098 <ol> 2099 <li> 2100 <code>res/xml/</code> <code>contacts.xml</code> 2101 . . 2102 </li> 2103 <li> 2104 , 2105 <code><ContactsAccountType xmlns:android="http://schemas.android.com/apk/res/android"></code> . 2106 . 2107 </li> 2108 <li> 2109 . 2110 <ul> 2111 <li><code>inviteContactActivity="<em>activityclass</em>"</code></li> 2112 <li> 2113 <code>inviteContactActionLabel="@string/<em>invite_action_label</em>"</code> 2114 </li> 2115 </ul> 2116 <code><em>activityclass</em></code> 2117 . <code><em>invite_action_label</em></code> 2118 <strong> </strong> 2119 . 2120 </li> 2121 </ol> 2122 <p class="note"> 2123 <strong>:</strong> <code>ContactsSource</code> 2124 <code>ContactsAccountType</code> . 2125 </p> 2126 <h3 id="ContactsFile">contacts.xml </h3> 2127 <p> 2128 <code>contacts.xml</code> XML 2129 , . 2130 . 2131 </p> 2132 <h4 id="SocialStreamAcctType"><ContactsAccountType> </h4> 2133 <p> 2134 <code><ContactsAccountType></code> 2135 . . 2136 </p> 2137 <pre> 2138 <ContactsAccountType 2139 xmlns:android="http://schemas.android.com/apk/res/android" 2140 inviteContactActivity="<em>activity_name</em>" 2141 inviteContactActionLabel="<em>invite_command_text</em>" 2142 viewContactNotifyService="<em>view_notify_service</em>" 2143 viewGroupActivity="<em>group_view_activity</em>" 2144 viewGroupActionLabel="<em>group_action_text</em>" 2145 viewStreamItemActivity="<em>viewstream_activity_name</em>" 2146 viewStreamItemPhotoActivity="<em>viewphotostream_activity_name</em>"> 2147 </pre> 2148 <p> 2149 <strong> :</strong> 2150 </p> 2151 <p> 2152 <code>res/xml/contacts.xml</code> 2153 </p> 2154 <p> 2155 <strong> :</strong> 2156 </p> 2157 <p> 2158 <strong><code><ContactsDataKind></code></strong> 2159 </p> 2160 <p> 2161 <strong>:</strong> 2162 </p> 2163 <p> 2164 , 2165 2166 Android UI . 2167 </p> 2168 <p> 2169 <code>android:</code> 2170 <code><ContactsAccountType></code> . 2171 </p> 2172 <p> 2173 <strong>:</strong> 2174 </p> 2175 <dl> 2176 <dt>{@code inviteContactActivity}</dt> 2177 <dd> 2178 2179 <strong> </strong> 2180 . 2181 </dd> 2182 <dt>{@code inviteContactActionLabel}</dt> 2183 <dd> 2184 <strong> </strong> 2185 {@code inviteContactActivity} . 2186 , " " . 2187 . 2188 </dd> 2189 <dt>{@code viewContactNotifyService}</dt> 2190 <dd> 2191 2192 . 2193 . 2194 . , 2195 2196 . 2197 <a href="#SocialStreamInteraction"> </a> . 2198 <a href="{@docRoot}resources/samples/SampleSyncAdapter/index.html">SampleSyncAdapter</a> 2199 <code>NotifierService.java</code> 2200 . 2201 </dd> 2202 <dt>{@code viewGroupActivity}</dt> 2203 <dd> 2204 2205 . , 2206 UI . 2207 </dd> 2208 <dt>{@code viewGroupActionLabel}</dt> 2209 <dd> 2210 UI 2211 . 2212 <p> 2213 , Google+ 2214 Google+ , Google+ 2215 <strong></strong> . Google+ 2216 "" . 2217 Google+ , 2218 Google+ . 2219 {@code viewGroupActivity} , Google+ 2220 {@code viewGroupActionLabel} . 2221 </p> 2222 <p> 2223 . 2224 </p> 2225 </dd> 2226 <dt>{@code viewStreamItemActivity}</dt> 2227 <dd> 2228 2229 . 2230 </dd> 2231 <dt>{@code viewStreamItemPhotoActivity}</dt> 2232 <dd> 2233 2234 2235 . 2236 </dd> 2237 </dl> 2238 <h4 id="SocialStreamDataKind"><ContactsDataKind> </h4> 2239 <p> 2240 <code><ContactsDataKind></code> UI 2241 . . 2242 </p> 2243 <pre> 2244 <ContactsDataKind 2245 android:mimeType="<em>MIMEtype</em>" 2246 android:icon="<em>icon_resources</em>" 2247 android:summaryColumn="<em>column_name</em>" 2248 android:detailColumn="<em>column_name</em>"> 2249 </pre> 2250 <p> 2251 <strong> :</strong> 2252 </p> 2253 <code><ContactsAccountType></code> 2254 <p> 2255 <strong>:</strong> 2256 </p> 2257 <p> 2258 2259 . <code><ContactsAccountType></code> <code><ContactsDataKind></code> 2260 {@link android.provider.ContactsContract.Data} 2261 . MIME 2262 <code><ContactsDataKind></code> . 2263 , . 2264 </p> 2265 <p> 2266 <strong>:</strong> 2267 </p> 2268 <dl> 2269 <dt>{@code android:mimeType}</dt> 2270 <dd> 2271 {@link android.provider.ContactsContract.Data} 2272 MIME . , 2273 <code>vnd.android.cursor.item/vnd.example.locationstatus</code> 2274 MIME . 2275 </dd> 2276 <dt>{@code android:icon}</dt> 2277 <dd> 2278 2279 Android <a href="{@docRoot}guide/topics/resources/drawable-resource.html"> </a> 2280 . 2281 . 2282 </dd> 2283 <dt>{@code android:summaryColumn}</dt> 2284 <dd> 2285 . 2286 . 2287 , . 2288 <a href="#detailColumn">android:detailColumn</a> . 2289 </dd> 2290 <dt>{@code android:detailColumn}</dt> 2291 <dd> 2292 . 2293 . 2294 {@code android:summaryColumn} . 2295 </dd> 2296 </dl> 2297 <h2 id="AdditionalFeatures"> </h2> 2298 <p> 2299 2300 . . 2301 </p> 2302 <ul> 2303 <li> </li> 2304 <li> </li> 2305 </ul> 2306 <h3 id="Groups"> </h3> 2307 <p> 2308 2309 <strong></strong> . 2310 , 2311 . 2312 , 2313 {@link android.provider.ContactsContract.Groups} . ( ) 2314 {@link android.provider.ContactsContract.Data} , 2315 {@link android.provider.ContactsContract.CommonDataKinds.GroupMembership} MIME . 2316 </p> 2317 <p> 2318 2319 , 2320 . 2321 {@link android.provider.ContactsContract.Settings} 2322 . 2323 {@link android.provider.ContactsContract.SettingsColumns#UNGROUPED_VISIBLE 2324 Settings.UNGROUPED_VISIBLE} 1 . 2325 , . 2326 </p> 2327 <h3 id="Photos"> </h3> 2328 <p> 2329 {@link android.provider.ContactsContract.Data} 2330 {@link android.provider.ContactsContract.CommonDataKinds.Photo#CONTENT_ITEM_TYPE 2331 Photo.CONTENT_ITEM_TYPE} MIME . 2332 {@link android.provider.ContactsContract.RawContactsColumns#CONTACT_ID} 2333 {@code android.provider.BaseColumns#_ID} . 2334 {@link android.provider.ContactsContract.Contacts.Photo} 2335 {@link android.provider.ContactsContract.Contacts} . 2336 . , 2337 {@link android.provider.ContactsContract.RawContacts.DisplayPhoto} 2338 {@link android.provider.ContactsContract.RawContacts} 2339 . 2340 </p> 2341 <p> 2342 {@link android.provider.ContactsContract.Contacts.Photo} 2343 {@link android.provider.ContactsContract.RawContacts.DisplayPhoto} 2344 . 2345 . 2346 {@link android.provider.ContactsContract.Data} 2347 {@code android.provider.BaseColumns#_ID}, 2348 {@link android.provider.ContactsContract.CommonDataKinds.Photo#CONTENT_ITEM_TYPE 2349 Photo.CONTENT_ITEM_TYPE}, {@link android.provider.ContactsContract.Data#IS_PRIMARY} 2350 . 2351 </p> 2352 <p> 2353 . 2354 {@code android.provider.ContactsContract.StreamItemPhotos} , 2355 <a href="#StreamPhotos"> </a> . 2356 </p> 2357