ContactsContract.java revision fb5bccf229b52803649c70780e706c063e835447
1/* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17package android.provider; 18 19import android.accounts.Account; 20import android.content.ContentProviderClient; 21import android.content.ContentProviderOperation; 22import android.content.ContentResolver; 23import android.content.ContentUris; 24import android.content.ContentValues; 25import android.content.Context; 26import android.content.CursorEntityIterator; 27import android.content.Entity; 28import android.content.EntityIterator; 29import android.content.Intent; 30import android.content.res.Resources; 31import android.database.Cursor; 32import android.database.DatabaseUtils; 33import android.database.sqlite.SQLiteException; 34import android.graphics.Rect; 35import android.net.Uri; 36import android.os.RemoteException; 37import android.text.TextUtils; 38import android.util.DisplayMetrics; 39import android.util.Pair; 40import android.view.View; 41 42import java.io.ByteArrayInputStream; 43import java.io.InputStream; 44 45/** 46 * <p> 47 * The contract between the contacts provider and applications. Contains 48 * definitions for the supported URIs and columns. These APIs supersede 49 * {@link Contacts}. 50 * </p> 51 * <h3>Overview</h3> 52 * <p> 53 * ContactsContract defines an extensible database of contact-related 54 * information. Contact information is stored in a three-tier data model: 55 * </p> 56 * <ul> 57 * <li> 58 * A row in the {@link Data} table can store any kind of personal data, such 59 * as a phone number or email addresses. The set of data kinds that can be 60 * stored in this table is open-ended. There is a predefined set of common 61 * kinds, but any application can add its own data kinds. 62 * </li> 63 * <li> 64 * A row in the {@link RawContacts} table represents a set of data describing a 65 * person and associated with a single account (for example, one of the user's 66 * Gmail accounts). 67 * </li> 68 * <li> 69 * A row in the {@link Contacts} table represents an aggregate of one or more 70 * RawContacts presumably describing the same person. When data in or associated with 71 * the RawContacts table is changed, the affected aggregate contacts are updated as 72 * necessary. 73 * </li> 74 * </ul> 75 * <p> 76 * Other tables include: 77 * </p> 78 * <ul> 79 * <li> 80 * {@link Groups}, which contains information about raw contact groups 81 * such as Gmail contact groups. The 82 * current API does not support the notion of groups spanning multiple accounts. 83 * </li> 84 * <li> 85 * {@link StatusUpdates}, which contains social status updates including IM 86 * availability. 87 * </li> 88 * <li> 89 * {@link AggregationExceptions}, which is used for manual aggregation and 90 * disaggregation of raw contacts 91 * </li> 92 * <li> 93 * {@link Settings}, which contains visibility and sync settings for accounts 94 * and groups. 95 * </li> 96 * <li> 97 * {@link SyncState}, which contains free-form data maintained on behalf of sync 98 * adapters 99 * </li> 100 * <li> 101 * {@link PhoneLookup}, which is used for quick caller-ID lookup</li> 102 * </ul> 103 */ 104@SuppressWarnings("unused") 105public final class ContactsContract { 106 /** The authority for the contacts provider */ 107 public static final String AUTHORITY = "com.android.contacts"; 108 /** A content:// style uri to the authority for the contacts provider */ 109 public static final Uri AUTHORITY_URI = Uri.parse("content://" + AUTHORITY); 110 111 /** 112 * An optional URI parameter for insert, update, or delete queries 113 * that allows the caller 114 * to specify that it is a sync adapter. The default value is false. If true 115 * {@link RawContacts#DIRTY} is not automatically set and the 116 * "syncToNetwork" parameter is set to false when calling 117 * {@link 118 * ContentResolver#notifyChange(android.net.Uri, android.database.ContentObserver, boolean)}. 119 * This prevents an unnecessary extra synchronization, see the discussion of 120 * the delete operation in {@link RawContacts}. 121 */ 122 public static final String CALLER_IS_SYNCADAPTER = "caller_is_syncadapter"; 123 124 /** 125 * A query parameter key used to specify the package that is requesting a query. 126 * This is used for restricting data based on package name. 127 * 128 * @hide 129 */ 130 public static final String REQUESTING_PACKAGE_PARAM_KEY = "requesting_package"; 131 132 /** 133 * Query parameter that should be used by the client to access a specific 134 * {@link Directory}. The parameter value should be the _ID of the corresponding 135 * directory, e.g. 136 * {@code content://com.android.contacts/data/emails/filter/acme?directory=3} 137 * 138 * @hide 139 */ 140 public static final String DIRECTORY_PARAM_KEY = "directory"; 141 142 143 /** 144 * @hide 145 */ 146 public static final class Preferences { 147 148 /** 149 * A key in the {@link android.provider.Settings android.provider.Settings} provider 150 * that stores the preferred sorting order for contacts (by given name vs. by family name). 151 * 152 * @hide 153 */ 154 public static final String SORT_ORDER = "android.contacts.SORT_ORDER"; 155 156 /** 157 * The value for the SORT_ORDER key corresponding to sorting by given name first. 158 * 159 * @hide 160 */ 161 public static final int SORT_ORDER_PRIMARY = 1; 162 163 /** 164 * The value for the SORT_ORDER key corresponding to sorting by family name first. 165 * 166 * @hide 167 */ 168 public static final int SORT_ORDER_ALTERNATIVE = 2; 169 170 /** 171 * A key in the {@link android.provider.Settings android.provider.Settings} provider 172 * that stores the preferred display order for contacts (given name first vs. family 173 * name first). 174 * 175 * @hide 176 */ 177 public static final String DISPLAY_ORDER = "android.contacts.DISPLAY_ORDER"; 178 179 /** 180 * The value for the DISPLAY_ORDER key corresponding to showing the given name first. 181 * 182 * @hide 183 */ 184 public static final int DISPLAY_ORDER_PRIMARY = 1; 185 186 /** 187 * The value for the DISPLAY_ORDER key corresponding to showing the family name first. 188 * 189 * @hide 190 */ 191 public static final int DISPLAY_ORDER_ALTERNATIVE = 2; 192 } 193 194 /** 195 * A Directory represents a contacts corpus, e.g. Local contacts, 196 * Google Apps Global Address List or Corporate Global Address List. 197 * <p> 198 * A Directory is implemented as a content provider with its unique authority and 199 * the same API as the main Contacts Provider. However, there is no expectation that 200 * every directory provider will implement this Contract in its entirety. If a 201 * directory provider does not have an implementation for a specific request, it 202 * should throw an UnsupportedOperationException. 203 * </p> 204 * <p> 205 * The most important use case for Directories is search. A Directory provider is 206 * expected to support at least {@link Contacts#CONTENT_FILTER_URI 207 * Contacts#CONTENT_FILTER_URI}. If a Directory provider wants to participate 208 * in email and phone lookup functionalities, it should also implement 209 * {@link CommonDataKinds.Email#CONTENT_FILTER_URI CommonDataKinds.Email.CONTENT_FILTER_URI} 210 * and 211 * {@link CommonDataKinds.Phone#CONTENT_FILTER_URI CommonDataKinds.Phone.CONTENT_FILTER_URI}. 212 * </p> 213 * <p> 214 * A directory provider should return NULL for every projection field it does not 215 * recognize, rather than throwing an exception. This way it will not be broken 216 * if ContactsContract is extended with new fields in the future. 217 * </p> 218 * <p> 219 * The client interacts with a directory via Contacts Provider by supplying an 220 * optional {@code directory=} query parameter. 221 * <p> 222 * <p> 223 * When the Contacts Provider receives the request, it transforms the URI and forwards 224 * the request to the corresponding directory content provider. 225 * The URI is transformed in the following fashion: 226 * <ul> 227 * <li>The URI authority is replaced with the corresponding {@link #DIRECTORY_AUTHORITY}.</li> 228 * <li>The {@code accountName=} and {@code accountType=} parameters are added or 229 * replaced using the corresponding {@link #ACCOUNT_TYPE} and {@link #ACCOUNT_NAME} values.</li> 230 * <li>If the URI is missing a {@link ContactsContract#REQUESTING_PACKAGE_PARAM_KEY} 231 * parameter, this parameter is added.</li> 232 * </ul> 233 * </p> 234 * <p> 235 * Clients should send directory requests to Contacts Provider and let it 236 * forward them to the respective providers rather than constructing directory provider 237 * URIs by themselves. This level of indirection allows Contacts Provider to 238 * implement additional system-level features and optimizations. 239 * Also, directory providers may reject requests coming from other 240 * clients than the Contacts Provider itself. 241 * </p> 242 * <p> 243 * The Directory table always has at least these two rows: 244 * <ul> 245 * <li> 246 * The local directory. It has {@link Directory#_ID Directory._ID} = 247 * {@link Directory#DEFAULT Directory.DEFAULT}. This directory can be used to access locally 248 * stored contacts. The same can be achieved by omitting the {@code directory=} 249 * parameter altogether. 250 * </li> 251 * <li> 252 * The local invisible contacts. The corresponding directory ID is 253 * {@link Directory#LOCAL_INVISIBLE Directory.LOCAL_INVISIBLE}. 254 * </li> 255 * </ul> 256 * </p> 257 * <p> 258 * Other directories should register themselves by explicitly adding rows to this table. 259 * </p> 260 * <p> 261 * When a row is inserted in this table, it is automatically associated with the package 262 * (apk) that made the request. If the package is later uninstalled, all directory rows 263 * it inserted are automatically removed. 264 * </p> 265 * <p> 266 * A directory row can be optionally associated with an account. 267 * If the account is later removed, the corresponding directory rows are 268 * automatically removed. 269 * </p> 270 * 271 * @hide 272 */ 273 public static final class Directory implements BaseColumns { 274 275 /** 276 * Not instantiable. 277 */ 278 private Directory() { 279 } 280 281 /** 282 * The content:// style URI for this table. Requests to this URI can be 283 * performed on the UI thread because they are always unblocking. 284 * 285 * @hide 286 */ 287 public static final Uri CONTENT_URI = 288 Uri.withAppendedPath(AUTHORITY_URI, "directories"); 289 290 /** 291 * The MIME-type of {@link #CONTENT_URI} providing a directory of 292 * contact directories. 293 * 294 * @hide 295 */ 296 public static final String CONTENT_TYPE = 297 "vnd.android.cursor.dir/contact_directories"; 298 299 /** 300 * The MIME type of a {@link #CONTENT_URI} item. 301 */ 302 public static final String CONTENT_ITEM_TYPE = 303 "vnd.android.cursor.item/contact_directory"; 304 305 /** 306 * _ID of the default directory, which represents locally stored contacts. 307 * 308 * @hide 309 */ 310 public static final long DEFAULT = 0; 311 312 /** 313 * _ID of the directory that represents locally stored invisible contacts. 314 * 315 * @hide 316 */ 317 public static final long LOCAL_INVISIBLE = 1; 318 319 /** 320 * The name of the package that owns this directory. This field is 321 * required in an insert request and must match the name of the package 322 * making the request. If the package is later uninstalled, the 323 * directories it owns are automatically removed from this table. Only 324 * the specified package is allowed to modify or delete this row later. 325 * 326 * <p>TYPE: TEXT</p> 327 * 328 * @hide 329 */ 330 public static final String PACKAGE_NAME = "packageName"; 331 332 /** 333 * The type of directory captured as a resource ID in the context of the 334 * package {@link #PACKAGE_NAME}, e.g. "Corporate Directory" 335 * 336 * <p>TYPE: INTEGER</p> 337 * 338 * @hide 339 */ 340 public static final String TYPE_RESOURCE_ID = "typeResourceId"; 341 342 /** 343 * An optional name that can be used in the UI to represent this directory, 344 * e.g. "Acme Corp" 345 * <p>TYPE: text</p> 346 * 347 * @hide 348 */ 349 public static final String DISPLAY_NAME = "displayName"; 350 351 /** 352 * The authority to which the request should forwarded in order to access 353 * this directory. 354 * 355 * <p>TYPE: text</p> 356 * 357 * @hide 358 */ 359 public static final String DIRECTORY_AUTHORITY = "authority"; 360 361 /** 362 * The account type which this directory is associated. 363 * 364 * <p>TYPE: text</p> 365 * 366 * @hide 367 */ 368 public static final String ACCOUNT_TYPE = "accountType"; 369 370 /** 371 * The account with which this directory is associated. If the account is later 372 * removed, the directories it owns are automatically removed from this table. 373 * 374 * <p>TYPE: text</p> 375 * 376 * @hide 377 */ 378 public static final String ACCOUNT_NAME = "accountName"; 379 380 /** 381 * One of {@link #EXPORT_SUPPORT_NONE}, {@link #EXPORT_SUPPORT_ANY_ACCOUNT}, 382 * {@link #EXPORT_SUPPORT_SAME_ACCOUNT_ONLY}. This is the expectation the 383 * directory has for data exported from it. Clients must obey this setting. 384 * 385 * @hide 386 */ 387 public static final String EXPORT_SUPPORT = "exportSupport"; 388 389 /** 390 * An {@link #EXPORT_SUPPORT} setting that indicates that the directory 391 * does not allow any data to be copied out of it. 392 * 393 * @hide 394 */ 395 public static final int EXPORT_SUPPORT_NONE = 0; 396 397 /** 398 * An {@link #EXPORT_SUPPORT} setting that indicates that the directory 399 * allow its data copied only to the account specified by 400 * {@link #ACCOUNT_TYPE}/{@link #ACCOUNT_NAME}. 401 * 402 * @hide 403 */ 404 public static final int EXPORT_SUPPORT_SAME_ACCOUNT_ONLY = 1; 405 406 /** 407 * An {@link #EXPORT_SUPPORT} setting that indicates that the directory 408 * allow its data copied to any contacts account. 409 * 410 * @hide 411 */ 412 public static final int EXPORT_SUPPORT_ANY_ACCOUNT = 2; 413 414 /** 415 * One of {@link #SHORTCUT_SUPPORT_NONE}, {@link #SHORTCUT_SUPPORT_DATA_ITEMS_ONLY}, 416 * {@link #SHORTCUT_SUPPORT_FULL}, This is the expectation the directory 417 * has for shortcuts created for its elements. Clients must obey this setting. 418 * 419 * @hide 420 */ 421 public static final String SHORTCUT_SUPPORT = "shortcutSupport"; 422 423 /** 424 * An {@link #SHORTCUT_SUPPORT} setting that indicates that the directory 425 * does not allow any shortcuts created for its contacts. 426 * 427 * @hide 428 */ 429 public static final int SHORTCUT_SUPPORT_NONE = 0; 430 431 /** 432 * An {@link #SHORTCUT_SUPPORT} setting that indicates that the directory 433 * allow creation of shortcuts for data items like email, phone or postal address, 434 * but not the entire contact. 435 * 436 * @hide 437 */ 438 public static final int SHORTCUT_SUPPORT_DATA_ITEMS_ONLY = 1; 439 440 /** 441 * An {@link #SHORTCUT_SUPPORT} setting that indicates that the directory 442 * allow creation of shortcuts for contact as well as their constituent elements. 443 * 444 * @hide 445 */ 446 public static final int SHORTCUT_SUPPORT_FULL = 2; 447 } 448 449 /** 450 * @hide should be removed when users are updated to refer to SyncState 451 * @deprecated use SyncState instead 452 */ 453 @Deprecated 454 public interface SyncStateColumns extends SyncStateContract.Columns { 455 } 456 457 /** 458 * A table provided for sync adapters to use for storing private sync state data. 459 * 460 * @see SyncStateContract 461 */ 462 public static final class SyncState implements SyncStateContract.Columns { 463 /** 464 * This utility class cannot be instantiated 465 */ 466 private SyncState() {} 467 468 public static final String CONTENT_DIRECTORY = 469 SyncStateContract.Constants.CONTENT_DIRECTORY; 470 471 /** 472 * The content:// style URI for this table 473 */ 474 public static final Uri CONTENT_URI = 475 Uri.withAppendedPath(AUTHORITY_URI, CONTENT_DIRECTORY); 476 477 /** 478 * @see android.provider.SyncStateContract.Helpers#get 479 */ 480 public static byte[] get(ContentProviderClient provider, Account account) 481 throws RemoteException { 482 return SyncStateContract.Helpers.get(provider, CONTENT_URI, account); 483 } 484 485 /** 486 * @see android.provider.SyncStateContract.Helpers#get 487 */ 488 public static Pair<Uri, byte[]> getWithUri(ContentProviderClient provider, Account account) 489 throws RemoteException { 490 return SyncStateContract.Helpers.getWithUri(provider, CONTENT_URI, account); 491 } 492 493 /** 494 * @see android.provider.SyncStateContract.Helpers#set 495 */ 496 public static void set(ContentProviderClient provider, Account account, byte[] data) 497 throws RemoteException { 498 SyncStateContract.Helpers.set(provider, CONTENT_URI, account, data); 499 } 500 501 /** 502 * @see android.provider.SyncStateContract.Helpers#newSetOperation 503 */ 504 public static ContentProviderOperation newSetOperation(Account account, byte[] data) { 505 return SyncStateContract.Helpers.newSetOperation(CONTENT_URI, account, data); 506 } 507 } 508 509 /** 510 * Generic columns for use by sync adapters. The specific functions of 511 * these columns are private to the sync adapter. Other clients of the API 512 * should not attempt to either read or write this column. 513 * 514 * @see RawContacts 515 * @see Groups 516 */ 517 protected interface BaseSyncColumns { 518 519 /** Generic column for use by sync adapters. */ 520 public static final String SYNC1 = "sync1"; 521 /** Generic column for use by sync adapters. */ 522 public static final String SYNC2 = "sync2"; 523 /** Generic column for use by sync adapters. */ 524 public static final String SYNC3 = "sync3"; 525 /** Generic column for use by sync adapters. */ 526 public static final String SYNC4 = "sync4"; 527 } 528 529 /** 530 * Columns that appear when each row of a table belongs to a specific 531 * account, including sync information that an account may need. 532 * 533 * @see RawContacts 534 * @see Groups 535 */ 536 protected interface SyncColumns extends BaseSyncColumns { 537 /** 538 * The name of the account instance to which this row belongs, which when paired with 539 * {@link #ACCOUNT_TYPE} identifies a specific account. 540 * <P>Type: TEXT</P> 541 */ 542 public static final String ACCOUNT_NAME = "account_name"; 543 544 /** 545 * The type of account to which this row belongs, which when paired with 546 * {@link #ACCOUNT_NAME} identifies a specific account. 547 * <P>Type: TEXT</P> 548 */ 549 public static final String ACCOUNT_TYPE = "account_type"; 550 551 /** 552 * String that uniquely identifies this row to its source account. 553 * <P>Type: TEXT</P> 554 */ 555 public static final String SOURCE_ID = "sourceid"; 556 557 /** 558 * Version number that is updated whenever this row or its related data 559 * changes. 560 * <P>Type: INTEGER</P> 561 */ 562 public static final String VERSION = "version"; 563 564 /** 565 * Flag indicating that {@link #VERSION} has changed, and this row needs 566 * to be synchronized by its owning account. 567 * <P>Type: INTEGER (boolean)</P> 568 */ 569 public static final String DIRTY = "dirty"; 570 } 571 572 /** 573 * Columns of {@link ContactsContract.Contacts} that track the user's 574 * preferences for, or interactions with, the contact. 575 * 576 * @see Contacts 577 * @see RawContacts 578 * @see ContactsContract.Data 579 * @see PhoneLookup 580 * @see ContactsContract.Contacts.AggregationSuggestions 581 */ 582 protected interface ContactOptionsColumns { 583 /** 584 * The number of times a contact has been contacted 585 * <P>Type: INTEGER</P> 586 */ 587 public static final String TIMES_CONTACTED = "times_contacted"; 588 589 /** 590 * The last time a contact was contacted. 591 * <P>Type: INTEGER</P> 592 */ 593 public static final String LAST_TIME_CONTACTED = "last_time_contacted"; 594 595 /** 596 * Is the contact starred? 597 * <P>Type: INTEGER (boolean)</P> 598 */ 599 public static final String STARRED = "starred"; 600 601 /** 602 * URI for a custom ringtone associated with the contact. If null or missing, 603 * the default ringtone is used. 604 * <P>Type: TEXT (URI to the ringtone)</P> 605 */ 606 public static final String CUSTOM_RINGTONE = "custom_ringtone"; 607 608 /** 609 * Whether the contact should always be sent to voicemail. If missing, 610 * defaults to false. 611 * <P>Type: INTEGER (0 for false, 1 for true)</P> 612 */ 613 public static final String SEND_TO_VOICEMAIL = "send_to_voicemail"; 614 } 615 616 /** 617 * Columns of {@link ContactsContract.Contacts} that refer to intrinsic 618 * properties of the contact, as opposed to the user-specified options 619 * found in {@link ContactOptionsColumns}. 620 * 621 * @see Contacts 622 * @see ContactsContract.Data 623 * @see PhoneLookup 624 * @see ContactsContract.Contacts.AggregationSuggestions 625 */ 626 protected interface ContactsColumns { 627 /** 628 * The display name for the contact. 629 * <P>Type: TEXT</P> 630 */ 631 public static final String DISPLAY_NAME = ContactNameColumns.DISPLAY_NAME_PRIMARY; 632 633 /** 634 * Reference to the row in the RawContacts table holding the contact name. 635 * <P>Type: INTEGER REFERENCES raw_contacts(_id)</P> 636 * @hide 637 */ 638 public static final String NAME_RAW_CONTACT_ID = "name_raw_contact_id"; 639 640 /** 641 * Reference to the row in the data table holding the photo. 642 * <P>Type: INTEGER REFERENCES data(_id)</P> 643 */ 644 public static final String PHOTO_ID = "photo_id"; 645 646 /** 647 * Lookup value that reflects the {@link Groups#GROUP_VISIBLE} state of 648 * any {@link CommonDataKinds.GroupMembership} for this contact. 649 */ 650 public static final String IN_VISIBLE_GROUP = "in_visible_group"; 651 652 /** 653 * An indicator of whether this contact has at least one phone number. "1" if there is 654 * at least one phone number, "0" otherwise. 655 * <P>Type: INTEGER</P> 656 */ 657 public static final String HAS_PHONE_NUMBER = "has_phone_number"; 658 659 /** 660 * An opaque value that contains hints on how to find the contact if 661 * its row id changed as a result of a sync or aggregation. 662 */ 663 public static final String LOOKUP_KEY = "lookup"; 664 } 665 666 /** 667 * @see Contacts 668 */ 669 protected interface ContactStatusColumns { 670 /** 671 * Contact presence status. See {@link StatusUpdates} for individual status 672 * definitions. 673 * <p>Type: NUMBER</p> 674 */ 675 public static final String CONTACT_PRESENCE = "contact_presence"; 676 677 /** 678 * Contact Chat Capabilities. See {@link StatusUpdates} for individual 679 * definitions. 680 * <p>Type: NUMBER</p> 681 */ 682 public static final String CONTACT_CHAT_CAPABILITY = "contact_chat_capability"; 683 684 /** 685 * Contact's latest status update. 686 * <p>Type: TEXT</p> 687 */ 688 public static final String CONTACT_STATUS = "contact_status"; 689 690 /** 691 * The absolute time in milliseconds when the latest status was 692 * inserted/updated. 693 * <p>Type: NUMBER</p> 694 */ 695 public static final String CONTACT_STATUS_TIMESTAMP = "contact_status_ts"; 696 697 /** 698 * The package containing resources for this status: label and icon. 699 * <p>Type: TEXT</p> 700 */ 701 public static final String CONTACT_STATUS_RES_PACKAGE = "contact_status_res_package"; 702 703 /** 704 * The resource ID of the label describing the source of contact 705 * status, e.g. "Google Talk". This resource is scoped by the 706 * {@link #CONTACT_STATUS_RES_PACKAGE}. 707 * <p>Type: NUMBER</p> 708 */ 709 public static final String CONTACT_STATUS_LABEL = "contact_status_label"; 710 711 /** 712 * The resource ID of the icon for the source of contact status. This 713 * resource is scoped by the {@link #CONTACT_STATUS_RES_PACKAGE}. 714 * <p>Type: NUMBER</p> 715 */ 716 public static final String CONTACT_STATUS_ICON = "contact_status_icon"; 717 } 718 719 /** 720 * Constants for various styles of combining given name, family name etc into 721 * a full name. For example, the western tradition follows the pattern 722 * 'given name' 'middle name' 'family name' with the alternative pattern being 723 * 'family name', 'given name' 'middle name'. The CJK tradition is 724 * 'family name' 'middle name' 'given name', with Japanese favoring a space between 725 * the names and Chinese omitting the space. 726 * @hide 727 */ 728 public interface FullNameStyle { 729 public static final int UNDEFINED = 0; 730 public static final int WESTERN = 1; 731 732 /** 733 * Used if the name is written in Hanzi/Kanji/Hanja and we could not determine 734 * which specific language it belongs to: Chinese, Japanese or Korean. 735 */ 736 public static final int CJK = 2; 737 738 public static final int CHINESE = 3; 739 public static final int JAPANESE = 4; 740 public static final int KOREAN = 5; 741 } 742 743 /** 744 * Constants for various styles of capturing the pronunciation of a person's name. 745 * @hide 746 */ 747 public interface PhoneticNameStyle { 748 public static final int UNDEFINED = 0; 749 750 /** 751 * Pinyin is a phonetic method of entering Chinese characters. Typically not explicitly 752 * shown in UIs, but used for searches and sorting. 753 */ 754 public static final int PINYIN = 3; 755 756 /** 757 * Hiragana and Katakana are two common styles of writing out the pronunciation 758 * of a Japanese names. 759 */ 760 public static final int JAPANESE = 4; 761 762 /** 763 * Hangul is the Korean phonetic alphabet. 764 */ 765 public static final int KOREAN = 5; 766 } 767 768 /** 769 * Types of data used to produce the display name for a contact. Listed in the order 770 * of increasing priority. 771 * 772 * @hide 773 */ 774 public interface DisplayNameSources { 775 public static final int UNDEFINED = 0; 776 public static final int EMAIL = 10; 777 public static final int PHONE = 20; 778 public static final int ORGANIZATION = 30; 779 public static final int NICKNAME = 35; 780 public static final int STRUCTURED_NAME = 40; 781 } 782 783 /** 784 * Contact name and contact name metadata columns in the RawContacts table. 785 * 786 * @see Contacts 787 * @see RawContacts 788 * @hide 789 */ 790 protected interface ContactNameColumns { 791 792 /** 793 * The kind of data that is used as the display name for the contact, such as 794 * structured name or email address. See DisplayNameSources. 795 * 796 * TODO: convert DisplayNameSources to a link after it is un-hidden 797 */ 798 public static final String DISPLAY_NAME_SOURCE = "display_name_source"; 799 800 /** 801 * <p> 802 * The standard text shown as the contact's display name, based on the best 803 * available information for the contact (for example, it might be the email address 804 * if the name is not available). 805 * The information actually used to compute the name is stored in 806 * {@link #DISPLAY_NAME_SOURCE}. 807 * </p> 808 * <p> 809 * A contacts provider is free to choose whatever representation makes most 810 * sense for its target market. 811 * For example in the default Android Open Source Project implementation, 812 * if the display name is 813 * based on the structured name and the structured name follows 814 * the Western full-name style, then this field contains the "given name first" 815 * version of the full name. 816 * <p> 817 * 818 * @see ContactsContract.ContactNameColumns#DISPLAY_NAME_ALTERNATIVE 819 */ 820 public static final String DISPLAY_NAME_PRIMARY = "display_name"; 821 822 /** 823 * <p> 824 * An alternative representation of the display name, such as "family name first" 825 * instead of "given name first" for Western names. If an alternative is not 826 * available, the values should be the same as {@link #DISPLAY_NAME_PRIMARY}. 827 * </p> 828 * <p> 829 * A contacts provider is free to provide alternatives as necessary for 830 * its target market. 831 * For example the default Android Open Source Project contacts provider 832 * currently provides an 833 * alternative in a single case: if the display name is 834 * based on the structured name and the structured name follows 835 * the Western full name style, then the field contains the "family name first" 836 * version of the full name. 837 * Other cases may be added later. 838 * </p> 839 */ 840 public static final String DISPLAY_NAME_ALTERNATIVE = "display_name_alt"; 841 842 /** 843 * The phonetic alphabet used to represent the {@link #PHONETIC_NAME}. See 844 * PhoneticNameStyle. 845 * 846 * TODO: convert PhoneticNameStyle to a link after it is un-hidden 847 */ 848 public static final String PHONETIC_NAME_STYLE = "phonetic_name_style"; 849 850 /** 851 * <p> 852 * Pronunciation of the full name in the phonetic alphabet specified by 853 * {@link #PHONETIC_NAME_STYLE}. 854 * </p> 855 * <p> 856 * The value may be set manually by the user. 857 * This capability is is of interest only in countries 858 * with commonly used phonetic 859 * alphabets, such as Japan and Korea. See PhoneticNameStyle. 860 * </p> 861 * 862 * TODO: convert PhoneticNameStyle to a link after it is un-hidden 863 */ 864 public static final String PHONETIC_NAME = "phonetic_name"; 865 866 /** 867 * Sort key that takes into account locale-based traditions for sorting 868 * names in address books. The default 869 * sort key is {@link #DISPLAY_NAME_PRIMARY}. For Chinese names 870 * the sort key is the name's Pinyin spelling, and for Japanese names 871 * it is the Hiragana version of the phonetic name. 872 */ 873 public static final String SORT_KEY_PRIMARY = "sort_key"; 874 875 /** 876 * Sort key based on the alternative representation of the full name, 877 * {@link #DISPLAY_NAME_ALTERNATIVE}. Thus for Western names, 878 * it is the one using the "family name first" format. 879 */ 880 public static final String SORT_KEY_ALTERNATIVE = "sort_key_alt"; 881 } 882 883 /** 884 * URI parameter and cursor extras that return counts of rows grouped by the 885 * address book index, which is usually the first letter of the sort key. 886 * When this parameter is supplied, the row counts are returned in the 887 * cursor extras bundle. 888 * 889 * @hide 890 */ 891 public final static class ContactCounts { 892 893 /** 894 * Add this query parameter to a URI to get back row counts grouped by 895 * the address book index as cursor extras. For most languages it is the 896 * first letter of the sort key. This parameter does not affect the main 897 * content of the cursor. 898 * 899 * @hide 900 */ 901 public static final String ADDRESS_BOOK_INDEX_EXTRAS = "address_book_index_extras"; 902 903 /** 904 * The array of address book index titles, which are returned in the 905 * same order as the data in the cursor. 906 * <p>TYPE: String[]</p> 907 * 908 * @hide 909 */ 910 public static final String EXTRA_ADDRESS_BOOK_INDEX_TITLES = "address_book_index_titles"; 911 912 /** 913 * The array of group counts for the corresponding group. Contains the same number 914 * of elements as the EXTRA_ADDRESS_BOOK_INDEX_TITLES array. 915 * <p>TYPE: int[]</p> 916 * 917 * @hide 918 */ 919 public static final String EXTRA_ADDRESS_BOOK_INDEX_COUNTS = "address_book_index_counts"; 920 } 921 922 /** 923 * Constants for the contacts table, which contains a record per aggregate 924 * of raw contacts representing the same person. 925 * <h3>Operations</h3> 926 * <dl> 927 * <dt><b>Insert</b></dt> 928 * <dd>A Contact cannot be created explicitly. When a raw contact is 929 * inserted, the provider will first try to find a Contact representing the 930 * same person. If one is found, the raw contact's 931 * {@link RawContacts#CONTACT_ID} column gets the _ID of the aggregate 932 * Contact. If no match is found, the provider automatically inserts a new 933 * Contact and puts its _ID into the {@link RawContacts#CONTACT_ID} column 934 * of the newly inserted raw contact.</dd> 935 * <dt><b>Update</b></dt> 936 * <dd>Only certain columns of Contact are modifiable: 937 * {@link #TIMES_CONTACTED}, {@link #LAST_TIME_CONTACTED}, {@link #STARRED}, 938 * {@link #CUSTOM_RINGTONE}, {@link #SEND_TO_VOICEMAIL}. Changing any of 939 * these columns on the Contact also changes them on all constituent raw 940 * contacts.</dd> 941 * <dt><b>Delete</b></dt> 942 * <dd>Be careful with deleting Contacts! Deleting an aggregate contact 943 * deletes all constituent raw contacts. The corresponding sync adapters 944 * will notice the deletions of their respective raw contacts and remove 945 * them from their back end storage.</dd> 946 * <dt><b>Query</b></dt> 947 * <dd> 948 * <ul> 949 * <li>If you need to read an individual contact, consider using 950 * {@link #CONTENT_LOOKUP_URI} instead of {@link #CONTENT_URI}.</li> 951 * <li>If you need to look up a contact by the phone number, use 952 * {@link PhoneLookup#CONTENT_FILTER_URI PhoneLookup.CONTENT_FILTER_URI}, 953 * which is optimized for this purpose.</li> 954 * <li>If you need to look up a contact by partial name, e.g. to produce 955 * filter-as-you-type suggestions, use the {@link #CONTENT_FILTER_URI} URI. 956 * <li>If you need to look up a contact by some data element like email 957 * address, nickname, etc, use a query against the {@link ContactsContract.Data} table. 958 * The result will contain contact ID, name etc. 959 * </ul> 960 * </dd> 961 * </dl> 962 * <h2>Columns</h2> 963 * <table class="jd-sumtable"> 964 * <tr> 965 * <th colspan='4'>Contacts</th> 966 * </tr> 967 * <tr> 968 * <td>long</td> 969 * <td>{@link #_ID}</td> 970 * <td>read-only</td> 971 * <td>Row ID. Consider using {@link #LOOKUP_KEY} instead.</td> 972 * </tr> 973 * <tr> 974 * <td>String</td> 975 * <td>{@link #LOOKUP_KEY}</td> 976 * <td>read-only</td> 977 * <td>An opaque value that contains hints on how to find the contact if its 978 * row id changed as a result of a sync or aggregation.</td> 979 * </tr> 980 * <tr> 981 * <td>long</td> 982 * <td>NAME_RAW_CONTACT_ID</td> 983 * <td>read-only</td> 984 * <td>The ID of the raw contact that contributes the display name 985 * to the aggregate contact. During aggregation one of the constituent 986 * raw contacts is chosen using a heuristic: a longer name or a name 987 * with more diacritic marks or more upper case characters is chosen.</td> 988 * </tr> 989 * <tr> 990 * <td>String</td> 991 * <td>DISPLAY_NAME_PRIMARY</td> 992 * <td>read-only</td> 993 * <td>The display name for the contact. It is the display name 994 * contributed by the raw contact referred to by the NAME_RAW_CONTACT_ID 995 * column.</td> 996 * </tr> 997 * <tr> 998 * <td>long</td> 999 * <td>{@link #PHOTO_ID}</td> 1000 * <td>read-only</td> 1001 * <td>Reference to the row in the {@link ContactsContract.Data} table holding the photo. 1002 * That row has the mime type 1003 * {@link CommonDataKinds.Photo#CONTENT_ITEM_TYPE}. The value of this field 1004 * is computed automatically based on the 1005 * {@link CommonDataKinds.Photo#IS_SUPER_PRIMARY} field of the data rows of 1006 * that mime type.</td> 1007 * </tr> 1008 * <tr> 1009 * <td>int</td> 1010 * <td>{@link #IN_VISIBLE_GROUP}</td> 1011 * <td>read-only</td> 1012 * <td>An indicator of whether this contact is supposed to be visible in the 1013 * UI. "1" if the contact has at least one raw contact that belongs to a 1014 * visible group; "0" otherwise.</td> 1015 * </tr> 1016 * <tr> 1017 * <td>int</td> 1018 * <td>{@link #HAS_PHONE_NUMBER}</td> 1019 * <td>read-only</td> 1020 * <td>An indicator of whether this contact has at least one phone number. 1021 * "1" if there is at least one phone number, "0" otherwise.</td> 1022 * </tr> 1023 * <tr> 1024 * <td>int</td> 1025 * <td>{@link #TIMES_CONTACTED}</td> 1026 * <td>read/write</td> 1027 * <td>The number of times the contact has been contacted. See 1028 * {@link #markAsContacted}. When raw contacts are aggregated, this field is 1029 * computed automatically as the maximum number of times contacted among all 1030 * constituent raw contacts. Setting this field automatically changes the 1031 * corresponding field on all constituent raw contacts.</td> 1032 * </tr> 1033 * <tr> 1034 * <td>long</td> 1035 * <td>{@link #LAST_TIME_CONTACTED}</td> 1036 * <td>read/write</td> 1037 * <td>The timestamp of the last time the contact was contacted. See 1038 * {@link #markAsContacted}. Setting this field also automatically 1039 * increments {@link #TIMES_CONTACTED}. When raw contacts are aggregated, 1040 * this field is computed automatically as the latest time contacted of all 1041 * constituent raw contacts. Setting this field automatically changes the 1042 * corresponding field on all constituent raw contacts.</td> 1043 * </tr> 1044 * <tr> 1045 * <td>int</td> 1046 * <td>{@link #STARRED}</td> 1047 * <td>read/write</td> 1048 * <td>An indicator for favorite contacts: '1' if favorite, '0' otherwise. 1049 * When raw contacts are aggregated, this field is automatically computed: 1050 * if any constituent raw contacts are starred, then this field is set to 1051 * '1'. Setting this field automatically changes the corresponding field on 1052 * all constituent raw contacts.</td> 1053 * </tr> 1054 * <tr> 1055 * <td>String</td> 1056 * <td>{@link #CUSTOM_RINGTONE}</td> 1057 * <td>read/write</td> 1058 * <td>A custom ringtone associated with a contact. Typically this is the 1059 * URI returned by an activity launched with the 1060 * {@link android.media.RingtoneManager#ACTION_RINGTONE_PICKER} intent.</td> 1061 * </tr> 1062 * <tr> 1063 * <td>int</td> 1064 * <td>{@link #SEND_TO_VOICEMAIL}</td> 1065 * <td>read/write</td> 1066 * <td>An indicator of whether calls from this contact should be forwarded 1067 * directly to voice mail ('1') or not ('0'). When raw contacts are 1068 * aggregated, this field is automatically computed: if <i>all</i> 1069 * constituent raw contacts have SEND_TO_VOICEMAIL=1, then this field is set 1070 * to '1'. Setting this field automatically changes the corresponding field 1071 * on all constituent raw contacts.</td> 1072 * </tr> 1073 * <tr> 1074 * <td>int</td> 1075 * <td>{@link #CONTACT_PRESENCE}</td> 1076 * <td>read-only</td> 1077 * <td>Contact IM presence status. See {@link StatusUpdates} for individual 1078 * status definitions. Automatically computed as the highest presence of all 1079 * constituent raw contacts. The provider may choose not to store this value 1080 * in persistent storage. The expectation is that presence status will be 1081 * updated on a regular basic.</td> 1082 * </tr> 1083 * <tr> 1084 * <td>String</td> 1085 * <td>{@link #CONTACT_STATUS}</td> 1086 * <td>read-only</td> 1087 * <td>Contact's latest status update. Automatically computed as the latest 1088 * of all constituent raw contacts' status updates.</td> 1089 * </tr> 1090 * <tr> 1091 * <td>long</td> 1092 * <td>{@link #CONTACT_STATUS_TIMESTAMP}</td> 1093 * <td>read-only</td> 1094 * <td>The absolute time in milliseconds when the latest status was 1095 * inserted/updated.</td> 1096 * </tr> 1097 * <tr> 1098 * <td>String</td> 1099 * <td>{@link #CONTACT_STATUS_RES_PACKAGE}</td> 1100 * <td>read-only</td> 1101 * <td> The package containing resources for this status: label and icon.</td> 1102 * </tr> 1103 * <tr> 1104 * <td>long</td> 1105 * <td>{@link #CONTACT_STATUS_LABEL}</td> 1106 * <td>read-only</td> 1107 * <td>The resource ID of the label describing the source of contact status, 1108 * e.g. "Google Talk". This resource is scoped by the 1109 * {@link #CONTACT_STATUS_RES_PACKAGE}.</td> 1110 * </tr> 1111 * <tr> 1112 * <td>long</td> 1113 * <td>{@link #CONTACT_STATUS_ICON}</td> 1114 * <td>read-only</td> 1115 * <td>The resource ID of the icon for the source of contact status. This 1116 * resource is scoped by the {@link #CONTACT_STATUS_RES_PACKAGE}.</td> 1117 * </tr> 1118 * </table> 1119 */ 1120 public static class Contacts implements BaseColumns, ContactsColumns, 1121 ContactOptionsColumns, ContactNameColumns, ContactStatusColumns { 1122 /** 1123 * This utility class cannot be instantiated 1124 */ 1125 private Contacts() {} 1126 1127 /** 1128 * The content:// style URI for this table 1129 */ 1130 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "contacts"); 1131 1132 /** 1133 * A content:// style URI for this table that should be used to create 1134 * shortcuts or otherwise create long-term links to contacts. This URI 1135 * should always be followed by a "/" and the contact's {@link #LOOKUP_KEY}. 1136 * It can optionally also have a "/" and last known contact ID appended after 1137 * that. This "complete" format is an important optimization and is highly recommended. 1138 * <p> 1139 * As long as the contact's row ID remains the same, this URI is 1140 * equivalent to {@link #CONTENT_URI}. If the contact's row ID changes 1141 * as a result of a sync or aggregation, this URI will look up the 1142 * contact using indirect information (sync IDs or constituent raw 1143 * contacts). 1144 * <p> 1145 * Lookup key should be appended unencoded - it is stored in the encoded 1146 * form, ready for use in a URI. 1147 */ 1148 public static final Uri CONTENT_LOOKUP_URI = Uri.withAppendedPath(CONTENT_URI, 1149 "lookup"); 1150 1151 /** 1152 * Base {@link Uri} for referencing a single {@link Contacts} entry, 1153 * created by appending {@link #LOOKUP_KEY} using 1154 * {@link Uri#withAppendedPath(Uri, String)}. Provides 1155 * {@link OpenableColumns} columns when queried, or returns the 1156 * referenced contact formatted as a vCard when opened through 1157 * {@link ContentResolver#openAssetFileDescriptor(Uri, String)}. 1158 */ 1159 public static final Uri CONTENT_VCARD_URI = Uri.withAppendedPath(CONTENT_URI, 1160 "as_vcard"); 1161 1162 /** 1163 * Base {@link Uri} for referencing multiple {@link Contacts} entry, 1164 * created by appending {@link #LOOKUP_KEY} using 1165 * {@link Uri#withAppendedPath(Uri, String)}. The lookup keys have to be 1166 * encoded and joined with the colon (":") seperator. The resulting string 1167 * has to be encoded again. Provides 1168 * {@link OpenableColumns} columns when queried, or returns the 1169 * referenced contact formatted as a vCard when opened through 1170 * {@link ContentResolver#openAssetFileDescriptor(Uri, String)}. 1171 * 1172 * This is private API because we do not have a well-defined way to 1173 * specify several entities yet. The format of this Uri might change in the future 1174 * or the Uri might be completely removed. 1175 * 1176 * @hide 1177 */ 1178 public static final Uri CONTENT_MULTI_VCARD_URI = Uri.withAppendedPath(CONTENT_URI, 1179 "as_multi_vcard"); 1180 1181 /** 1182 * Builds a {@link #CONTENT_LOOKUP_URI} style {@link Uri} describing the 1183 * requested {@link Contacts} entry. 1184 * 1185 * @param contactUri A {@link #CONTENT_URI} row, or an existing 1186 * {@link #CONTENT_LOOKUP_URI} to attempt refreshing. 1187 */ 1188 public static Uri getLookupUri(ContentResolver resolver, Uri contactUri) { 1189 final Cursor c = resolver.query(contactUri, new String[] { 1190 Contacts.LOOKUP_KEY, Contacts._ID 1191 }, null, null, null); 1192 if (c == null) { 1193 return null; 1194 } 1195 1196 try { 1197 if (c.moveToFirst()) { 1198 final String lookupKey = c.getString(0); 1199 final long contactId = c.getLong(1); 1200 return getLookupUri(contactId, lookupKey); 1201 } 1202 } finally { 1203 c.close(); 1204 } 1205 return null; 1206 } 1207 1208 /** 1209 * Build a {@link #CONTENT_LOOKUP_URI} lookup {@link Uri} using the 1210 * given {@link ContactsContract.Contacts#_ID} and {@link #LOOKUP_KEY}. 1211 */ 1212 public static Uri getLookupUri(long contactId, String lookupKey) { 1213 return ContentUris.withAppendedId(Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, 1214 lookupKey), contactId); 1215 } 1216 1217 /** 1218 * Computes a content URI (see {@link #CONTENT_URI}) given a lookup URI. 1219 * <p> 1220 * Returns null if the contact cannot be found. 1221 */ 1222 public static Uri lookupContact(ContentResolver resolver, Uri lookupUri) { 1223 if (lookupUri == null) { 1224 return null; 1225 } 1226 1227 Cursor c = resolver.query(lookupUri, new String[]{Contacts._ID}, null, null, null); 1228 if (c == null) { 1229 return null; 1230 } 1231 1232 try { 1233 if (c.moveToFirst()) { 1234 long contactId = c.getLong(0); 1235 return ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId); 1236 } 1237 } finally { 1238 c.close(); 1239 } 1240 return null; 1241 } 1242 1243 /** 1244 * Mark a contact as having been contacted. This updates the 1245 * {@link #TIMES_CONTACTED} and {@link #LAST_TIME_CONTACTED} for the 1246 * contact, plus the corresponding values of any associated raw 1247 * contacts. 1248 * 1249 * @param resolver the ContentResolver to use 1250 * @param contactId the person who was contacted 1251 */ 1252 public static void markAsContacted(ContentResolver resolver, long contactId) { 1253 Uri uri = ContentUris.withAppendedId(CONTENT_URI, contactId); 1254 ContentValues values = new ContentValues(); 1255 // TIMES_CONTACTED will be incremented when LAST_TIME_CONTACTED is modified. 1256 values.put(LAST_TIME_CONTACTED, System.currentTimeMillis()); 1257 resolver.update(uri, values, null, null); 1258 } 1259 1260 /** 1261 * The content:// style URI used for "type-to-filter" functionality on the 1262 * {@link #CONTENT_URI} URI. The filter string will be used to match 1263 * various parts of the contact name. The filter argument should be passed 1264 * as an additional path segment after this URI. 1265 */ 1266 public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath( 1267 CONTENT_URI, "filter"); 1268 1269 /** 1270 * The content:// style URI for this table joined with useful data from 1271 * {@link ContactsContract.Data}, filtered to include only starred contacts 1272 * and the most frequently contacted contacts. 1273 */ 1274 public static final Uri CONTENT_STREQUENT_URI = Uri.withAppendedPath( 1275 CONTENT_URI, "strequent"); 1276 1277 /** 1278 * The content:// style URI used for "type-to-filter" functionality on the 1279 * {@link #CONTENT_STREQUENT_URI} URI. The filter string will be used to match 1280 * various parts of the contact name. The filter argument should be passed 1281 * as an additional path segment after this URI. 1282 */ 1283 public static final Uri CONTENT_STREQUENT_FILTER_URI = Uri.withAppendedPath( 1284 CONTENT_STREQUENT_URI, "filter"); 1285 1286 public static final Uri CONTENT_GROUP_URI = Uri.withAppendedPath( 1287 CONTENT_URI, "group"); 1288 1289 /** 1290 * The MIME type of {@link #CONTENT_URI} providing a directory of 1291 * people. 1292 */ 1293 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/contact"; 1294 1295 /** 1296 * The MIME type of a {@link #CONTENT_URI} subdirectory of a single 1297 * person. 1298 */ 1299 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact"; 1300 1301 /** 1302 * The MIME type of a {@link #CONTENT_URI} subdirectory of a single 1303 * person. 1304 */ 1305 public static final String CONTENT_VCARD_TYPE = "text/x-vcard"; 1306 1307 /** 1308 * A sub-directory of a single contact that contains all of the constituent raw contact 1309 * {@link ContactsContract.Data} rows. 1310 */ 1311 public static final class Data implements BaseColumns, DataColumns { 1312 /** 1313 * no public constructor since this is a utility class 1314 */ 1315 private Data() {} 1316 1317 /** 1318 * The directory twig for this sub-table 1319 */ 1320 public static final String CONTENT_DIRECTORY = "data"; 1321 } 1322 1323 /** 1324 * <p> 1325 * A <i>read-only</i> sub-directory of a single contact aggregate that 1326 * contains all aggregation suggestions (other contacts). The 1327 * aggregation suggestions are computed based on approximate data 1328 * matches with this contact. 1329 * </p> 1330 * <p> 1331 * <i>Note: this query may be expensive! If you need to use it in bulk, 1332 * make sure the user experience is acceptable when the query runs for a 1333 * long time.</i> 1334 * <p> 1335 * Usage example: 1336 * 1337 * <pre> 1338 * Uri uri = Contacts.CONTENT_URI.buildUpon() 1339 * .appendEncodedPath(String.valueOf(contactId)) 1340 * .appendPath(Contacts.AggregationSuggestions.CONTENT_DIRECTORY) 1341 * .appendQueryParameter("limit", "3") 1342 * .build() 1343 * Cursor cursor = getContentResolver().query(suggestionsUri, 1344 * new String[] {Contacts.DISPLAY_NAME, Contacts._ID, Contacts.LOOKUP_KEY}, 1345 * null, null, null); 1346 * </pre> 1347 * 1348 * </p> 1349 */ 1350 // TODO: add ContactOptionsColumns, ContactStatusColumns 1351 public static final class AggregationSuggestions implements BaseColumns, ContactsColumns { 1352 /** 1353 * No public constructor since this is a utility class 1354 */ 1355 private AggregationSuggestions() {} 1356 1357 /** 1358 * The directory twig for this sub-table. The URI can be followed by an optional 1359 * type-to-filter, similar to 1360 * {@link android.provider.ContactsContract.Contacts#CONTENT_FILTER_URI}. 1361 */ 1362 public static final String CONTENT_DIRECTORY = "suggestions"; 1363 } 1364 1365 /** 1366 * A <i>read-only</i> sub-directory of a single contact that contains 1367 * the contact's primary photo. 1368 * <p> 1369 * Usage example: 1370 * 1371 * <pre> 1372 * public InputStream openPhoto(long contactId) { 1373 * Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId); 1374 * Uri photoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.CONTENT_DIRECTORY); 1375 * Cursor cursor = getContentResolver().query(photoUri, 1376 * new String[] {Contacts.Photo.PHOTO}, null, null, null); 1377 * if (cursor == null) { 1378 * return null; 1379 * } 1380 * try { 1381 * if (cursor.moveToFirst()) { 1382 * byte[] data = cursor.getBlob(0); 1383 * if (data != null) { 1384 * return new ByteArrayInputStream(data); 1385 * } 1386 * } 1387 * } finally { 1388 * cursor.close(); 1389 * } 1390 * return null; 1391 * } 1392 * </pre> 1393 * 1394 * </p> 1395 * <p>You should also consider using the convenience method 1396 * {@link ContactsContract.Contacts#openContactPhotoInputStream(ContentResolver, Uri)} 1397 * </p> 1398 */ 1399 // TODO: change DataColumns to DataColumnsWithJoins 1400 public static final class Photo implements BaseColumns, DataColumns { 1401 /** 1402 * no public constructor since this is a utility class 1403 */ 1404 private Photo() {} 1405 1406 /** 1407 * The directory twig for this sub-table 1408 */ 1409 public static final String CONTENT_DIRECTORY = "photo"; 1410 1411 /** 1412 * Thumbnail photo of the raw contact. This is the raw bytes of an image 1413 * that could be inflated using {@link android.graphics.BitmapFactory}. 1414 * <p> 1415 * Type: BLOB 1416 * @hide TODO: Unhide in a separate CL 1417 */ 1418 public static final String PHOTO = DATA15; 1419 } 1420 1421 /** 1422 * Opens an InputStream for the contacts's default photo and returns the 1423 * photo as a byte stream. If there is not photo null will be returned. 1424 * 1425 * @param contactUri the contact whose photo should be used 1426 * @return an InputStream of the photo, or null if no photo is present 1427 */ 1428 public static InputStream openContactPhotoInputStream(ContentResolver cr, Uri contactUri) { 1429 Uri photoUri = Uri.withAppendedPath(contactUri, Photo.CONTENT_DIRECTORY); 1430 if (photoUri == null) { 1431 return null; 1432 } 1433 Cursor cursor = cr.query(photoUri, 1434 new String[]{ContactsContract.CommonDataKinds.Photo.PHOTO}, null, null, null); 1435 try { 1436 if (cursor == null || !cursor.moveToNext()) { 1437 return null; 1438 } 1439 byte[] data = cursor.getBlob(0); 1440 if (data == null) { 1441 return null; 1442 } 1443 return new ByteArrayInputStream(data); 1444 } finally { 1445 if (cursor != null) { 1446 cursor.close(); 1447 } 1448 } 1449 } 1450 } 1451 1452 protected interface RawContactsColumns { 1453 /** 1454 * A reference to the {@link ContactsContract.Contacts#_ID} that this 1455 * data belongs to. 1456 * <P>Type: INTEGER</P> 1457 */ 1458 public static final String CONTACT_ID = "contact_id"; 1459 1460 /** 1461 * Flag indicating that this {@link RawContacts} entry and its children have 1462 * been restricted to specific platform apps. 1463 * <P>Type: INTEGER (boolean)</P> 1464 * 1465 * @hide until finalized in future platform release 1466 */ 1467 public static final String IS_RESTRICTED = "is_restricted"; 1468 1469 /** 1470 * The aggregation mode for this contact. 1471 * <P>Type: INTEGER</P> 1472 */ 1473 public static final String AGGREGATION_MODE = "aggregation_mode"; 1474 1475 /** 1476 * The "deleted" flag: "0" by default, "1" if the row has been marked 1477 * for deletion. When {@link android.content.ContentResolver#delete} is 1478 * called on a raw contact, it is marked for deletion and removed from its 1479 * aggregate contact. The sync adaptor deletes the raw contact on the server and 1480 * then calls ContactResolver.delete once more, this time passing the 1481 * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to finalize 1482 * the data removal. 1483 * <P>Type: INTEGER</P> 1484 */ 1485 public static final String DELETED = "deleted"; 1486 1487 /** 1488 * The "name_verified" flag: "1" means that the name fields on this raw 1489 * contact can be trusted and therefore should be used for the entire 1490 * aggregated contact. 1491 * <p> 1492 * If an aggregated contact contains more than one raw contact with a 1493 * verified name, one of those verified names is chosen at random. 1494 * If an aggregated contact contains no verified names, the 1495 * name is chosen randomly from the constituent raw contacts. 1496 * </p> 1497 * <p> 1498 * Updating this flag from "0" to "1" automatically resets it to "0" on 1499 * all other raw contacts in the same aggregated contact. 1500 * </p> 1501 * <p> 1502 * Sync adapters should only specify a value for this column when 1503 * inserting a raw contact and leave it out when doing an update. 1504 * </p> 1505 * <p> 1506 * The default value is "0" 1507 * </p> 1508 * <p>Type: INTEGER</p> 1509 * 1510 * @hide 1511 */ 1512 public static final String NAME_VERIFIED = "name_verified"; 1513 1514 /** 1515 * The "read-only" flag: "0" by default, "1" if the row cannot be modified or 1516 * deleted except by a sync adapter. See {@link ContactsContract#CALLER_IS_SYNCADAPTER}. 1517 * <P>Type: INTEGER</P> 1518 * @hide 1519 */ 1520 public static final String RAW_CONTACT_IS_READ_ONLY = "raw_contact_is_read_only"; 1521 } 1522 1523 /** 1524 * Constants for the raw contacts table, which contains one row of contact 1525 * information for each person in each synced account. Sync adapters and 1526 * contact management apps 1527 * are the primary consumers of this API. 1528 * 1529 * <h3>Aggregation</h3> 1530 * <p> 1531 * As soon as a raw contact is inserted or whenever its constituent data 1532 * changes, the provider will check if the raw contact matches other 1533 * existing raw contacts and if so will aggregate it with those. The 1534 * aggregation is reflected in the {@link RawContacts} table by the change of the 1535 * {@link #CONTACT_ID} field, which is the reference to the aggregate contact. 1536 * </p> 1537 * <p> 1538 * Changes to the structured name, organization, phone number, email address, 1539 * or nickname trigger a re-aggregation. 1540 * </p> 1541 * <p> 1542 * See also {@link AggregationExceptions} for a mechanism to control 1543 * aggregation programmatically. 1544 * </p> 1545 * 1546 * <h3>Operations</h3> 1547 * <dl> 1548 * <dt><b>Insert</b></dt> 1549 * <dd> 1550 * <p> 1551 * Raw contacts can be inserted incrementally or in a batch. 1552 * The incremental method is more traditional but less efficient. 1553 * It should be used 1554 * only if no {@link Data} values are available at the time the raw contact is created: 1555 * <pre> 1556 * ContentValues values = new ContentValues(); 1557 * values.put(RawContacts.ACCOUNT_TYPE, accountType); 1558 * values.put(RawContacts.ACCOUNT_NAME, accountName); 1559 * Uri rawContactUri = getContentResolver().insert(RawContacts.CONTENT_URI, values); 1560 * long rawContactId = ContentUris.parseId(rawContactUri); 1561 * </pre> 1562 * </p> 1563 * <p> 1564 * Once {@link Data} values become available, insert those. 1565 * For example, here's how you would insert a name: 1566 * 1567 * <pre> 1568 * values.clear(); 1569 * values.put(Data.RAW_CONTACT_ID, rawContactId); 1570 * values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE); 1571 * values.put(StructuredName.DISPLAY_NAME, "Mike Sullivan"); 1572 * getContentResolver().insert(Data.CONTENT_URI, values); 1573 * </pre> 1574 * </p> 1575 * <p> 1576 * The batch method is by far preferred. It inserts the raw contact and its 1577 * constituent data rows in a single database transaction 1578 * and causes at most one aggregation pass. 1579 * <pre> 1580 * ArrayList<ContentProviderOperation> ops = Lists.newArrayList(); 1581 * ... 1582 * int rawContactInsertIndex = ops.size(); 1583 * ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI) 1584 * .withValue(RawContacts.ACCOUNT_TYPE, accountType) 1585 * .withValue(RawContacts.ACCOUNT_NAME, accountName) 1586 * .build()); 1587 * 1588 * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI) 1589 * .withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex) 1590 * .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE) 1591 * .withValue(StructuredName.DISPLAY_NAME, "Mike Sullivan") 1592 * .build()); 1593 * 1594 * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); 1595 * </pre> 1596 * </p> 1597 * <p> 1598 * Note the use of {@link ContentProviderOperation.Builder#withValueBackReference(String, int)} 1599 * to refer to the as-yet-unknown index value of the raw contact inserted in the 1600 * first operation. 1601 * </p> 1602 * 1603 * <dt><b>Update</b></dt> 1604 * <dd><p> 1605 * Raw contacts can be updated incrementally or in a batch. 1606 * Batch mode should be used whenever possible. 1607 * The procedures and considerations are analogous to those documented above for inserts. 1608 * </p></dd> 1609 * <dt><b>Delete</b></dt> 1610 * <dd><p>When a raw contact is deleted, all of its Data rows as well as StatusUpdates, 1611 * AggregationExceptions, PhoneLookup rows are deleted automatically. When all raw 1612 * contacts associated with a {@link Contacts} row are deleted, the {@link Contacts} row 1613 * itself is also deleted automatically. 1614 * </p> 1615 * <p> 1616 * The invocation of {@code resolver.delete(...)}, does not immediately delete 1617 * a raw contacts row. 1618 * Instead, it sets the {@link #DELETED} flag on the raw contact and 1619 * removes the raw contact from its aggregate contact. 1620 * The sync adapter then deletes the raw contact from the server and 1621 * finalizes phone-side deletion by calling {@code resolver.delete(...)} 1622 * again and passing the {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter.<p> 1623 * <p>Some sync adapters are read-only, meaning that they only sync server-side 1624 * changes to the phone, but not the reverse. If one of those raw contacts 1625 * is marked for deletion, it will remain on the phone. However it will be 1626 * effectively invisible, because it will not be part of any aggregate contact. 1627 * </dd> 1628 * 1629 * <dt><b>Query</b></dt> 1630 * <dd> 1631 * <p> 1632 * It is easy to find all raw contacts in a Contact: 1633 * <pre> 1634 * Cursor c = getContentResolver().query(RawContacts.CONTENT_URI, 1635 * new String[]{RawContacts._ID}, 1636 * RawContacts.CONTACT_ID + "=?", 1637 * new String[]{String.valueOf(contactId)}, null); 1638 * </pre> 1639 * </p> 1640 * <p> 1641 * To find raw contacts within a specific account, 1642 * you can either put the account name and type in the selection or pass them as query 1643 * parameters. The latter approach is preferable, especially when you can reuse the 1644 * URI: 1645 * <pre> 1646 * Uri rawContactUri = RawContacts.URI.buildUpon() 1647 * .appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName) 1648 * .appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType) 1649 * .build(); 1650 * Cursor c1 = getContentResolver().query(rawContactUri, 1651 * RawContacts.STARRED + "<>0", null, null, null); 1652 * ... 1653 * Cursor c2 = getContentResolver().query(rawContactUri, 1654 * RawContacts.DELETED + "<>0", null, null, null); 1655 * </pre> 1656 * </p> 1657 * <p>The best way to read a raw contact along with all the data associated with it is 1658 * by using the {@link Entity} directory. If the raw contact has data rows, 1659 * the Entity cursor will contain a row for each data row. If the raw contact has no 1660 * data rows, the cursor will still contain one row with the raw contact-level information. 1661 * <pre> 1662 * Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId); 1663 * Uri entityUri = Uri.withAppendedPath(rawContactUri, Entity.CONTENT_DIRECTORY); 1664 * Cursor c = getContentResolver().query(entityUri, 1665 * new String[]{RawContacts.SOURCE_ID, Entity.DATA_ID, Entity.MIMETYPE, Entity.DATA1}, 1666 * null, null, null); 1667 * try { 1668 * while (c.moveToNext()) { 1669 * String sourceId = c.getString(0); 1670 * if (!c.isNull(1)) { 1671 * String mimeType = c.getString(2); 1672 * String data = c.getString(3); 1673 * ... 1674 * } 1675 * } 1676 * } finally { 1677 * c.close(); 1678 * } 1679 * </pre> 1680 * </p> 1681 * </dd> 1682 * </dl> 1683 * <h2>Columns</h2> 1684 * 1685 * <table class="jd-sumtable"> 1686 * <tr> 1687 * <th colspan='4'>RawContacts</th> 1688 * </tr> 1689 * <tr> 1690 * <td>long</td> 1691 * <td>{@link #_ID}</td> 1692 * <td>read-only</td> 1693 * <td>Row ID. Sync adapters should try to preserve row IDs during updates. In other words, 1694 * it is much better for a sync adapter to update a raw contact rather than to delete and 1695 * re-insert it.</td> 1696 * </tr> 1697 * <tr> 1698 * <td>long</td> 1699 * <td>{@link #CONTACT_ID}</td> 1700 * <td>read-only</td> 1701 * <td>The ID of the row in the {@link ContactsContract.Contacts} table 1702 * that this raw contact belongs 1703 * to. Raw contacts are linked to contacts by the aggregation process, which can be controlled 1704 * by the {@link #AGGREGATION_MODE} field and {@link AggregationExceptions}.</td> 1705 * </tr> 1706 * <tr> 1707 * <td>int</td> 1708 * <td>{@link #AGGREGATION_MODE}</td> 1709 * <td>read/write</td> 1710 * <td>A mechanism that allows programmatic control of the aggregation process. The allowed 1711 * values are {@link #AGGREGATION_MODE_DEFAULT}, {@link #AGGREGATION_MODE_DISABLED} 1712 * and {@link #AGGREGATION_MODE_SUSPENDED}. See also {@link AggregationExceptions}.</td> 1713 * </tr> 1714 * <tr> 1715 * <td>int</td> 1716 * <td>{@link #DELETED}</td> 1717 * <td>read/write</td> 1718 * <td>The "deleted" flag: "0" by default, "1" if the row has been marked 1719 * for deletion. When {@link android.content.ContentResolver#delete} is 1720 * called on a raw contact, it is marked for deletion and removed from its 1721 * aggregate contact. The sync adaptor deletes the raw contact on the server and 1722 * then calls ContactResolver.delete once more, this time passing the 1723 * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to finalize 1724 * the data removal.</td> 1725 * </tr> 1726 * <tr> 1727 * <td>int</td> 1728 * <td>{@link #TIMES_CONTACTED}</td> 1729 * <td>read/write</td> 1730 * <td>The number of times the contact has been contacted. To have an effect 1731 * on the corresponding value of the aggregate contact, this field 1732 * should be set at the time the raw contact is inserted. 1733 * After that, this value is typically updated via 1734 * {@link ContactsContract.Contacts#markAsContacted}.</td> 1735 * </tr> 1736 * <tr> 1737 * <td>long</td> 1738 * <td>{@link #LAST_TIME_CONTACTED}</td> 1739 * <td>read/write</td> 1740 * <td>The timestamp of the last time the contact was contacted. To have an effect 1741 * on the corresponding value of the aggregate contact, this field 1742 * should be set at the time the raw contact is inserted. 1743 * After that, this value is typically updated via 1744 * {@link ContactsContract.Contacts#markAsContacted}. 1745 * </td> 1746 * </tr> 1747 * <tr> 1748 * <td>int</td> 1749 * <td>{@link #STARRED}</td> 1750 * <td>read/write</td> 1751 * <td>An indicator for favorite contacts: '1' if favorite, '0' otherwise. 1752 * Changing this field immediately affects the corresponding aggregate contact: 1753 * if any raw contacts in that aggregate contact are starred, then the contact 1754 * itself is marked as starred.</td> 1755 * </tr> 1756 * <tr> 1757 * <td>String</td> 1758 * <td>{@link #CUSTOM_RINGTONE}</td> 1759 * <td>read/write</td> 1760 * <td>A custom ringtone associated with a raw contact. Typically this is the 1761 * URI returned by an activity launched with the 1762 * {@link android.media.RingtoneManager#ACTION_RINGTONE_PICKER} intent. 1763 * To have an effect on the corresponding value of the aggregate contact, this field 1764 * should be set at the time the raw contact is inserted. To set a custom 1765 * ringtone on a contact, use the field {@link ContactsContract.Contacts#CUSTOM_RINGTONE 1766 * Contacts.CUSTOM_RINGTONE} 1767 * instead.</td> 1768 * </tr> 1769 * <tr> 1770 * <td>int</td> 1771 * <td>{@link #SEND_TO_VOICEMAIL}</td> 1772 * <td>read/write</td> 1773 * <td>An indicator of whether calls from this raw contact should be forwarded 1774 * directly to voice mail ('1') or not ('0'). To have an effect 1775 * on the corresponding value of the aggregate contact, this field 1776 * should be set at the time the raw contact is inserted.</td> 1777 * </tr> 1778 * <tr> 1779 * <td>String</td> 1780 * <td>{@link #ACCOUNT_NAME}</td> 1781 * <td>read/write-once</td> 1782 * <td>The name of the account instance to which this row belongs, which when paired with 1783 * {@link #ACCOUNT_TYPE} identifies a specific account. 1784 * For example, this will be the Gmail address if it is a Google account. 1785 * It should be set at the time 1786 * the raw contact is inserted and never changed afterwards.</td> 1787 * </tr> 1788 * <tr> 1789 * <td>String</td> 1790 * <td>{@link #ACCOUNT_TYPE}</td> 1791 * <td>read/write-once</td> 1792 * <td> 1793 * <p> 1794 * The type of account to which this row belongs, which when paired with 1795 * {@link #ACCOUNT_NAME} identifies a specific account. 1796 * It should be set at the time 1797 * the raw contact is inserted and never changed afterwards. 1798 * </p> 1799 * <p> 1800 * To ensure uniqueness, new account types should be chosen according to the 1801 * Java package naming convention. Thus a Google account is of type "com.google". 1802 * </p> 1803 * </td> 1804 * </tr> 1805 * <tr> 1806 * <td>String</td> 1807 * <td>{@link #SOURCE_ID}</td> 1808 * <td>read/write</td> 1809 * <td>String that uniquely identifies this row to its source account. 1810 * Typically it is set at the time the raw contact is inserted and never 1811 * changed afterwards. The one notable exception is a new raw contact: it 1812 * will have an account name and type, but no source id. This 1813 * indicates to the sync adapter that a new contact needs to be created 1814 * server-side and its ID stored in the corresponding SOURCE_ID field on 1815 * the phone. 1816 * </td> 1817 * </tr> 1818 * <tr> 1819 * <td>int</td> 1820 * <td>{@link #VERSION}</td> 1821 * <td>read-only</td> 1822 * <td>Version number that is updated whenever this row or its related data 1823 * changes. This field can be used for optimistic locking of a raw contact. 1824 * </td> 1825 * </tr> 1826 * <tr> 1827 * <td>int</td> 1828 * <td>{@link #DIRTY}</td> 1829 * <td>read/write</td> 1830 * <td>Flag indicating that {@link #VERSION} has changed, and this row needs 1831 * to be synchronized by its owning account. The value is set to "1" automatically 1832 * whenever the raw contact changes, unless the URI has the 1833 * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter specified. 1834 * The sync adapter should always supply this query parameter to prevent 1835 * unnecessary synchronization: user changes some data on the server, 1836 * the sync adapter updates the contact on the phone (without the 1837 * CALLER_IS_SYNCADAPTER flag) flag, which sets the DIRTY flag, 1838 * which triggers a sync to bring the changes to the server. 1839 * </td> 1840 * </tr> 1841 * <tr> 1842 * <td>String</td> 1843 * <td>{@link #SYNC1}</td> 1844 * <td>read/write</td> 1845 * <td>Generic column provided for arbitrary use by sync adapters. 1846 * The content provider 1847 * stores this information on behalf of the sync adapter but does not 1848 * interpret it in any way. 1849 * </td> 1850 * </tr> 1851 * <tr> 1852 * <td>String</td> 1853 * <td>{@link #SYNC2}</td> 1854 * <td>read/write</td> 1855 * <td>Generic column for use by sync adapters. 1856 * </td> 1857 * </tr> 1858 * <tr> 1859 * <td>String</td> 1860 * <td>{@link #SYNC3}</td> 1861 * <td>read/write</td> 1862 * <td>Generic column for use by sync adapters. 1863 * </td> 1864 * </tr> 1865 * <tr> 1866 * <td>String</td> 1867 * <td>{@link #SYNC4}</td> 1868 * <td>read/write</td> 1869 * <td>Generic column for use by sync adapters. 1870 * </td> 1871 * </tr> 1872 * </table> 1873 */ 1874 public static final class RawContacts implements BaseColumns, RawContactsColumns, 1875 ContactOptionsColumns, ContactNameColumns, SyncColumns { 1876 /** 1877 * This utility class cannot be instantiated 1878 */ 1879 private RawContacts() { 1880 } 1881 1882 /** 1883 * The content:// style URI for this table, which requests a directory of 1884 * raw contact rows matching the selection criteria. 1885 */ 1886 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "raw_contacts"); 1887 1888 /** 1889 * The MIME type of the results from {@link #CONTENT_URI} when a specific 1890 * ID value is not provided, and multiple raw contacts may be returned. 1891 */ 1892 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/raw_contact"; 1893 1894 /** 1895 * The MIME type of the results when a raw contact ID is appended to {@link #CONTENT_URI}, 1896 * yielding a subdirectory of a single person. 1897 */ 1898 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/raw_contact"; 1899 1900 /** 1901 * Aggregation mode: aggregate immediately after insert or update operation(s) are complete. 1902 */ 1903 public static final int AGGREGATION_MODE_DEFAULT = 0; 1904 1905 /** 1906 * Do not use. 1907 * 1908 * TODO: deprecate in favor of {@link #AGGREGATION_MODE_DEFAULT} 1909 */ 1910 public static final int AGGREGATION_MODE_IMMEDIATE = 1; 1911 1912 /** 1913 * <p> 1914 * Aggregation mode: aggregation suspended temporarily, and is likely to be resumed later. 1915 * Changes to the raw contact will update the associated aggregate contact but will not 1916 * result in any change in how the contact is aggregated. Similar to 1917 * {@link #AGGREGATION_MODE_DISABLED}, but maintains a link to the corresponding 1918 * {@link Contacts} aggregate. 1919 * </p> 1920 * <p> 1921 * This can be used to postpone aggregation until after a series of updates, for better 1922 * performance and/or user experience. 1923 * </p> 1924 * <p> 1925 * Note that changing 1926 * {@link #AGGREGATION_MODE} from {@link #AGGREGATION_MODE_SUSPENDED} to 1927 * {@link #AGGREGATION_MODE_DEFAULT} does not trigger an aggregation pass, but any 1928 * subsequent 1929 * change to the raw contact's data will. 1930 * </p> 1931 */ 1932 public static final int AGGREGATION_MODE_SUSPENDED = 2; 1933 1934 /** 1935 * <p> 1936 * Aggregation mode: never aggregate this raw contact. The raw contact will not 1937 * have a corresponding {@link Contacts} aggregate and therefore will not be included in 1938 * {@link Contacts} query results. 1939 * </p> 1940 * <p> 1941 * For example, this mode can be used for a raw contact that is marked for deletion while 1942 * waiting for the deletion to occur on the server side. 1943 * </p> 1944 * 1945 * @see #AGGREGATION_MODE_SUSPENDED 1946 */ 1947 public static final int AGGREGATION_MODE_DISABLED = 3; 1948 1949 /** 1950 * Build a {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI} 1951 * style {@link Uri} for the parent {@link android.provider.ContactsContract.Contacts} 1952 * entry of the given {@link RawContacts} entry. 1953 */ 1954 public static Uri getContactLookupUri(ContentResolver resolver, Uri rawContactUri) { 1955 // TODO: use a lighter query by joining rawcontacts with contacts in provider 1956 final Uri dataUri = Uri.withAppendedPath(rawContactUri, Data.CONTENT_DIRECTORY); 1957 final Cursor cursor = resolver.query(dataUri, new String[] { 1958 RawContacts.CONTACT_ID, Contacts.LOOKUP_KEY 1959 }, null, null, null); 1960 1961 Uri lookupUri = null; 1962 try { 1963 if (cursor != null && cursor.moveToFirst()) { 1964 final long contactId = cursor.getLong(0); 1965 final String lookupKey = cursor.getString(1); 1966 return Contacts.getLookupUri(contactId, lookupKey); 1967 } 1968 } finally { 1969 if (cursor != null) cursor.close(); 1970 } 1971 return lookupUri; 1972 } 1973 1974 /** 1975 * A sub-directory of a single raw contact that contains all of its 1976 * {@link ContactsContract.Data} rows. To access this directory 1977 * append {@link Data#CONTENT_DIRECTORY} to the contact URI. 1978 * 1979 * TODO: deprecate in favor of {@link RawContacts.Entity}. 1980 */ 1981 public static final class Data implements BaseColumns, DataColumns { 1982 /** 1983 * no public constructor since this is a utility class 1984 */ 1985 private Data() { 1986 } 1987 1988 /** 1989 * The directory twig for this sub-table 1990 */ 1991 public static final String CONTENT_DIRECTORY = "data"; 1992 } 1993 1994 /** 1995 * <p> 1996 * A sub-directory of a single raw contact that contains all of its 1997 * {@link ContactsContract.Data} rows. To access this directory append 1998 * {@link #CONTENT_DIRECTORY} to the contact URI. See 1999 * {@link RawContactsEntity} for a stand-alone table containing the same 2000 * data. 2001 * </p> 2002 * <p> 2003 * Entity has two ID fields: {@link #_ID} for the raw contact 2004 * and {@link #DATA_ID} for the data rows. 2005 * Entity always contains at least one row, even if there are no 2006 * actual data rows. In this case the {@link #DATA_ID} field will be 2007 * null. 2008 * </p> 2009 * <p> 2010 * Entity reads all 2011 * data for a raw contact in one transaction, to guarantee 2012 * consistency. 2013 * </p> 2014 */ 2015 public static final class Entity implements BaseColumns, DataColumns { 2016 /** 2017 * no public constructor since this is a utility class 2018 */ 2019 private Entity() { 2020 } 2021 2022 /** 2023 * The directory twig for this sub-table 2024 */ 2025 public static final String CONTENT_DIRECTORY = "entity"; 2026 2027 /** 2028 * The ID of the data column. The value will be null if this raw contact has no 2029 * data rows. 2030 * <P>Type: INTEGER</P> 2031 */ 2032 public static final String DATA_ID = "data_id"; 2033 } 2034 2035 /** 2036 * TODO: javadoc 2037 * @param cursor 2038 * @return 2039 */ 2040 public static EntityIterator newEntityIterator(Cursor cursor) { 2041 return new EntityIteratorImpl(cursor); 2042 } 2043 2044 private static class EntityIteratorImpl extends CursorEntityIterator { 2045 private static final String[] DATA_KEYS = new String[]{ 2046 Data.DATA1, 2047 Data.DATA2, 2048 Data.DATA3, 2049 Data.DATA4, 2050 Data.DATA5, 2051 Data.DATA6, 2052 Data.DATA7, 2053 Data.DATA8, 2054 Data.DATA9, 2055 Data.DATA10, 2056 Data.DATA11, 2057 Data.DATA12, 2058 Data.DATA13, 2059 Data.DATA14, 2060 Data.DATA15, 2061 Data.SYNC1, 2062 Data.SYNC2, 2063 Data.SYNC3, 2064 Data.SYNC4}; 2065 2066 public EntityIteratorImpl(Cursor cursor) { 2067 super(cursor); 2068 } 2069 2070 @Override 2071 public android.content.Entity getEntityAndIncrementCursor(Cursor cursor) 2072 throws RemoteException { 2073 final int columnRawContactId = cursor.getColumnIndexOrThrow(RawContacts._ID); 2074 final long rawContactId = cursor.getLong(columnRawContactId); 2075 2076 // we expect the cursor is already at the row we need to read from 2077 ContentValues cv = new ContentValues(); 2078 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ACCOUNT_NAME); 2079 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ACCOUNT_TYPE); 2080 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, _ID); 2081 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DIRTY); 2082 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, VERSION); 2083 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SOURCE_ID); 2084 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC1); 2085 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC2); 2086 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC3); 2087 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC4); 2088 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DELETED); 2089 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, CONTACT_ID); 2090 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, STARRED); 2091 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, IS_RESTRICTED); 2092 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, NAME_VERIFIED); 2093 android.content.Entity contact = new android.content.Entity(cv); 2094 2095 // read data rows until the contact id changes 2096 do { 2097 if (rawContactId != cursor.getLong(columnRawContactId)) { 2098 break; 2099 } 2100 // add the data to to the contact 2101 cv = new ContentValues(); 2102 cv.put(Data._ID, cursor.getLong(cursor.getColumnIndexOrThrow(Entity.DATA_ID))); 2103 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, 2104 Data.RES_PACKAGE); 2105 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, Data.MIMETYPE); 2106 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, Data.IS_PRIMARY); 2107 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, 2108 Data.IS_SUPER_PRIMARY); 2109 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, Data.DATA_VERSION); 2110 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, 2111 CommonDataKinds.GroupMembership.GROUP_SOURCE_ID); 2112 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, 2113 Data.DATA_VERSION); 2114 for (String key : DATA_KEYS) { 2115 final int columnIndex = cursor.getColumnIndexOrThrow(key); 2116 if (cursor.isNull(columnIndex)) { 2117 // don't put anything 2118 } else { 2119 try { 2120 cv.put(key, cursor.getString(columnIndex)); 2121 } catch (SQLiteException e) { 2122 cv.put(key, cursor.getBlob(columnIndex)); 2123 } 2124 } 2125 // TODO: go back to this version of the code when bug 2126 // http://b/issue?id=2306370 is fixed. 2127// if (cursor.isNull(columnIndex)) { 2128// // don't put anything 2129// } else if (cursor.isLong(columnIndex)) { 2130// values.put(key, cursor.getLong(columnIndex)); 2131// } else if (cursor.isFloat(columnIndex)) { 2132// values.put(key, cursor.getFloat(columnIndex)); 2133// } else if (cursor.isString(columnIndex)) { 2134// values.put(key, cursor.getString(columnIndex)); 2135// } else if (cursor.isBlob(columnIndex)) { 2136// values.put(key, cursor.getBlob(columnIndex)); 2137// } 2138 } 2139 contact.addSubValue(ContactsContract.Data.CONTENT_URI, cv); 2140 } while (cursor.moveToNext()); 2141 2142 return contact; 2143 } 2144 2145 } 2146 } 2147 2148 /** 2149 * Social status update columns. 2150 * 2151 * @see StatusUpdates 2152 * @see ContactsContract.Data 2153 */ 2154 protected interface StatusColumns { 2155 /** 2156 * Contact's latest presence level. 2157 * <P>Type: INTEGER (one of the values below)</P> 2158 */ 2159 public static final String PRESENCE = "mode"; 2160 2161 /** 2162 * @deprecated use {@link #PRESENCE} 2163 */ 2164 @Deprecated 2165 public static final String PRESENCE_STATUS = PRESENCE; 2166 2167 /** 2168 * An allowed value of {@link #PRESENCE}. 2169 */ 2170 int OFFLINE = 0; 2171 2172 /** 2173 * An allowed value of {@link #PRESENCE}. 2174 */ 2175 int INVISIBLE = 1; 2176 2177 /** 2178 * An allowed value of {@link #PRESENCE}. 2179 */ 2180 int AWAY = 2; 2181 2182 /** 2183 * An allowed value of {@link #PRESENCE}. 2184 */ 2185 int IDLE = 3; 2186 2187 /** 2188 * An allowed value of {@link #PRESENCE}. 2189 */ 2190 int DO_NOT_DISTURB = 4; 2191 2192 /** 2193 * An allowed value of {@link #PRESENCE}. 2194 */ 2195 int AVAILABLE = 5; 2196 2197 /** 2198 * Contact latest status update. 2199 * <p>Type: TEXT</p> 2200 */ 2201 public static final String STATUS = "status"; 2202 2203 /** 2204 * @deprecated use {@link #STATUS} 2205 */ 2206 @Deprecated 2207 public static final String PRESENCE_CUSTOM_STATUS = STATUS; 2208 2209 /** 2210 * The absolute time in milliseconds when the latest status was inserted/updated. 2211 * <p>Type: NUMBER</p> 2212 */ 2213 public static final String STATUS_TIMESTAMP = "status_ts"; 2214 2215 /** 2216 * The package containing resources for this status: label and icon. 2217 * <p>Type: NUMBER</p> 2218 */ 2219 public static final String STATUS_RES_PACKAGE = "status_res_package"; 2220 2221 /** 2222 * The resource ID of the label describing the source of the status update, e.g. "Google 2223 * Talk". This resource should be scoped by the {@link #STATUS_RES_PACKAGE}. 2224 * <p>Type: NUMBER</p> 2225 */ 2226 public static final String STATUS_LABEL = "status_label"; 2227 2228 /** 2229 * The resource ID of the icon for the source of the status update. 2230 * This resource should be scoped by the {@link #STATUS_RES_PACKAGE}. 2231 * <p>Type: NUMBER</p> 2232 */ 2233 public static final String STATUS_ICON = "status_icon"; 2234 2235 /** 2236 * Contact's audio/video chat capability level. 2237 * <P>Type: INTEGER (one of the values below)</P> 2238 */ 2239 public static final String CHAT_CAPABILITY = "chat_capability"; 2240 2241 /** 2242 * An allowed value of {@link #CHAT_CAPABILITY}. Indicates that the contact's device can 2243 * display a video feed. 2244 */ 2245 public static final int CAPABILITY_HAS_VIDEO_PLAYBACK_ONLY = 1; 2246 2247 /** 2248 * An allowed value of {@link #CHAT_CAPABILITY}. Indicates audio-chat capability. 2249 */ 2250 public static final int CAPABILITY_HAS_VOICE = 2; 2251 2252 /** 2253 * An allowed value of {@link #CHAT_CAPABILITY}. Indicates that the contact's device has a 2254 * camera that can be used for video chat (e.g. a front-facing camera on a phone). 2255 */ 2256 public static final int CAPABILITY_HAS_CAMERA = 4; 2257 } 2258 2259 /** 2260 * Columns in the Data table. 2261 * 2262 * @see ContactsContract.Data 2263 */ 2264 protected interface DataColumns { 2265 /** 2266 * The package name to use when creating {@link Resources} objects for 2267 * this data row. This value is only designed for use when building user 2268 * interfaces, and should not be used to infer the owner. 2269 * 2270 * @hide 2271 */ 2272 public static final String RES_PACKAGE = "res_package"; 2273 2274 /** 2275 * The MIME type of the item represented by this row. 2276 */ 2277 public static final String MIMETYPE = "mimetype"; 2278 2279 /** 2280 * A reference to the {@link RawContacts#_ID} 2281 * that this data belongs to. 2282 */ 2283 public static final String RAW_CONTACT_ID = "raw_contact_id"; 2284 2285 /** 2286 * Whether this is the primary entry of its kind for the raw contact it belongs to. 2287 * <P>Type: INTEGER (if set, non-0 means true)</P> 2288 */ 2289 public static final String IS_PRIMARY = "is_primary"; 2290 2291 /** 2292 * Whether this is the primary entry of its kind for the aggregate 2293 * contact it belongs to. Any data record that is "super primary" must 2294 * also be "primary". 2295 * <P>Type: INTEGER (if set, non-0 means true)</P> 2296 */ 2297 public static final String IS_SUPER_PRIMARY = "is_super_primary"; 2298 2299 /** 2300 * The "read-only" flag: "0" by default, "1" if the row cannot be modified or 2301 * deleted except by a sync adapter. See {@link ContactsContract#CALLER_IS_SYNCADAPTER}. 2302 * <P>Type: INTEGER</P> 2303 * @hide 2304 */ 2305 public static final String IS_READ_ONLY = "is_read_only"; 2306 2307 /** 2308 * The version of this data record. This is a read-only value. The data column is 2309 * guaranteed to not change without the version going up. This value is monotonically 2310 * increasing. 2311 * <P>Type: INTEGER</P> 2312 */ 2313 public static final String DATA_VERSION = "data_version"; 2314 2315 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 2316 public static final String DATA1 = "data1"; 2317 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 2318 public static final String DATA2 = "data2"; 2319 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 2320 public static final String DATA3 = "data3"; 2321 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 2322 public static final String DATA4 = "data4"; 2323 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 2324 public static final String DATA5 = "data5"; 2325 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 2326 public static final String DATA6 = "data6"; 2327 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 2328 public static final String DATA7 = "data7"; 2329 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 2330 public static final String DATA8 = "data8"; 2331 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 2332 public static final String DATA9 = "data9"; 2333 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 2334 public static final String DATA10 = "data10"; 2335 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 2336 public static final String DATA11 = "data11"; 2337 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 2338 public static final String DATA12 = "data12"; 2339 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 2340 public static final String DATA13 = "data13"; 2341 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 2342 public static final String DATA14 = "data14"; 2343 /** 2344 * Generic data column, the meaning is {@link #MIMETYPE} specific. By convention, 2345 * this field is used to store BLOBs (binary data). 2346 */ 2347 public static final String DATA15 = "data15"; 2348 2349 /** Generic column for use by sync adapters. */ 2350 public static final String SYNC1 = "data_sync1"; 2351 /** Generic column for use by sync adapters. */ 2352 public static final String SYNC2 = "data_sync2"; 2353 /** Generic column for use by sync adapters. */ 2354 public static final String SYNC3 = "data_sync3"; 2355 /** Generic column for use by sync adapters. */ 2356 public static final String SYNC4 = "data_sync4"; 2357 } 2358 2359 /** 2360 * Combines all columns returned by {@link ContactsContract.Data} table queries. 2361 * 2362 * @see ContactsContract.Data 2363 */ 2364 protected interface DataColumnsWithJoins extends BaseColumns, DataColumns, StatusColumns, 2365 RawContactsColumns, ContactsColumns, ContactNameColumns, ContactOptionsColumns, 2366 ContactStatusColumns { 2367 } 2368 2369 /** 2370 * <p> 2371 * Constants for the data table, which contains data points tied to a raw 2372 * contact. Each row of the data table is typically used to store a single 2373 * piece of contact 2374 * information (such as a phone number) and its 2375 * associated metadata (such as whether it is a work or home number). 2376 * </p> 2377 * <h3>Data kinds</h3> 2378 * <p> 2379 * Data is a generic table that can hold any kind of contact data. 2380 * The kind of data stored in a given row is specified by the row's 2381 * {@link #MIMETYPE} value, which determines the meaning of the 2382 * generic columns {@link #DATA1} through 2383 * {@link #DATA15}. 2384 * For example, if the data kind is 2385 * {@link CommonDataKinds.Phone Phone.CONTENT_ITEM_TYPE}, then the column 2386 * {@link #DATA1} stores the 2387 * phone number, but if the data kind is 2388 * {@link CommonDataKinds.Email Email.CONTENT_ITEM_TYPE}, then {@link #DATA1} 2389 * stores the email address. 2390 * Sync adapters and applications can introduce their own data kinds. 2391 * </p> 2392 * <p> 2393 * ContactsContract defines a small number of pre-defined data kinds, e.g. 2394 * {@link CommonDataKinds.Phone}, {@link CommonDataKinds.Email} etc. As a 2395 * convenience, these classes define data kind specific aliases for DATA1 etc. 2396 * For example, {@link CommonDataKinds.Phone Phone.NUMBER} is the same as 2397 * {@link ContactsContract.Data Data.DATA1}. 2398 * </p> 2399 * <p> 2400 * {@link #DATA1} is an indexed column and should be used for the data element that is 2401 * expected to be most frequently used in query selections. For example, in the 2402 * case of a row representing email addresses {@link #DATA1} should probably 2403 * be used for the email address itself, while {@link #DATA2} etc can be 2404 * used for auxiliary information like type of email address. 2405 * <p> 2406 * <p> 2407 * By convention, {@link #DATA15} is used for storing BLOBs (binary data). 2408 * </p> 2409 * <p> 2410 * The sync adapter for a given account type must correctly handle every data type 2411 * used in the corresponding raw contacts. Otherwise it could result in lost or 2412 * corrupted data. 2413 * </p> 2414 * <p> 2415 * Similarly, you should refrain from introducing new kinds of data for an other 2416 * party's account types. For example, if you add a data row for 2417 * "favorite song" to a raw contact owned by a Google account, it will not 2418 * get synced to the server, because the Google sync adapter does not know 2419 * how to handle this data kind. Thus new data kinds are typically 2420 * introduced along with new account types, i.e. new sync adapters. 2421 * </p> 2422 * <h3>Batch operations</h3> 2423 * <p> 2424 * Data rows can be inserted/updated/deleted using the traditional 2425 * {@link ContentResolver#insert}, {@link ContentResolver#update} and 2426 * {@link ContentResolver#delete} methods, however the newer mechanism based 2427 * on a batch of {@link ContentProviderOperation} will prove to be a better 2428 * choice in almost all cases. All operations in a batch are executed in a 2429 * single transaction, which ensures that the phone-side and server-side 2430 * state of a raw contact are always consistent. Also, the batch-based 2431 * approach is far more efficient: not only are the database operations 2432 * faster when executed in a single transaction, but also sending a batch of 2433 * commands to the content provider saves a lot of time on context switching 2434 * between your process and the process in which the content provider runs. 2435 * </p> 2436 * <p> 2437 * The flip side of using batched operations is that a large batch may lock 2438 * up the database for a long time preventing other applications from 2439 * accessing data and potentially causing ANRs ("Application Not Responding" 2440 * dialogs.) 2441 * </p> 2442 * <p> 2443 * To avoid such lockups of the database, make sure to insert "yield points" 2444 * in the batch. A yield point indicates to the content provider that before 2445 * executing the next operation it can commit the changes that have already 2446 * been made, yield to other requests, open another transaction and continue 2447 * processing operations. A yield point will not automatically commit the 2448 * transaction, but only if there is another request waiting on the 2449 * database. Normally a sync adapter should insert a yield point at the 2450 * beginning of each raw contact operation sequence in the batch. See 2451 * {@link ContentProviderOperation.Builder#withYieldAllowed(boolean)}. 2452 * </p> 2453 * <h3>Operations</h3> 2454 * <dl> 2455 * <dt><b>Insert</b></dt> 2456 * <dd> 2457 * <p> 2458 * An individual data row can be inserted using the traditional 2459 * {@link ContentResolver#insert(Uri, ContentValues)} method. Multiple rows 2460 * should always be inserted as a batch. 2461 * </p> 2462 * <p> 2463 * An example of a traditional insert: 2464 * <pre> 2465 * ContentValues values = new ContentValues(); 2466 * values.put(Data.RAW_CONTACT_ID, rawContactId); 2467 * values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE); 2468 * values.put(Phone.NUMBER, "1-800-GOOG-411"); 2469 * values.put(Phone.TYPE, Phone.TYPE_CUSTOM); 2470 * values.put(Phone.LABEL, "free directory assistance"); 2471 * Uri dataUri = getContentResolver().insert(Data.CONTENT_URI, values); 2472 * </pre> 2473 * <p> 2474 * The same done using ContentProviderOperations: 2475 * <pre> 2476 * ArrayList<ContentProviderOperation> ops = Lists.newArrayList(); 2477 * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI) 2478 * .withValue(Data.RAW_CONTACT_ID, rawContactId) 2479 * .withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE) 2480 * .withValue(Phone.NUMBER, "1-800-GOOG-411") 2481 * .withValue(Phone.TYPE, Phone.TYPE_CUSTOM) 2482 * .withValue(Phone.LABEL, "free directory assistance") 2483 * .build()); 2484 * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); 2485 * </pre> 2486 * </p> 2487 * <dt><b>Update</b></dt> 2488 * <dd> 2489 * <p> 2490 * Just as with insert, update can be done incrementally or as a batch, 2491 * the batch mode being the preferred method: 2492 * <pre> 2493 * ArrayList<ContentProviderOperation> ops = Lists.newArrayList(); 2494 * ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI) 2495 * .withSelection(Data._ID + "=?", new String[]{String.valueOf(dataId)}) 2496 * .withValue(Email.DATA, "somebody@android.com") 2497 * .build()); 2498 * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); 2499 * </pre> 2500 * </p> 2501 * </dd> 2502 * <dt><b>Delete</b></dt> 2503 * <dd> 2504 * <p> 2505 * Just as with insert and update, deletion can be done either using the 2506 * {@link ContentResolver#delete} method or using a ContentProviderOperation: 2507 * <pre> 2508 * ArrayList<ContentProviderOperation> ops = Lists.newArrayList(); 2509 * ops.add(ContentProviderOperation.newDelete(Data.CONTENT_URI) 2510 * .withSelection(Data._ID + "=?", new String[]{String.valueOf(dataId)}) 2511 * .build()); 2512 * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); 2513 * </pre> 2514 * </p> 2515 * </dd> 2516 * <dt><b>Query</b></dt> 2517 * <dd> 2518 * <p> 2519 * <dl> 2520 * <dt>Finding all Data of a given type for a given contact</dt> 2521 * <dd> 2522 * <pre> 2523 * Cursor c = getContentResolver().query(Data.CONTENT_URI, 2524 * new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL}, 2525 * Data.CONTACT_ID + "=?" + " AND " 2526 * + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'", 2527 * new String[] {String.valueOf(contactId)}, null); 2528 * </pre> 2529 * </p> 2530 * <p> 2531 * </dd> 2532 * <dt>Finding all Data of a given type for a given raw contact</dt> 2533 * <dd> 2534 * <pre> 2535 * Cursor c = getContentResolver().query(Data.CONTENT_URI, 2536 * new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL}, 2537 * Data.RAW_CONTACT_ID + "=?" + " AND " 2538 * + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'", 2539 * new String[] {String.valueOf(rawContactId)}, null); 2540 * </pre> 2541 * </dd> 2542 * <dt>Finding all Data for a given raw contact</dt> 2543 * <dd> 2544 * Most sync adapters will want to read all data rows for a raw contact 2545 * along with the raw contact itself. For that you should use the 2546 * {@link RawContactsEntity}. See also {@link RawContacts}. 2547 * </dd> 2548 * </dl> 2549 * </p> 2550 * </dd> 2551 * </dl> 2552 * <h2>Columns</h2> 2553 * <p> 2554 * Many columns are available via a {@link Data#CONTENT_URI} query. For best performance you 2555 * should explicitly specify a projection to only those columns that you need. 2556 * </p> 2557 * <table class="jd-sumtable"> 2558 * <tr> 2559 * <th colspan='4'>Data</th> 2560 * </tr> 2561 * <tr> 2562 * <td style="width: 7em;">long</td> 2563 * <td style="width: 20em;">{@link #_ID}</td> 2564 * <td style="width: 5em;">read-only</td> 2565 * <td>Row ID. Sync adapter should try to preserve row IDs during updates. In other words, 2566 * it would be a bad idea to delete and reinsert a data row. A sync adapter should 2567 * always do an update instead.</td> 2568 * </tr> 2569 * <tr> 2570 * <td>String</td> 2571 * <td>{@link #MIMETYPE}</td> 2572 * <td>read/write-once</td> 2573 * <td> 2574 * <p>The MIME type of the item represented by this row. Examples of common 2575 * MIME types are: 2576 * <ul> 2577 * <li>{@link CommonDataKinds.StructuredName StructuredName.CONTENT_ITEM_TYPE}</li> 2578 * <li>{@link CommonDataKinds.Phone Phone.CONTENT_ITEM_TYPE}</li> 2579 * <li>{@link CommonDataKinds.Email Email.CONTENT_ITEM_TYPE}</li> 2580 * <li>{@link CommonDataKinds.Photo Photo.CONTENT_ITEM_TYPE}</li> 2581 * <li>{@link CommonDataKinds.Organization Organization.CONTENT_ITEM_TYPE}</li> 2582 * <li>{@link CommonDataKinds.Im Im.CONTENT_ITEM_TYPE}</li> 2583 * <li>{@link CommonDataKinds.Nickname Nickname.CONTENT_ITEM_TYPE}</li> 2584 * <li>{@link CommonDataKinds.Note Note.CONTENT_ITEM_TYPE}</li> 2585 * <li>{@link CommonDataKinds.StructuredPostal StructuredPostal.CONTENT_ITEM_TYPE}</li> 2586 * <li>{@link CommonDataKinds.GroupMembership GroupMembership.CONTENT_ITEM_TYPE}</li> 2587 * <li>{@link CommonDataKinds.Website Website.CONTENT_ITEM_TYPE}</li> 2588 * <li>{@link CommonDataKinds.Event Event.CONTENT_ITEM_TYPE}</li> 2589 * <li>{@link CommonDataKinds.Relation Relation.CONTENT_ITEM_TYPE}</li> 2590 * </ul> 2591 * </p> 2592 * </td> 2593 * </tr> 2594 * <tr> 2595 * <td>long</td> 2596 * <td>{@link #RAW_CONTACT_ID}</td> 2597 * <td>read/write-once</td> 2598 * <td>The id of the row in the {@link RawContacts} table that this data belongs to.</td> 2599 * </tr> 2600 * <tr> 2601 * <td>int</td> 2602 * <td>{@link #IS_PRIMARY}</td> 2603 * <td>read/write</td> 2604 * <td>Whether this is the primary entry of its kind for the raw contact it belongs to. 2605 * "1" if true, "0" if false. 2606 * </td> 2607 * </tr> 2608 * <tr> 2609 * <td>int</td> 2610 * <td>{@link #IS_SUPER_PRIMARY}</td> 2611 * <td>read/write</td> 2612 * <td>Whether this is the primary entry of its kind for the aggregate 2613 * contact it belongs to. Any data record that is "super primary" must 2614 * also be "primary". For example, the super-primary entry may be 2615 * interpreted as the default contact value of its kind (for example, 2616 * the default phone number to use for the contact).</td> 2617 * </tr> 2618 * <tr> 2619 * <td>int</td> 2620 * <td>{@link #DATA_VERSION}</td> 2621 * <td>read-only</td> 2622 * <td>The version of this data record. Whenever the data row changes 2623 * the version goes up. This value is monotonically increasing.</td> 2624 * </tr> 2625 * <tr> 2626 * <td>Any type</td> 2627 * <td> 2628 * {@link #DATA1}<br> 2629 * {@link #DATA2}<br> 2630 * {@link #DATA3}<br> 2631 * {@link #DATA4}<br> 2632 * {@link #DATA5}<br> 2633 * {@link #DATA6}<br> 2634 * {@link #DATA7}<br> 2635 * {@link #DATA8}<br> 2636 * {@link #DATA9}<br> 2637 * {@link #DATA10}<br> 2638 * {@link #DATA11}<br> 2639 * {@link #DATA12}<br> 2640 * {@link #DATA13}<br> 2641 * {@link #DATA14}<br> 2642 * {@link #DATA15} 2643 * </td> 2644 * <td>read/write</td> 2645 * <td> 2646 * <p> 2647 * Generic data columns. The meaning of each column is determined by the 2648 * {@link #MIMETYPE}. By convention, {@link #DATA15} is used for storing 2649 * BLOBs (binary data). 2650 * </p> 2651 * <p> 2652 * Data columns whose meaning is not explicitly defined for a given MIMETYPE 2653 * should not be used. There is no guarantee that any sync adapter will 2654 * preserve them. Sync adapters themselves should not use such columns either, 2655 * but should instead use {@link #SYNC1}-{@link #SYNC4}. 2656 * </p> 2657 * </td> 2658 * </tr> 2659 * <tr> 2660 * <td>Any type</td> 2661 * <td> 2662 * {@link #SYNC1}<br> 2663 * {@link #SYNC2}<br> 2664 * {@link #SYNC3}<br> 2665 * {@link #SYNC4} 2666 * </td> 2667 * <td>read/write</td> 2668 * <td>Generic columns for use by sync adapters. For example, a Photo row 2669 * may store the image URL in SYNC1, a status (not loaded, loading, loaded, error) 2670 * in SYNC2, server-side version number in SYNC3 and error code in SYNC4.</td> 2671 * </tr> 2672 * </table> 2673 * 2674 * <p> 2675 * Some columns from the most recent associated status update are also available 2676 * through an implicit join. 2677 * </p> 2678 * <table class="jd-sumtable"> 2679 * <tr> 2680 * <th colspan='4'>Join with {@link StatusUpdates}</th> 2681 * </tr> 2682 * <tr> 2683 * <td style="width: 7em;">int</td> 2684 * <td style="width: 20em;">{@link #PRESENCE}</td> 2685 * <td style="width: 5em;">read-only</td> 2686 * <td>IM presence status linked to this data row. Compare with 2687 * {@link #CONTACT_PRESENCE}, which contains the contact's presence across 2688 * all IM rows. See {@link StatusUpdates} for individual status definitions. 2689 * The provider may choose not to store this value 2690 * in persistent storage. The expectation is that presence status will be 2691 * updated on a regular basic. 2692 * </td> 2693 * </tr> 2694 * <tr> 2695 * <td>String</td> 2696 * <td>{@link #STATUS}</td> 2697 * <td>read-only</td> 2698 * <td>Latest status update linked with this data row.</td> 2699 * </tr> 2700 * <tr> 2701 * <td>long</td> 2702 * <td>{@link #STATUS_TIMESTAMP}</td> 2703 * <td>read-only</td> 2704 * <td>The absolute time in milliseconds when the latest status was 2705 * inserted/updated for this data row.</td> 2706 * </tr> 2707 * <tr> 2708 * <td>String</td> 2709 * <td>{@link #STATUS_RES_PACKAGE}</td> 2710 * <td>read-only</td> 2711 * <td>The package containing resources for this status: label and icon.</td> 2712 * </tr> 2713 * <tr> 2714 * <td>long</td> 2715 * <td>{@link #STATUS_LABEL}</td> 2716 * <td>read-only</td> 2717 * <td>The resource ID of the label describing the source of status update linked 2718 * to this data row. This resource is scoped by the {@link #STATUS_RES_PACKAGE}.</td> 2719 * </tr> 2720 * <tr> 2721 * <td>long</td> 2722 * <td>{@link #STATUS_ICON}</td> 2723 * <td>read-only</td> 2724 * <td>The resource ID of the icon for the source of the status update linked 2725 * to this data row. This resource is scoped by the {@link #STATUS_RES_PACKAGE}.</td> 2726 * </tr> 2727 * </table> 2728 * 2729 * <p> 2730 * Some columns from the associated raw contact are also available through an 2731 * implicit join. The other columns are excluded as uninteresting in this 2732 * context. 2733 * </p> 2734 * 2735 * <table class="jd-sumtable"> 2736 * <tr> 2737 * <th colspan='4'>Join with {@link ContactsContract.RawContacts}</th> 2738 * </tr> 2739 * <tr> 2740 * <td style="width: 7em;">long</td> 2741 * <td style="width: 20em;">{@link #CONTACT_ID}</td> 2742 * <td style="width: 5em;">read-only</td> 2743 * <td>The id of the row in the {@link Contacts} table that this data belongs 2744 * to.</td> 2745 * </tr> 2746 * <tr> 2747 * <td>int</td> 2748 * <td>{@link #AGGREGATION_MODE}</td> 2749 * <td>read-only</td> 2750 * <td>See {@link RawContacts}.</td> 2751 * </tr> 2752 * <tr> 2753 * <td>int</td> 2754 * <td>{@link #DELETED}</td> 2755 * <td>read-only</td> 2756 * <td>See {@link RawContacts}.</td> 2757 * </tr> 2758 * </table> 2759 * 2760 * <p> 2761 * The ID column for the associated aggregated contact table 2762 * {@link ContactsContract.Contacts} is available 2763 * via the implicit join to the {@link RawContacts} table, see above. 2764 * The remaining columns from this table are also 2765 * available, through an implicit join. This 2766 * facilitates lookup by 2767 * the value of a single data element, such as the email address. 2768 * </p> 2769 * 2770 * <table class="jd-sumtable"> 2771 * <tr> 2772 * <th colspan='4'>Join with {@link ContactsContract.Contacts}</th> 2773 * </tr> 2774 * <tr> 2775 * <td style="width: 7em;">String</td> 2776 * <td style="width: 20em;">{@link #LOOKUP_KEY}</td> 2777 * <td style="width: 5em;">read-only</td> 2778 * <td>See {@link ContactsContract.Contacts}</td> 2779 * </tr> 2780 * <tr> 2781 * <td>String</td> 2782 * <td>{@link #DISPLAY_NAME}</td> 2783 * <td>read-only</td> 2784 * <td>See {@link ContactsContract.Contacts}</td> 2785 * </tr> 2786 * <tr> 2787 * <td>long</td> 2788 * <td>{@link #PHOTO_ID}</td> 2789 * <td>read-only</td> 2790 * <td>See {@link ContactsContract.Contacts}.</td> 2791 * </tr> 2792 * <tr> 2793 * <td>int</td> 2794 * <td>{@link #IN_VISIBLE_GROUP}</td> 2795 * <td>read-only</td> 2796 * <td>See {@link ContactsContract.Contacts}.</td> 2797 * </tr> 2798 * <tr> 2799 * <td>int</td> 2800 * <td>{@link #HAS_PHONE_NUMBER}</td> 2801 * <td>read-only</td> 2802 * <td>See {@link ContactsContract.Contacts}.</td> 2803 * </tr> 2804 * <tr> 2805 * <td>int</td> 2806 * <td>{@link #TIMES_CONTACTED}</td> 2807 * <td>read-only</td> 2808 * <td>See {@link ContactsContract.Contacts}.</td> 2809 * </tr> 2810 * <tr> 2811 * <td>long</td> 2812 * <td>{@link #LAST_TIME_CONTACTED}</td> 2813 * <td>read-only</td> 2814 * <td>See {@link ContactsContract.Contacts}.</td> 2815 * </tr> 2816 * <tr> 2817 * <td>int</td> 2818 * <td>{@link #STARRED}</td> 2819 * <td>read-only</td> 2820 * <td>See {@link ContactsContract.Contacts}.</td> 2821 * </tr> 2822 * <tr> 2823 * <td>String</td> 2824 * <td>{@link #CUSTOM_RINGTONE}</td> 2825 * <td>read-only</td> 2826 * <td>See {@link ContactsContract.Contacts}.</td> 2827 * </tr> 2828 * <tr> 2829 * <td>int</td> 2830 * <td>{@link #SEND_TO_VOICEMAIL}</td> 2831 * <td>read-only</td> 2832 * <td>See {@link ContactsContract.Contacts}.</td> 2833 * </tr> 2834 * <tr> 2835 * <td>int</td> 2836 * <td>{@link #CONTACT_PRESENCE}</td> 2837 * <td>read-only</td> 2838 * <td>See {@link ContactsContract.Contacts}.</td> 2839 * </tr> 2840 * <tr> 2841 * <td>String</td> 2842 * <td>{@link #CONTACT_STATUS}</td> 2843 * <td>read-only</td> 2844 * <td>See {@link ContactsContract.Contacts}.</td> 2845 * </tr> 2846 * <tr> 2847 * <td>long</td> 2848 * <td>{@link #CONTACT_STATUS_TIMESTAMP}</td> 2849 * <td>read-only</td> 2850 * <td>See {@link ContactsContract.Contacts}.</td> 2851 * </tr> 2852 * <tr> 2853 * <td>String</td> 2854 * <td>{@link #CONTACT_STATUS_RES_PACKAGE}</td> 2855 * <td>read-only</td> 2856 * <td>See {@link ContactsContract.Contacts}.</td> 2857 * </tr> 2858 * <tr> 2859 * <td>long</td> 2860 * <td>{@link #CONTACT_STATUS_LABEL}</td> 2861 * <td>read-only</td> 2862 * <td>See {@link ContactsContract.Contacts}.</td> 2863 * </tr> 2864 * <tr> 2865 * <td>long</td> 2866 * <td>{@link #CONTACT_STATUS_ICON}</td> 2867 * <td>read-only</td> 2868 * <td>See {@link ContactsContract.Contacts}.</td> 2869 * </tr> 2870 * </table> 2871 */ 2872 public final static class Data implements DataColumnsWithJoins { 2873 /** 2874 * This utility class cannot be instantiated 2875 */ 2876 private Data() {} 2877 2878 /** 2879 * The content:// style URI for this table, which requests a directory 2880 * of data rows matching the selection criteria. 2881 */ 2882 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "data"); 2883 2884 /** 2885 * The MIME type of the results from {@link #CONTENT_URI}. 2886 */ 2887 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/data"; 2888 2889 /** 2890 * <p> 2891 * If {@link #FOR_EXPORT_ONLY} is explicitly set to "1", returned Cursor toward 2892 * Data.CONTENT_URI contains only exportable data. 2893 * </p> 2894 * <p> 2895 * This flag is useful (currently) only for vCard exporter in Contacts app, which 2896 * needs to exclude "un-exportable" data from available data to export, while 2897 * Contacts app itself has priviledge to access all data including "un-exportable" 2898 * ones and providers return all of them regardless of the callers' intention. 2899 * </p> 2900 * <p> 2901 * Type: INTEGER 2902 * </p> 2903 * 2904 * @hide Maybe available only in Eclair and not really ready for public use. 2905 * TODO: remove, or implement this feature completely. As of now (Eclair), 2906 * we only use this flag in queryEntities(), not query(). 2907 */ 2908 public static final String FOR_EXPORT_ONLY = "for_export_only"; 2909 2910 /** 2911 * <p> 2912 * Build a {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI} 2913 * style {@link Uri} for the parent {@link android.provider.ContactsContract.Contacts} 2914 * entry of the given {@link ContactsContract.Data} entry. 2915 * </p> 2916 * <p> 2917 * Returns the Uri for the contact in the first entry returned by 2918 * {@link ContentResolver#query(Uri, String[], String, String[], String)} 2919 * for the provided {@code dataUri}. If the query returns null or empty 2920 * results, silently returns null. 2921 * </p> 2922 */ 2923 public static Uri getContactLookupUri(ContentResolver resolver, Uri dataUri) { 2924 final Cursor cursor = resolver.query(dataUri, new String[] { 2925 RawContacts.CONTACT_ID, Contacts.LOOKUP_KEY 2926 }, null, null, null); 2927 2928 Uri lookupUri = null; 2929 try { 2930 if (cursor != null && cursor.moveToFirst()) { 2931 final long contactId = cursor.getLong(0); 2932 final String lookupKey = cursor.getString(1); 2933 return Contacts.getLookupUri(contactId, lookupKey); 2934 } 2935 } finally { 2936 if (cursor != null) cursor.close(); 2937 } 2938 return lookupUri; 2939 } 2940 } 2941 2942 /** 2943 * <p> 2944 * Constants for the raw contacts entities table, which can be thought of as 2945 * an outer join of the raw_contacts table with the data table. It is a strictly 2946 * read-only table. 2947 * </p> 2948 * <p> 2949 * If a raw contact has data rows, the RawContactsEntity cursor will contain 2950 * a one row for each data row. If the raw contact has no data rows, the 2951 * cursor will still contain one row with the raw contact-level information 2952 * and nulls for data columns. 2953 * 2954 * <pre> 2955 * Uri entityUri = ContentUris.withAppendedId(RawContactsEntity.CONTENT_URI, rawContactId); 2956 * Cursor c = getContentResolver().query(entityUri, 2957 * new String[]{ 2958 * RawContactsEntity.SOURCE_ID, 2959 * RawContactsEntity.DATA_ID, 2960 * RawContactsEntity.MIMETYPE, 2961 * RawContactsEntity.DATA1 2962 * }, null, null, null); 2963 * try { 2964 * while (c.moveToNext()) { 2965 * String sourceId = c.getString(0); 2966 * if (!c.isNull(1)) { 2967 * String mimeType = c.getString(2); 2968 * String data = c.getString(3); 2969 * ... 2970 * } 2971 * } 2972 * } finally { 2973 * c.close(); 2974 * } 2975 * </pre> 2976 * 2977 * <h3>Columns</h3> 2978 * RawContactsEntity has a combination of RawContact and Data columns. 2979 * 2980 * <table class="jd-sumtable"> 2981 * <tr> 2982 * <th colspan='4'>RawContacts</th> 2983 * </tr> 2984 * <tr> 2985 * <td style="width: 7em;">long</td> 2986 * <td style="width: 20em;">{@link #_ID}</td> 2987 * <td style="width: 5em;">read-only</td> 2988 * <td>Raw contact row ID. See {@link RawContacts}.</td> 2989 * </tr> 2990 * <tr> 2991 * <td>long</td> 2992 * <td>{@link #CONTACT_ID}</td> 2993 * <td>read-only</td> 2994 * <td>See {@link RawContacts}.</td> 2995 * </tr> 2996 * <tr> 2997 * <td>int</td> 2998 * <td>{@link #AGGREGATION_MODE}</td> 2999 * <td>read-only</td> 3000 * <td>See {@link RawContacts}.</td> 3001 * </tr> 3002 * <tr> 3003 * <td>int</td> 3004 * <td>{@link #DELETED}</td> 3005 * <td>read-only</td> 3006 * <td>See {@link RawContacts}.</td> 3007 * </tr> 3008 * </table> 3009 * 3010 * <table class="jd-sumtable"> 3011 * <tr> 3012 * <th colspan='4'>Data</th> 3013 * </tr> 3014 * <tr> 3015 * <td style="width: 7em;">long</td> 3016 * <td style="width: 20em;">{@link #DATA_ID}</td> 3017 * <td style="width: 5em;">read-only</td> 3018 * <td>Data row ID. It will be null if the raw contact has no data rows.</td> 3019 * </tr> 3020 * <tr> 3021 * <td>String</td> 3022 * <td>{@link #MIMETYPE}</td> 3023 * <td>read-only</td> 3024 * <td>See {@link ContactsContract.Data}.</td> 3025 * </tr> 3026 * <tr> 3027 * <td>int</td> 3028 * <td>{@link #IS_PRIMARY}</td> 3029 * <td>read-only</td> 3030 * <td>See {@link ContactsContract.Data}.</td> 3031 * </tr> 3032 * <tr> 3033 * <td>int</td> 3034 * <td>{@link #IS_SUPER_PRIMARY}</td> 3035 * <td>read-only</td> 3036 * <td>See {@link ContactsContract.Data}.</td> 3037 * </tr> 3038 * <tr> 3039 * <td>int</td> 3040 * <td>{@link #DATA_VERSION}</td> 3041 * <td>read-only</td> 3042 * <td>See {@link ContactsContract.Data}.</td> 3043 * </tr> 3044 * <tr> 3045 * <td>Any type</td> 3046 * <td> 3047 * {@link #DATA1}<br> 3048 * {@link #DATA2}<br> 3049 * {@link #DATA3}<br> 3050 * {@link #DATA4}<br> 3051 * {@link #DATA5}<br> 3052 * {@link #DATA6}<br> 3053 * {@link #DATA7}<br> 3054 * {@link #DATA8}<br> 3055 * {@link #DATA9}<br> 3056 * {@link #DATA10}<br> 3057 * {@link #DATA11}<br> 3058 * {@link #DATA12}<br> 3059 * {@link #DATA13}<br> 3060 * {@link #DATA14}<br> 3061 * {@link #DATA15} 3062 * </td> 3063 * <td>read-only</td> 3064 * <td>See {@link ContactsContract.Data}.</td> 3065 * </tr> 3066 * <tr> 3067 * <td>Any type</td> 3068 * <td> 3069 * {@link #SYNC1}<br> 3070 * {@link #SYNC2}<br> 3071 * {@link #SYNC3}<br> 3072 * {@link #SYNC4} 3073 * </td> 3074 * <td>read-only</td> 3075 * <td>See {@link ContactsContract.Data}.</td> 3076 * </tr> 3077 * </table> 3078 */ 3079 public final static class RawContactsEntity 3080 implements BaseColumns, DataColumns, RawContactsColumns { 3081 /** 3082 * This utility class cannot be instantiated 3083 */ 3084 private RawContactsEntity() {} 3085 3086 /** 3087 * The content:// style URI for this table 3088 */ 3089 public static final Uri CONTENT_URI = 3090 Uri.withAppendedPath(AUTHORITY_URI, "raw_contact_entities"); 3091 3092 /** 3093 * The MIME type of {@link #CONTENT_URI} providing a directory of raw contact entities. 3094 */ 3095 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/raw_contact_entity"; 3096 3097 /** 3098 * If {@link #FOR_EXPORT_ONLY} is explicitly set to "1", returned Cursor toward 3099 * Data.CONTENT_URI contains only exportable data. 3100 * 3101 * This flag is useful (currently) only for vCard exporter in Contacts app, which 3102 * needs to exclude "un-exportable" data from available data to export, while 3103 * Contacts app itself has priviledge to access all data including "un-expotable" 3104 * ones and providers return all of them regardless of the callers' intention. 3105 * <P>Type: INTEGER</p> 3106 * 3107 * @hide Maybe available only in Eclair and not really ready for public use. 3108 * TODO: remove, or implement this feature completely. As of now (Eclair), 3109 * we only use this flag in queryEntities(), not query(). 3110 */ 3111 public static final String FOR_EXPORT_ONLY = "for_export_only"; 3112 3113 /** 3114 * The ID of the data column. The value will be null if this raw contact has no data rows. 3115 * <P>Type: INTEGER</P> 3116 */ 3117 public static final String DATA_ID = "data_id"; 3118 } 3119 3120 /** 3121 * @see PhoneLookup 3122 */ 3123 protected interface PhoneLookupColumns { 3124 /** 3125 * The phone number as the user entered it. 3126 * <P>Type: TEXT</P> 3127 */ 3128 public static final String NUMBER = "number"; 3129 3130 /** 3131 * The type of phone number, for example Home or Work. 3132 * <P>Type: INTEGER</P> 3133 */ 3134 public static final String TYPE = "type"; 3135 3136 /** 3137 * The user defined label for the phone number. 3138 * <P>Type: TEXT</P> 3139 */ 3140 public static final String LABEL = "label"; 3141 } 3142 3143 /** 3144 * A table that represents the result of looking up a phone number, for 3145 * example for caller ID. To perform a lookup you must append the number you 3146 * want to find to {@link #CONTENT_FILTER_URI}. This query is highly 3147 * optimized. 3148 * <pre> 3149 * Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)); 3150 * resolver.query(uri, new String[]{PhoneLookup.DISPLAY_NAME,... 3151 * </pre> 3152 * 3153 * <h3>Columns</h3> 3154 * 3155 * <table class="jd-sumtable"> 3156 * <tr> 3157 * <th colspan='4'>PhoneLookup</th> 3158 * </tr> 3159 * <tr> 3160 * <td>long</td> 3161 * <td>{@link #_ID}</td> 3162 * <td>read-only</td> 3163 * <td>Data row ID.</td> 3164 * </tr> 3165 * <tr> 3166 * <td>String</td> 3167 * <td>{@link #NUMBER}</td> 3168 * <td>read-only</td> 3169 * <td>Phone number.</td> 3170 * </tr> 3171 * <tr> 3172 * <td>String</td> 3173 * <td>{@link #TYPE}</td> 3174 * <td>read-only</td> 3175 * <td>Phone number type. See {@link CommonDataKinds.Phone}.</td> 3176 * </tr> 3177 * <tr> 3178 * <td>String</td> 3179 * <td>{@link #LABEL}</td> 3180 * <td>read-only</td> 3181 * <td>Custom label for the phone number. See {@link CommonDataKinds.Phone}.</td> 3182 * </tr> 3183 * </table> 3184 * <p> 3185 * Columns from the Contacts table are also available through a join. 3186 * </p> 3187 * <table class="jd-sumtable"> 3188 * <tr> 3189 * <th colspan='4'>Join with {@link Contacts}</th> 3190 * </tr> 3191 * <tr> 3192 * <td>String</td> 3193 * <td>{@link #LOOKUP_KEY}</td> 3194 * <td>read-only</td> 3195 * <td>See {@link ContactsContract.Contacts}</td> 3196 * </tr> 3197 * <tr> 3198 * <td>String</td> 3199 * <td>{@link #DISPLAY_NAME}</td> 3200 * <td>read-only</td> 3201 * <td>See {@link ContactsContract.Contacts}</td> 3202 * </tr> 3203 * <tr> 3204 * <td>long</td> 3205 * <td>{@link #PHOTO_ID}</td> 3206 * <td>read-only</td> 3207 * <td>See {@link ContactsContract.Contacts}.</td> 3208 * </tr> 3209 * <tr> 3210 * <td>int</td> 3211 * <td>{@link #IN_VISIBLE_GROUP}</td> 3212 * <td>read-only</td> 3213 * <td>See {@link ContactsContract.Contacts}.</td> 3214 * </tr> 3215 * <tr> 3216 * <td>int</td> 3217 * <td>{@link #HAS_PHONE_NUMBER}</td> 3218 * <td>read-only</td> 3219 * <td>See {@link ContactsContract.Contacts}.</td> 3220 * </tr> 3221 * <tr> 3222 * <td>int</td> 3223 * <td>{@link #TIMES_CONTACTED}</td> 3224 * <td>read-only</td> 3225 * <td>See {@link ContactsContract.Contacts}.</td> 3226 * </tr> 3227 * <tr> 3228 * <td>long</td> 3229 * <td>{@link #LAST_TIME_CONTACTED}</td> 3230 * <td>read-only</td> 3231 * <td>See {@link ContactsContract.Contacts}.</td> 3232 * </tr> 3233 * <tr> 3234 * <td>int</td> 3235 * <td>{@link #STARRED}</td> 3236 * <td>read-only</td> 3237 * <td>See {@link ContactsContract.Contacts}.</td> 3238 * </tr> 3239 * <tr> 3240 * <td>String</td> 3241 * <td>{@link #CUSTOM_RINGTONE}</td> 3242 * <td>read-only</td> 3243 * <td>See {@link ContactsContract.Contacts}.</td> 3244 * </tr> 3245 * <tr> 3246 * <td>int</td> 3247 * <td>{@link #SEND_TO_VOICEMAIL}</td> 3248 * <td>read-only</td> 3249 * <td>See {@link ContactsContract.Contacts}.</td> 3250 * </tr> 3251 * </table> 3252 */ 3253 public static final class PhoneLookup implements BaseColumns, PhoneLookupColumns, 3254 ContactsColumns, ContactOptionsColumns { 3255 /** 3256 * This utility class cannot be instantiated 3257 */ 3258 private PhoneLookup() {} 3259 3260 /** 3261 * The content:// style URI for this table. Append the phone number you want to lookup 3262 * to this URI and query it to perform a lookup. For example: 3263 * <pre> 3264 * Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_URI, Uri.encode(phoneNumber)); 3265 * </pre> 3266 */ 3267 public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(AUTHORITY_URI, 3268 "phone_lookup"); 3269 3270 /** 3271 * The MIME type of {@link #CONTENT_FILTER_URI} providing a directory of phone lookup rows. 3272 * 3273 * @hide 3274 */ 3275 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/phone_lookup"; 3276 } 3277 3278 /** 3279 * Additional data mixed in with {@link StatusColumns} to link 3280 * back to specific {@link ContactsContract.Data#_ID} entries. 3281 * 3282 * @see StatusUpdates 3283 */ 3284 protected interface PresenceColumns { 3285 3286 /** 3287 * Reference to the {@link Data#_ID} entry that owns this presence. 3288 * <P>Type: INTEGER</P> 3289 */ 3290 public static final String DATA_ID = "presence_data_id"; 3291 3292 /** 3293 * See {@link CommonDataKinds.Im} for a list of defined protocol constants. 3294 * <p>Type: NUMBER</p> 3295 */ 3296 public static final String PROTOCOL = "protocol"; 3297 3298 /** 3299 * Name of the custom protocol. Should be supplied along with the {@link #PROTOCOL} value 3300 * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}. Should be null or 3301 * omitted if {@link #PROTOCOL} value is not 3302 * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}. 3303 * 3304 * <p>Type: NUMBER</p> 3305 */ 3306 public static final String CUSTOM_PROTOCOL = "custom_protocol"; 3307 3308 /** 3309 * The IM handle the presence item is for. The handle is scoped to 3310 * {@link #PROTOCOL}. 3311 * <P>Type: TEXT</P> 3312 */ 3313 public static final String IM_HANDLE = "im_handle"; 3314 3315 /** 3316 * The IM account for the local user that the presence data came from. 3317 * <P>Type: TEXT</P> 3318 */ 3319 public static final String IM_ACCOUNT = "im_account"; 3320 } 3321 3322 /** 3323 * <p> 3324 * A status update is linked to a {@link ContactsContract.Data} row and captures 3325 * the user's latest status update via the corresponding source, e.g. 3326 * "Having lunch" via "Google Talk". 3327 * </p> 3328 * <p> 3329 * There are two ways a status update can be inserted: by explicitly linking 3330 * it to a Data row using {@link #DATA_ID} or indirectly linking it to a data row 3331 * using a combination of {@link #PROTOCOL} (or {@link #CUSTOM_PROTOCOL}) and 3332 * {@link #IM_HANDLE}. There is no difference between insert and update, you can use 3333 * either. 3334 * </p> 3335 * <p> 3336 * You cannot use {@link ContentResolver#update} to change a status, but 3337 * {@link ContentResolver#insert} will replace the latests status if it already 3338 * exists. 3339 * </p> 3340 * <p> 3341 * Use {@link ContentResolver#bulkInsert(Uri, ContentValues[])} to insert/update statuses 3342 * for multiple contacts at once. 3343 * </p> 3344 * 3345 * <h3>Columns</h3> 3346 * <table class="jd-sumtable"> 3347 * <tr> 3348 * <th colspan='4'>StatusUpdates</th> 3349 * </tr> 3350 * <tr> 3351 * <td>long</td> 3352 * <td>{@link #DATA_ID}</td> 3353 * <td>read/write</td> 3354 * <td>Reference to the {@link Data#_ID} entry that owns this presence. If this 3355 * field is <i>not</i> specified, the provider will attempt to find a data row 3356 * that matches the {@link #PROTOCOL} (or {@link #CUSTOM_PROTOCOL}) and 3357 * {@link #IM_HANDLE} columns. 3358 * </td> 3359 * </tr> 3360 * <tr> 3361 * <td>long</td> 3362 * <td>{@link #PROTOCOL}</td> 3363 * <td>read/write</td> 3364 * <td>See {@link CommonDataKinds.Im} for a list of defined protocol constants.</td> 3365 * </tr> 3366 * <tr> 3367 * <td>String</td> 3368 * <td>{@link #CUSTOM_PROTOCOL}</td> 3369 * <td>read/write</td> 3370 * <td>Name of the custom protocol. Should be supplied along with the {@link #PROTOCOL} value 3371 * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}. Should be null or 3372 * omitted if {@link #PROTOCOL} value is not 3373 * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.</td> 3374 * </tr> 3375 * <tr> 3376 * <td>String</td> 3377 * <td>{@link #IM_HANDLE}</td> 3378 * <td>read/write</td> 3379 * <td> The IM handle the presence item is for. The handle is scoped to 3380 * {@link #PROTOCOL}.</td> 3381 * </tr> 3382 * <tr> 3383 * <td>String</td> 3384 * <td>{@link #IM_ACCOUNT}</td> 3385 * <td>read/write</td> 3386 * <td>The IM account for the local user that the presence data came from.</td> 3387 * </tr> 3388 * <tr> 3389 * <td>int</td> 3390 * <td>{@link #PRESENCE}</td> 3391 * <td>read/write</td> 3392 * <td>Contact IM presence status. The allowed values are: 3393 * <p> 3394 * <ul> 3395 * <li>{@link #OFFLINE}</li> 3396 * <li>{@link #INVISIBLE}</li> 3397 * <li>{@link #AWAY}</li> 3398 * <li>{@link #IDLE}</li> 3399 * <li>{@link #DO_NOT_DISTURB}</li> 3400 * <li>{@link #AVAILABLE}</li> 3401 * </ul> 3402 * </p> 3403 * <p> 3404 * Since presence status is inherently volatile, the content provider 3405 * may choose not to store this field in long-term storage. 3406 * </p> 3407 * </td> 3408 * </tr> 3409 * <tr> 3410 * <td>int</td> 3411 * <td>{@link #CHAT_CAPABILITY}</td> 3412 * <td>read/write</td> 3413 * <td>Contact IM chat compatibility value. The allowed values are: 3414 * <p> 3415 * <ul> 3416 * <li>{@link #CAPABILITY_HAS_VIDEO_PLAYBACK_ONLY}</li> 3417 * <li>{@link #CAPABILITY_HAS_VOICE}</li> 3418 * <li>{@link #CAPABILITY_HAS_CAMERA}</li> 3419 * </ul> 3420 * </p> 3421 * <p> 3422 * Since chat compatibility is inherently volatile as the contact's availability moves from 3423 * one device to another, the content provider may choose not to store this field in long-term 3424 * storage. 3425 * </p> 3426 * </td> 3427 * </tr> 3428 * <tr> 3429 * <td>String</td> 3430 * <td>{@link #STATUS}</td> 3431 * <td>read/write</td> 3432 * <td>Contact's latest status update, e.g. "having toast for breakfast"</td> 3433 * </tr> 3434 * <tr> 3435 * <td>long</td> 3436 * <td>{@link #STATUS_TIMESTAMP}</td> 3437 * <td>read/write</td> 3438 * <td>The absolute time in milliseconds when the status was 3439 * entered by the user. If this value is not provided, the provider will follow 3440 * this logic: if there was no prior status update, the value will be left as null. 3441 * If there was a prior status update, the provider will default this field 3442 * to the current time.</td> 3443 * </tr> 3444 * <tr> 3445 * <td>String</td> 3446 * <td>{@link #STATUS_RES_PACKAGE}</td> 3447 * <td>read/write</td> 3448 * <td> The package containing resources for this status: label and icon.</td> 3449 * </tr> 3450 * <tr> 3451 * <td>long</td> 3452 * <td>{@link #STATUS_LABEL}</td> 3453 * <td>read/write</td> 3454 * <td>The resource ID of the label describing the source of contact status, 3455 * e.g. "Google Talk". This resource is scoped by the 3456 * {@link #STATUS_RES_PACKAGE}.</td> 3457 * </tr> 3458 * <tr> 3459 * <td>long</td> 3460 * <td>{@link #STATUS_ICON}</td> 3461 * <td>read/write</td> 3462 * <td>The resource ID of the icon for the source of contact status. This 3463 * resource is scoped by the {@link #STATUS_RES_PACKAGE}.</td> 3464 * </tr> 3465 * </table> 3466 */ 3467 public static class StatusUpdates implements StatusColumns, PresenceColumns { 3468 3469 /** 3470 * This utility class cannot be instantiated 3471 */ 3472 private StatusUpdates() {} 3473 3474 /** 3475 * The content:// style URI for this table 3476 */ 3477 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "status_updates"); 3478 3479 /** 3480 * Gets the resource ID for the proper presence icon. 3481 * 3482 * @param status the status to get the icon for 3483 * @return the resource ID for the proper presence icon 3484 */ 3485 public static final int getPresenceIconResourceId(int status) { 3486 switch (status) { 3487 case AVAILABLE: 3488 return android.R.drawable.presence_online; 3489 case IDLE: 3490 case AWAY: 3491 return android.R.drawable.presence_away; 3492 case DO_NOT_DISTURB: 3493 return android.R.drawable.presence_busy; 3494 case INVISIBLE: 3495 return android.R.drawable.presence_invisible; 3496 case OFFLINE: 3497 default: 3498 return android.R.drawable.presence_offline; 3499 } 3500 } 3501 3502 /** 3503 * Returns the precedence of the status code the higher number being the higher precedence. 3504 * 3505 * @param status The status code. 3506 * @return An integer representing the precedence, 0 being the lowest. 3507 */ 3508 public static final int getPresencePrecedence(int status) { 3509 // Keep this function here incase we want to enforce a different precedence than the 3510 // natural order of the status constants. 3511 return status; 3512 } 3513 3514 /** 3515 * The MIME type of {@link #CONTENT_URI} providing a directory of 3516 * status update details. 3517 */ 3518 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/status-update"; 3519 3520 /** 3521 * The MIME type of a {@link #CONTENT_URI} subdirectory of a single 3522 * status update detail. 3523 */ 3524 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/status-update"; 3525 } 3526 3527 /** 3528 * @deprecated This old name was never meant to be made public. Do not use. 3529 */ 3530 @Deprecated 3531 public static final class Presence extends StatusUpdates { 3532 3533 } 3534 3535 /** 3536 * Additional columns returned by the {@link Contacts#CONTENT_FILTER_URI} providing the 3537 * explanation of why the filter matched the contact. Specifically, they contain the 3538 * data type and element that was used for matching. 3539 * <p> 3540 * This is temporary API, it will need to change when we move to FTS. 3541 * 3542 * @hide 3543 */ 3544 public static class SearchSnippetColumns { 3545 3546 /** 3547 * The ID of the data row that was matched by the filter. 3548 * 3549 * @hide 3550 */ 3551 public static final String SNIPPET_DATA_ID = "snippet_data_id"; 3552 3553 /** 3554 * The type of data that was matched by the filter. 3555 * 3556 * @hide 3557 */ 3558 public static final String SNIPPET_MIMETYPE = "snippet_mimetype"; 3559 3560 /** 3561 * The {@link Data#DATA1} field of the data row that was matched by the filter. 3562 * 3563 * @hide 3564 */ 3565 public static final String SNIPPET_DATA1 = "snippet_data1"; 3566 3567 /** 3568 * The {@link Data#DATA2} field of the data row that was matched by the filter. 3569 * 3570 * @hide 3571 */ 3572 public static final String SNIPPET_DATA2 = "snippet_data2"; 3573 3574 /** 3575 * The {@link Data#DATA3} field of the data row that was matched by the filter. 3576 * 3577 * @hide 3578 */ 3579 public static final String SNIPPET_DATA3 = "snippet_data3"; 3580 3581 /** 3582 * The {@link Data#DATA4} field of the data row that was matched by the filter. 3583 * 3584 * @hide 3585 */ 3586 public static final String SNIPPET_DATA4 = "snippet_data4"; 3587 3588 } 3589 3590 /** 3591 * Container for definitions of common data types stored in the {@link ContactsContract.Data} 3592 * table. 3593 */ 3594 public static final class CommonDataKinds { 3595 /** 3596 * This utility class cannot be instantiated 3597 */ 3598 private CommonDataKinds() {} 3599 3600 /** 3601 * The {@link Data#RES_PACKAGE} value for common data that should be 3602 * shown using a default style. 3603 * 3604 * @hide RES_PACKAGE is hidden 3605 */ 3606 public static final String PACKAGE_COMMON = "common"; 3607 3608 /** 3609 * The base types that all "Typed" data kinds support. 3610 */ 3611 public interface BaseTypes { 3612 /** 3613 * A custom type. The custom label should be supplied by user. 3614 */ 3615 public static int TYPE_CUSTOM = 0; 3616 } 3617 3618 /** 3619 * Columns common across the specific types. 3620 */ 3621 protected interface CommonColumns extends BaseTypes { 3622 /** 3623 * The data for the contact method. 3624 * <P>Type: TEXT</P> 3625 */ 3626 public static final String DATA = DataColumns.DATA1; 3627 3628 /** 3629 * The type of data, for example Home or Work. 3630 * <P>Type: INTEGER</P> 3631 */ 3632 public static final String TYPE = DataColumns.DATA2; 3633 3634 /** 3635 * The user defined label for the the contact method. 3636 * <P>Type: TEXT</P> 3637 */ 3638 public static final String LABEL = DataColumns.DATA3; 3639 } 3640 3641 /** 3642 * A data kind representing the contact's proper name. You can use all 3643 * columns defined for {@link ContactsContract.Data} as well as the following aliases. 3644 * 3645 * <h2>Column aliases</h2> 3646 * <table class="jd-sumtable"> 3647 * <tr> 3648 * <th>Type</th><th>Alias</th><th colspan='2'>Data column</th> 3649 * </tr> 3650 * <tr> 3651 * <td>String</td> 3652 * <td>{@link #DISPLAY_NAME}</td> 3653 * <td>{@link #DATA1}</td> 3654 * <td></td> 3655 * </tr> 3656 * <tr> 3657 * <td>String</td> 3658 * <td>{@link #GIVEN_NAME}</td> 3659 * <td>{@link #DATA2}</td> 3660 * <td></td> 3661 * </tr> 3662 * <tr> 3663 * <td>String</td> 3664 * <td>{@link #FAMILY_NAME}</td> 3665 * <td>{@link #DATA3}</td> 3666 * <td></td> 3667 * </tr> 3668 * <tr> 3669 * <td>String</td> 3670 * <td>{@link #PREFIX}</td> 3671 * <td>{@link #DATA4}</td> 3672 * <td>Common prefixes in English names are "Mr", "Ms", "Dr" etc.</td> 3673 * </tr> 3674 * <tr> 3675 * <td>String</td> 3676 * <td>{@link #MIDDLE_NAME}</td> 3677 * <td>{@link #DATA5}</td> 3678 * <td></td> 3679 * </tr> 3680 * <tr> 3681 * <td>String</td> 3682 * <td>{@link #SUFFIX}</td> 3683 * <td>{@link #DATA6}</td> 3684 * <td>Common suffixes in English names are "Sr", "Jr", "III" etc.</td> 3685 * </tr> 3686 * <tr> 3687 * <td>String</td> 3688 * <td>{@link #PHONETIC_GIVEN_NAME}</td> 3689 * <td>{@link #DATA7}</td> 3690 * <td>Used for phonetic spelling of the name, e.g. Pinyin, Katakana, Hiragana</td> 3691 * </tr> 3692 * <tr> 3693 * <td>String</td> 3694 * <td>{@link #PHONETIC_MIDDLE_NAME}</td> 3695 * <td>{@link #DATA8}</td> 3696 * <td></td> 3697 * </tr> 3698 * <tr> 3699 * <td>String</td> 3700 * <td>{@link #PHONETIC_FAMILY_NAME}</td> 3701 * <td>{@link #DATA9}</td> 3702 * <td></td> 3703 * </tr> 3704 * </table> 3705 */ 3706 public static final class StructuredName implements DataColumnsWithJoins { 3707 /** 3708 * This utility class cannot be instantiated 3709 */ 3710 private StructuredName() {} 3711 3712 /** MIME type used when storing this in data table. */ 3713 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/name"; 3714 3715 /** 3716 * The name that should be used to display the contact. 3717 * <i>Unstructured component of the name should be consistent with 3718 * its structured representation.</i> 3719 * <p> 3720 * Type: TEXT 3721 */ 3722 public static final String DISPLAY_NAME = DATA1; 3723 3724 /** 3725 * The given name for the contact. 3726 * <P>Type: TEXT</P> 3727 */ 3728 public static final String GIVEN_NAME = DATA2; 3729 3730 /** 3731 * The family name for the contact. 3732 * <P>Type: TEXT</P> 3733 */ 3734 public static final String FAMILY_NAME = DATA3; 3735 3736 /** 3737 * The contact's honorific prefix, e.g. "Sir" 3738 * <P>Type: TEXT</P> 3739 */ 3740 public static final String PREFIX = DATA4; 3741 3742 /** 3743 * The contact's middle name 3744 * <P>Type: TEXT</P> 3745 */ 3746 public static final String MIDDLE_NAME = DATA5; 3747 3748 /** 3749 * The contact's honorific suffix, e.g. "Jr" 3750 */ 3751 public static final String SUFFIX = DATA6; 3752 3753 /** 3754 * The phonetic version of the given name for the contact. 3755 * <P>Type: TEXT</P> 3756 */ 3757 public static final String PHONETIC_GIVEN_NAME = DATA7; 3758 3759 /** 3760 * The phonetic version of the additional name for the contact. 3761 * <P>Type: TEXT</P> 3762 */ 3763 public static final String PHONETIC_MIDDLE_NAME = DATA8; 3764 3765 /** 3766 * The phonetic version of the family name for the contact. 3767 * <P>Type: TEXT</P> 3768 */ 3769 public static final String PHONETIC_FAMILY_NAME = DATA9; 3770 3771 /** 3772 * The style used for combining given/middle/family name into a full name. 3773 * See {@link ContactsContract.FullNameStyle}. 3774 * 3775 * @hide 3776 */ 3777 public static final String FULL_NAME_STYLE = DATA10; 3778 3779 /** 3780 * The alphabet used for capturing the phonetic name. 3781 * See ContactsContract.PhoneticNameStyle. 3782 * @hide 3783 */ 3784 public static final String PHONETIC_NAME_STYLE = DATA11; 3785 } 3786 3787 /** 3788 * <p>A data kind representing the contact's nickname. For example, for 3789 * Bob Parr ("Mr. Incredible"): 3790 * <pre> 3791 * ArrayList<ContentProviderOperation> ops = Lists.newArrayList(); 3792 * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI) 3793 * .withValue(Data.RAW_CONTACT_ID, rawContactId) 3794 * .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE) 3795 * .withValue(StructuredName.DISPLAY_NAME, "Bob Parr") 3796 * .build()); 3797 * 3798 * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI) 3799 * .withValue(Data.RAW_CONTACT_ID, rawContactId) 3800 * .withValue(Data.MIMETYPE, Nickname.CONTENT_ITEM_TYPE) 3801 * .withValue(Nickname.NAME, "Mr. Incredible") 3802 * .withValue(Nickname.TYPE, Nickname.TYPE_CUSTOM) 3803 * .withValue(Nickname.LABEL, "Superhero") 3804 * .build()); 3805 * 3806 * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); 3807 * </pre> 3808 * </p> 3809 * <p> 3810 * You can use all columns defined for {@link ContactsContract.Data} as well as the 3811 * following aliases. 3812 * </p> 3813 * 3814 * <h2>Column aliases</h2> 3815 * <table class="jd-sumtable"> 3816 * <tr> 3817 * <th>Type</th><th>Alias</th><th colspan='2'>Data column</th> 3818 * </tr> 3819 * <tr> 3820 * <td>String</td> 3821 * <td>{@link #NAME}</td> 3822 * <td>{@link #DATA1}</td> 3823 * <td></td> 3824 * </tr> 3825 * <tr> 3826 * <td>int</td> 3827 * <td>{@link #TYPE}</td> 3828 * <td>{@link #DATA2}</td> 3829 * <td> 3830 * Allowed values are: 3831 * <p> 3832 * <ul> 3833 * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li> 3834 * <li>{@link #TYPE_DEFAULT}</li> 3835 * <li>{@link #TYPE_OTHER_NAME}</li> 3836 * <li>{@link #TYPE_MAINDEN_NAME}</li> 3837 * <li>{@link #TYPE_SHORT_NAME}</li> 3838 * <li>{@link #TYPE_INITIALS}</li> 3839 * </ul> 3840 * </p> 3841 * </td> 3842 * </tr> 3843 * <tr> 3844 * <td>String</td> 3845 * <td>{@link #LABEL}</td> 3846 * <td>{@link #DATA3}</td> 3847 * <td></td> 3848 * </tr> 3849 * </table> 3850 */ 3851 public static final class Nickname implements DataColumnsWithJoins, CommonColumns { 3852 /** 3853 * This utility class cannot be instantiated 3854 */ 3855 private Nickname() {} 3856 3857 /** MIME type used when storing this in data table. */ 3858 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/nickname"; 3859 3860 public static final int TYPE_DEFAULT = 1; 3861 public static final int TYPE_OTHER_NAME = 2; 3862 public static final int TYPE_MAINDEN_NAME = 3; 3863 public static final int TYPE_SHORT_NAME = 4; 3864 public static final int TYPE_INITIALS = 5; 3865 3866 /** 3867 * The name itself 3868 */ 3869 public static final String NAME = DATA; 3870 } 3871 3872 /** 3873 * <p> 3874 * A data kind representing a telephone number. 3875 * </p> 3876 * <p> 3877 * You can use all columns defined for {@link ContactsContract.Data} as 3878 * well as the following aliases. 3879 * </p> 3880 * <h2>Column aliases</h2> 3881 * <table class="jd-sumtable"> 3882 * <tr> 3883 * <th>Type</th> 3884 * <th>Alias</th><th colspan='2'>Data column</th> 3885 * </tr> 3886 * <tr> 3887 * <td>String</td> 3888 * <td>{@link #NUMBER}</td> 3889 * <td>{@link #DATA1}</td> 3890 * <td></td> 3891 * </tr> 3892 * <tr> 3893 * <td>int</td> 3894 * <td>{@link #TYPE}</td> 3895 * <td>{@link #DATA2}</td> 3896 * <td>Allowed values are: 3897 * <p> 3898 * <ul> 3899 * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li> 3900 * <li>{@link #TYPE_HOME}</li> 3901 * <li>{@link #TYPE_MOBILE}</li> 3902 * <li>{@link #TYPE_WORK}</li> 3903 * <li>{@link #TYPE_FAX_WORK}</li> 3904 * <li>{@link #TYPE_FAX_HOME}</li> 3905 * <li>{@link #TYPE_PAGER}</li> 3906 * <li>{@link #TYPE_OTHER}</li> 3907 * <li>{@link #TYPE_CALLBACK}</li> 3908 * <li>{@link #TYPE_CAR}</li> 3909 * <li>{@link #TYPE_COMPANY_MAIN}</li> 3910 * <li>{@link #TYPE_ISDN}</li> 3911 * <li>{@link #TYPE_MAIN}</li> 3912 * <li>{@link #TYPE_OTHER_FAX}</li> 3913 * <li>{@link #TYPE_RADIO}</li> 3914 * <li>{@link #TYPE_TELEX}</li> 3915 * <li>{@link #TYPE_TTY_TDD}</li> 3916 * <li>{@link #TYPE_WORK_MOBILE}</li> 3917 * <li>{@link #TYPE_WORK_PAGER}</li> 3918 * <li>{@link #TYPE_ASSISTANT}</li> 3919 * <li>{@link #TYPE_MMS}</li> 3920 * </ul> 3921 * </p> 3922 * </td> 3923 * </tr> 3924 * <tr> 3925 * <td>String</td> 3926 * <td>{@link #LABEL}</td> 3927 * <td>{@link #DATA3}</td> 3928 * <td></td> 3929 * </tr> 3930 * </table> 3931 */ 3932 public static final class Phone implements DataColumnsWithJoins, CommonColumns { 3933 /** 3934 * This utility class cannot be instantiated 3935 */ 3936 private Phone() {} 3937 3938 /** MIME type used when storing this in data table. */ 3939 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/phone_v2"; 3940 3941 /** 3942 * The MIME type of {@link #CONTENT_URI} providing a directory of 3943 * phones. 3944 */ 3945 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/phone_v2"; 3946 3947 /** 3948 * The content:// style URI for all data records of the 3949 * {@link #CONTENT_ITEM_TYPE} MIME type, combined with the 3950 * associated raw contact and aggregate contact data. 3951 */ 3952 public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI, 3953 "phones"); 3954 3955 /** 3956 * The content:// style URL for phone lookup using a filter. The filter returns 3957 * records of MIME type {@link #CONTENT_ITEM_TYPE}. The filter is applied 3958 * to display names as well as phone numbers. The filter argument should be passed 3959 * as an additional path segment after this URI. 3960 */ 3961 public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI, 3962 "filter"); 3963 3964 public static final int TYPE_HOME = 1; 3965 public static final int TYPE_MOBILE = 2; 3966 public static final int TYPE_WORK = 3; 3967 public static final int TYPE_FAX_WORK = 4; 3968 public static final int TYPE_FAX_HOME = 5; 3969 public static final int TYPE_PAGER = 6; 3970 public static final int TYPE_OTHER = 7; 3971 public static final int TYPE_CALLBACK = 8; 3972 public static final int TYPE_CAR = 9; 3973 public static final int TYPE_COMPANY_MAIN = 10; 3974 public static final int TYPE_ISDN = 11; 3975 public static final int TYPE_MAIN = 12; 3976 public static final int TYPE_OTHER_FAX = 13; 3977 public static final int TYPE_RADIO = 14; 3978 public static final int TYPE_TELEX = 15; 3979 public static final int TYPE_TTY_TDD = 16; 3980 public static final int TYPE_WORK_MOBILE = 17; 3981 public static final int TYPE_WORK_PAGER = 18; 3982 public static final int TYPE_ASSISTANT = 19; 3983 public static final int TYPE_MMS = 20; 3984 3985 /** 3986 * The phone number as the user entered it. 3987 * <P>Type: TEXT</P> 3988 */ 3989 public static final String NUMBER = DATA; 3990 3991 /** 3992 * @deprecated use {@link #getTypeLabel(Resources, int, CharSequence)} instead. 3993 * @hide 3994 */ 3995 @Deprecated 3996 public static final CharSequence getDisplayLabel(Context context, int type, 3997 CharSequence label, CharSequence[] labelArray) { 3998 return getTypeLabel(context.getResources(), type, label); 3999 } 4000 4001 /** 4002 * @deprecated use {@link #getTypeLabel(Resources, int, CharSequence)} instead. 4003 * @hide 4004 */ 4005 @Deprecated 4006 public static final CharSequence getDisplayLabel(Context context, int type, 4007 CharSequence label) { 4008 return getTypeLabel(context.getResources(), type, label); 4009 } 4010 4011 /** 4012 * Return the string resource that best describes the given 4013 * {@link #TYPE}. Will always return a valid resource. 4014 */ 4015 public static final int getTypeLabelResource(int type) { 4016 switch (type) { 4017 case TYPE_HOME: return com.android.internal.R.string.phoneTypeHome; 4018 case TYPE_MOBILE: return com.android.internal.R.string.phoneTypeMobile; 4019 case TYPE_WORK: return com.android.internal.R.string.phoneTypeWork; 4020 case TYPE_FAX_WORK: return com.android.internal.R.string.phoneTypeFaxWork; 4021 case TYPE_FAX_HOME: return com.android.internal.R.string.phoneTypeFaxHome; 4022 case TYPE_PAGER: return com.android.internal.R.string.phoneTypePager; 4023 case TYPE_OTHER: return com.android.internal.R.string.phoneTypeOther; 4024 case TYPE_CALLBACK: return com.android.internal.R.string.phoneTypeCallback; 4025 case TYPE_CAR: return com.android.internal.R.string.phoneTypeCar; 4026 case TYPE_COMPANY_MAIN: return com.android.internal.R.string.phoneTypeCompanyMain; 4027 case TYPE_ISDN: return com.android.internal.R.string.phoneTypeIsdn; 4028 case TYPE_MAIN: return com.android.internal.R.string.phoneTypeMain; 4029 case TYPE_OTHER_FAX: return com.android.internal.R.string.phoneTypeOtherFax; 4030 case TYPE_RADIO: return com.android.internal.R.string.phoneTypeRadio; 4031 case TYPE_TELEX: return com.android.internal.R.string.phoneTypeTelex; 4032 case TYPE_TTY_TDD: return com.android.internal.R.string.phoneTypeTtyTdd; 4033 case TYPE_WORK_MOBILE: return com.android.internal.R.string.phoneTypeWorkMobile; 4034 case TYPE_WORK_PAGER: return com.android.internal.R.string.phoneTypeWorkPager; 4035 case TYPE_ASSISTANT: return com.android.internal.R.string.phoneTypeAssistant; 4036 case TYPE_MMS: return com.android.internal.R.string.phoneTypeMms; 4037 default: return com.android.internal.R.string.phoneTypeCustom; 4038 } 4039 } 4040 4041 /** 4042 * Return a {@link CharSequence} that best describes the given type, 4043 * possibly substituting the given {@link #LABEL} value 4044 * for {@link #TYPE_CUSTOM}. 4045 */ 4046 public static final CharSequence getTypeLabel(Resources res, int type, 4047 CharSequence label) { 4048 if ((type == TYPE_CUSTOM || type == TYPE_ASSISTANT) && !TextUtils.isEmpty(label)) { 4049 return label; 4050 } else { 4051 final int labelRes = getTypeLabelResource(type); 4052 return res.getText(labelRes); 4053 } 4054 } 4055 } 4056 4057 /** 4058 * <p> 4059 * A data kind representing an email address. 4060 * </p> 4061 * <p> 4062 * You can use all columns defined for {@link ContactsContract.Data} as 4063 * well as the following aliases. 4064 * </p> 4065 * <h2>Column aliases</h2> 4066 * <table class="jd-sumtable"> 4067 * <tr> 4068 * <th>Type</th> 4069 * <th>Alias</th><th colspan='2'>Data column</th> 4070 * </tr> 4071 * <tr> 4072 * <td>String</td> 4073 * <td>{@link #DATA}</td> 4074 * <td>{@link #DATA1}</td> 4075 * <td>Email address itself.</td> 4076 * </tr> 4077 * <tr> 4078 * <td>int</td> 4079 * <td>{@link #TYPE}</td> 4080 * <td>{@link #DATA2}</td> 4081 * <td>Allowed values are: 4082 * <p> 4083 * <ul> 4084 * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li> 4085 * <li>{@link #TYPE_HOME}</li> 4086 * <li>{@link #TYPE_WORK}</li> 4087 * <li>{@link #TYPE_OTHER}</li> 4088 * <li>{@link #TYPE_MOBILE}</li> 4089 * </ul> 4090 * </p> 4091 * </td> 4092 * </tr> 4093 * <tr> 4094 * <td>String</td> 4095 * <td>{@link #LABEL}</td> 4096 * <td>{@link #DATA3}</td> 4097 * <td></td> 4098 * </tr> 4099 * </table> 4100 */ 4101 public static final class Email implements DataColumnsWithJoins, CommonColumns { 4102 /** 4103 * This utility class cannot be instantiated 4104 */ 4105 private Email() {} 4106 4107 /** MIME type used when storing this in data table. */ 4108 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/email_v2"; 4109 4110 /** 4111 * The MIME type of {@link #CONTENT_URI} providing a directory of email addresses. 4112 */ 4113 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/email_v2"; 4114 4115 /** 4116 * The content:// style URI for all data records of the 4117 * {@link #CONTENT_ITEM_TYPE} MIME type, combined with the 4118 * associated raw contact and aggregate contact data. 4119 */ 4120 public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI, 4121 "emails"); 4122 4123 /** 4124 * <p> 4125 * The content:// style URL for looking up data rows by email address. The 4126 * lookup argument, an email address, should be passed as an additional path segment 4127 * after this URI. 4128 * </p> 4129 * <p>Example: 4130 * <pre> 4131 * Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(email)); 4132 * Cursor c = getContentResolver().query(uri, 4133 * new String[]{Email.CONTACT_ID, Email.DISPLAY_NAME, Email.DATA}, 4134 * null, null, null); 4135 * </pre> 4136 * </p> 4137 */ 4138 public static final Uri CONTENT_LOOKUP_URI = Uri.withAppendedPath(CONTENT_URI, 4139 "lookup"); 4140 4141 /** 4142 * <p> 4143 * The content:// style URL for email lookup using a filter. The filter returns 4144 * records of MIME type {@link #CONTENT_ITEM_TYPE}. The filter is applied 4145 * to display names as well as email addresses. The filter argument should be passed 4146 * as an additional path segment after this URI. 4147 * </p> 4148 * <p>The query in the following example will return "Robert Parr (bob@incredibles.com)" 4149 * as well as "Bob Parr (incredible@android.com)". 4150 * <pre> 4151 * Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode("bob")); 4152 * Cursor c = getContentResolver().query(uri, 4153 * new String[]{Email.DISPLAY_NAME, Email.DATA}, 4154 * null, null, null); 4155 * </pre> 4156 * </p> 4157 */ 4158 public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI, 4159 "filter"); 4160 4161 /** 4162 * The email address. 4163 * <P>Type: TEXT</P> 4164 * @hide TODO: Unhide in a separate CL 4165 */ 4166 public static final String ADDRESS = DATA1; 4167 4168 public static final int TYPE_HOME = 1; 4169 public static final int TYPE_WORK = 2; 4170 public static final int TYPE_OTHER = 3; 4171 public static final int TYPE_MOBILE = 4; 4172 4173 /** 4174 * The display name for the email address 4175 * <P>Type: TEXT</P> 4176 */ 4177 public static final String DISPLAY_NAME = DATA4; 4178 4179 /** 4180 * Return the string resource that best describes the given 4181 * {@link #TYPE}. Will always return a valid resource. 4182 */ 4183 public static final int getTypeLabelResource(int type) { 4184 switch (type) { 4185 case TYPE_HOME: return com.android.internal.R.string.emailTypeHome; 4186 case TYPE_WORK: return com.android.internal.R.string.emailTypeWork; 4187 case TYPE_OTHER: return com.android.internal.R.string.emailTypeOther; 4188 case TYPE_MOBILE: return com.android.internal.R.string.emailTypeMobile; 4189 default: return com.android.internal.R.string.emailTypeCustom; 4190 } 4191 } 4192 4193 /** 4194 * Return a {@link CharSequence} that best describes the given type, 4195 * possibly substituting the given {@link #LABEL} value 4196 * for {@link #TYPE_CUSTOM}. 4197 */ 4198 public static final CharSequence getTypeLabel(Resources res, int type, 4199 CharSequence label) { 4200 if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) { 4201 return label; 4202 } else { 4203 final int labelRes = getTypeLabelResource(type); 4204 return res.getText(labelRes); 4205 } 4206 } 4207 } 4208 4209 /** 4210 * <p> 4211 * A data kind representing a postal addresses. 4212 * </p> 4213 * <p> 4214 * You can use all columns defined for {@link ContactsContract.Data} as 4215 * well as the following aliases. 4216 * </p> 4217 * <h2>Column aliases</h2> 4218 * <table class="jd-sumtable"> 4219 * <tr> 4220 * <th>Type</th> 4221 * <th>Alias</th><th colspan='2'>Data column</th> 4222 * </tr> 4223 * <tr> 4224 * <td>String</td> 4225 * <td>{@link #FORMATTED_ADDRESS}</td> 4226 * <td>{@link #DATA1}</td> 4227 * <td></td> 4228 * </tr> 4229 * <tr> 4230 * <td>int</td> 4231 * <td>{@link #TYPE}</td> 4232 * <td>{@link #DATA2}</td> 4233 * <td>Allowed values are: 4234 * <p> 4235 * <ul> 4236 * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li> 4237 * <li>{@link #TYPE_HOME}</li> 4238 * <li>{@link #TYPE_WORK}</li> 4239 * <li>{@link #TYPE_OTHER}</li> 4240 * </ul> 4241 * </p> 4242 * </td> 4243 * </tr> 4244 * <tr> 4245 * <td>String</td> 4246 * <td>{@link #LABEL}</td> 4247 * <td>{@link #DATA3}</td> 4248 * <td></td> 4249 * </tr> 4250 * <tr> 4251 * <td>String</td> 4252 * <td>{@link #STREET}</td> 4253 * <td>{@link #DATA4}</td> 4254 * <td></td> 4255 * </tr> 4256 * <tr> 4257 * <td>String</td> 4258 * <td>{@link #POBOX}</td> 4259 * <td>{@link #DATA5}</td> 4260 * <td>Post Office Box number</td> 4261 * </tr> 4262 * <tr> 4263 * <td>String</td> 4264 * <td>{@link #NEIGHBORHOOD}</td> 4265 * <td>{@link #DATA6}</td> 4266 * <td></td> 4267 * </tr> 4268 * <tr> 4269 * <td>String</td> 4270 * <td>{@link #CITY}</td> 4271 * <td>{@link #DATA7}</td> 4272 * <td></td> 4273 * </tr> 4274 * <tr> 4275 * <td>String</td> 4276 * <td>{@link #REGION}</td> 4277 * <td>{@link #DATA8}</td> 4278 * <td></td> 4279 * </tr> 4280 * <tr> 4281 * <td>String</td> 4282 * <td>{@link #POSTCODE}</td> 4283 * <td>{@link #DATA9}</td> 4284 * <td></td> 4285 * </tr> 4286 * <tr> 4287 * <td>String</td> 4288 * <td>{@link #COUNTRY}</td> 4289 * <td>{@link #DATA10}</td> 4290 * <td></td> 4291 * </tr> 4292 * </table> 4293 */ 4294 public static final class StructuredPostal implements DataColumnsWithJoins, CommonColumns { 4295 /** 4296 * This utility class cannot be instantiated 4297 */ 4298 private StructuredPostal() { 4299 } 4300 4301 /** MIME type used when storing this in data table. */ 4302 public static final String CONTENT_ITEM_TYPE = 4303 "vnd.android.cursor.item/postal-address_v2"; 4304 4305 /** 4306 * The MIME type of {@link #CONTENT_URI} providing a directory of 4307 * postal addresses. 4308 */ 4309 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/postal-address_v2"; 4310 4311 /** 4312 * The content:// style URI for all data records of the 4313 * {@link StructuredPostal#CONTENT_ITEM_TYPE} MIME type. 4314 */ 4315 public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI, 4316 "postals"); 4317 4318 public static final int TYPE_HOME = 1; 4319 public static final int TYPE_WORK = 2; 4320 public static final int TYPE_OTHER = 3; 4321 4322 /** 4323 * The full, unstructured postal address. <i>This field must be 4324 * consistent with any structured data.</i> 4325 * <p> 4326 * Type: TEXT 4327 */ 4328 public static final String FORMATTED_ADDRESS = DATA; 4329 4330 /** 4331 * Can be street, avenue, road, etc. This element also includes the 4332 * house number and room/apartment/flat/floor number. 4333 * <p> 4334 * Type: TEXT 4335 */ 4336 public static final String STREET = DATA4; 4337 4338 /** 4339 * Covers actual P.O. boxes, drawers, locked bags, etc. This is 4340 * usually but not always mutually exclusive with street. 4341 * <p> 4342 * Type: TEXT 4343 */ 4344 public static final String POBOX = DATA5; 4345 4346 /** 4347 * This is used to disambiguate a street address when a city 4348 * contains more than one street with the same name, or to specify a 4349 * small place whose mail is routed through a larger postal town. In 4350 * China it could be a county or a minor city. 4351 * <p> 4352 * Type: TEXT 4353 */ 4354 public static final String NEIGHBORHOOD = DATA6; 4355 4356 /** 4357 * Can be city, village, town, borough, etc. This is the postal town 4358 * and not necessarily the place of residence or place of business. 4359 * <p> 4360 * Type: TEXT 4361 */ 4362 public static final String CITY = DATA7; 4363 4364 /** 4365 * A state, province, county (in Ireland), Land (in Germany), 4366 * departement (in France), etc. 4367 * <p> 4368 * Type: TEXT 4369 */ 4370 public static final String REGION = DATA8; 4371 4372 /** 4373 * Postal code. Usually country-wide, but sometimes specific to the 4374 * city (e.g. "2" in "Dublin 2, Ireland" addresses). 4375 * <p> 4376 * Type: TEXT 4377 */ 4378 public static final String POSTCODE = DATA9; 4379 4380 /** 4381 * The name or code of the country. 4382 * <p> 4383 * Type: TEXT 4384 */ 4385 public static final String COUNTRY = DATA10; 4386 4387 /** 4388 * Return the string resource that best describes the given 4389 * {@link #TYPE}. Will always return a valid resource. 4390 */ 4391 public static final int getTypeLabelResource(int type) { 4392 switch (type) { 4393 case TYPE_HOME: return com.android.internal.R.string.postalTypeHome; 4394 case TYPE_WORK: return com.android.internal.R.string.postalTypeWork; 4395 case TYPE_OTHER: return com.android.internal.R.string.postalTypeOther; 4396 default: return com.android.internal.R.string.postalTypeCustom; 4397 } 4398 } 4399 4400 /** 4401 * Return a {@link CharSequence} that best describes the given type, 4402 * possibly substituting the given {@link #LABEL} value 4403 * for {@link #TYPE_CUSTOM}. 4404 */ 4405 public static final CharSequence getTypeLabel(Resources res, int type, 4406 CharSequence label) { 4407 if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) { 4408 return label; 4409 } else { 4410 final int labelRes = getTypeLabelResource(type); 4411 return res.getText(labelRes); 4412 } 4413 } 4414 } 4415 4416 /** 4417 * <p> 4418 * A data kind representing an IM address 4419 * </p> 4420 * <p> 4421 * You can use all columns defined for {@link ContactsContract.Data} as 4422 * well as the following aliases. 4423 * </p> 4424 * <h2>Column aliases</h2> 4425 * <table class="jd-sumtable"> 4426 * <tr> 4427 * <th>Type</th> 4428 * <th>Alias</th><th colspan='2'>Data column</th> 4429 * </tr> 4430 * <tr> 4431 * <td>String</td> 4432 * <td>{@link #DATA}</td> 4433 * <td>{@link #DATA1}</td> 4434 * <td></td> 4435 * </tr> 4436 * <tr> 4437 * <td>int</td> 4438 * <td>{@link #TYPE}</td> 4439 * <td>{@link #DATA2}</td> 4440 * <td>Allowed values are: 4441 * <p> 4442 * <ul> 4443 * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li> 4444 * <li>{@link #TYPE_HOME}</li> 4445 * <li>{@link #TYPE_WORK}</li> 4446 * <li>{@link #TYPE_OTHER}</li> 4447 * </ul> 4448 * </p> 4449 * </td> 4450 * </tr> 4451 * <tr> 4452 * <td>String</td> 4453 * <td>{@link #LABEL}</td> 4454 * <td>{@link #DATA3}</td> 4455 * <td></td> 4456 * </tr> 4457 * <tr> 4458 * <td>String</td> 4459 * <td>{@link #PROTOCOL}</td> 4460 * <td>{@link #DATA5}</td> 4461 * <td> 4462 * <p> 4463 * Allowed values: 4464 * <ul> 4465 * <li>{@link #PROTOCOL_CUSTOM}. Also provide the actual protocol name 4466 * as {@link #CUSTOM_PROTOCOL}.</li> 4467 * <li>{@link #PROTOCOL_AIM}</li> 4468 * <li>{@link #PROTOCOL_MSN}</li> 4469 * <li>{@link #PROTOCOL_YAHOO}</li> 4470 * <li>{@link #PROTOCOL_SKYPE}</li> 4471 * <li>{@link #PROTOCOL_QQ}</li> 4472 * <li>{@link #PROTOCOL_GOOGLE_TALK}</li> 4473 * <li>{@link #PROTOCOL_ICQ}</li> 4474 * <li>{@link #PROTOCOL_JABBER}</li> 4475 * <li>{@link #PROTOCOL_NETMEETING}</li> 4476 * </ul> 4477 * </p> 4478 * </td> 4479 * </tr> 4480 * <tr> 4481 * <td>String</td> 4482 * <td>{@link #CUSTOM_PROTOCOL}</td> 4483 * <td>{@link #DATA6}</td> 4484 * <td></td> 4485 * </tr> 4486 * </table> 4487 */ 4488 public static final class Im implements DataColumnsWithJoins, CommonColumns { 4489 /** 4490 * This utility class cannot be instantiated 4491 */ 4492 private Im() {} 4493 4494 /** MIME type used when storing this in data table. */ 4495 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/im"; 4496 4497 public static final int TYPE_HOME = 1; 4498 public static final int TYPE_WORK = 2; 4499 public static final int TYPE_OTHER = 3; 4500 4501 /** 4502 * This column should be populated with one of the defined 4503 * constants, e.g. {@link #PROTOCOL_YAHOO}. If the value of this 4504 * column is {@link #PROTOCOL_CUSTOM}, the {@link #CUSTOM_PROTOCOL} 4505 * should contain the name of the custom protocol. 4506 */ 4507 public static final String PROTOCOL = DATA5; 4508 4509 public static final String CUSTOM_PROTOCOL = DATA6; 4510 4511 /* 4512 * The predefined IM protocol types. 4513 */ 4514 public static final int PROTOCOL_CUSTOM = -1; 4515 public static final int PROTOCOL_AIM = 0; 4516 public static final int PROTOCOL_MSN = 1; 4517 public static final int PROTOCOL_YAHOO = 2; 4518 public static final int PROTOCOL_SKYPE = 3; 4519 public static final int PROTOCOL_QQ = 4; 4520 public static final int PROTOCOL_GOOGLE_TALK = 5; 4521 public static final int PROTOCOL_ICQ = 6; 4522 public static final int PROTOCOL_JABBER = 7; 4523 public static final int PROTOCOL_NETMEETING = 8; 4524 4525 /** 4526 * Return the string resource that best describes the given 4527 * {@link #TYPE}. Will always return a valid resource. 4528 */ 4529 public static final int getTypeLabelResource(int type) { 4530 switch (type) { 4531 case TYPE_HOME: return com.android.internal.R.string.imTypeHome; 4532 case TYPE_WORK: return com.android.internal.R.string.imTypeWork; 4533 case TYPE_OTHER: return com.android.internal.R.string.imTypeOther; 4534 default: return com.android.internal.R.string.imTypeCustom; 4535 } 4536 } 4537 4538 /** 4539 * Return a {@link CharSequence} that best describes the given type, 4540 * possibly substituting the given {@link #LABEL} value 4541 * for {@link #TYPE_CUSTOM}. 4542 */ 4543 public static final CharSequence getTypeLabel(Resources res, int type, 4544 CharSequence label) { 4545 if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) { 4546 return label; 4547 } else { 4548 final int labelRes = getTypeLabelResource(type); 4549 return res.getText(labelRes); 4550 } 4551 } 4552 4553 /** 4554 * Return the string resource that best describes the given 4555 * {@link #PROTOCOL}. Will always return a valid resource. 4556 */ 4557 public static final int getProtocolLabelResource(int type) { 4558 switch (type) { 4559 case PROTOCOL_AIM: return com.android.internal.R.string.imProtocolAim; 4560 case PROTOCOL_MSN: return com.android.internal.R.string.imProtocolMsn; 4561 case PROTOCOL_YAHOO: return com.android.internal.R.string.imProtocolYahoo; 4562 case PROTOCOL_SKYPE: return com.android.internal.R.string.imProtocolSkype; 4563 case PROTOCOL_QQ: return com.android.internal.R.string.imProtocolQq; 4564 case PROTOCOL_GOOGLE_TALK: return com.android.internal.R.string.imProtocolGoogleTalk; 4565 case PROTOCOL_ICQ: return com.android.internal.R.string.imProtocolIcq; 4566 case PROTOCOL_JABBER: return com.android.internal.R.string.imProtocolJabber; 4567 case PROTOCOL_NETMEETING: return com.android.internal.R.string.imProtocolNetMeeting; 4568 default: return com.android.internal.R.string.imProtocolCustom; 4569 } 4570 } 4571 4572 /** 4573 * Return a {@link CharSequence} that best describes the given 4574 * protocol, possibly substituting the given 4575 * {@link #CUSTOM_PROTOCOL} value for {@link #PROTOCOL_CUSTOM}. 4576 */ 4577 public static final CharSequence getProtocolLabel(Resources res, int type, 4578 CharSequence label) { 4579 if (type == PROTOCOL_CUSTOM && !TextUtils.isEmpty(label)) { 4580 return label; 4581 } else { 4582 final int labelRes = getProtocolLabelResource(type); 4583 return res.getText(labelRes); 4584 } 4585 } 4586 } 4587 4588 /** 4589 * <p> 4590 * A data kind representing an organization. 4591 * </p> 4592 * <p> 4593 * You can use all columns defined for {@link ContactsContract.Data} as 4594 * well as the following aliases. 4595 * </p> 4596 * <h2>Column aliases</h2> 4597 * <table class="jd-sumtable"> 4598 * <tr> 4599 * <th>Type</th> 4600 * <th>Alias</th><th colspan='2'>Data column</th> 4601 * </tr> 4602 * <tr> 4603 * <td>String</td> 4604 * <td>{@link #COMPANY}</td> 4605 * <td>{@link #DATA1}</td> 4606 * <td></td> 4607 * </tr> 4608 * <tr> 4609 * <td>int</td> 4610 * <td>{@link #TYPE}</td> 4611 * <td>{@link #DATA2}</td> 4612 * <td>Allowed values are: 4613 * <p> 4614 * <ul> 4615 * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li> 4616 * <li>{@link #TYPE_WORK}</li> 4617 * <li>{@link #TYPE_OTHER}</li> 4618 * </ul> 4619 * </p> 4620 * </td> 4621 * </tr> 4622 * <tr> 4623 * <td>String</td> 4624 * <td>{@link #LABEL}</td> 4625 * <td>{@link #DATA3}</td> 4626 * <td></td> 4627 * </tr> 4628 * <tr> 4629 * <td>String</td> 4630 * <td>{@link #TITLE}</td> 4631 * <td>{@link #DATA4}</td> 4632 * <td></td> 4633 * </tr> 4634 * <tr> 4635 * <td>String</td> 4636 * <td>{@link #DEPARTMENT}</td> 4637 * <td>{@link #DATA5}</td> 4638 * <td></td> 4639 * </tr> 4640 * <tr> 4641 * <td>String</td> 4642 * <td>{@link #JOB_DESCRIPTION}</td> 4643 * <td>{@link #DATA6}</td> 4644 * <td></td> 4645 * </tr> 4646 * <tr> 4647 * <td>String</td> 4648 * <td>{@link #SYMBOL}</td> 4649 * <td>{@link #DATA7}</td> 4650 * <td></td> 4651 * </tr> 4652 * <tr> 4653 * <td>String</td> 4654 * <td>{@link #PHONETIC_NAME}</td> 4655 * <td>{@link #DATA8}</td> 4656 * <td></td> 4657 * </tr> 4658 * <tr> 4659 * <td>String</td> 4660 * <td>{@link #OFFICE_LOCATION}</td> 4661 * <td>{@link #DATA9}</td> 4662 * <td></td> 4663 * </tr> 4664 * <tr> 4665 * <td>String</td> 4666 * <td>PHONETIC_NAME_STYLE</td> 4667 * <td>{@link #DATA10}</td> 4668 * <td></td> 4669 * </tr> 4670 * </table> 4671 */ 4672 public static final class Organization implements DataColumnsWithJoins, CommonColumns { 4673 /** 4674 * This utility class cannot be instantiated 4675 */ 4676 private Organization() {} 4677 4678 /** MIME type used when storing this in data table. */ 4679 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/organization"; 4680 4681 public static final int TYPE_WORK = 1; 4682 public static final int TYPE_OTHER = 2; 4683 4684 /** 4685 * The company as the user entered it. 4686 * <P>Type: TEXT</P> 4687 */ 4688 public static final String COMPANY = DATA; 4689 4690 /** 4691 * The position title at this company as the user entered it. 4692 * <P>Type: TEXT</P> 4693 */ 4694 public static final String TITLE = DATA4; 4695 4696 /** 4697 * The department at this company as the user entered it. 4698 * <P>Type: TEXT</P> 4699 */ 4700 public static final String DEPARTMENT = DATA5; 4701 4702 /** 4703 * The job description at this company as the user entered it. 4704 * <P>Type: TEXT</P> 4705 */ 4706 public static final String JOB_DESCRIPTION = DATA6; 4707 4708 /** 4709 * The symbol of this company as the user entered it. 4710 * <P>Type: TEXT</P> 4711 */ 4712 public static final String SYMBOL = DATA7; 4713 4714 /** 4715 * The phonetic name of this company as the user entered it. 4716 * <P>Type: TEXT</P> 4717 */ 4718 public static final String PHONETIC_NAME = DATA8; 4719 4720 /** 4721 * The office location of this organization. 4722 * <P>Type: TEXT</P> 4723 */ 4724 public static final String OFFICE_LOCATION = DATA9; 4725 4726 /** 4727 * The alphabet used for capturing the phonetic name. 4728 * See {@link ContactsContract.PhoneticNameStyle}. 4729 * @hide 4730 */ 4731 public static final String PHONETIC_NAME_STYLE = DATA10; 4732 4733 /** 4734 * Return the string resource that best describes the given 4735 * {@link #TYPE}. Will always return a valid resource. 4736 */ 4737 public static final int getTypeLabelResource(int type) { 4738 switch (type) { 4739 case TYPE_WORK: return com.android.internal.R.string.orgTypeWork; 4740 case TYPE_OTHER: return com.android.internal.R.string.orgTypeOther; 4741 default: return com.android.internal.R.string.orgTypeCustom; 4742 } 4743 } 4744 4745 /** 4746 * Return a {@link CharSequence} that best describes the given type, 4747 * possibly substituting the given {@link #LABEL} value 4748 * for {@link #TYPE_CUSTOM}. 4749 */ 4750 public static final CharSequence getTypeLabel(Resources res, int type, 4751 CharSequence label) { 4752 if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) { 4753 return label; 4754 } else { 4755 final int labelRes = getTypeLabelResource(type); 4756 return res.getText(labelRes); 4757 } 4758 } 4759 } 4760 4761 /** 4762 * <p> 4763 * A data kind representing a relation. 4764 * </p> 4765 * <p> 4766 * You can use all columns defined for {@link ContactsContract.Data} as 4767 * well as the following aliases. 4768 * </p> 4769 * <h2>Column aliases</h2> 4770 * <table class="jd-sumtable"> 4771 * <tr> 4772 * <th>Type</th> 4773 * <th>Alias</th><th colspan='2'>Data column</th> 4774 * </tr> 4775 * <tr> 4776 * <td>String</td> 4777 * <td>{@link #NAME}</td> 4778 * <td>{@link #DATA1}</td> 4779 * <td></td> 4780 * </tr> 4781 * <tr> 4782 * <td>int</td> 4783 * <td>{@link #TYPE}</td> 4784 * <td>{@link #DATA2}</td> 4785 * <td>Allowed values are: 4786 * <p> 4787 * <ul> 4788 * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li> 4789 * <li>{@link #TYPE_ASSISTANT}</li> 4790 * <li>{@link #TYPE_BROTHER}</li> 4791 * <li>{@link #TYPE_CHILD}</li> 4792 * <li>{@link #TYPE_DOMESTIC_PARTNER}</li> 4793 * <li>{@link #TYPE_FATHER}</li> 4794 * <li>{@link #TYPE_FRIEND}</li> 4795 * <li>{@link #TYPE_MANAGER}</li> 4796 * <li>{@link #TYPE_MOTHER}</li> 4797 * <li>{@link #TYPE_PARENT}</li> 4798 * <li>{@link #TYPE_PARTNER}</li> 4799 * <li>{@link #TYPE_REFERRED_BY}</li> 4800 * <li>{@link #TYPE_RELATIVE}</li> 4801 * <li>{@link #TYPE_SISTER}</li> 4802 * <li>{@link #TYPE_SPOUSE}</li> 4803 * </ul> 4804 * </p> 4805 * </td> 4806 * </tr> 4807 * <tr> 4808 * <td>String</td> 4809 * <td>{@link #LABEL}</td> 4810 * <td>{@link #DATA3}</td> 4811 * <td></td> 4812 * </tr> 4813 * </table> 4814 */ 4815 public static final class Relation implements DataColumnsWithJoins, CommonColumns { 4816 /** 4817 * This utility class cannot be instantiated 4818 */ 4819 private Relation() {} 4820 4821 /** MIME type used when storing this in data table. */ 4822 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/relation"; 4823 4824 public static final int TYPE_ASSISTANT = 1; 4825 public static final int TYPE_BROTHER = 2; 4826 public static final int TYPE_CHILD = 3; 4827 public static final int TYPE_DOMESTIC_PARTNER = 4; 4828 public static final int TYPE_FATHER = 5; 4829 public static final int TYPE_FRIEND = 6; 4830 public static final int TYPE_MANAGER = 7; 4831 public static final int TYPE_MOTHER = 8; 4832 public static final int TYPE_PARENT = 9; 4833 public static final int TYPE_PARTNER = 10; 4834 public static final int TYPE_REFERRED_BY = 11; 4835 public static final int TYPE_RELATIVE = 12; 4836 public static final int TYPE_SISTER = 13; 4837 public static final int TYPE_SPOUSE = 14; 4838 4839 /** 4840 * The name of the relative as the user entered it. 4841 * <P>Type: TEXT</P> 4842 */ 4843 public static final String NAME = DATA; 4844 } 4845 4846 /** 4847 * <p> 4848 * A data kind representing an event. 4849 * </p> 4850 * <p> 4851 * You can use all columns defined for {@link ContactsContract.Data} as 4852 * well as the following aliases. 4853 * </p> 4854 * <h2>Column aliases</h2> 4855 * <table class="jd-sumtable"> 4856 * <tr> 4857 * <th>Type</th> 4858 * <th>Alias</th><th colspan='2'>Data column</th> 4859 * </tr> 4860 * <tr> 4861 * <td>String</td> 4862 * <td>{@link #START_DATE}</td> 4863 * <td>{@link #DATA1}</td> 4864 * <td></td> 4865 * </tr> 4866 * <tr> 4867 * <td>int</td> 4868 * <td>{@link #TYPE}</td> 4869 * <td>{@link #DATA2}</td> 4870 * <td>Allowed values are: 4871 * <p> 4872 * <ul> 4873 * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li> 4874 * <li>{@link #TYPE_ANNIVERSARY}</li> 4875 * <li>{@link #TYPE_OTHER}</li> 4876 * <li>{@link #TYPE_BIRTHDAY}</li> 4877 * </ul> 4878 * </p> 4879 * </td> 4880 * </tr> 4881 * <tr> 4882 * <td>String</td> 4883 * <td>{@link #LABEL}</td> 4884 * <td>{@link #DATA3}</td> 4885 * <td></td> 4886 * </tr> 4887 * </table> 4888 */ 4889 public static final class Event implements DataColumnsWithJoins, CommonColumns { 4890 /** 4891 * This utility class cannot be instantiated 4892 */ 4893 private Event() {} 4894 4895 /** MIME type used when storing this in data table. */ 4896 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact_event"; 4897 4898 public static final int TYPE_ANNIVERSARY = 1; 4899 public static final int TYPE_OTHER = 2; 4900 public static final int TYPE_BIRTHDAY = 3; 4901 4902 /** 4903 * The event start date as the user entered it. 4904 * <P>Type: TEXT</P> 4905 */ 4906 public static final String START_DATE = DATA; 4907 4908 /** 4909 * Return the string resource that best describes the given 4910 * {@link #TYPE}. Will always return a valid resource. 4911 */ 4912 public static int getTypeResource(Integer type) { 4913 if (type == null) { 4914 return com.android.internal.R.string.eventTypeOther; 4915 } 4916 switch (type) { 4917 case TYPE_ANNIVERSARY: 4918 return com.android.internal.R.string.eventTypeAnniversary; 4919 case TYPE_BIRTHDAY: return com.android.internal.R.string.eventTypeBirthday; 4920 case TYPE_OTHER: return com.android.internal.R.string.eventTypeOther; 4921 default: return com.android.internal.R.string.eventTypeOther; 4922 } 4923 } 4924 } 4925 4926 /** 4927 * <p> 4928 * A data kind representing an photo for the contact. 4929 * </p> 4930 * <p> 4931 * Some sync adapters will choose to download photos in a separate 4932 * pass. A common pattern is to use columns {@link ContactsContract.Data#SYNC1} 4933 * through {@link ContactsContract.Data#SYNC4} to store temporary 4934 * data, e.g. the image URL or ID, state of download, server-side version 4935 * of the image. It is allowed for the {@link #PHOTO} to be null. 4936 * </p> 4937 * <p> 4938 * You can use all columns defined for {@link ContactsContract.Data} as 4939 * well as the following aliases. 4940 * </p> 4941 * <h2>Column aliases</h2> 4942 * <table class="jd-sumtable"> 4943 * <tr> 4944 * <th>Type</th> 4945 * <th>Alias</th><th colspan='2'>Data column</th> 4946 * </tr> 4947 * <tr> 4948 * <td>BLOB</td> 4949 * <td>{@link #PHOTO}</td> 4950 * <td>{@link #DATA15}</td> 4951 * <td>By convention, binary data is stored in DATA15.</td> 4952 * </tr> 4953 * </table> 4954 */ 4955 public static final class Photo implements DataColumnsWithJoins { 4956 /** 4957 * This utility class cannot be instantiated 4958 */ 4959 private Photo() {} 4960 4961 /** MIME type used when storing this in data table. */ 4962 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/photo"; 4963 4964 /** 4965 * Thumbnail photo of the raw contact. This is the raw bytes of an image 4966 * that could be inflated using {@link android.graphics.BitmapFactory}. 4967 * <p> 4968 * Type: BLOB 4969 */ 4970 public static final String PHOTO = DATA15; 4971 } 4972 4973 /** 4974 * <p> 4975 * Notes about the contact. 4976 * </p> 4977 * <p> 4978 * You can use all columns defined for {@link ContactsContract.Data} as 4979 * well as the following aliases. 4980 * </p> 4981 * <h2>Column aliases</h2> 4982 * <table class="jd-sumtable"> 4983 * <tr> 4984 * <th>Type</th> 4985 * <th>Alias</th><th colspan='2'>Data column</th> 4986 * </tr> 4987 * <tr> 4988 * <td>String</td> 4989 * <td>{@link #NOTE}</td> 4990 * <td>{@link #DATA1}</td> 4991 * <td></td> 4992 * </tr> 4993 * </table> 4994 */ 4995 public static final class Note implements DataColumnsWithJoins { 4996 /** 4997 * This utility class cannot be instantiated 4998 */ 4999 private Note() {} 5000 5001 /** MIME type used when storing this in data table. */ 5002 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/note"; 5003 5004 /** 5005 * The note text. 5006 * <P>Type: TEXT</P> 5007 */ 5008 public static final String NOTE = DATA1; 5009 } 5010 5011 /** 5012 * <p> 5013 * Group Membership. 5014 * </p> 5015 * <p> 5016 * You can use all columns defined for {@link ContactsContract.Data} as 5017 * well as the following aliases. 5018 * </p> 5019 * <h2>Column aliases</h2> 5020 * <table class="jd-sumtable"> 5021 * <tr> 5022 * <th>Type</th> 5023 * <th>Alias</th><th colspan='2'>Data column</th> 5024 * </tr> 5025 * <tr> 5026 * <td>long</td> 5027 * <td>{@link #GROUP_ROW_ID}</td> 5028 * <td>{@link #DATA1}</td> 5029 * <td></td> 5030 * </tr> 5031 * <tr> 5032 * <td>String</td> 5033 * <td>{@link #GROUP_SOURCE_ID}</td> 5034 * <td>none</td> 5035 * <td> 5036 * <p> 5037 * The sourceid of the group that this group membership refers to. 5038 * Exactly one of this or {@link #GROUP_ROW_ID} must be set when 5039 * inserting a row. 5040 * </p> 5041 * <p> 5042 * If this field is specified, the provider will first try to 5043 * look up a group with this {@link Groups Groups.SOURCE_ID}. If such a group 5044 * is found, it will use the corresponding row id. If the group is not 5045 * found, it will create one. 5046 * </td> 5047 * </tr> 5048 * </table> 5049 */ 5050 public static final class GroupMembership implements DataColumnsWithJoins { 5051 /** 5052 * This utility class cannot be instantiated 5053 */ 5054 private GroupMembership() {} 5055 5056 /** MIME type used when storing this in data table. */ 5057 public static final String CONTENT_ITEM_TYPE = 5058 "vnd.android.cursor.item/group_membership"; 5059 5060 /** 5061 * The row id of the group that this group membership refers to. Exactly one of 5062 * this or {@link #GROUP_SOURCE_ID} must be set when inserting a row. 5063 * <P>Type: INTEGER</P> 5064 */ 5065 public static final String GROUP_ROW_ID = DATA1; 5066 5067 /** 5068 * The sourceid of the group that this group membership refers to. Exactly one of 5069 * this or {@link #GROUP_ROW_ID} must be set when inserting a row. 5070 * <P>Type: TEXT</P> 5071 */ 5072 public static final String GROUP_SOURCE_ID = "group_sourceid"; 5073 } 5074 5075 /** 5076 * <p> 5077 * A data kind representing a website related to the contact. 5078 * </p> 5079 * <p> 5080 * You can use all columns defined for {@link ContactsContract.Data} as 5081 * well as the following aliases. 5082 * </p> 5083 * <h2>Column aliases</h2> 5084 * <table class="jd-sumtable"> 5085 * <tr> 5086 * <th>Type</th> 5087 * <th>Alias</th><th colspan='2'>Data column</th> 5088 * </tr> 5089 * <tr> 5090 * <td>String</td> 5091 * <td>{@link #URL}</td> 5092 * <td>{@link #DATA1}</td> 5093 * <td></td> 5094 * </tr> 5095 * <tr> 5096 * <td>int</td> 5097 * <td>{@link #TYPE}</td> 5098 * <td>{@link #DATA2}</td> 5099 * <td>Allowed values are: 5100 * <p> 5101 * <ul> 5102 * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li> 5103 * <li>{@link #TYPE_HOMEPAGE}</li> 5104 * <li>{@link #TYPE_BLOG}</li> 5105 * <li>{@link #TYPE_PROFILE}</li> 5106 * <li>{@link #TYPE_HOME}</li> 5107 * <li>{@link #TYPE_WORK}</li> 5108 * <li>{@link #TYPE_FTP}</li> 5109 * <li>{@link #TYPE_OTHER}</li> 5110 * </ul> 5111 * </p> 5112 * </td> 5113 * </tr> 5114 * <tr> 5115 * <td>String</td> 5116 * <td>{@link #LABEL}</td> 5117 * <td>{@link #DATA3}</td> 5118 * <td></td> 5119 * </tr> 5120 * </table> 5121 */ 5122 public static final class Website implements DataColumnsWithJoins, CommonColumns { 5123 /** 5124 * This utility class cannot be instantiated 5125 */ 5126 private Website() {} 5127 5128 /** MIME type used when storing this in data table. */ 5129 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/website"; 5130 5131 public static final int TYPE_HOMEPAGE = 1; 5132 public static final int TYPE_BLOG = 2; 5133 public static final int TYPE_PROFILE = 3; 5134 public static final int TYPE_HOME = 4; 5135 public static final int TYPE_WORK = 5; 5136 public static final int TYPE_FTP = 6; 5137 public static final int TYPE_OTHER = 7; 5138 5139 /** 5140 * The website URL string. 5141 * <P>Type: TEXT</P> 5142 */ 5143 public static final String URL = DATA; 5144 } 5145 } 5146 5147 /** 5148 * @see Groups 5149 */ 5150 protected interface GroupsColumns { 5151 /** 5152 * The display title of this group. 5153 * <p> 5154 * Type: TEXT 5155 */ 5156 public static final String TITLE = "title"; 5157 5158 /** 5159 * The package name to use when creating {@link Resources} objects for 5160 * this group. This value is only designed for use when building user 5161 * interfaces, and should not be used to infer the owner. 5162 * 5163 * @hide 5164 */ 5165 public static final String RES_PACKAGE = "res_package"; 5166 5167 /** 5168 * The display title of this group to load as a resource from 5169 * {@link #RES_PACKAGE}, which may be localized. 5170 * <P>Type: TEXT</P> 5171 * 5172 * @hide 5173 */ 5174 public static final String TITLE_RES = "title_res"; 5175 5176 /** 5177 * Notes about the group. 5178 * <p> 5179 * Type: TEXT 5180 */ 5181 public static final String NOTES = "notes"; 5182 5183 /** 5184 * The ID of this group if it is a System Group, i.e. a group that has a special meaning 5185 * to the sync adapter, null otherwise. 5186 * <P>Type: TEXT</P> 5187 */ 5188 public static final String SYSTEM_ID = "system_id"; 5189 5190 /** 5191 * The total number of {@link Contacts} that have 5192 * {@link CommonDataKinds.GroupMembership} in this group. Read-only value that is only 5193 * present when querying {@link Groups#CONTENT_SUMMARY_URI}. 5194 * <p> 5195 * Type: INTEGER 5196 */ 5197 public static final String SUMMARY_COUNT = "summ_count"; 5198 5199 /** 5200 * The total number of {@link Contacts} that have both 5201 * {@link CommonDataKinds.GroupMembership} in this group, and also have phone numbers. 5202 * Read-only value that is only present when querying 5203 * {@link Groups#CONTENT_SUMMARY_URI}. 5204 * <p> 5205 * Type: INTEGER 5206 */ 5207 public static final String SUMMARY_WITH_PHONES = "summ_phones"; 5208 5209 /** 5210 * Flag indicating if the contacts belonging to this group should be 5211 * visible in any user interface. 5212 * <p> 5213 * Type: INTEGER (boolean) 5214 */ 5215 public static final String GROUP_VISIBLE = "group_visible"; 5216 5217 /** 5218 * The "deleted" flag: "0" by default, "1" if the row has been marked 5219 * for deletion. When {@link android.content.ContentResolver#delete} is 5220 * called on a group, it is marked for deletion. The sync adaptor 5221 * deletes the group on the server and then calls ContactResolver.delete 5222 * once more, this time setting the the 5223 * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to 5224 * finalize the data removal. 5225 * <P>Type: INTEGER</P> 5226 */ 5227 public static final String DELETED = "deleted"; 5228 5229 /** 5230 * Whether this group should be synced if the SYNC_EVERYTHING settings 5231 * is false for this group's account. 5232 * <p> 5233 * Type: INTEGER (boolean) 5234 */ 5235 public static final String SHOULD_SYNC = "should_sync"; 5236 5237 /** 5238 * Any newly created contacts will automatically be added to groups that have this 5239 * flag set to true. 5240 * <p> 5241 * Type: INTEGER (boolean) 5242 */ 5243 public static final String AUTO_ADD = "auto_add"; 5244 5245 /** 5246 * When a contacts is marked as a favorites it will be automatically added 5247 * to the groups that have this flag set, and when it is removed from favorites 5248 * it will be removed from these groups. 5249 * <p> 5250 * Type: INTEGER (boolean) 5251 */ 5252 public static final String FAVORITES = "favorites"; 5253 } 5254 5255 /** 5256 * Constants for the groups table. Only per-account groups are supported. 5257 * <h2>Columns</h2> 5258 * <table class="jd-sumtable"> 5259 * <tr> 5260 * <th colspan='4'>Groups</th> 5261 * </tr> 5262 * <tr> 5263 * <td>long</td> 5264 * <td>{@link #_ID}</td> 5265 * <td>read-only</td> 5266 * <td>Row ID. Sync adapter should try to preserve row IDs during updates. 5267 * In other words, it would be a really bad idea to delete and reinsert a 5268 * group. A sync adapter should always do an update instead.</td> 5269 * </tr> 5270 * <tr> 5271 * <td>String</td> 5272 * <td>{@link #TITLE}</td> 5273 * <td>read/write</td> 5274 * <td>The display title of this group.</td> 5275 * </tr> 5276 * <tr> 5277 * <td>String</td> 5278 * <td>{@link #NOTES}</td> 5279 * <td>read/write</td> 5280 * <td>Notes about the group.</td> 5281 * </tr> 5282 * <tr> 5283 * <td>String</td> 5284 * <td>{@link #SYSTEM_ID}</td> 5285 * <td>read/write</td> 5286 * <td>The ID of this group if it is a System Group, i.e. a group that has a 5287 * special meaning to the sync adapter, null otherwise.</td> 5288 * </tr> 5289 * <tr> 5290 * <td>int</td> 5291 * <td>{@link #SUMMARY_COUNT}</td> 5292 * <td>read-only</td> 5293 * <td>The total number of {@link Contacts} that have 5294 * {@link CommonDataKinds.GroupMembership} in this group. Read-only value 5295 * that is only present when querying {@link Groups#CONTENT_SUMMARY_URI}.</td> 5296 * </tr> 5297 * <tr> 5298 * <td>int</td> 5299 * <td>{@link #SUMMARY_WITH_PHONES}</td> 5300 * <td>read-only</td> 5301 * <td>The total number of {@link Contacts} that have both 5302 * {@link CommonDataKinds.GroupMembership} in this group, and also have 5303 * phone numbers. Read-only value that is only present when querying 5304 * {@link Groups#CONTENT_SUMMARY_URI}.</td> 5305 * </tr> 5306 * <tr> 5307 * <td>int</td> 5308 * <td>{@link #GROUP_VISIBLE}</td> 5309 * <td>read-only</td> 5310 * <td>Flag indicating if the contacts belonging to this group should be 5311 * visible in any user interface. Allowed values: 0 and 1.</td> 5312 * </tr> 5313 * <tr> 5314 * <td>int</td> 5315 * <td>{@link #DELETED}</td> 5316 * <td>read/write</td> 5317 * <td>The "deleted" flag: "0" by default, "1" if the row has been marked 5318 * for deletion. When {@link android.content.ContentResolver#delete} is 5319 * called on a group, it is marked for deletion. The sync adaptor deletes 5320 * the group on the server and then calls ContactResolver.delete once more, 5321 * this time setting the the {@link ContactsContract#CALLER_IS_SYNCADAPTER} 5322 * query parameter to finalize the data removal.</td> 5323 * </tr> 5324 * <tr> 5325 * <td>int</td> 5326 * <td>{@link #SHOULD_SYNC}</td> 5327 * <td>read/write</td> 5328 * <td>Whether this group should be synced if the SYNC_EVERYTHING settings 5329 * is false for this group's account.</td> 5330 * </tr> 5331 * </table> 5332 */ 5333 public static final class Groups implements BaseColumns, GroupsColumns, SyncColumns { 5334 /** 5335 * This utility class cannot be instantiated 5336 */ 5337 private Groups() { 5338 } 5339 5340 /** 5341 * The content:// style URI for this table 5342 */ 5343 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "groups"); 5344 5345 /** 5346 * The content:// style URI for this table joined with details data from 5347 * {@link ContactsContract.Data}. 5348 */ 5349 public static final Uri CONTENT_SUMMARY_URI = Uri.withAppendedPath(AUTHORITY_URI, 5350 "groups_summary"); 5351 5352 /** 5353 * The MIME type of a directory of groups. 5354 */ 5355 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/group"; 5356 5357 /** 5358 * The MIME type of a single group. 5359 */ 5360 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/group"; 5361 5362 public static EntityIterator newEntityIterator(Cursor cursor) { 5363 return new EntityIteratorImpl(cursor); 5364 } 5365 5366 private static class EntityIteratorImpl extends CursorEntityIterator { 5367 public EntityIteratorImpl(Cursor cursor) { 5368 super(cursor); 5369 } 5370 5371 @Override 5372 public Entity getEntityAndIncrementCursor(Cursor cursor) throws RemoteException { 5373 // we expect the cursor is already at the row we need to read from 5374 final ContentValues values = new ContentValues(); 5375 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, _ID); 5376 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, ACCOUNT_NAME); 5377 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, ACCOUNT_TYPE); 5378 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, DIRTY); 5379 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, VERSION); 5380 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SOURCE_ID); 5381 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, RES_PACKAGE); 5382 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, TITLE); 5383 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, TITLE_RES); 5384 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, GROUP_VISIBLE); 5385 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC1); 5386 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC2); 5387 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC3); 5388 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC4); 5389 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYSTEM_ID); 5390 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, DELETED); 5391 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, NOTES); 5392 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SHOULD_SYNC); 5393 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, FAVORITES); 5394 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, AUTO_ADD); 5395 cursor.moveToNext(); 5396 return new Entity(values); 5397 } 5398 } 5399 } 5400 5401 /** 5402 * <p> 5403 * Constants for the contact aggregation exceptions table, which contains 5404 * aggregation rules overriding those used by automatic aggregation. This 5405 * type only supports query and update. Neither insert nor delete are 5406 * supported. 5407 * </p> 5408 * <h2>Columns</h2> 5409 * <table class="jd-sumtable"> 5410 * <tr> 5411 * <th colspan='4'>AggregationExceptions</th> 5412 * </tr> 5413 * <tr> 5414 * <td>int</td> 5415 * <td>{@link #TYPE}</td> 5416 * <td>read/write</td> 5417 * <td>The type of exception: {@link #TYPE_KEEP_TOGETHER}, 5418 * {@link #TYPE_KEEP_SEPARATE} or {@link #TYPE_AUTOMATIC}.</td> 5419 * </tr> 5420 * <tr> 5421 * <td>long</td> 5422 * <td>{@link #RAW_CONTACT_ID1}</td> 5423 * <td>read/write</td> 5424 * <td>A reference to the {@link RawContacts#_ID} of the raw contact that 5425 * the rule applies to.</td> 5426 * </tr> 5427 * <tr> 5428 * <td>long</td> 5429 * <td>{@link #RAW_CONTACT_ID2}</td> 5430 * <td>read/write</td> 5431 * <td>A reference to the other {@link RawContacts#_ID} of the raw contact 5432 * that the rule applies to.</td> 5433 * </tr> 5434 * </table> 5435 */ 5436 public static final class AggregationExceptions implements BaseColumns { 5437 /** 5438 * This utility class cannot be instantiated 5439 */ 5440 private AggregationExceptions() {} 5441 5442 /** 5443 * The content:// style URI for this table 5444 */ 5445 public static final Uri CONTENT_URI = 5446 Uri.withAppendedPath(AUTHORITY_URI, "aggregation_exceptions"); 5447 5448 /** 5449 * The MIME type of {@link #CONTENT_URI} providing a directory of data. 5450 */ 5451 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/aggregation_exception"; 5452 5453 /** 5454 * The MIME type of a {@link #CONTENT_URI} subdirectory of an aggregation exception 5455 */ 5456 public static final String CONTENT_ITEM_TYPE = 5457 "vnd.android.cursor.item/aggregation_exception"; 5458 5459 /** 5460 * The type of exception: {@link #TYPE_KEEP_TOGETHER}, {@link #TYPE_KEEP_SEPARATE} or 5461 * {@link #TYPE_AUTOMATIC}. 5462 * 5463 * <P>Type: INTEGER</P> 5464 */ 5465 public static final String TYPE = "type"; 5466 5467 /** 5468 * Allows the provider to automatically decide whether the specified raw contacts should 5469 * be included in the same aggregate contact or not. 5470 */ 5471 public static final int TYPE_AUTOMATIC = 0; 5472 5473 /** 5474 * Makes sure that the specified raw contacts are included in the same 5475 * aggregate contact. 5476 */ 5477 public static final int TYPE_KEEP_TOGETHER = 1; 5478 5479 /** 5480 * Makes sure that the specified raw contacts are NOT included in the same 5481 * aggregate contact. 5482 */ 5483 public static final int TYPE_KEEP_SEPARATE = 2; 5484 5485 /** 5486 * A reference to the {@link RawContacts#_ID} of the raw contact that the rule applies to. 5487 */ 5488 public static final String RAW_CONTACT_ID1 = "raw_contact_id1"; 5489 5490 /** 5491 * A reference to the other {@link RawContacts#_ID} of the raw contact that the rule 5492 * applies to. 5493 */ 5494 public static final String RAW_CONTACT_ID2 = "raw_contact_id2"; 5495 } 5496 5497 /** 5498 * @see Settings 5499 */ 5500 protected interface SettingsColumns { 5501 /** 5502 * The name of the account instance to which this row belongs. 5503 * <P>Type: TEXT</P> 5504 */ 5505 public static final String ACCOUNT_NAME = "account_name"; 5506 5507 /** 5508 * The type of account to which this row belongs, which when paired with 5509 * {@link #ACCOUNT_NAME} identifies a specific account. 5510 * <P>Type: TEXT</P> 5511 */ 5512 public static final String ACCOUNT_TYPE = "account_type"; 5513 5514 /** 5515 * Depending on the mode defined by the sync-adapter, this flag controls 5516 * the top-level sync behavior for this data source. 5517 * <p> 5518 * Type: INTEGER (boolean) 5519 */ 5520 public static final String SHOULD_SYNC = "should_sync"; 5521 5522 /** 5523 * Flag indicating if contacts without any {@link CommonDataKinds.GroupMembership} 5524 * entries should be visible in any user interface. 5525 * <p> 5526 * Type: INTEGER (boolean) 5527 */ 5528 public static final String UNGROUPED_VISIBLE = "ungrouped_visible"; 5529 5530 /** 5531 * Read-only flag indicating if this {@link #SHOULD_SYNC} or any 5532 * {@link Groups#SHOULD_SYNC} under this account have been marked as 5533 * unsynced. 5534 */ 5535 public static final String ANY_UNSYNCED = "any_unsynced"; 5536 5537 /** 5538 * Read-only count of {@link Contacts} from a specific source that have 5539 * no {@link CommonDataKinds.GroupMembership} entries. 5540 * <p> 5541 * Type: INTEGER 5542 */ 5543 public static final String UNGROUPED_COUNT = "summ_count"; 5544 5545 /** 5546 * Read-only count of {@link Contacts} from a specific source that have 5547 * no {@link CommonDataKinds.GroupMembership} entries, and also have phone numbers. 5548 * <p> 5549 * Type: INTEGER 5550 */ 5551 public static final String UNGROUPED_WITH_PHONES = "summ_phones"; 5552 } 5553 5554 /** 5555 * <p> 5556 * Contacts-specific settings for various {@link Account}'s. 5557 * </p> 5558 * <h2>Columns</h2> 5559 * <table class="jd-sumtable"> 5560 * <tr> 5561 * <th colspan='4'>Settings</th> 5562 * </tr> 5563 * <tr> 5564 * <td>String</td> 5565 * <td>{@link #ACCOUNT_NAME}</td> 5566 * <td>read/write-once</td> 5567 * <td>The name of the account instance to which this row belongs.</td> 5568 * </tr> 5569 * <tr> 5570 * <td>String</td> 5571 * <td>{@link #ACCOUNT_TYPE}</td> 5572 * <td>read/write-once</td> 5573 * <td>The type of account to which this row belongs, which when paired with 5574 * {@link #ACCOUNT_NAME} identifies a specific account.</td> 5575 * </tr> 5576 * <tr> 5577 * <td>int</td> 5578 * <td>{@link #SHOULD_SYNC}</td> 5579 * <td>read/write</td> 5580 * <td>Depending on the mode defined by the sync-adapter, this flag controls 5581 * the top-level sync behavior for this data source.</td> 5582 * </tr> 5583 * <tr> 5584 * <td>int</td> 5585 * <td>{@link #UNGROUPED_VISIBLE}</td> 5586 * <td>read/write</td> 5587 * <td>Flag indicating if contacts without any 5588 * {@link CommonDataKinds.GroupMembership} entries should be visible in any 5589 * user interface.</td> 5590 * </tr> 5591 * <tr> 5592 * <td>int</td> 5593 * <td>{@link #ANY_UNSYNCED}</td> 5594 * <td>read-only</td> 5595 * <td>Read-only flag indicating if this {@link #SHOULD_SYNC} or any 5596 * {@link Groups#SHOULD_SYNC} under this account have been marked as 5597 * unsynced.</td> 5598 * </tr> 5599 * <tr> 5600 * <td>int</td> 5601 * <td>{@link #UNGROUPED_COUNT}</td> 5602 * <td>read-only</td> 5603 * <td>Read-only count of {@link Contacts} from a specific source that have 5604 * no {@link CommonDataKinds.GroupMembership} entries.</td> 5605 * </tr> 5606 * <tr> 5607 * <td>int</td> 5608 * <td>{@link #UNGROUPED_WITH_PHONES}</td> 5609 * <td>read-only</td> 5610 * <td>Read-only count of {@link Contacts} from a specific source that have 5611 * no {@link CommonDataKinds.GroupMembership} entries, and also have phone 5612 * numbers.</td> 5613 * </tr> 5614 * </table> 5615 */ 5616 public static final class Settings implements SettingsColumns { 5617 /** 5618 * This utility class cannot be instantiated 5619 */ 5620 private Settings() { 5621 } 5622 5623 /** 5624 * The content:// style URI for this table 5625 */ 5626 public static final Uri CONTENT_URI = 5627 Uri.withAppendedPath(AUTHORITY_URI, "settings"); 5628 5629 /** 5630 * The MIME-type of {@link #CONTENT_URI} providing a directory of 5631 * settings. 5632 */ 5633 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/setting"; 5634 5635 /** 5636 * The MIME-type of {@link #CONTENT_URI} providing a single setting. 5637 */ 5638 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/setting"; 5639 } 5640 5641 /** 5642 * Private API for inquiring about the general status of the provider. 5643 * 5644 * @hide 5645 */ 5646 public static final class ProviderStatus { 5647 5648 /** 5649 * Not instantiable. 5650 */ 5651 private ProviderStatus() { 5652 } 5653 5654 /** 5655 * The content:// style URI for this table. Requests to this URI can be 5656 * performed on the UI thread because they are always unblocking. 5657 * 5658 * @hide 5659 */ 5660 public static final Uri CONTENT_URI = 5661 Uri.withAppendedPath(AUTHORITY_URI, "provider_status"); 5662 5663 /** 5664 * The MIME-type of {@link #CONTENT_URI} providing a directory of 5665 * settings. 5666 * 5667 * @hide 5668 */ 5669 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/provider_status"; 5670 5671 /** 5672 * An integer representing the current status of the provider. 5673 * 5674 * @hide 5675 */ 5676 public static final String STATUS = "status"; 5677 5678 /** 5679 * Default status of the provider. 5680 * 5681 * @hide 5682 */ 5683 public static final int STATUS_NORMAL = 0; 5684 5685 /** 5686 * The status used when the provider is in the process of upgrading. Contacts 5687 * are temporarily unaccessible. 5688 * 5689 * @hide 5690 */ 5691 public static final int STATUS_UPGRADING = 1; 5692 5693 /** 5694 * The status used if the provider was in the process of upgrading but ran 5695 * out of storage. The DATA1 column will contain the estimated amount of 5696 * storage required (in bytes). Update status to STATUS_NORMAL to force 5697 * the provider to retry the upgrade. 5698 * 5699 * @hide 5700 */ 5701 public static final int STATUS_UPGRADE_OUT_OF_MEMORY = 2; 5702 5703 /** 5704 * The status used during a locale change. 5705 * 5706 * @hide 5707 */ 5708 public static final int STATUS_CHANGING_LOCALE = 3; 5709 5710 /** 5711 * Additional data associated with the status. 5712 * 5713 * @hide 5714 */ 5715 public static final String DATA1 = "data1"; 5716 } 5717 5718 /** 5719 * Helper methods to display QuickContact dialogs that allow users to pivot on 5720 * a specific {@link Contacts} entry. 5721 */ 5722 public static final class QuickContact { 5723 /** 5724 * Action used to trigger person pivot dialog. 5725 * @hide 5726 */ 5727 public static final String ACTION_QUICK_CONTACT = 5728 "com.android.contacts.action.QUICK_CONTACT"; 5729 5730 /** 5731 * Extra used to specify pivot dialog location in screen coordinates. 5732 * @deprecated Use {@link Intent#setSourceBounds(Rect)} instead. 5733 * @hide 5734 */ 5735 @Deprecated 5736 public static final String EXTRA_TARGET_RECT = "target_rect"; 5737 5738 /** 5739 * Extra used to specify size of pivot dialog. 5740 * @hide 5741 */ 5742 public static final String EXTRA_MODE = "mode"; 5743 5744 /** 5745 * Extra used to indicate a list of specific MIME-types to exclude and 5746 * not display. Stored as a {@link String} array. 5747 * @hide 5748 */ 5749 public static final String EXTRA_EXCLUDE_MIMES = "exclude_mimes"; 5750 5751 /** 5752 * Small QuickContact mode, usually presented with minimal actions. 5753 */ 5754 public static final int MODE_SMALL = 1; 5755 5756 /** 5757 * Medium QuickContact mode, includes actions and light summary describing 5758 * the {@link Contacts} entry being shown. This may include social 5759 * status and presence details. 5760 */ 5761 public static final int MODE_MEDIUM = 2; 5762 5763 /** 5764 * Large QuickContact mode, includes actions and larger, card-like summary 5765 * of the {@link Contacts} entry being shown. This may include detailed 5766 * information, such as a photo. 5767 */ 5768 public static final int MODE_LARGE = 3; 5769 5770 /** 5771 * Trigger a dialog that lists the various methods of interacting with 5772 * the requested {@link Contacts} entry. This may be based on available 5773 * {@link ContactsContract.Data} rows under that contact, and may also 5774 * include social status and presence details. 5775 * 5776 * @param context The parent {@link Context} that may be used as the 5777 * parent for this dialog. 5778 * @param target Specific {@link View} from your layout that this dialog 5779 * should be centered around. In particular, if the dialog 5780 * has a "callout" arrow, it will be pointed and centered 5781 * around this {@link View}. 5782 * @param lookupUri A {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style 5783 * {@link Uri} that describes a specific contact to feature 5784 * in this dialog. 5785 * @param mode Any of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or 5786 * {@link #MODE_LARGE}, indicating the desired dialog size, 5787 * when supported. 5788 * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types 5789 * to exclude when showing this dialog. For example, when 5790 * already viewing the contact details card, this can be used 5791 * to omit the details entry from the dialog. 5792 */ 5793 public static void showQuickContact(Context context, View target, Uri lookupUri, int mode, 5794 String[] excludeMimes) { 5795 // Find location and bounds of target view, adjusting based on the 5796 // assumed local density. 5797 final float appScale = context.getResources().getCompatibilityInfo().applicationScale; 5798 final int[] pos = new int[2]; 5799 target.getLocationOnScreen(pos); 5800 5801 final Rect rect = new Rect(); 5802 rect.left = (int) (pos[0] * appScale + 0.5f); 5803 rect.top = (int) (pos[1] * appScale + 0.5f); 5804 rect.right = (int) ((pos[0] + target.getWidth()) * appScale + 0.5f); 5805 rect.bottom = (int) ((pos[1] + target.getHeight()) * appScale + 0.5f); 5806 5807 // Trigger with obtained rectangle 5808 showQuickContact(context, rect, lookupUri, mode, excludeMimes); 5809 } 5810 5811 /** 5812 * Trigger a dialog that lists the various methods of interacting with 5813 * the requested {@link Contacts} entry. This may be based on available 5814 * {@link ContactsContract.Data} rows under that contact, and may also 5815 * include social status and presence details. 5816 * 5817 * @param context The parent {@link Context} that may be used as the 5818 * parent for this dialog. 5819 * @param target Specific {@link Rect} that this dialog should be 5820 * centered around, in screen coordinates. In particular, if 5821 * the dialog has a "callout" arrow, it will be pointed and 5822 * centered around this {@link Rect}. If you are running at a 5823 * non-native density, you need to manually adjust using 5824 * {@link DisplayMetrics#density} before calling. 5825 * @param lookupUri A 5826 * {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style 5827 * {@link Uri} that describes a specific contact to feature 5828 * in this dialog. 5829 * @param mode Any of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or 5830 * {@link #MODE_LARGE}, indicating the desired dialog size, 5831 * when supported. 5832 * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types 5833 * to exclude when showing this dialog. For example, when 5834 * already viewing the contact details card, this can be used 5835 * to omit the details entry from the dialog. 5836 */ 5837 public static void showQuickContact(Context context, Rect target, Uri lookupUri, int mode, 5838 String[] excludeMimes) { 5839 // Launch pivot dialog through intent for now 5840 final Intent intent = new Intent(ACTION_QUICK_CONTACT); 5841 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP 5842 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 5843 5844 intent.setData(lookupUri); 5845 intent.setSourceBounds(target); 5846 intent.putExtra(EXTRA_MODE, mode); 5847 intent.putExtra(EXTRA_EXCLUDE_MIMES, excludeMimes); 5848 context.startActivity(intent); 5849 } 5850 } 5851 5852 /** 5853 * Contains helper classes used to create or manage {@link android.content.Intent Intents} 5854 * that involve contacts. 5855 */ 5856 public static final class Intents { 5857 /** 5858 * This is the intent that is fired when a search suggestion is clicked on. 5859 */ 5860 public static final String SEARCH_SUGGESTION_CLICKED = 5861 "android.provider.Contacts.SEARCH_SUGGESTION_CLICKED"; 5862 5863 /** 5864 * This is the intent that is fired when a search suggestion for dialing a number 5865 * is clicked on. 5866 */ 5867 public static final String SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED = 5868 "android.provider.Contacts.SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED"; 5869 5870 /** 5871 * This is the intent that is fired when a search suggestion for creating a contact 5872 * is clicked on. 5873 */ 5874 public static final String SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED = 5875 "android.provider.Contacts.SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED"; 5876 5877 /** 5878 * Starts an Activity that lets the user pick a contact to attach an image to. 5879 * After picking the contact it launches the image cropper in face detection mode. 5880 */ 5881 public static final String ATTACH_IMAGE = 5882 "com.android.contacts.action.ATTACH_IMAGE"; 5883 5884 /** 5885 * Takes as input a data URI with a mailto: or tel: scheme. If a single 5886 * contact exists with the given data it will be shown. If no contact 5887 * exists, a dialog will ask the user if they want to create a new 5888 * contact with the provided details filled in. If multiple contacts 5889 * share the data the user will be prompted to pick which contact they 5890 * want to view. 5891 * <p> 5892 * For <code>mailto:</code> URIs, the scheme specific portion must be a 5893 * raw email address, such as one built using 5894 * {@link Uri#fromParts(String, String, String)}. 5895 * <p> 5896 * For <code>tel:</code> URIs, the scheme specific portion is compared 5897 * to existing numbers using the standard caller ID lookup algorithm. 5898 * The number must be properly encoded, for example using 5899 * {@link Uri#fromParts(String, String, String)}. 5900 * <p> 5901 * Any extras from the {@link Insert} class will be passed along to the 5902 * create activity if there are no contacts to show. 5903 * <p> 5904 * Passing true for the {@link #EXTRA_FORCE_CREATE} extra will skip 5905 * prompting the user when the contact doesn't exist. 5906 */ 5907 public static final String SHOW_OR_CREATE_CONTACT = 5908 "com.android.contacts.action.SHOW_OR_CREATE_CONTACT"; 5909 5910 /** 5911 * Starts an Activity that lets the user select the multiple phones from a 5912 * list of phone numbers which come from the contacts or 5913 * {@link #EXTRA_PHONE_URIS}. 5914 * <p> 5915 * The phone numbers being passed in through {@link #EXTRA_PHONE_URIS} 5916 * could belong to the contacts or not, and will be selected by default. 5917 * <p> 5918 * The user's selection will be returned from 5919 * {@link android.app.Activity#onActivityResult(int, int, android.content.Intent)} 5920 * if the resultCode is 5921 * {@link android.app.Activity#RESULT_OK}, the array of picked phone 5922 * numbers are in the Intent's 5923 * {@link #EXTRA_PHONE_URIS}; otherwise, the 5924 * {@link android.app.Activity#RESULT_CANCELED} is returned if the user 5925 * left the Activity without changing the selection. 5926 * 5927 * @hide 5928 */ 5929 public static final String ACTION_GET_MULTIPLE_PHONES = 5930 "com.android.contacts.action.GET_MULTIPLE_PHONES"; 5931 5932 /** 5933 * Used with {@link #SHOW_OR_CREATE_CONTACT} to force creating a new 5934 * contact if no matching contact found. Otherwise, default behavior is 5935 * to prompt user with dialog before creating. 5936 * <p> 5937 * Type: BOOLEAN 5938 */ 5939 public static final String EXTRA_FORCE_CREATE = 5940 "com.android.contacts.action.FORCE_CREATE"; 5941 5942 /** 5943 * Used with {@link #SHOW_OR_CREATE_CONTACT} to specify an exact 5944 * description to be shown when prompting user about creating a new 5945 * contact. 5946 * <p> 5947 * Type: STRING 5948 */ 5949 public static final String EXTRA_CREATE_DESCRIPTION = 5950 "com.android.contacts.action.CREATE_DESCRIPTION"; 5951 5952 /** 5953 * Used with {@link #ACTION_GET_MULTIPLE_PHONES} as the input or output value. 5954 * <p> 5955 * The phone numbers want to be picked by default should be passed in as 5956 * input value. These phone numbers could belong to the contacts or not. 5957 * <p> 5958 * The phone numbers which were picked by the user are returned as output 5959 * value. 5960 * <p> 5961 * Type: array of URIs, the tel URI is used for the phone numbers which don't 5962 * belong to any contact, the content URI is used for phone id in contacts. 5963 * 5964 * @hide 5965 */ 5966 public static final String EXTRA_PHONE_URIS = 5967 "com.android.contacts.extra.PHONE_URIS"; 5968 5969 /** 5970 * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a 5971 * dialog location using screen coordinates. When not specified, the 5972 * dialog will be centered. 5973 * 5974 * @hide 5975 */ 5976 @Deprecated 5977 public static final String EXTRA_TARGET_RECT = "target_rect"; 5978 5979 /** 5980 * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a 5981 * desired dialog style, usually a variation on size. One of 5982 * {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or {@link #MODE_LARGE}. 5983 * 5984 * @hide 5985 */ 5986 @Deprecated 5987 public static final String EXTRA_MODE = "mode"; 5988 5989 /** 5990 * Value for {@link #EXTRA_MODE} to show a small-sized dialog. 5991 * 5992 * @hide 5993 */ 5994 @Deprecated 5995 public static final int MODE_SMALL = 1; 5996 5997 /** 5998 * Value for {@link #EXTRA_MODE} to show a medium-sized dialog. 5999 * 6000 * @hide 6001 */ 6002 @Deprecated 6003 public static final int MODE_MEDIUM = 2; 6004 6005 /** 6006 * Value for {@link #EXTRA_MODE} to show a large-sized dialog. 6007 * 6008 * @hide 6009 */ 6010 @Deprecated 6011 public static final int MODE_LARGE = 3; 6012 6013 /** 6014 * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to indicate 6015 * a list of specific MIME-types to exclude and not display. Stored as a 6016 * {@link String} array. 6017 * 6018 * @hide 6019 */ 6020 @Deprecated 6021 public static final String EXTRA_EXCLUDE_MIMES = "exclude_mimes"; 6022 6023 /** 6024 * Intents related to the Contacts app UI. 6025 * 6026 * @hide 6027 */ 6028 public static final class UI { 6029 /** 6030 * The action for the default contacts list tab. 6031 */ 6032 public static final String LIST_DEFAULT = 6033 "com.android.contacts.action.LIST_DEFAULT"; 6034 6035 /** 6036 * The action for the contacts list tab. 6037 */ 6038 public static final String LIST_GROUP_ACTION = 6039 "com.android.contacts.action.LIST_GROUP"; 6040 6041 /** 6042 * When in LIST_GROUP_ACTION mode, this is the group to display. 6043 */ 6044 public static final String GROUP_NAME_EXTRA_KEY = "com.android.contacts.extra.GROUP"; 6045 6046 /** 6047 * The action for the all contacts list tab. 6048 */ 6049 public static final String LIST_ALL_CONTACTS_ACTION = 6050 "com.android.contacts.action.LIST_ALL_CONTACTS"; 6051 6052 /** 6053 * The action for the contacts with phone numbers list tab. 6054 */ 6055 public static final String LIST_CONTACTS_WITH_PHONES_ACTION = 6056 "com.android.contacts.action.LIST_CONTACTS_WITH_PHONES"; 6057 6058 /** 6059 * The action for the starred contacts list tab. 6060 */ 6061 public static final String LIST_STARRED_ACTION = 6062 "com.android.contacts.action.LIST_STARRED"; 6063 6064 /** 6065 * The action for the frequent contacts list tab. 6066 */ 6067 public static final String LIST_FREQUENT_ACTION = 6068 "com.android.contacts.action.LIST_FREQUENT"; 6069 6070 /** 6071 * The action for the "strequent" contacts list tab. It first lists the starred 6072 * contacts in alphabetical order and then the frequent contacts in descending 6073 * order of the number of times they have been contacted. 6074 */ 6075 public static final String LIST_STREQUENT_ACTION = 6076 "com.android.contacts.action.LIST_STREQUENT"; 6077 6078 /** 6079 * A key for to be used as an intent extra to set the activity 6080 * title to a custom String value. 6081 */ 6082 public static final String TITLE_EXTRA_KEY = 6083 "com.android.contacts.extra.TITLE_EXTRA"; 6084 6085 /** 6086 * Activity Action: Display a filtered list of contacts 6087 * <p> 6088 * Input: Extra field {@link #FILTER_TEXT_EXTRA_KEY} is the text to use for 6089 * filtering 6090 * <p> 6091 * Output: Nothing. 6092 */ 6093 public static final String FILTER_CONTACTS_ACTION = 6094 "com.android.contacts.action.FILTER_CONTACTS"; 6095 6096 /** 6097 * Used as an int extra field in {@link #FILTER_CONTACTS_ACTION} 6098 * intents to supply the text on which to filter. 6099 */ 6100 public static final String FILTER_TEXT_EXTRA_KEY = 6101 "com.android.contacts.extra.FILTER_TEXT"; 6102 } 6103 6104 /** 6105 * Convenience class that contains string constants used 6106 * to create contact {@link android.content.Intent Intents}. 6107 */ 6108 public static final class Insert { 6109 /** The action code to use when adding a contact */ 6110 public static final String ACTION = Intent.ACTION_INSERT; 6111 6112 /** 6113 * If present, forces a bypass of quick insert mode. 6114 */ 6115 public static final String FULL_MODE = "full_mode"; 6116 6117 /** 6118 * The extra field for the contact name. 6119 * <P>Type: String</P> 6120 */ 6121 public static final String NAME = "name"; 6122 6123 // TODO add structured name values here. 6124 6125 /** 6126 * The extra field for the contact phonetic name. 6127 * <P>Type: String</P> 6128 */ 6129 public static final String PHONETIC_NAME = "phonetic_name"; 6130 6131 /** 6132 * The extra field for the contact company. 6133 * <P>Type: String</P> 6134 */ 6135 public static final String COMPANY = "company"; 6136 6137 /** 6138 * The extra field for the contact job title. 6139 * <P>Type: String</P> 6140 */ 6141 public static final String JOB_TITLE = "job_title"; 6142 6143 /** 6144 * The extra field for the contact notes. 6145 * <P>Type: String</P> 6146 */ 6147 public static final String NOTES = "notes"; 6148 6149 /** 6150 * The extra field for the contact phone number. 6151 * <P>Type: String</P> 6152 */ 6153 public static final String PHONE = "phone"; 6154 6155 /** 6156 * The extra field for the contact phone number type. 6157 * <P>Type: Either an integer value from 6158 * {@link CommonDataKinds.Phone}, 6159 * or a string specifying a custom label.</P> 6160 */ 6161 public static final String PHONE_TYPE = "phone_type"; 6162 6163 /** 6164 * The extra field for the phone isprimary flag. 6165 * <P>Type: boolean</P> 6166 */ 6167 public static final String PHONE_ISPRIMARY = "phone_isprimary"; 6168 6169 /** 6170 * The extra field for an optional second contact phone number. 6171 * <P>Type: String</P> 6172 */ 6173 public static final String SECONDARY_PHONE = "secondary_phone"; 6174 6175 /** 6176 * The extra field for an optional second contact phone number type. 6177 * <P>Type: Either an integer value from 6178 * {@link CommonDataKinds.Phone}, 6179 * or a string specifying a custom label.</P> 6180 */ 6181 public static final String SECONDARY_PHONE_TYPE = "secondary_phone_type"; 6182 6183 /** 6184 * The extra field for an optional third contact phone number. 6185 * <P>Type: String</P> 6186 */ 6187 public static final String TERTIARY_PHONE = "tertiary_phone"; 6188 6189 /** 6190 * The extra field for an optional third contact phone number type. 6191 * <P>Type: Either an integer value from 6192 * {@link CommonDataKinds.Phone}, 6193 * or a string specifying a custom label.</P> 6194 */ 6195 public static final String TERTIARY_PHONE_TYPE = "tertiary_phone_type"; 6196 6197 /** 6198 * The extra field for the contact email address. 6199 * <P>Type: String</P> 6200 */ 6201 public static final String EMAIL = "email"; 6202 6203 /** 6204 * The extra field for the contact email type. 6205 * <P>Type: Either an integer value from 6206 * {@link CommonDataKinds.Email} 6207 * or a string specifying a custom label.</P> 6208 */ 6209 public static final String EMAIL_TYPE = "email_type"; 6210 6211 /** 6212 * The extra field for the email isprimary flag. 6213 * <P>Type: boolean</P> 6214 */ 6215 public static final String EMAIL_ISPRIMARY = "email_isprimary"; 6216 6217 /** 6218 * The extra field for an optional second contact email address. 6219 * <P>Type: String</P> 6220 */ 6221 public static final String SECONDARY_EMAIL = "secondary_email"; 6222 6223 /** 6224 * The extra field for an optional second contact email type. 6225 * <P>Type: Either an integer value from 6226 * {@link CommonDataKinds.Email} 6227 * or a string specifying a custom label.</P> 6228 */ 6229 public static final String SECONDARY_EMAIL_TYPE = "secondary_email_type"; 6230 6231 /** 6232 * The extra field for an optional third contact email address. 6233 * <P>Type: String</P> 6234 */ 6235 public static final String TERTIARY_EMAIL = "tertiary_email"; 6236 6237 /** 6238 * The extra field for an optional third contact email type. 6239 * <P>Type: Either an integer value from 6240 * {@link CommonDataKinds.Email} 6241 * or a string specifying a custom label.</P> 6242 */ 6243 public static final String TERTIARY_EMAIL_TYPE = "tertiary_email_type"; 6244 6245 /** 6246 * The extra field for the contact postal address. 6247 * <P>Type: String</P> 6248 */ 6249 public static final String POSTAL = "postal"; 6250 6251 /** 6252 * The extra field for the contact postal address type. 6253 * <P>Type: Either an integer value from 6254 * {@link CommonDataKinds.StructuredPostal} 6255 * or a string specifying a custom label.</P> 6256 */ 6257 public static final String POSTAL_TYPE = "postal_type"; 6258 6259 /** 6260 * The extra field for the postal isprimary flag. 6261 * <P>Type: boolean</P> 6262 */ 6263 public static final String POSTAL_ISPRIMARY = "postal_isprimary"; 6264 6265 /** 6266 * The extra field for an IM handle. 6267 * <P>Type: String</P> 6268 */ 6269 public static final String IM_HANDLE = "im_handle"; 6270 6271 /** 6272 * The extra field for the IM protocol 6273 */ 6274 public static final String IM_PROTOCOL = "im_protocol"; 6275 6276 /** 6277 * The extra field for the IM isprimary flag. 6278 * <P>Type: boolean</P> 6279 */ 6280 public static final String IM_ISPRIMARY = "im_isprimary"; 6281 } 6282 } 6283} 6284