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