ContactsContract.java revision d49eea7831d7386fc429984eee0e8ef117a1d927
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.app.Activity; 21import android.content.ContentProviderClient; 22import android.content.ContentProviderOperation; 23import android.content.ContentResolver; 24import android.content.ContentUris; 25import android.content.ContentValues; 26import android.content.Context; 27import android.content.CursorEntityIterator; 28import android.content.Entity; 29import android.content.EntityIterator; 30import android.content.Intent; 31import android.content.res.AssetFileDescriptor; 32import android.content.res.Resources; 33import android.database.Cursor; 34import android.database.DatabaseUtils; 35import android.graphics.Rect; 36import android.net.Uri; 37import android.os.RemoteException; 38import android.text.TextUtils; 39import android.util.DisplayMetrics; 40import android.util.Pair; 41import android.view.View; 42 43import java.io.ByteArrayInputStream; 44import java.io.IOException; 45import java.io.InputStream; 46import java.util.ArrayList; 47 48/** 49 * <p> 50 * The contract between the contacts provider and applications. Contains 51 * definitions for the supported URIs and columns. These APIs supersede 52 * {@link Contacts}. 53 * </p> 54 * <h3>Overview</h3> 55 * <p> 56 * ContactsContract defines an extensible database of contact-related 57 * information. Contact information is stored in a three-tier data model: 58 * </p> 59 * <ul> 60 * <li> 61 * A row in the {@link Data} table can store any kind of personal data, such 62 * as a phone number or email addresses. The set of data kinds that can be 63 * stored in this table is open-ended. There is a predefined set of common 64 * kinds, but any application can add its own data kinds. 65 * </li> 66 * <li> 67 * A row in the {@link RawContacts} table represents a set of data describing a 68 * person and associated with a single account (for example, one of the user's 69 * Gmail accounts). 70 * </li> 71 * <li> 72 * A row in the {@link Contacts} table represents an aggregate of one or more 73 * RawContacts presumably describing the same person. When data in or associated with 74 * the RawContacts table is changed, the affected aggregate contacts are updated as 75 * necessary. 76 * </li> 77 * </ul> 78 * <p> 79 * Other tables include: 80 * </p> 81 * <ul> 82 * <li> 83 * {@link Groups}, which contains information about raw contact groups 84 * such as Gmail contact groups. The 85 * current API does not support the notion of groups spanning multiple accounts. 86 * </li> 87 * <li> 88 * {@link StatusUpdates}, which contains social status updates including IM 89 * availability. 90 * </li> 91 * <li> 92 * {@link AggregationExceptions}, which is used for manual aggregation and 93 * disaggregation of raw contacts 94 * </li> 95 * <li> 96 * {@link Settings}, which contains visibility and sync settings for accounts 97 * and groups. 98 * </li> 99 * <li> 100 * {@link SyncState}, which contains free-form data maintained on behalf of sync 101 * adapters 102 * </li> 103 * <li> 104 * {@link PhoneLookup}, which is used for quick caller-ID lookup</li> 105 * </ul> 106 */ 107@SuppressWarnings("unused") 108public final class ContactsContract { 109 /** The authority for the contacts provider */ 110 public static final String AUTHORITY = "com.android.contacts"; 111 /** A content:// style uri to the authority for the contacts provider */ 112 public static final Uri AUTHORITY_URI = Uri.parse("content://" + AUTHORITY); 113 114 /** 115 * An optional URI parameter for insert, update, or delete queries 116 * that allows the caller 117 * to specify that it is a sync adapter. The default value is false. If true 118 * {@link RawContacts#DIRTY} is not automatically set and the 119 * "syncToNetwork" parameter is set to false when calling 120 * {@link 121 * ContentResolver#notifyChange(android.net.Uri, android.database.ContentObserver, boolean)}. 122 * This prevents an unnecessary extra synchronization, see the discussion of 123 * the delete operation in {@link RawContacts}. 124 */ 125 public static final String CALLER_IS_SYNCADAPTER = "caller_is_syncadapter"; 126 127 /** 128 * Query parameter that should be used by the client to access a specific 129 * {@link Directory}. The parameter value should be the _ID of the corresponding 130 * directory, e.g. 131 * {@code content://com.android.contacts/data/emails/filter/acme?directory=3} 132 */ 133 public static final String DIRECTORY_PARAM_KEY = "directory"; 134 135 /** 136 * A query parameter that limits the number of results returned. The 137 * parameter value should be an integer. 138 */ 139 public static final String LIMIT_PARAM_KEY = "limit"; 140 141 /** 142 * A query parameter specifing a primary account. This parameter should be used with 143 * {@link #PRIMARY_ACCOUNT_TYPE}. The contacts provider handling a query may rely on 144 * this information to optimize its query results. 145 * 146 * For example, in an email composition screen, its implementation can specify an account when 147 * obtaining possible recipients, letting the provider know which account is selected during 148 * the composition. The provider may use the "primary account" information to optimize 149 * the search result. 150 */ 151 public static final String PRIMARY_ACCOUNT_NAME = "name_for_primary_account"; 152 153 /** 154 * A query parameter specifing a primary account. This parameter should be used with 155 * {@link #PRIMARY_ACCOUNT_NAME}. See the doc in {@link #PRIMARY_ACCOUNT_NAME}. 156 */ 157 public static final String PRIMARY_ACCOUNT_TYPE = "type_for_primary_account"; 158 159 /** 160 * A boolean parameter for {@link Contacts#CONTENT_STREQUENT_URI} and 161 * {@link Contacts#CONTENT_STREQUENT_FILTER_URI}, which requires the ContactsProvider to 162 * return only phone-related results. For example, frequently contacted person list should 163 * include persons contacted via phone (not email, sms, etc.) 164 * 165 * @hide 166 */ 167 public static final String STREQUENT_PHONE_ONLY = "strequent_phone_only"; 168 169 /** 170 * @hide 171 */ 172 public static final class Preferences { 173 174 /** 175 * A key in the {@link android.provider.Settings android.provider.Settings} provider 176 * that stores the preferred sorting order for contacts (by given name vs. by family name). 177 * 178 * @hide 179 */ 180 public static final String SORT_ORDER = "android.contacts.SORT_ORDER"; 181 182 /** 183 * The value for the SORT_ORDER key corresponding to sorting by given name first. 184 * 185 * @hide 186 */ 187 public static final int SORT_ORDER_PRIMARY = 1; 188 189 /** 190 * The value for the SORT_ORDER key corresponding to sorting by family name first. 191 * 192 * @hide 193 */ 194 public static final int SORT_ORDER_ALTERNATIVE = 2; 195 196 /** 197 * A key in the {@link android.provider.Settings android.provider.Settings} provider 198 * that stores the preferred display order for contacts (given name first vs. family 199 * name first). 200 * 201 * @hide 202 */ 203 public static final String DISPLAY_ORDER = "android.contacts.DISPLAY_ORDER"; 204 205 /** 206 * The value for the DISPLAY_ORDER key corresponding to showing the given name first. 207 * 208 * @hide 209 */ 210 public static final int DISPLAY_ORDER_PRIMARY = 1; 211 212 /** 213 * The value for the DISPLAY_ORDER key corresponding to showing the family name first. 214 * 215 * @hide 216 */ 217 public static final int DISPLAY_ORDER_ALTERNATIVE = 2; 218 } 219 220 /** 221 * A Directory represents a contacts corpus, e.g. Local contacts, 222 * Google Apps Global Address List or Corporate Global Address List. 223 * <p> 224 * A Directory is implemented as a content provider with its unique authority and 225 * the same API as the main Contacts Provider. However, there is no expectation that 226 * every directory provider will implement this Contract in its entirety. If a 227 * directory provider does not have an implementation for a specific request, it 228 * should throw an UnsupportedOperationException. 229 * </p> 230 * <p> 231 * The most important use case for Directories is search. A Directory provider is 232 * expected to support at least {@link ContactsContract.Contacts#CONTENT_FILTER_URI 233 * Contacts.CONTENT_FILTER_URI}. If a Directory provider wants to participate 234 * in email and phone lookup functionalities, it should also implement 235 * {@link CommonDataKinds.Email#CONTENT_FILTER_URI CommonDataKinds.Email.CONTENT_FILTER_URI} 236 * and 237 * {@link CommonDataKinds.Phone#CONTENT_FILTER_URI CommonDataKinds.Phone.CONTENT_FILTER_URI}. 238 * </p> 239 * <p> 240 * A directory provider should return NULL for every projection field it does not 241 * recognize, rather than throwing an exception. This way it will not be broken 242 * if ContactsContract is extended with new fields in the future. 243 * </p> 244 * <p> 245 * The client interacts with a directory via Contacts Provider by supplying an 246 * optional {@code directory=} query parameter. 247 * <p> 248 * <p> 249 * When the Contacts Provider receives the request, it transforms the URI and forwards 250 * the request to the corresponding directory content provider. 251 * The URI is transformed in the following fashion: 252 * <ul> 253 * <li>The URI authority is replaced with the corresponding {@link #DIRECTORY_AUTHORITY}.</li> 254 * <li>The {@code accountName=} and {@code accountType=} parameters are added or 255 * replaced using the corresponding {@link #ACCOUNT_TYPE} and {@link #ACCOUNT_NAME} values.</li> 256 * </ul> 257 * </p> 258 * <p> 259 * Clients should send directory requests to Contacts Provider and let it 260 * forward them to the respective providers rather than constructing 261 * directory provider URIs by themselves. This level of indirection allows 262 * Contacts Provider to implement additional system-level features and 263 * optimizations. Access to Contacts Provider is protected by the 264 * READ_CONTACTS permission, but access to the directory provider is not. 265 * Therefore directory providers must reject requests coming from clients 266 * other than the Contacts Provider itself. An easy way to prevent such 267 * unauthorized access is to check the name of the calling package: 268 * <pre> 269 * private boolean isCallerAllowed() { 270 * PackageManager pm = getContext().getPackageManager(); 271 * for (String packageName: pm.getPackagesForUid(Binder.getCallingUid())) { 272 * if (packageName.equals("com.android.providers.contacts")) { 273 * return true; 274 * } 275 * } 276 * return false; 277 * } 278 * </pre> 279 * </p> 280 * <p> 281 * The Directory table is read-only and is maintained by the Contacts Provider 282 * automatically. 283 * </p> 284 * <p>It always has at least these two rows: 285 * <ul> 286 * <li> 287 * The local directory. It has {@link Directory#_ID Directory._ID} = 288 * {@link Directory#DEFAULT Directory.DEFAULT}. This directory can be used to access locally 289 * stored contacts. The same can be achieved by omitting the {@code directory=} 290 * parameter altogether. 291 * </li> 292 * <li> 293 * The local invisible contacts. The corresponding directory ID is 294 * {@link Directory#LOCAL_INVISIBLE Directory.LOCAL_INVISIBLE}. 295 * </li> 296 * </ul> 297 * </p> 298 * <p>Custom Directories are discovered by the Contacts Provider following this procedure: 299 * <ul> 300 * <li>It finds all installed content providers with meta data identifying them 301 * as directory providers in AndroidManifest.xml: 302 * <code> 303 * <meta-data android:name="android.content.ContactDirectory" 304 * android:value="true" /> 305 * </code> 306 * <p> 307 * This tag should be placed inside the corresponding content provider declaration. 308 * </p> 309 * </li> 310 * <li> 311 * Then Contacts Provider sends a {@link Directory#CONTENT_URI Directory.CONTENT_URI} 312 * query to each of the directory authorities. A directory provider must implement 313 * this query and return a list of directories. Each directory returned by 314 * the provider must have a unique combination for the {@link #ACCOUNT_NAME} and 315 * {@link #ACCOUNT_TYPE} columns (nulls are allowed). Since directory IDs are assigned 316 * automatically, the _ID field will not be part of the query projection. 317 * </li> 318 * <li>Contacts Provider compiles directory lists received from all directory 319 * providers into one, assigns each individual directory a globally unique ID and 320 * stores all directory records in the Directory table. 321 * </li> 322 * </ul> 323 * </p> 324 * <p>Contacts Provider automatically interrogates newly installed or replaced packages. 325 * Thus simply installing a package containing a directory provider is sufficient 326 * to have that provider registered. A package supplying a directory provider does 327 * not have to contain launchable activities. 328 * </p> 329 * <p> 330 * Every row in the Directory table is automatically associated with the corresponding package 331 * (apk). If the package is later uninstalled, all corresponding directory rows 332 * are automatically removed from the Contacts Provider. 333 * </p> 334 * <p> 335 * When the list of directories handled by a directory provider changes 336 * (for instance when the user adds a new Directory account), the directory provider 337 * should call {@link #notifyDirectoryChange} to notify the Contacts Provider of the change. 338 * In response, the Contacts Provider will requery the directory provider to obtain the 339 * new list of directories. 340 * </p> 341 * <p> 342 * A directory row can be optionally associated with an existing account 343 * (see {@link android.accounts.AccountManager}). If the account is later removed, 344 * the corresponding directory rows are automatically removed from the Contacts Provider. 345 * </p> 346 */ 347 public static final class Directory implements BaseColumns { 348 349 /** 350 * Not instantiable. 351 */ 352 private Directory() { 353 } 354 355 /** 356 * The content:// style URI for this table. Requests to this URI can be 357 * performed on the UI thread because they are always unblocking. 358 */ 359 public static final Uri CONTENT_URI = 360 Uri.withAppendedPath(AUTHORITY_URI, "directories"); 361 362 /** 363 * The MIME-type of {@link #CONTENT_URI} providing a directory of 364 * contact directories. 365 */ 366 public static final String CONTENT_TYPE = 367 "vnd.android.cursor.dir/contact_directories"; 368 369 /** 370 * The MIME type of a {@link #CONTENT_URI} item. 371 */ 372 public static final String CONTENT_ITEM_TYPE = 373 "vnd.android.cursor.item/contact_directory"; 374 375 /** 376 * _ID of the default directory, which represents locally stored contacts. 377 */ 378 public static final long DEFAULT = 0; 379 380 /** 381 * _ID of the directory that represents locally stored invisible contacts. 382 */ 383 public static final long LOCAL_INVISIBLE = 1; 384 385 /** 386 * The name of the package that owns this directory. Contacts Provider 387 * fill it in with the name of the package containing the directory provider. 388 * If the package is later uninstalled, the directories it owns are 389 * automatically removed from this table. 390 * 391 * <p>TYPE: TEXT</p> 392 */ 393 public static final String PACKAGE_NAME = "packageName"; 394 395 /** 396 * The type of directory captured as a resource ID in the context of the 397 * package {@link #PACKAGE_NAME}, e.g. "Corporate Directory" 398 * 399 * <p>TYPE: INTEGER</p> 400 */ 401 public static final String TYPE_RESOURCE_ID = "typeResourceId"; 402 403 /** 404 * An optional name that can be used in the UI to represent this directory, 405 * e.g. "Acme Corp" 406 * <p>TYPE: text</p> 407 */ 408 public static final String DISPLAY_NAME = "displayName"; 409 410 /** 411 * <p> 412 * The authority of the Directory Provider. Contacts Provider will 413 * use this authority to forward requests to the directory provider. 414 * A directory provider can leave this column empty - Contacts Provider will fill it in. 415 * </p> 416 * <p> 417 * Clients of this API should not send requests directly to this authority. 418 * All directory requests must be routed through Contacts Provider. 419 * </p> 420 * 421 * <p>TYPE: text</p> 422 */ 423 public static final String DIRECTORY_AUTHORITY = "authority"; 424 425 /** 426 * The account type which this directory is associated. 427 * 428 * <p>TYPE: text</p> 429 */ 430 public static final String ACCOUNT_TYPE = "accountType"; 431 432 /** 433 * The account with which this directory is associated. If the account is later 434 * removed, the directories it owns are automatically removed from this table. 435 * 436 * <p>TYPE: text</p> 437 */ 438 public static final String ACCOUNT_NAME = "accountName"; 439 440 /** 441 * One of {@link #EXPORT_SUPPORT_NONE}, {@link #EXPORT_SUPPORT_ANY_ACCOUNT}, 442 * {@link #EXPORT_SUPPORT_SAME_ACCOUNT_ONLY}. This is the expectation the 443 * directory has for data exported from it. Clients must obey this setting. 444 */ 445 public static final String EXPORT_SUPPORT = "exportSupport"; 446 447 /** 448 * An {@link #EXPORT_SUPPORT} setting that indicates that the directory 449 * does not allow any data to be copied out of it. 450 */ 451 public static final int EXPORT_SUPPORT_NONE = 0; 452 453 /** 454 * An {@link #EXPORT_SUPPORT} setting that indicates that the directory 455 * allow its data copied only to the account specified by 456 * {@link #ACCOUNT_TYPE}/{@link #ACCOUNT_NAME}. 457 */ 458 public static final int EXPORT_SUPPORT_SAME_ACCOUNT_ONLY = 1; 459 460 /** 461 * An {@link #EXPORT_SUPPORT} setting that indicates that the directory 462 * allow its data copied to any contacts account. 463 */ 464 public static final int EXPORT_SUPPORT_ANY_ACCOUNT = 2; 465 466 /** 467 * One of {@link #SHORTCUT_SUPPORT_NONE}, {@link #SHORTCUT_SUPPORT_DATA_ITEMS_ONLY}, 468 * {@link #SHORTCUT_SUPPORT_FULL}. This is the expectation the directory 469 * has for shortcuts created for its elements. Clients must obey this setting. 470 */ 471 public static final String SHORTCUT_SUPPORT = "shortcutSupport"; 472 473 /** 474 * An {@link #SHORTCUT_SUPPORT} setting that indicates that the directory 475 * does not allow any shortcuts created for its contacts. 476 */ 477 public static final int SHORTCUT_SUPPORT_NONE = 0; 478 479 /** 480 * An {@link #SHORTCUT_SUPPORT} setting that indicates that the directory 481 * allow creation of shortcuts for data items like email, phone or postal address, 482 * but not the entire contact. 483 */ 484 public static final int SHORTCUT_SUPPORT_DATA_ITEMS_ONLY = 1; 485 486 /** 487 * An {@link #SHORTCUT_SUPPORT} setting that indicates that the directory 488 * allow creation of shortcuts for contact as well as their constituent elements. 489 */ 490 public static final int SHORTCUT_SUPPORT_FULL = 2; 491 492 /** 493 * One of {@link #PHOTO_SUPPORT_NONE}, {@link #PHOTO_SUPPORT_THUMBNAIL_ONLY}, 494 * {@link #PHOTO_SUPPORT_FULL}. This is a feature flag indicating the extent 495 * to which the directory supports contact photos. 496 */ 497 public static final String PHOTO_SUPPORT = "photoSupport"; 498 499 /** 500 * An {@link #PHOTO_SUPPORT} setting that indicates that the directory 501 * does not provide any photos. 502 */ 503 public static final int PHOTO_SUPPORT_NONE = 0; 504 505 /** 506 * An {@link #PHOTO_SUPPORT} setting that indicates that the directory 507 * can only produce small size thumbnails of contact photos. 508 */ 509 public static final int PHOTO_SUPPORT_THUMBNAIL_ONLY = 1; 510 511 /** 512 * An {@link #PHOTO_SUPPORT} setting that indicates that the directory 513 * has full-size contact photos, but cannot provide scaled thumbnails. 514 */ 515 public static final int PHOTO_SUPPORT_FULL_SIZE_ONLY = 2; 516 517 /** 518 * An {@link #PHOTO_SUPPORT} setting that indicates that the directory 519 * can produce thumbnails as well as full-size contact photos. 520 */ 521 public static final int PHOTO_SUPPORT_FULL = 3; 522 523 /** 524 * Notifies the system of a change in the list of directories handled by 525 * a particular directory provider. The Contacts provider will turn around 526 * and send a query to the directory provider for the full list of directories, 527 * which will replace the previous list. 528 */ 529 public static void notifyDirectoryChange(ContentResolver resolver) { 530 // This is done to trigger a query by Contacts Provider back to the directory provider. 531 // No data needs to be sent back, because the provider can infer the calling 532 // package from binder. 533 ContentValues contentValues = new ContentValues(); 534 resolver.update(Directory.CONTENT_URI, contentValues, null, null); 535 } 536 } 537 538 /** 539 * @hide should be removed when users are updated to refer to SyncState 540 * @deprecated use SyncState instead 541 */ 542 @Deprecated 543 public interface SyncStateColumns extends SyncStateContract.Columns { 544 } 545 546 /** 547 * A table provided for sync adapters to use for storing private sync state data for contacts. 548 * 549 * @see SyncStateContract 550 */ 551 public static final class SyncState implements SyncStateContract.Columns { 552 /** 553 * This utility class cannot be instantiated 554 */ 555 private SyncState() {} 556 557 public static final String CONTENT_DIRECTORY = 558 SyncStateContract.Constants.CONTENT_DIRECTORY; 559 560 /** 561 * The content:// style URI for this table 562 */ 563 public static final Uri CONTENT_URI = 564 Uri.withAppendedPath(AUTHORITY_URI, CONTENT_DIRECTORY); 565 566 /** 567 * @see android.provider.SyncStateContract.Helpers#get 568 */ 569 public static byte[] get(ContentProviderClient provider, Account account) 570 throws RemoteException { 571 return SyncStateContract.Helpers.get(provider, CONTENT_URI, account); 572 } 573 574 /** 575 * @see android.provider.SyncStateContract.Helpers#get 576 */ 577 public static Pair<Uri, byte[]> getWithUri(ContentProviderClient provider, Account account) 578 throws RemoteException { 579 return SyncStateContract.Helpers.getWithUri(provider, CONTENT_URI, account); 580 } 581 582 /** 583 * @see android.provider.SyncStateContract.Helpers#set 584 */ 585 public static void set(ContentProviderClient provider, Account account, byte[] data) 586 throws RemoteException { 587 SyncStateContract.Helpers.set(provider, CONTENT_URI, account, data); 588 } 589 590 /** 591 * @see android.provider.SyncStateContract.Helpers#newSetOperation 592 */ 593 public static ContentProviderOperation newSetOperation(Account account, byte[] data) { 594 return SyncStateContract.Helpers.newSetOperation(CONTENT_URI, account, data); 595 } 596 } 597 598 599 /** 600 * A table provided for sync adapters to use for storing private sync state data for the 601 * user's personal profile. 602 * 603 * @see SyncStateContract 604 */ 605 public static final class ProfileSyncState implements SyncStateContract.Columns { 606 /** 607 * This utility class cannot be instantiated 608 */ 609 private ProfileSyncState() {} 610 611 public static final String CONTENT_DIRECTORY = 612 SyncStateContract.Constants.CONTENT_DIRECTORY; 613 614 /** 615 * The content:// style URI for this table 616 */ 617 public static final Uri CONTENT_URI = 618 Uri.withAppendedPath(Profile.CONTENT_URI, CONTENT_DIRECTORY); 619 620 /** 621 * @see android.provider.SyncStateContract.Helpers#get 622 */ 623 public static byte[] get(ContentProviderClient provider, Account account) 624 throws RemoteException { 625 return SyncStateContract.Helpers.get(provider, CONTENT_URI, account); 626 } 627 628 /** 629 * @see android.provider.SyncStateContract.Helpers#get 630 */ 631 public static Pair<Uri, byte[]> getWithUri(ContentProviderClient provider, Account account) 632 throws RemoteException { 633 return SyncStateContract.Helpers.getWithUri(provider, CONTENT_URI, account); 634 } 635 636 /** 637 * @see android.provider.SyncStateContract.Helpers#set 638 */ 639 public static void set(ContentProviderClient provider, Account account, byte[] data) 640 throws RemoteException { 641 SyncStateContract.Helpers.set(provider, CONTENT_URI, account, data); 642 } 643 644 /** 645 * @see android.provider.SyncStateContract.Helpers#newSetOperation 646 */ 647 public static ContentProviderOperation newSetOperation(Account account, byte[] data) { 648 return SyncStateContract.Helpers.newSetOperation(CONTENT_URI, account, data); 649 } 650 } 651 652 /** 653 * Generic columns for use by sync adapters. The specific functions of 654 * these columns are private to the sync adapter. Other clients of the API 655 * should not attempt to either read or write this column. 656 * 657 * @see RawContacts 658 * @see Groups 659 */ 660 protected interface BaseSyncColumns { 661 662 /** Generic column for use by sync adapters. */ 663 public static final String SYNC1 = "sync1"; 664 /** Generic column for use by sync adapters. */ 665 public static final String SYNC2 = "sync2"; 666 /** Generic column for use by sync adapters. */ 667 public static final String SYNC3 = "sync3"; 668 /** Generic column for use by sync adapters. */ 669 public static final String SYNC4 = "sync4"; 670 } 671 672 /** 673 * Columns that appear when each row of a table belongs to a specific 674 * account, including sync information that an account may need. 675 * 676 * @see RawContacts 677 * @see Groups 678 */ 679 protected interface SyncColumns extends BaseSyncColumns { 680 /** 681 * The name of the account instance to which this row belongs, which when paired with 682 * {@link #ACCOUNT_TYPE} identifies a specific account. 683 * <P>Type: TEXT</P> 684 */ 685 public static final String ACCOUNT_NAME = "account_name"; 686 687 /** 688 * The type of account to which this row belongs, which when paired with 689 * {@link #ACCOUNT_NAME} identifies a specific account. 690 * <P>Type: TEXT</P> 691 */ 692 public static final String ACCOUNT_TYPE = "account_type"; 693 694 /** 695 * String that uniquely identifies this row to its source account. 696 * <P>Type: TEXT</P> 697 */ 698 public static final String SOURCE_ID = "sourceid"; 699 700 /** 701 * Version number that is updated whenever this row or its related data 702 * changes. 703 * <P>Type: INTEGER</P> 704 */ 705 public static final String VERSION = "version"; 706 707 /** 708 * Flag indicating that {@link #VERSION} has changed, and this row needs 709 * to be synchronized by its owning account. 710 * <P>Type: INTEGER (boolean)</P> 711 */ 712 public static final String DIRTY = "dirty"; 713 } 714 715 /** 716 * Columns of {@link ContactsContract.Contacts} that track the user's 717 * preferences for, or interactions with, the contact. 718 * 719 * @see Contacts 720 * @see RawContacts 721 * @see ContactsContract.Data 722 * @see PhoneLookup 723 * @see ContactsContract.Contacts.AggregationSuggestions 724 */ 725 protected interface ContactOptionsColumns { 726 /** 727 * The number of times a contact has been contacted 728 * <P>Type: INTEGER</P> 729 */ 730 public static final String TIMES_CONTACTED = "times_contacted"; 731 732 /** 733 * The last time a contact was contacted. 734 * <P>Type: INTEGER</P> 735 */ 736 public static final String LAST_TIME_CONTACTED = "last_time_contacted"; 737 738 /** 739 * Is the contact starred? 740 * <P>Type: INTEGER (boolean)</P> 741 */ 742 public static final String STARRED = "starred"; 743 744 /** 745 * URI for a custom ringtone associated with the contact. If null or missing, 746 * the default ringtone is used. 747 * <P>Type: TEXT (URI to the ringtone)</P> 748 */ 749 public static final String CUSTOM_RINGTONE = "custom_ringtone"; 750 751 /** 752 * Whether the contact should always be sent to voicemail. If missing, 753 * defaults to false. 754 * <P>Type: INTEGER (0 for false, 1 for true)</P> 755 */ 756 public static final String SEND_TO_VOICEMAIL = "send_to_voicemail"; 757 } 758 759 /** 760 * Columns of {@link ContactsContract.Contacts} that refer to intrinsic 761 * properties of the contact, as opposed to the user-specified options 762 * found in {@link ContactOptionsColumns}. 763 * 764 * @see Contacts 765 * @see ContactsContract.Data 766 * @see PhoneLookup 767 * @see ContactsContract.Contacts.AggregationSuggestions 768 */ 769 protected interface ContactsColumns { 770 /** 771 * The display name for the contact. 772 * <P>Type: TEXT</P> 773 */ 774 public static final String DISPLAY_NAME = ContactNameColumns.DISPLAY_NAME_PRIMARY; 775 776 /** 777 * Reference to the row in the RawContacts table holding the contact name. 778 * <P>Type: INTEGER REFERENCES raw_contacts(_id)</P> 779 * @hide 780 */ 781 public static final String NAME_RAW_CONTACT_ID = "name_raw_contact_id"; 782 783 /** 784 * Reference to the row in the data table holding the photo. A photo can 785 * be referred to either by ID (this field) or by URI (see {@link #PHOTO_THUMBNAIL_URI} 786 * and {@link #PHOTO_URI}). 787 * If PHOTO_ID is null, consult {@link #PHOTO_URI} or {@link #PHOTO_THUMBNAIL_URI}, 788 * which is a more generic mechanism for referencing the contact photo, especially for 789 * contacts returned by non-local directories (see {@link Directory}). 790 * 791 * <P>Type: INTEGER REFERENCES data(_id)</P> 792 */ 793 public static final String PHOTO_ID = "photo_id"; 794 795 /** 796 * Photo file ID of the full-size photo. If present, this will be used to populate 797 * {@link #PHOTO_URI}. The ID can also be used with 798 * {@link ContactsContract.DisplayPhoto#CONTENT_URI} to create a URI to the photo. 799 * If this is present, {@link #PHOTO_ID} is also guaranteed to be populated. 800 * 801 * <P>Type: INTEGER</P> 802 */ 803 public static final String PHOTO_FILE_ID = "photo_file_id"; 804 805 /** 806 * A URI that can be used to retrieve the contact's full-size photo. 807 * If PHOTO_FILE_ID is not null, this will be populated with a URI based off 808 * {@link ContactsContract.DisplayPhoto#CONTENT_URI}. Otherwise, this will 809 * be populated with the same value as {@link #PHOTO_THUMBNAIL_URI}. 810 * A photo can be referred to either by a URI (this field) or by ID 811 * (see {@link #PHOTO_ID}). If either PHOTO_FILE_ID or PHOTO_ID is not null, 812 * PHOTO_URI and PHOTO_THUMBNAIL_URI shall not be null (but not necessarily 813 * vice versa). Thus using PHOTO_URI is a more robust method of retrieving 814 * contact photos. 815 * 816 * <P>Type: TEXT</P> 817 */ 818 public static final String PHOTO_URI = "photo_uri"; 819 820 /** 821 * A URI that can be used to retrieve a thumbnail of the contact's photo. 822 * A photo can be referred to either by a URI (this field or {@link #PHOTO_URI}) 823 * or by ID (see {@link #PHOTO_ID}). If PHOTO_ID is not null, PHOTO_URI and 824 * PHOTO_THUMBNAIL_URI shall not be null (but not necessarily vice versa). 825 * If the content provider does not differentiate between full-size photos 826 * and thumbnail photos, PHOTO_THUMBNAIL_URI and {@link #PHOTO_URI} can contain 827 * the same value, but either both shall be null or both not null. 828 * 829 * <P>Type: TEXT</P> 830 */ 831 public static final String PHOTO_THUMBNAIL_URI = "photo_thumb_uri"; 832 833 /** 834 * Flag that reflects the {@link Groups#GROUP_VISIBLE} state of any 835 * {@link CommonDataKinds.GroupMembership} for this contact. 836 */ 837 public static final String IN_VISIBLE_GROUP = "in_visible_group"; 838 839 /** 840 * Flag that reflects whether this contact represents the user's 841 * personal profile entry. 842 */ 843 public static final String IS_USER_PROFILE = "is_user_profile"; 844 845 /** 846 * An indicator of whether this contact has at least one phone number. "1" if there is 847 * at least one phone number, "0" otherwise. 848 * <P>Type: INTEGER</P> 849 */ 850 public static final String HAS_PHONE_NUMBER = "has_phone_number"; 851 852 /** 853 * An opaque value that contains hints on how to find the contact if 854 * its row id changed as a result of a sync or aggregation. 855 */ 856 public static final String LOOKUP_KEY = "lookup"; 857 } 858 859 /** 860 * @see Contacts 861 */ 862 protected interface ContactStatusColumns { 863 /** 864 * Contact presence status. See {@link StatusUpdates} for individual status 865 * definitions. 866 * <p>Type: NUMBER</p> 867 */ 868 public static final String CONTACT_PRESENCE = "contact_presence"; 869 870 /** 871 * Contact Chat Capabilities. See {@link StatusUpdates} for individual 872 * definitions. 873 * <p>Type: NUMBER</p> 874 */ 875 public static final String CONTACT_CHAT_CAPABILITY = "contact_chat_capability"; 876 877 /** 878 * Contact's latest status update. 879 * <p>Type: TEXT</p> 880 */ 881 public static final String CONTACT_STATUS = "contact_status"; 882 883 /** 884 * The absolute time in milliseconds when the latest status was 885 * inserted/updated. 886 * <p>Type: NUMBER</p> 887 */ 888 public static final String CONTACT_STATUS_TIMESTAMP = "contact_status_ts"; 889 890 /** 891 * The package containing resources for this status: label and icon. 892 * <p>Type: TEXT</p> 893 */ 894 public static final String CONTACT_STATUS_RES_PACKAGE = "contact_status_res_package"; 895 896 /** 897 * The resource ID of the label describing the source of contact 898 * status, e.g. "Google Talk". This resource is scoped by the 899 * {@link #CONTACT_STATUS_RES_PACKAGE}. 900 * <p>Type: NUMBER</p> 901 */ 902 public static final String CONTACT_STATUS_LABEL = "contact_status_label"; 903 904 /** 905 * The resource ID of the icon for the source of contact status. This 906 * resource is scoped by the {@link #CONTACT_STATUS_RES_PACKAGE}. 907 * <p>Type: NUMBER</p> 908 */ 909 public static final String CONTACT_STATUS_ICON = "contact_status_icon"; 910 } 911 912 /** 913 * Constants for various styles of combining given name, family name etc into 914 * a full name. For example, the western tradition follows the pattern 915 * 'given name' 'middle name' 'family name' with the alternative pattern being 916 * 'family name', 'given name' 'middle name'. The CJK tradition is 917 * 'family name' 'middle name' 'given name', with Japanese favoring a space between 918 * the names and Chinese omitting the space. 919 */ 920 public interface FullNameStyle { 921 public static final int UNDEFINED = 0; 922 public static final int WESTERN = 1; 923 924 /** 925 * Used if the name is written in Hanzi/Kanji/Hanja and we could not determine 926 * which specific language it belongs to: Chinese, Japanese or Korean. 927 */ 928 public static final int CJK = 2; 929 930 public static final int CHINESE = 3; 931 public static final int JAPANESE = 4; 932 public static final int KOREAN = 5; 933 } 934 935 /** 936 * Constants for various styles of capturing the pronunciation of a person's name. 937 */ 938 public interface PhoneticNameStyle { 939 public static final int UNDEFINED = 0; 940 941 /** 942 * Pinyin is a phonetic method of entering Chinese characters. Typically not explicitly 943 * shown in UIs, but used for searches and sorting. 944 */ 945 public static final int PINYIN = 3; 946 947 /** 948 * Hiragana and Katakana are two common styles of writing out the pronunciation 949 * of a Japanese names. 950 */ 951 public static final int JAPANESE = 4; 952 953 /** 954 * Hangul is the Korean phonetic alphabet. 955 */ 956 public static final int KOREAN = 5; 957 } 958 959 /** 960 * Types of data used to produce the display name for a contact. In the order 961 * of increasing priority: {@link #EMAIL}, {@link #PHONE}, 962 * {@link #ORGANIZATION}, {@link #NICKNAME}, {@link #STRUCTURED_NAME}. 963 */ 964 public interface DisplayNameSources { 965 public static final int UNDEFINED = 0; 966 public static final int EMAIL = 10; 967 public static final int PHONE = 20; 968 public static final int ORGANIZATION = 30; 969 public static final int NICKNAME = 35; 970 public static final int STRUCTURED_NAME = 40; 971 } 972 973 /** 974 * Contact name and contact name metadata columns in the RawContacts table. 975 * 976 * @see Contacts 977 * @see RawContacts 978 */ 979 protected interface ContactNameColumns { 980 981 /** 982 * The kind of data that is used as the display name for the contact, such as 983 * structured name or email address. See {@link DisplayNameSources}. 984 */ 985 public static final String DISPLAY_NAME_SOURCE = "display_name_source"; 986 987 /** 988 * <p> 989 * The standard text shown as the contact's display name, based on the best 990 * available information for the contact (for example, it might be the email address 991 * if the name is not available). 992 * The information actually used to compute the name is stored in 993 * {@link #DISPLAY_NAME_SOURCE}. 994 * </p> 995 * <p> 996 * A contacts provider is free to choose whatever representation makes most 997 * sense for its target market. 998 * For example in the default Android Open Source Project implementation, 999 * if the display name is 1000 * based on the structured name and the structured name follows 1001 * the Western full-name style, then this field contains the "given name first" 1002 * version of the full name. 1003 * <p> 1004 * 1005 * @see ContactsContract.ContactNameColumns#DISPLAY_NAME_ALTERNATIVE 1006 */ 1007 public static final String DISPLAY_NAME_PRIMARY = "display_name"; 1008 1009 /** 1010 * <p> 1011 * An alternative representation of the display name, such as "family name first" 1012 * instead of "given name first" for Western names. If an alternative is not 1013 * available, the values should be the same as {@link #DISPLAY_NAME_PRIMARY}. 1014 * </p> 1015 * <p> 1016 * A contacts provider is free to provide alternatives as necessary for 1017 * its target market. 1018 * For example the default Android Open Source Project contacts provider 1019 * currently provides an 1020 * alternative in a single case: if the display name is 1021 * based on the structured name and the structured name follows 1022 * the Western full name style, then the field contains the "family name first" 1023 * version of the full name. 1024 * Other cases may be added later. 1025 * </p> 1026 */ 1027 public static final String DISPLAY_NAME_ALTERNATIVE = "display_name_alt"; 1028 1029 /** 1030 * The phonetic alphabet used to represent the {@link #PHONETIC_NAME}. See 1031 * {@link PhoneticNameStyle}. 1032 */ 1033 public static final String PHONETIC_NAME_STYLE = "phonetic_name_style"; 1034 1035 /** 1036 * <p> 1037 * Pronunciation of the full name in the phonetic alphabet specified by 1038 * {@link #PHONETIC_NAME_STYLE}. 1039 * </p> 1040 * <p> 1041 * The value may be set manually by the user. This capability is of 1042 * interest only in countries with commonly used phonetic alphabets, 1043 * such as Japan and Korea. See {@link PhoneticNameStyle}. 1044 * </p> 1045 */ 1046 public static final String PHONETIC_NAME = "phonetic_name"; 1047 1048 /** 1049 * Sort key that takes into account locale-based traditions for sorting 1050 * names in address books. The default 1051 * sort key is {@link #DISPLAY_NAME_PRIMARY}. For Chinese names 1052 * the sort key is the name's Pinyin spelling, and for Japanese names 1053 * it is the Hiragana version of the phonetic name. 1054 */ 1055 public static final String SORT_KEY_PRIMARY = "sort_key"; 1056 1057 /** 1058 * Sort key based on the alternative representation of the full name, 1059 * {@link #DISPLAY_NAME_ALTERNATIVE}. Thus for Western names, 1060 * it is the one using the "family name first" format. 1061 */ 1062 public static final String SORT_KEY_ALTERNATIVE = "sort_key_alt"; 1063 } 1064 1065 /** 1066 * URI parameter and cursor extras that return counts of rows grouped by the 1067 * address book index, which is usually the first letter of the sort key. 1068 * When this parameter is supplied, the row counts are returned in the 1069 * cursor extras bundle. 1070 * 1071 * @hide 1072 */ 1073 public final static class ContactCounts { 1074 1075 /** 1076 * Add this query parameter to a URI to get back row counts grouped by 1077 * the address book index as cursor extras. For most languages it is the 1078 * first letter of the sort key. This parameter does not affect the main 1079 * content of the cursor. 1080 * 1081 * @hide 1082 */ 1083 public static final String ADDRESS_BOOK_INDEX_EXTRAS = "address_book_index_extras"; 1084 1085 /** 1086 * The array of address book index titles, which are returned in the 1087 * same order as the data in the cursor. 1088 * <p>TYPE: String[]</p> 1089 * 1090 * @hide 1091 */ 1092 public static final String EXTRA_ADDRESS_BOOK_INDEX_TITLES = "address_book_index_titles"; 1093 1094 /** 1095 * The array of group counts for the corresponding group. Contains the same number 1096 * of elements as the EXTRA_ADDRESS_BOOK_INDEX_TITLES array. 1097 * <p>TYPE: int[]</p> 1098 * 1099 * @hide 1100 */ 1101 public static final String EXTRA_ADDRESS_BOOK_INDEX_COUNTS = "address_book_index_counts"; 1102 } 1103 1104 /** 1105 * Constants for the contacts table, which contains a record per aggregate 1106 * of raw contacts representing the same person. 1107 * <h3>Operations</h3> 1108 * <dl> 1109 * <dt><b>Insert</b></dt> 1110 * <dd>A Contact cannot be created explicitly. When a raw contact is 1111 * inserted, the provider will first try to find a Contact representing the 1112 * same person. If one is found, the raw contact's 1113 * {@link RawContacts#CONTACT_ID} column gets the _ID of the aggregate 1114 * Contact. If no match is found, the provider automatically inserts a new 1115 * Contact and puts its _ID into the {@link RawContacts#CONTACT_ID} column 1116 * of the newly inserted raw contact.</dd> 1117 * <dt><b>Update</b></dt> 1118 * <dd>Only certain columns of Contact are modifiable: 1119 * {@link #TIMES_CONTACTED}, {@link #LAST_TIME_CONTACTED}, {@link #STARRED}, 1120 * {@link #CUSTOM_RINGTONE}, {@link #SEND_TO_VOICEMAIL}. Changing any of 1121 * these columns on the Contact also changes them on all constituent raw 1122 * contacts.</dd> 1123 * <dt><b>Delete</b></dt> 1124 * <dd>Be careful with deleting Contacts! Deleting an aggregate contact 1125 * deletes all constituent raw contacts. The corresponding sync adapters 1126 * will notice the deletions of their respective raw contacts and remove 1127 * them from their back end storage.</dd> 1128 * <dt><b>Query</b></dt> 1129 * <dd> 1130 * <ul> 1131 * <li>If you need to read an individual contact, consider using 1132 * {@link #CONTENT_LOOKUP_URI} instead of {@link #CONTENT_URI}.</li> 1133 * <li>If you need to look up a contact by the phone number, use 1134 * {@link PhoneLookup#CONTENT_FILTER_URI PhoneLookup.CONTENT_FILTER_URI}, 1135 * which is optimized for this purpose.</li> 1136 * <li>If you need to look up a contact by partial name, e.g. to produce 1137 * filter-as-you-type suggestions, use the {@link #CONTENT_FILTER_URI} URI. 1138 * <li>If you need to look up a contact by some data element like email 1139 * address, nickname, etc, use a query against the {@link ContactsContract.Data} table. 1140 * The result will contain contact ID, name etc. 1141 * </ul> 1142 * </dd> 1143 * </dl> 1144 * <h2>Columns</h2> 1145 * <table class="jd-sumtable"> 1146 * <tr> 1147 * <th colspan='4'>Contacts</th> 1148 * </tr> 1149 * <tr> 1150 * <td>long</td> 1151 * <td>{@link #_ID}</td> 1152 * <td>read-only</td> 1153 * <td>Row ID. Consider using {@link #LOOKUP_KEY} instead.</td> 1154 * </tr> 1155 * <tr> 1156 * <td>String</td> 1157 * <td>{@link #LOOKUP_KEY}</td> 1158 * <td>read-only</td> 1159 * <td>An opaque value that contains hints on how to find the contact if its 1160 * row id changed as a result of a sync or aggregation.</td> 1161 * </tr> 1162 * <tr> 1163 * <td>long</td> 1164 * <td>NAME_RAW_CONTACT_ID</td> 1165 * <td>read-only</td> 1166 * <td>The ID of the raw contact that contributes the display name 1167 * to the aggregate contact. During aggregation one of the constituent 1168 * raw contacts is chosen using a heuristic: a longer name or a name 1169 * with more diacritic marks or more upper case characters is chosen.</td> 1170 * </tr> 1171 * <tr> 1172 * <td>String</td> 1173 * <td>DISPLAY_NAME_PRIMARY</td> 1174 * <td>read-only</td> 1175 * <td>The display name for the contact. It is the display name 1176 * contributed by the raw contact referred to by the NAME_RAW_CONTACT_ID 1177 * column.</td> 1178 * </tr> 1179 * <tr> 1180 * <td>long</td> 1181 * <td>{@link #PHOTO_ID}</td> 1182 * <td>read-only</td> 1183 * <td>Reference to the row in the {@link ContactsContract.Data} table holding the photo. 1184 * That row has the mime type 1185 * {@link CommonDataKinds.Photo#CONTENT_ITEM_TYPE}. The value of this field 1186 * is computed automatically based on the 1187 * {@link CommonDataKinds.Photo#IS_SUPER_PRIMARY} field of the data rows of 1188 * that mime type.</td> 1189 * </tr> 1190 * <tr> 1191 * <td>long</td> 1192 * <td>{@link #PHOTO_URI}</td> 1193 * <td>read-only</td> 1194 * <td>A URI that can be used to retrieve the contact's full-size photo. This 1195 * column is the preferred method of retrieving the contact photo.</td> 1196 * </tr> 1197 * <tr> 1198 * <td>long</td> 1199 * <td>{@link #PHOTO_THUMBNAIL_URI}</td> 1200 * <td>read-only</td> 1201 * <td>A URI that can be used to retrieve the thumbnail of contact's photo. This 1202 * column is the preferred method of retrieving the contact photo.</td> 1203 * </tr> 1204 * <tr> 1205 * <td>int</td> 1206 * <td>{@link #IN_VISIBLE_GROUP}</td> 1207 * <td>read-only</td> 1208 * <td>An indicator of whether this contact is supposed to be visible in the 1209 * UI. "1" if the contact has at least one raw contact that belongs to a 1210 * visible group; "0" otherwise.</td> 1211 * </tr> 1212 * <tr> 1213 * <td>int</td> 1214 * <td>{@link #HAS_PHONE_NUMBER}</td> 1215 * <td>read-only</td> 1216 * <td>An indicator of whether this contact has at least one phone number. 1217 * "1" if there is at least one phone number, "0" otherwise.</td> 1218 * </tr> 1219 * <tr> 1220 * <td>int</td> 1221 * <td>{@link #TIMES_CONTACTED}</td> 1222 * <td>read/write</td> 1223 * <td>The number of times the contact has been contacted. See 1224 * {@link #markAsContacted}. When raw contacts are aggregated, this field is 1225 * computed automatically as the maximum number of times contacted among all 1226 * constituent raw contacts. Setting this field automatically changes the 1227 * corresponding field on all constituent raw contacts.</td> 1228 * </tr> 1229 * <tr> 1230 * <td>long</td> 1231 * <td>{@link #LAST_TIME_CONTACTED}</td> 1232 * <td>read/write</td> 1233 * <td>The timestamp of the last time the contact was contacted. See 1234 * {@link #markAsContacted}. Setting this field also automatically 1235 * increments {@link #TIMES_CONTACTED}. When raw contacts are aggregated, 1236 * this field is computed automatically as the latest time contacted of all 1237 * constituent raw contacts. Setting this field automatically changes the 1238 * corresponding field on all constituent raw contacts.</td> 1239 * </tr> 1240 * <tr> 1241 * <td>int</td> 1242 * <td>{@link #STARRED}</td> 1243 * <td>read/write</td> 1244 * <td>An indicator for favorite contacts: '1' if favorite, '0' otherwise. 1245 * When raw contacts are aggregated, this field is automatically computed: 1246 * if any constituent raw contacts are starred, then this field is set to 1247 * '1'. Setting this field automatically changes the corresponding field on 1248 * all constituent raw contacts.</td> 1249 * </tr> 1250 * <tr> 1251 * <td>String</td> 1252 * <td>{@link #CUSTOM_RINGTONE}</td> 1253 * <td>read/write</td> 1254 * <td>A custom ringtone associated with a contact. Typically this is the 1255 * URI returned by an activity launched with the 1256 * {@link android.media.RingtoneManager#ACTION_RINGTONE_PICKER} intent.</td> 1257 * </tr> 1258 * <tr> 1259 * <td>int</td> 1260 * <td>{@link #SEND_TO_VOICEMAIL}</td> 1261 * <td>read/write</td> 1262 * <td>An indicator of whether calls from this contact should be forwarded 1263 * directly to voice mail ('1') or not ('0'). When raw contacts are 1264 * aggregated, this field is automatically computed: if <i>all</i> 1265 * constituent raw contacts have SEND_TO_VOICEMAIL=1, then this field is set 1266 * to '1'. Setting this field automatically changes the corresponding field 1267 * on all constituent raw contacts.</td> 1268 * </tr> 1269 * <tr> 1270 * <td>int</td> 1271 * <td>{@link #CONTACT_PRESENCE}</td> 1272 * <td>read-only</td> 1273 * <td>Contact IM presence status. See {@link StatusUpdates} for individual 1274 * status definitions. Automatically computed as the highest presence of all 1275 * constituent raw contacts. The provider may choose not to store this value 1276 * in persistent storage. The expectation is that presence status will be 1277 * updated on a regular basic.</td> 1278 * </tr> 1279 * <tr> 1280 * <td>String</td> 1281 * <td>{@link #CONTACT_STATUS}</td> 1282 * <td>read-only</td> 1283 * <td>Contact's latest status update. Automatically computed as the latest 1284 * of all constituent raw contacts' status updates.</td> 1285 * </tr> 1286 * <tr> 1287 * <td>long</td> 1288 * <td>{@link #CONTACT_STATUS_TIMESTAMP}</td> 1289 * <td>read-only</td> 1290 * <td>The absolute time in milliseconds when the latest status was 1291 * inserted/updated.</td> 1292 * </tr> 1293 * <tr> 1294 * <td>String</td> 1295 * <td>{@link #CONTACT_STATUS_RES_PACKAGE}</td> 1296 * <td>read-only</td> 1297 * <td> The package containing resources for this status: label and icon.</td> 1298 * </tr> 1299 * <tr> 1300 * <td>long</td> 1301 * <td>{@link #CONTACT_STATUS_LABEL}</td> 1302 * <td>read-only</td> 1303 * <td>The resource ID of the label describing the source of contact status, 1304 * e.g. "Google Talk". This resource is scoped by the 1305 * {@link #CONTACT_STATUS_RES_PACKAGE}.</td> 1306 * </tr> 1307 * <tr> 1308 * <td>long</td> 1309 * <td>{@link #CONTACT_STATUS_ICON}</td> 1310 * <td>read-only</td> 1311 * <td>The resource ID of the icon for the source of contact status. This 1312 * resource is scoped by the {@link #CONTACT_STATUS_RES_PACKAGE}.</td> 1313 * </tr> 1314 * </table> 1315 */ 1316 public static class Contacts implements BaseColumns, ContactsColumns, 1317 ContactOptionsColumns, ContactNameColumns, ContactStatusColumns { 1318 /** 1319 * This utility class cannot be instantiated 1320 */ 1321 private Contacts() {} 1322 1323 /** 1324 * The content:// style URI for this table 1325 */ 1326 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "contacts"); 1327 1328 /** 1329 * A content:// style URI for this table that should be used to create 1330 * shortcuts or otherwise create long-term links to contacts. This URI 1331 * should always be followed by a "/" and the contact's {@link #LOOKUP_KEY}. 1332 * It can optionally also have a "/" and last known contact ID appended after 1333 * that. This "complete" format is an important optimization and is highly recommended. 1334 * <p> 1335 * As long as the contact's row ID remains the same, this URI is 1336 * equivalent to {@link #CONTENT_URI}. If the contact's row ID changes 1337 * as a result of a sync or aggregation, this URI will look up the 1338 * contact using indirect information (sync IDs or constituent raw 1339 * contacts). 1340 * <p> 1341 * Lookup key should be appended unencoded - it is stored in the encoded 1342 * form, ready for use in a URI. 1343 */ 1344 public static final Uri CONTENT_LOOKUP_URI = Uri.withAppendedPath(CONTENT_URI, 1345 "lookup"); 1346 1347 /** 1348 * Base {@link Uri} for referencing a single {@link Contacts} entry, 1349 * created by appending {@link #LOOKUP_KEY} using 1350 * {@link Uri#withAppendedPath(Uri, String)}. Provides 1351 * {@link OpenableColumns} columns when queried, or returns the 1352 * referenced contact formatted as a vCard when opened through 1353 * {@link ContentResolver#openAssetFileDescriptor(Uri, String)}. 1354 */ 1355 public static final Uri CONTENT_VCARD_URI = Uri.withAppendedPath(CONTENT_URI, 1356 "as_vcard"); 1357 1358 /** 1359 * Boolean parameter that may be used with {@link #CONTENT_VCARD_URI} 1360 * and {@link #CONTENT_MULTI_VCARD_URI} to indicate that the returned 1361 * vcard should not contain a photo. 1362 * 1363 * @hide 1364 */ 1365 public static final String QUERY_PARAMETER_VCARD_NO_PHOTO = "nophoto"; 1366 1367 /** 1368 * Base {@link Uri} for referencing multiple {@link Contacts} entry, 1369 * created by appending {@link #LOOKUP_KEY} using 1370 * {@link Uri#withAppendedPath(Uri, String)}. The lookup keys have to be 1371 * encoded and joined with the colon (":") separator. The resulting string 1372 * has to be encoded again. Provides 1373 * {@link OpenableColumns} columns when queried, or returns the 1374 * referenced contact formatted as a vCard when opened through 1375 * {@link ContentResolver#openAssetFileDescriptor(Uri, String)}. 1376 * 1377 * This is private API because we do not have a well-defined way to 1378 * specify several entities yet. The format of this Uri might change in the future 1379 * or the Uri might be completely removed. 1380 * 1381 * @hide 1382 */ 1383 public static final Uri CONTENT_MULTI_VCARD_URI = Uri.withAppendedPath(CONTENT_URI, 1384 "as_multi_vcard"); 1385 1386 /** 1387 * Builds a {@link #CONTENT_LOOKUP_URI} style {@link Uri} describing the 1388 * requested {@link Contacts} entry. 1389 * 1390 * @param contactUri A {@link #CONTENT_URI} row, or an existing 1391 * {@link #CONTENT_LOOKUP_URI} to attempt refreshing. 1392 */ 1393 public static Uri getLookupUri(ContentResolver resolver, Uri contactUri) { 1394 final Cursor c = resolver.query(contactUri, new String[] { 1395 Contacts.LOOKUP_KEY, Contacts._ID 1396 }, null, null, null); 1397 if (c == null) { 1398 return null; 1399 } 1400 1401 try { 1402 if (c.moveToFirst()) { 1403 final String lookupKey = c.getString(0); 1404 final long contactId = c.getLong(1); 1405 return getLookupUri(contactId, lookupKey); 1406 } 1407 } finally { 1408 c.close(); 1409 } 1410 return null; 1411 } 1412 1413 /** 1414 * Build a {@link #CONTENT_LOOKUP_URI} lookup {@link Uri} using the 1415 * given {@link ContactsContract.Contacts#_ID} and {@link #LOOKUP_KEY}. 1416 */ 1417 public static Uri getLookupUri(long contactId, String lookupKey) { 1418 return ContentUris.withAppendedId(Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, 1419 lookupKey), contactId); 1420 } 1421 1422 /** 1423 * Computes a content URI (see {@link #CONTENT_URI}) given a lookup URI. 1424 * <p> 1425 * Returns null if the contact cannot be found. 1426 */ 1427 public static Uri lookupContact(ContentResolver resolver, Uri lookupUri) { 1428 if (lookupUri == null) { 1429 return null; 1430 } 1431 1432 Cursor c = resolver.query(lookupUri, new String[]{Contacts._ID}, null, null, null); 1433 if (c == null) { 1434 return null; 1435 } 1436 1437 try { 1438 if (c.moveToFirst()) { 1439 long contactId = c.getLong(0); 1440 return ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId); 1441 } 1442 } finally { 1443 c.close(); 1444 } 1445 return null; 1446 } 1447 1448 /** 1449 * Mark a contact as having been contacted. Updates two fields: 1450 * {@link #TIMES_CONTACTED} and {@link #LAST_TIME_CONTACTED}. The 1451 * TIMES_CONTACTED field is incremented by 1 and the LAST_TIME_CONTACTED 1452 * field is populated with the current system time. 1453 * 1454 * @param resolver the ContentResolver to use 1455 * @param contactId the person who was contacted 1456 */ 1457 public static void markAsContacted(ContentResolver resolver, long contactId) { 1458 Uri uri = ContentUris.withAppendedId(CONTENT_URI, contactId); 1459 ContentValues values = new ContentValues(); 1460 // TIMES_CONTACTED will be incremented when LAST_TIME_CONTACTED is modified. 1461 values.put(LAST_TIME_CONTACTED, System.currentTimeMillis()); 1462 resolver.update(uri, values, null, null); 1463 } 1464 1465 /** 1466 * The content:// style URI used for "type-to-filter" functionality on the 1467 * {@link #CONTENT_URI} URI. The filter string will be used to match 1468 * various parts of the contact name. The filter argument should be passed 1469 * as an additional path segment after this URI. 1470 */ 1471 public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath( 1472 CONTENT_URI, "filter"); 1473 1474 /** 1475 * The content:// style URI for this table joined with useful data from 1476 * {@link ContactsContract.Data}, filtered to include only starred contacts 1477 * and the most frequently contacted contacts. 1478 */ 1479 public static final Uri CONTENT_STREQUENT_URI = Uri.withAppendedPath( 1480 CONTENT_URI, "strequent"); 1481 1482 /** 1483 * The content:// style URI for showing frequently contacted person listing. 1484 * @hide 1485 */ 1486 public static final Uri CONTENT_FREQUENT_URI = Uri.withAppendedPath( 1487 CONTENT_URI, "frequent"); 1488 1489 /** 1490 * The content:// style URI used for "type-to-filter" functionality on the 1491 * {@link #CONTENT_STREQUENT_URI} URI. The filter string will be used to match 1492 * various parts of the contact name. The filter argument should be passed 1493 * as an additional path segment after this URI. 1494 */ 1495 public static final Uri CONTENT_STREQUENT_FILTER_URI = Uri.withAppendedPath( 1496 CONTENT_STREQUENT_URI, "filter"); 1497 1498 public static final Uri CONTENT_GROUP_URI = Uri.withAppendedPath( 1499 CONTENT_URI, "group"); 1500 1501 /** 1502 * The MIME type of {@link #CONTENT_URI} providing a directory of 1503 * people. 1504 */ 1505 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/contact"; 1506 1507 /** 1508 * The MIME type of a {@link #CONTENT_URI} subdirectory of a single 1509 * person. 1510 */ 1511 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact"; 1512 1513 /** 1514 * The MIME type of a {@link #CONTENT_URI} subdirectory of a single 1515 * person. 1516 */ 1517 public static final String CONTENT_VCARD_TYPE = "text/x-vcard"; 1518 1519 /** 1520 * A sub-directory of a single contact that contains all of the constituent raw contact 1521 * {@link ContactsContract.Data} rows. This directory can be used either 1522 * with a {@link #CONTENT_URI} or {@link #CONTENT_LOOKUP_URI}. 1523 */ 1524 public static final class Data implements BaseColumns, DataColumns { 1525 /** 1526 * no public constructor since this is a utility class 1527 */ 1528 private Data() {} 1529 1530 /** 1531 * The directory twig for this sub-table 1532 */ 1533 public static final String CONTENT_DIRECTORY = "data"; 1534 } 1535 1536 /** 1537 * <p> 1538 * A sub-directory of a contact that contains all of its 1539 * {@link ContactsContract.RawContacts} as well as 1540 * {@link ContactsContract.Data} rows. To access this directory append 1541 * {@link #CONTENT_DIRECTORY} to the contact URI. 1542 * </p> 1543 * <p> 1544 * Entity has three ID fields: {@link #CONTACT_ID} for the contact, 1545 * {@link #RAW_CONTACT_ID} for the raw contact and {@link #DATA_ID} for 1546 * the data rows. Entity always contains at least one row per 1547 * constituent raw contact, even if there are no actual data rows. In 1548 * this case the {@link #DATA_ID} field will be null. 1549 * </p> 1550 * <p> 1551 * Entity reads all data for the entire contact in one transaction, to 1552 * guarantee consistency. There is significant data duplication 1553 * in the Entity (each row repeats all Contact columns and all RawContact 1554 * columns), so the benefits of transactional consistency should be weighed 1555 * against the cost of transferring large amounts of denormalized data 1556 * from the Provider. 1557 * </p> 1558 * <p> 1559 * To reduce the amount of data duplication the contacts provider and directory 1560 * providers implementing this protocol are allowed to provide common Contacts 1561 * and RawContacts fields in the first row returned for each raw contact only and 1562 * leave them as null in subsequent rows. 1563 * </p> 1564 */ 1565 public static final class Entity implements BaseColumns, ContactsColumns, 1566 ContactNameColumns, RawContactsColumns, BaseSyncColumns, SyncColumns, DataColumns, 1567 StatusColumns, ContactOptionsColumns, ContactStatusColumns { 1568 /** 1569 * no public constructor since this is a utility class 1570 */ 1571 private Entity() { 1572 } 1573 1574 /** 1575 * The directory twig for this sub-table 1576 */ 1577 public static final String CONTENT_DIRECTORY = "entities"; 1578 1579 /** 1580 * The ID of the raw contact row. 1581 * <P>Type: INTEGER</P> 1582 */ 1583 public static final String RAW_CONTACT_ID = "raw_contact_id"; 1584 1585 /** 1586 * The ID of the data row. The value will be null if this raw contact has no 1587 * data rows. 1588 * <P>Type: INTEGER</P> 1589 */ 1590 public static final String DATA_ID = "data_id"; 1591 } 1592 1593 /** 1594 * A sub-directory of a single contact that contains all of the constituent raw contact 1595 * {@link ContactsContract.StreamItems} rows. This directory can be used either 1596 * with a {@link #CONTENT_URI} or {@link #CONTENT_LOOKUP_URI}. 1597 */ 1598 public static final class StreamItems implements StreamItemsColumns { 1599 /** 1600 * no public constructor since this is a utility class 1601 */ 1602 private StreamItems() {} 1603 1604 /** 1605 * The directory twig for this sub-table 1606 */ 1607 public static final String CONTENT_DIRECTORY = "stream_items"; 1608 } 1609 1610 /** 1611 * <p> 1612 * A <i>read-only</i> sub-directory of a single contact aggregate that 1613 * contains all aggregation suggestions (other contacts). The 1614 * aggregation suggestions are computed based on approximate data 1615 * matches with this contact. 1616 * </p> 1617 * <p> 1618 * <i>Note: this query may be expensive! If you need to use it in bulk, 1619 * make sure the user experience is acceptable when the query runs for a 1620 * long time.</i> 1621 * <p> 1622 * Usage example: 1623 * 1624 * <pre> 1625 * Uri uri = Contacts.CONTENT_URI.buildUpon() 1626 * .appendEncodedPath(String.valueOf(contactId)) 1627 * .appendPath(Contacts.AggregationSuggestions.CONTENT_DIRECTORY) 1628 * .appendQueryParameter("limit", "3") 1629 * .build() 1630 * Cursor cursor = getContentResolver().query(suggestionsUri, 1631 * new String[] {Contacts.DISPLAY_NAME, Contacts._ID, Contacts.LOOKUP_KEY}, 1632 * null, null, null); 1633 * </pre> 1634 * 1635 * </p> 1636 * <p> 1637 * This directory can be used either with a {@link #CONTENT_URI} or 1638 * {@link #CONTENT_LOOKUP_URI}. 1639 * </p> 1640 */ 1641 public static final class AggregationSuggestions implements BaseColumns, ContactsColumns, 1642 ContactOptionsColumns, ContactStatusColumns { 1643 /** 1644 * No public constructor since this is a utility class 1645 */ 1646 private AggregationSuggestions() {} 1647 1648 /** 1649 * The directory twig for this sub-table. The URI can be followed by an optional 1650 * type-to-filter, similar to 1651 * {@link android.provider.ContactsContract.Contacts#CONTENT_FILTER_URI}. 1652 */ 1653 public static final String CONTENT_DIRECTORY = "suggestions"; 1654 1655 /** 1656 * Used with {@link Builder#addParameter} to specify what kind of data is 1657 * supplied for the suggestion query. 1658 * 1659 * @hide 1660 */ 1661 public static final String PARAMETER_MATCH_NAME = "name"; 1662 1663 /** 1664 * Used with {@link Builder#addParameter} to specify what kind of data is 1665 * supplied for the suggestion query. 1666 * 1667 * @hide 1668 */ 1669 public static final String PARAMETER_MATCH_EMAIL = "email"; 1670 1671 /** 1672 * Used with {@link Builder#addParameter} to specify what kind of data is 1673 * supplied for the suggestion query. 1674 * 1675 * @hide 1676 */ 1677 public static final String PARAMETER_MATCH_PHONE = "phone"; 1678 1679 /** 1680 * Used with {@link Builder#addParameter} to specify what kind of data is 1681 * supplied for the suggestion query. 1682 * 1683 * @hide 1684 */ 1685 public static final String PARAMETER_MATCH_NICKNAME = "nickname"; 1686 1687 /** 1688 * A convenience builder for aggregation suggestion content URIs. 1689 * 1690 * TODO: change documentation for this class to use the builder. 1691 * @hide 1692 */ 1693 public static final class Builder { 1694 private long mContactId; 1695 private ArrayList<String> mKinds = new ArrayList<String>(); 1696 private ArrayList<String> mValues = new ArrayList<String>(); 1697 private int mLimit; 1698 1699 /** 1700 * Optional existing contact ID. If it is not provided, the search 1701 * will be based exclusively on the values supplied with {@link #addParameter}. 1702 */ 1703 public Builder setContactId(long contactId) { 1704 this.mContactId = contactId; 1705 return this; 1706 } 1707 1708 /** 1709 * A value that can be used when searching for an aggregation 1710 * suggestion. 1711 * 1712 * @param kind can be one of 1713 * {@link AggregationSuggestions#PARAMETER_MATCH_NAME}, 1714 * {@link AggregationSuggestions#PARAMETER_MATCH_EMAIL}, 1715 * {@link AggregationSuggestions#PARAMETER_MATCH_NICKNAME}, 1716 * {@link AggregationSuggestions#PARAMETER_MATCH_PHONE} 1717 */ 1718 public Builder addParameter(String kind, String value) { 1719 if (!TextUtils.isEmpty(value)) { 1720 mKinds.add(kind); 1721 mValues.add(value); 1722 } 1723 return this; 1724 } 1725 1726 public Builder setLimit(int limit) { 1727 mLimit = limit; 1728 return this; 1729 } 1730 1731 public Uri build() { 1732 android.net.Uri.Builder builder = Contacts.CONTENT_URI.buildUpon(); 1733 builder.appendEncodedPath(String.valueOf(mContactId)); 1734 builder.appendPath(Contacts.AggregationSuggestions.CONTENT_DIRECTORY); 1735 if (mLimit != 0) { 1736 builder.appendQueryParameter("limit", String.valueOf(mLimit)); 1737 } 1738 1739 int count = mKinds.size(); 1740 for (int i = 0; i < count; i++) { 1741 builder.appendQueryParameter("query", mKinds.get(i) + ":" + mValues.get(i)); 1742 } 1743 1744 return builder.build(); 1745 } 1746 } 1747 1748 /** 1749 * @hide 1750 */ 1751 public static final Builder builder() { 1752 return new Builder(); 1753 } 1754 } 1755 1756 /** 1757 * A <i>read-only</i> sub-directory of a single contact that contains 1758 * the contact's primary photo. The photo may be stored in up to two ways - 1759 * the default "photo" is a thumbnail-sized image stored directly in the data 1760 * row, while the "display photo", if present, is a larger version stored as 1761 * a file. 1762 * <p> 1763 * Usage example: 1764 * <dl> 1765 * <dt>Retrieving the thumbnail-sized photo</dt> 1766 * <dd> 1767 * <pre> 1768 * public InputStream openPhoto(long contactId) { 1769 * Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId); 1770 * Uri photoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.CONTENT_DIRECTORY); 1771 * Cursor cursor = getContentResolver().query(photoUri, 1772 * new String[] {Contacts.Photo.PHOTO}, null, null, null); 1773 * if (cursor == null) { 1774 * return null; 1775 * } 1776 * try { 1777 * if (cursor.moveToFirst()) { 1778 * byte[] data = cursor.getBlob(0); 1779 * if (data != null) { 1780 * return new ByteArrayInputStream(data); 1781 * } 1782 * } 1783 * } finally { 1784 * cursor.close(); 1785 * } 1786 * return null; 1787 * } 1788 * </pre> 1789 * </dd> 1790 * <dt>Retrieving the larger photo version</dt> 1791 * <dd> 1792 * <pre> 1793 * public InputStream openDisplayPhoto(long contactId) { 1794 * Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId); 1795 * Uri displayPhotoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.DISPLAY_PHOTO); 1796 * try { 1797 * AssetFileDescriptor fd = 1798 * getContentResolver().openAssetFileDescriptor(displayPhotoUri, "r"); 1799 * return fd.createInputStream(); 1800 * } catch (IOException e) { 1801 * return null; 1802 * } 1803 * } 1804 * </pre> 1805 * </dd> 1806 * </dl> 1807 * 1808 * </p> 1809 * <p>You may also consider using the convenience method 1810 * {@link ContactsContract.Contacts#openContactPhotoInputStream(ContentResolver, Uri, boolean)} 1811 * to retrieve the raw photo contents of either the thumbnail-sized or the full-sized photo. 1812 * </p> 1813 * <p> 1814 * This directory can be used either with a {@link #CONTENT_URI} or 1815 * {@link #CONTENT_LOOKUP_URI}. 1816 * </p> 1817 */ 1818 public static final class Photo implements BaseColumns, DataColumnsWithJoins { 1819 /** 1820 * no public constructor since this is a utility class 1821 */ 1822 private Photo() {} 1823 1824 /** 1825 * The directory twig for this sub-table 1826 */ 1827 public static final String CONTENT_DIRECTORY = "photo"; 1828 1829 /** 1830 * The directory twig for retrieving the full-size display photo. 1831 */ 1832 public static final String DISPLAY_PHOTO = "display_photo"; 1833 1834 /** 1835 * Full-size photo file ID of the raw contact. 1836 * See {@link ContactsContract.DisplayPhoto}. 1837 * <p> 1838 * Type: NUMBER 1839 */ 1840 public static final String PHOTO_FILE_ID = DATA14; 1841 1842 /** 1843 * Thumbnail photo of the raw contact. This is the raw bytes of an image 1844 * that could be inflated using {@link android.graphics.BitmapFactory}. 1845 * <p> 1846 * Type: BLOB 1847 */ 1848 public static final String PHOTO = DATA15; 1849 } 1850 1851 /** 1852 * Opens an InputStream for the contacts's photo and returns the 1853 * photo as a byte stream. 1854 * @param cr The content resolver to use for querying 1855 * @param contactUri the contact whose photo should be used. This can be used with 1856 * either a {@link #CONTENT_URI} or a {@link #CONTENT_LOOKUP_URI} URI. 1857 * @param preferHighres If this is true and the contact has a higher resolution photo 1858 * available, it is returned. If false, this function always tries to get the thumbnail 1859 * @return an InputStream of the photo, or null if no photo is present 1860 */ 1861 public static InputStream openContactPhotoInputStream(ContentResolver cr, Uri contactUri, 1862 boolean preferHighres) { 1863 if (preferHighres) { 1864 final Uri displayPhotoUri = Uri.withAppendedPath(contactUri, 1865 Contacts.Photo.DISPLAY_PHOTO); 1866 InputStream inputStream; 1867 try { 1868 AssetFileDescriptor fd = cr.openAssetFileDescriptor(displayPhotoUri, "r"); 1869 return fd.createInputStream(); 1870 } catch (IOException e) { 1871 // fallback to the thumbnail code 1872 } 1873 } 1874 1875 Uri photoUri = Uri.withAppendedPath(contactUri, Photo.CONTENT_DIRECTORY); 1876 if (photoUri == null) { 1877 return null; 1878 } 1879 Cursor cursor = cr.query(photoUri, 1880 new String[] { 1881 ContactsContract.CommonDataKinds.Photo.PHOTO 1882 }, null, null, null); 1883 try { 1884 if (cursor == null || !cursor.moveToNext()) { 1885 return null; 1886 } 1887 byte[] data = cursor.getBlob(0); 1888 if (data == null) { 1889 return null; 1890 } 1891 return new ByteArrayInputStream(data); 1892 } finally { 1893 if (cursor != null) { 1894 cursor.close(); 1895 } 1896 } 1897 } 1898 1899 /** 1900 * Opens an InputStream for the contacts's thumbnail photo and returns the 1901 * photo as a byte stream. 1902 * @param cr The content resolver to use for querying 1903 * @param contactUri the contact whose photo should be used. This can be used with 1904 * either a {@link #CONTENT_URI} or a {@link #CONTENT_LOOKUP_URI} URI. 1905 * @return an InputStream of the photo, or null if no photo is present 1906 * @see #openContactPhotoInputStream(ContentResolver, Uri, boolean), if instead 1907 * of the thumbnail the high-res picture is preferred 1908 */ 1909 public static InputStream openContactPhotoInputStream(ContentResolver cr, Uri contactUri) { 1910 return openContactPhotoInputStream(cr, contactUri, false); 1911 } 1912 } 1913 1914 /** 1915 * <p> 1916 * Constants for the user's profile data, which is represented as a single contact on 1917 * the device that represents the user. The profile contact is not aggregated 1918 * together automatically in the same way that normal contacts are; instead, each 1919 * account (including data set, if applicable) on the device may contribute a single 1920 * raw contact representing the user's personal profile data from that source. 1921 * </p> 1922 * <p> 1923 * Access to the profile entry through these URIs (or incidental access to parts of 1924 * the profile if retrieved directly via ID) requires additional permissions beyond 1925 * the read/write contact permissions required by the provider. Querying for profile 1926 * data requires android.permission.READ_PROFILE permission, and inserting or 1927 * updating profile data requires android.permission.WRITE_PROFILE permission. 1928 * </p> 1929 * <h3>Operations</h3> 1930 * <dl> 1931 * <dt><b>Insert</b></dt> 1932 * <dd>The user's profile entry cannot be created explicitly (attempting to do so 1933 * will throw an exception). When a raw contact is inserted into the profile, the 1934 * provider will check for the existence of a profile on the device. If one is 1935 * found, the raw contact's {@link RawContacts#CONTACT_ID} column gets the _ID of 1936 * the profile Contact. If no match is found, the profile Contact is created and 1937 * its _ID is put into the {@link RawContacts#CONTACT_ID} column of the newly 1938 * inserted raw contact.</dd> 1939 * <dt><b>Update</b></dt> 1940 * <dd>The profile Contact has the same update restrictions as Contacts in general, 1941 * but requires the android.permission.WRITE_PROFILE permission.</dd> 1942 * <dt><b>Delete</b></dt> 1943 * <dd>The profile Contact cannot be explicitly deleted. It will be removed 1944 * automatically if all of its constituent raw contact entries are deleted.</dd> 1945 * <dt><b>Query</b></dt> 1946 * <dd> 1947 * <ul> 1948 * <li>The {@link #CONTENT_URI} for profiles behaves in much the same way as 1949 * retrieving a contact by ID, except that it will only ever return the user's 1950 * profile contact. 1951 * </li> 1952 * <li> 1953 * The profile contact supports all of the same sub-paths as an individual contact 1954 * does - the content of the profile contact can be retrieved as entities or 1955 * data rows. Similarly, specific raw contact entries can be retrieved by appending 1956 * the desired raw contact ID within the profile. 1957 * </li> 1958 * </ul> 1959 * </dd> 1960 * </dl> 1961 */ 1962 public static final class Profile implements BaseColumns, ContactsColumns, 1963 ContactOptionsColumns, ContactNameColumns, ContactStatusColumns { 1964 /** 1965 * This utility class cannot be instantiated 1966 */ 1967 private Profile() { 1968 } 1969 1970 /** 1971 * The content:// style URI for this table, which requests the contact entry 1972 * representing the user's personal profile data. 1973 */ 1974 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "profile"); 1975 1976 /** 1977 * {@link Uri} for referencing the user's profile {@link Contacts} entry, 1978 * Provides {@link OpenableColumns} columns when queried, or returns the 1979 * user's profile contact formatted as a vCard when opened through 1980 * {@link ContentResolver#openAssetFileDescriptor(Uri, String)}. 1981 */ 1982 public static final Uri CONTENT_VCARD_URI = Uri.withAppendedPath(CONTENT_URI, 1983 "as_vcard"); 1984 1985 /** 1986 * {@link Uri} for referencing the raw contacts that make up the user's profile 1987 * {@link Contacts} entry. An individual raw contact entry within the profile 1988 * can be addressed by appending the raw contact ID. The entities or data within 1989 * that specific raw contact can be requested by appending the entity or data 1990 * path as well. 1991 */ 1992 public static final Uri CONTENT_RAW_CONTACTS_URI = Uri.withAppendedPath(CONTENT_URI, 1993 "raw_contacts"); 1994 1995 /** 1996 * The minimum ID for any entity that belongs to the profile. This essentially 1997 * defines an ID-space in which profile data is stored, and is used by the provider 1998 * to determine whether a request via a non-profile-specific URI should be directed 1999 * to the profile data rather than general contacts data, along with all the special 2000 * permission checks that entails. 2001 * 2002 * Callers may use {@link #isProfileId} to check whether a specific ID falls into 2003 * the set of data intended for the profile. 2004 */ 2005 public static final long MIN_ID = Long.MAX_VALUE - (long) Integer.MAX_VALUE; 2006 } 2007 2008 /** 2009 * This method can be used to identify whether the given ID is associated with profile 2010 * data. It does not necessarily indicate that the ID is tied to valid data, merely 2011 * that accessing data using this ID will result in profile access checks and will only 2012 * return data from the profile. 2013 * 2014 * @param id The ID to check. 2015 * @return Whether the ID is associated with profile data. 2016 */ 2017 public static boolean isProfileId(long id) { 2018 return id >= Profile.MIN_ID; 2019 } 2020 2021 protected interface RawContactsColumns { 2022 /** 2023 * A reference to the {@link ContactsContract.Contacts#_ID} that this 2024 * data belongs to. 2025 * <P>Type: INTEGER</P> 2026 */ 2027 public static final String CONTACT_ID = "contact_id"; 2028 2029 /** 2030 * The data set within the account that this row belongs to. This allows 2031 * multiple sync adapters for the same account type to distinguish between 2032 * each others' data. 2033 * 2034 * This is empty by default, and is completely optional. It only needs to 2035 * be populated if multiple sync adapters are entering distinct data for 2036 * the same account type and account name. 2037 * <P>Type: TEXT</P> 2038 */ 2039 public static final String DATA_SET = "data_set"; 2040 2041 /** 2042 * A concatenation of the account type and data set (delimited by a forward 2043 * slash) - if the data set is empty, this will be the same as the account 2044 * type. For applications that need to be aware of the data set, this can 2045 * be used instead of account type to distinguish sets of data. This is 2046 * never intended to be used for specifying accounts. 2047 * @hide 2048 */ 2049 public static final String ACCOUNT_TYPE_AND_DATA_SET = "account_type_and_data_set"; 2050 2051 /** 2052 * The aggregation mode for this contact. 2053 * <P>Type: INTEGER</P> 2054 */ 2055 public static final String AGGREGATION_MODE = "aggregation_mode"; 2056 2057 /** 2058 * The "deleted" flag: "0" by default, "1" if the row has been marked 2059 * for deletion. When {@link android.content.ContentResolver#delete} is 2060 * called on a raw contact, it is marked for deletion and removed from its 2061 * aggregate contact. The sync adaptor deletes the raw contact on the server and 2062 * then calls ContactResolver.delete once more, this time passing the 2063 * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to finalize 2064 * the data removal. 2065 * <P>Type: INTEGER</P> 2066 */ 2067 public static final String DELETED = "deleted"; 2068 2069 /** 2070 * The "name_verified" flag: "1" means that the name fields on this raw 2071 * contact can be trusted and therefore should be used for the entire 2072 * aggregated contact. 2073 * <p> 2074 * If an aggregated contact contains more than one raw contact with a 2075 * verified name, one of those verified names is chosen at random. 2076 * If an aggregated contact contains no verified names, the 2077 * name is chosen randomly from the constituent raw contacts. 2078 * </p> 2079 * <p> 2080 * Updating this flag from "0" to "1" automatically resets it to "0" on 2081 * all other raw contacts in the same aggregated contact. 2082 * </p> 2083 * <p> 2084 * Sync adapters should only specify a value for this column when 2085 * inserting a raw contact and leave it out when doing an update. 2086 * </p> 2087 * <p> 2088 * The default value is "0" 2089 * </p> 2090 * <p>Type: INTEGER</p> 2091 * 2092 * @hide 2093 */ 2094 public static final String NAME_VERIFIED = "name_verified"; 2095 2096 /** 2097 * The "read-only" flag: "0" by default, "1" if the row cannot be modified or 2098 * deleted except by a sync adapter. See {@link ContactsContract#CALLER_IS_SYNCADAPTER}. 2099 * <P>Type: INTEGER</P> 2100 */ 2101 public static final String RAW_CONTACT_IS_READ_ONLY = "raw_contact_is_read_only"; 2102 2103 /** 2104 * Flag that reflects whether this raw contact belongs to the user's 2105 * personal profile entry. 2106 */ 2107 public static final String RAW_CONTACT_IS_USER_PROFILE = "raw_contact_is_user_profile"; 2108 } 2109 2110 /** 2111 * Constants for the raw contacts table, which contains one row of contact 2112 * information for each person in each synced account. Sync adapters and 2113 * contact management apps 2114 * are the primary consumers of this API. 2115 * 2116 * <h3>Aggregation</h3> 2117 * <p> 2118 * As soon as a raw contact is inserted or whenever its constituent data 2119 * changes, the provider will check if the raw contact matches other 2120 * existing raw contacts and if so will aggregate it with those. The 2121 * aggregation is reflected in the {@link RawContacts} table by the change of the 2122 * {@link #CONTACT_ID} field, which is the reference to the aggregate contact. 2123 * </p> 2124 * <p> 2125 * Changes to the structured name, organization, phone number, email address, 2126 * or nickname trigger a re-aggregation. 2127 * </p> 2128 * <p> 2129 * See also {@link AggregationExceptions} for a mechanism to control 2130 * aggregation programmatically. 2131 * </p> 2132 * 2133 * <h3>Operations</h3> 2134 * <dl> 2135 * <dt><b>Insert</b></dt> 2136 * <dd> 2137 * <p> 2138 * Raw contacts can be inserted incrementally or in a batch. 2139 * The incremental method is more traditional but less efficient. 2140 * It should be used 2141 * only if no {@link Data} values are available at the time the raw contact is created: 2142 * <pre> 2143 * ContentValues values = new ContentValues(); 2144 * values.put(RawContacts.ACCOUNT_TYPE, accountType); 2145 * values.put(RawContacts.ACCOUNT_NAME, accountName); 2146 * Uri rawContactUri = getContentResolver().insert(RawContacts.CONTENT_URI, values); 2147 * long rawContactId = ContentUris.parseId(rawContactUri); 2148 * </pre> 2149 * </p> 2150 * <p> 2151 * Once {@link Data} values become available, insert those. 2152 * For example, here's how you would insert a name: 2153 * 2154 * <pre> 2155 * values.clear(); 2156 * values.put(Data.RAW_CONTACT_ID, rawContactId); 2157 * values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE); 2158 * values.put(StructuredName.DISPLAY_NAME, "Mike Sullivan"); 2159 * getContentResolver().insert(Data.CONTENT_URI, values); 2160 * </pre> 2161 * </p> 2162 * <p> 2163 * The batch method is by far preferred. It inserts the raw contact and its 2164 * constituent data rows in a single database transaction 2165 * and causes at most one aggregation pass. 2166 * <pre> 2167 * ArrayList<ContentProviderOperation> ops = 2168 * new ArrayList<ContentProviderOperation>(); 2169 * ... 2170 * int rawContactInsertIndex = ops.size(); 2171 * ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI) 2172 * .withValue(RawContacts.ACCOUNT_TYPE, accountType) 2173 * .withValue(RawContacts.ACCOUNT_NAME, accountName) 2174 * .build()); 2175 * 2176 * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI) 2177 * .withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex) 2178 * .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE) 2179 * .withValue(StructuredName.DISPLAY_NAME, "Mike Sullivan") 2180 * .build()); 2181 * 2182 * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); 2183 * </pre> 2184 * </p> 2185 * <p> 2186 * Note the use of {@link ContentProviderOperation.Builder#withValueBackReference(String, int)} 2187 * to refer to the as-yet-unknown index value of the raw contact inserted in the 2188 * first operation. 2189 * </p> 2190 * 2191 * <dt><b>Update</b></dt> 2192 * <dd><p> 2193 * Raw contacts can be updated incrementally or in a batch. 2194 * Batch mode should be used whenever possible. 2195 * The procedures and considerations are analogous to those documented above for inserts. 2196 * </p></dd> 2197 * <dt><b>Delete</b></dt> 2198 * <dd><p>When a raw contact is deleted, all of its Data rows as well as StatusUpdates, 2199 * AggregationExceptions, PhoneLookup rows are deleted automatically. When all raw 2200 * contacts associated with a {@link Contacts} row are deleted, the {@link Contacts} row 2201 * itself is also deleted automatically. 2202 * </p> 2203 * <p> 2204 * The invocation of {@code resolver.delete(...)}, does not immediately delete 2205 * a raw contacts row. 2206 * Instead, it sets the {@link #DELETED} flag on the raw contact and 2207 * removes the raw contact from its aggregate contact. 2208 * The sync adapter then deletes the raw contact from the server and 2209 * finalizes phone-side deletion by calling {@code resolver.delete(...)} 2210 * again and passing the {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter.<p> 2211 * <p>Some sync adapters are read-only, meaning that they only sync server-side 2212 * changes to the phone, but not the reverse. If one of those raw contacts 2213 * is marked for deletion, it will remain on the phone. However it will be 2214 * effectively invisible, because it will not be part of any aggregate contact. 2215 * </dd> 2216 * 2217 * <dt><b>Query</b></dt> 2218 * <dd> 2219 * <p> 2220 * It is easy to find all raw contacts in a Contact: 2221 * <pre> 2222 * Cursor c = getContentResolver().query(RawContacts.CONTENT_URI, 2223 * new String[]{RawContacts._ID}, 2224 * RawContacts.CONTACT_ID + "=?", 2225 * new String[]{String.valueOf(contactId)}, null); 2226 * </pre> 2227 * </p> 2228 * <p> 2229 * To find raw contacts within a specific account, 2230 * you can either put the account name and type in the selection or pass them as query 2231 * parameters. The latter approach is preferable, especially when you can reuse the 2232 * URI: 2233 * <pre> 2234 * Uri rawContactUri = RawContacts.URI.buildUpon() 2235 * .appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName) 2236 * .appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType) 2237 * .build(); 2238 * Cursor c1 = getContentResolver().query(rawContactUri, 2239 * RawContacts.STARRED + "<>0", null, null, null); 2240 * ... 2241 * Cursor c2 = getContentResolver().query(rawContactUri, 2242 * RawContacts.DELETED + "<>0", null, null, null); 2243 * </pre> 2244 * </p> 2245 * <p>The best way to read a raw contact along with all the data associated with it is 2246 * by using the {@link Entity} directory. If the raw contact has data rows, 2247 * the Entity cursor will contain a row for each data row. If the raw contact has no 2248 * data rows, the cursor will still contain one row with the raw contact-level information. 2249 * <pre> 2250 * Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId); 2251 * Uri entityUri = Uri.withAppendedPath(rawContactUri, Entity.CONTENT_DIRECTORY); 2252 * Cursor c = getContentResolver().query(entityUri, 2253 * new String[]{RawContacts.SOURCE_ID, Entity.DATA_ID, Entity.MIMETYPE, Entity.DATA1}, 2254 * null, null, null); 2255 * try { 2256 * while (c.moveToNext()) { 2257 * String sourceId = c.getString(0); 2258 * if (!c.isNull(1)) { 2259 * String mimeType = c.getString(2); 2260 * String data = c.getString(3); 2261 * ... 2262 * } 2263 * } 2264 * } finally { 2265 * c.close(); 2266 * } 2267 * </pre> 2268 * </p> 2269 * </dd> 2270 * </dl> 2271 * <h2>Columns</h2> 2272 * 2273 * <table class="jd-sumtable"> 2274 * <tr> 2275 * <th colspan='4'>RawContacts</th> 2276 * </tr> 2277 * <tr> 2278 * <td>long</td> 2279 * <td>{@link #_ID}</td> 2280 * <td>read-only</td> 2281 * <td>Row ID. Sync adapters should try to preserve row IDs during updates. In other words, 2282 * it is much better for a sync adapter to update a raw contact rather than to delete and 2283 * re-insert it.</td> 2284 * </tr> 2285 * <tr> 2286 * <td>long</td> 2287 * <td>{@link #CONTACT_ID}</td> 2288 * <td>read-only</td> 2289 * <td>The ID of the row in the {@link ContactsContract.Contacts} table 2290 * that this raw contact belongs 2291 * to. Raw contacts are linked to contacts by the aggregation process, which can be controlled 2292 * by the {@link #AGGREGATION_MODE} field and {@link AggregationExceptions}.</td> 2293 * </tr> 2294 * <tr> 2295 * <td>int</td> 2296 * <td>{@link #AGGREGATION_MODE}</td> 2297 * <td>read/write</td> 2298 * <td>A mechanism that allows programmatic control of the aggregation process. The allowed 2299 * values are {@link #AGGREGATION_MODE_DEFAULT}, {@link #AGGREGATION_MODE_DISABLED} 2300 * and {@link #AGGREGATION_MODE_SUSPENDED}. See also {@link AggregationExceptions}.</td> 2301 * </tr> 2302 * <tr> 2303 * <td>int</td> 2304 * <td>{@link #DELETED}</td> 2305 * <td>read/write</td> 2306 * <td>The "deleted" flag: "0" by default, "1" if the row has been marked 2307 * for deletion. When {@link android.content.ContentResolver#delete} is 2308 * called on a raw contact, it is marked for deletion and removed from its 2309 * aggregate contact. The sync adaptor deletes the raw contact on the server and 2310 * then calls ContactResolver.delete once more, this time passing the 2311 * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to finalize 2312 * the data removal.</td> 2313 * </tr> 2314 * <tr> 2315 * <td>int</td> 2316 * <td>{@link #TIMES_CONTACTED}</td> 2317 * <td>read/write</td> 2318 * <td>The number of times the contact has been contacted. To have an effect 2319 * on the corresponding value of the aggregate contact, this field 2320 * should be set at the time the raw contact is inserted. 2321 * After that, this value is typically updated via 2322 * {@link ContactsContract.Contacts#markAsContacted}.</td> 2323 * </tr> 2324 * <tr> 2325 * <td>long</td> 2326 * <td>{@link #LAST_TIME_CONTACTED}</td> 2327 * <td>read/write</td> 2328 * <td>The timestamp of the last time the contact was contacted. To have an effect 2329 * on the corresponding value of the aggregate contact, this field 2330 * should be set at the time the raw contact is inserted. 2331 * After that, this value is typically updated via 2332 * {@link ContactsContract.Contacts#markAsContacted}. 2333 * </td> 2334 * </tr> 2335 * <tr> 2336 * <td>int</td> 2337 * <td>{@link #STARRED}</td> 2338 * <td>read/write</td> 2339 * <td>An indicator for favorite contacts: '1' if favorite, '0' otherwise. 2340 * Changing this field immediately affects the corresponding aggregate contact: 2341 * if any raw contacts in that aggregate contact are starred, then the contact 2342 * itself is marked as starred.</td> 2343 * </tr> 2344 * <tr> 2345 * <td>String</td> 2346 * <td>{@link #CUSTOM_RINGTONE}</td> 2347 * <td>read/write</td> 2348 * <td>A custom ringtone associated with a raw contact. Typically this is the 2349 * URI returned by an activity launched with the 2350 * {@link android.media.RingtoneManager#ACTION_RINGTONE_PICKER} intent. 2351 * To have an effect on the corresponding value of the aggregate contact, this field 2352 * should be set at the time the raw contact is inserted. To set a custom 2353 * ringtone on a contact, use the field {@link ContactsContract.Contacts#CUSTOM_RINGTONE 2354 * Contacts.CUSTOM_RINGTONE} 2355 * instead.</td> 2356 * </tr> 2357 * <tr> 2358 * <td>int</td> 2359 * <td>{@link #SEND_TO_VOICEMAIL}</td> 2360 * <td>read/write</td> 2361 * <td>An indicator of whether calls from this raw contact should be forwarded 2362 * directly to voice mail ('1') or not ('0'). To have an effect 2363 * on the corresponding value of the aggregate contact, this field 2364 * should be set at the time the raw contact is inserted.</td> 2365 * </tr> 2366 * <tr> 2367 * <td>String</td> 2368 * <td>{@link #ACCOUNT_NAME}</td> 2369 * <td>read/write-once</td> 2370 * <td>The name of the account instance to which this row belongs, which when paired with 2371 * {@link #ACCOUNT_TYPE} identifies a specific account. 2372 * For example, this will be the Gmail address if it is a Google account. 2373 * It should be set at the time the raw contact is inserted and never 2374 * changed afterwards.</td> 2375 * </tr> 2376 * <tr> 2377 * <td>String</td> 2378 * <td>{@link #ACCOUNT_TYPE}</td> 2379 * <td>read/write-once</td> 2380 * <td> 2381 * <p> 2382 * The type of account to which this row belongs, which when paired with 2383 * {@link #ACCOUNT_NAME} identifies a specific account. 2384 * It should be set at the time the raw contact is inserted and never 2385 * changed afterwards. 2386 * </p> 2387 * <p> 2388 * To ensure uniqueness, new account types should be chosen according to the 2389 * Java package naming convention. Thus a Google account is of type "com.google". 2390 * </p> 2391 * </td> 2392 * </tr> 2393 * <tr> 2394 * <td>String</td> 2395 * <td>{@link #DATA_SET}</td> 2396 * <td>read/write-once</td> 2397 * <td> 2398 * <p> 2399 * The data set within the account that this row belongs to. This allows 2400 * multiple sync adapters for the same account type to distinguish between 2401 * each others' data. The combination of {@link #ACCOUNT_TYPE}, 2402 * {@link #ACCOUNT_NAME}, and {@link #DATA_SET} identifies a set of data 2403 * that is associated with a single sync adapter. 2404 * </p> 2405 * <p> 2406 * This is empty by default, and is completely optional. It only needs to 2407 * be populated if multiple sync adapters are entering distinct data for 2408 * the same account type and account name. 2409 * </p> 2410 * <p> 2411 * It should be set at the time the raw contact is inserted and never 2412 * changed afterwards. 2413 * </p> 2414 * </td> 2415 * </tr> 2416 * <tr> 2417 * <td>String</td> 2418 * <td>{@link #SOURCE_ID}</td> 2419 * <td>read/write</td> 2420 * <td>String that uniquely identifies this row to its source account. 2421 * Typically it is set at the time the raw contact is inserted and never 2422 * changed afterwards. The one notable exception is a new raw contact: it 2423 * will have an account name and type (and possibly a data set), but no 2424 * source id. This indicates to the sync adapter that a new contact needs 2425 * to be created server-side and its ID stored in the corresponding 2426 * SOURCE_ID field on the phone. 2427 * </td> 2428 * </tr> 2429 * <tr> 2430 * <td>int</td> 2431 * <td>{@link #VERSION}</td> 2432 * <td>read-only</td> 2433 * <td>Version number that is updated whenever this row or its related data 2434 * changes. This field can be used for optimistic locking of a raw contact. 2435 * </td> 2436 * </tr> 2437 * <tr> 2438 * <td>int</td> 2439 * <td>{@link #DIRTY}</td> 2440 * <td>read/write</td> 2441 * <td>Flag indicating that {@link #VERSION} has changed, and this row needs 2442 * to be synchronized by its owning account. The value is set to "1" automatically 2443 * whenever the raw contact changes, unless the URI has the 2444 * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter specified. 2445 * The sync adapter should always supply this query parameter to prevent 2446 * unnecessary synchronization: user changes some data on the server, 2447 * the sync adapter updates the contact on the phone (without the 2448 * CALLER_IS_SYNCADAPTER flag) flag, which sets the DIRTY flag, 2449 * which triggers a sync to bring the changes to the server. 2450 * </td> 2451 * </tr> 2452 * <tr> 2453 * <td>String</td> 2454 * <td>{@link #SYNC1}</td> 2455 * <td>read/write</td> 2456 * <td>Generic column provided for arbitrary use by sync adapters. 2457 * The content provider 2458 * stores this information on behalf of the sync adapter but does not 2459 * interpret it in any way. 2460 * </td> 2461 * </tr> 2462 * <tr> 2463 * <td>String</td> 2464 * <td>{@link #SYNC2}</td> 2465 * <td>read/write</td> 2466 * <td>Generic column for use by sync adapters. 2467 * </td> 2468 * </tr> 2469 * <tr> 2470 * <td>String</td> 2471 * <td>{@link #SYNC3}</td> 2472 * <td>read/write</td> 2473 * <td>Generic column for use by sync adapters. 2474 * </td> 2475 * </tr> 2476 * <tr> 2477 * <td>String</td> 2478 * <td>{@link #SYNC4}</td> 2479 * <td>read/write</td> 2480 * <td>Generic column for use by sync adapters. 2481 * </td> 2482 * </tr> 2483 * </table> 2484 */ 2485 public static final class RawContacts implements BaseColumns, RawContactsColumns, 2486 ContactOptionsColumns, ContactNameColumns, SyncColumns { 2487 /** 2488 * This utility class cannot be instantiated 2489 */ 2490 private RawContacts() { 2491 } 2492 2493 /** 2494 * The content:// style URI for this table, which requests a directory of 2495 * raw contact rows matching the selection criteria. 2496 */ 2497 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "raw_contacts"); 2498 2499 /** 2500 * The MIME type of the results from {@link #CONTENT_URI} when a specific 2501 * ID value is not provided, and multiple raw contacts may be returned. 2502 */ 2503 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/raw_contact"; 2504 2505 /** 2506 * The MIME type of the results when a raw contact ID is appended to {@link #CONTENT_URI}, 2507 * yielding a subdirectory of a single person. 2508 */ 2509 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/raw_contact"; 2510 2511 /** 2512 * Aggregation mode: aggregate immediately after insert or update operation(s) are complete. 2513 */ 2514 public static final int AGGREGATION_MODE_DEFAULT = 0; 2515 2516 /** 2517 * Aggregation mode: aggregate at the time the raw contact is inserted/updated. 2518 * @deprecated Aggregation is synchronous, this historic value is a no-op 2519 */ 2520 @Deprecated 2521 public static final int AGGREGATION_MODE_IMMEDIATE = 1; 2522 2523 /** 2524 * <p> 2525 * Aggregation mode: aggregation suspended temporarily, and is likely to be resumed later. 2526 * Changes to the raw contact will update the associated aggregate contact but will not 2527 * result in any change in how the contact is aggregated. Similar to 2528 * {@link #AGGREGATION_MODE_DISABLED}, but maintains a link to the corresponding 2529 * {@link Contacts} aggregate. 2530 * </p> 2531 * <p> 2532 * This can be used to postpone aggregation until after a series of updates, for better 2533 * performance and/or user experience. 2534 * </p> 2535 * <p> 2536 * Note that changing 2537 * {@link #AGGREGATION_MODE} from {@link #AGGREGATION_MODE_SUSPENDED} to 2538 * {@link #AGGREGATION_MODE_DEFAULT} does not trigger an aggregation pass, but any 2539 * subsequent 2540 * change to the raw contact's data will. 2541 * </p> 2542 */ 2543 public static final int AGGREGATION_MODE_SUSPENDED = 2; 2544 2545 /** 2546 * <p> 2547 * Aggregation mode: never aggregate this raw contact. The raw contact will not 2548 * have a corresponding {@link Contacts} aggregate and therefore will not be included in 2549 * {@link Contacts} query results. 2550 * </p> 2551 * <p> 2552 * For example, this mode can be used for a raw contact that is marked for deletion while 2553 * waiting for the deletion to occur on the server side. 2554 * </p> 2555 * 2556 * @see #AGGREGATION_MODE_SUSPENDED 2557 */ 2558 public static final int AGGREGATION_MODE_DISABLED = 3; 2559 2560 /** 2561 * Build a {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI} 2562 * style {@link Uri} for the parent {@link android.provider.ContactsContract.Contacts} 2563 * entry of the given {@link RawContacts} entry. 2564 */ 2565 public static Uri getContactLookupUri(ContentResolver resolver, Uri rawContactUri) { 2566 // TODO: use a lighter query by joining rawcontacts with contacts in provider 2567 final Uri dataUri = Uri.withAppendedPath(rawContactUri, Data.CONTENT_DIRECTORY); 2568 final Cursor cursor = resolver.query(dataUri, new String[] { 2569 RawContacts.CONTACT_ID, Contacts.LOOKUP_KEY 2570 }, null, null, null); 2571 2572 Uri lookupUri = null; 2573 try { 2574 if (cursor != null && cursor.moveToFirst()) { 2575 final long contactId = cursor.getLong(0); 2576 final String lookupKey = cursor.getString(1); 2577 return Contacts.getLookupUri(contactId, lookupKey); 2578 } 2579 } finally { 2580 if (cursor != null) cursor.close(); 2581 } 2582 return lookupUri; 2583 } 2584 2585 /** 2586 * A sub-directory of a single raw contact that contains all of its 2587 * {@link ContactsContract.Data} rows. To access this directory 2588 * append {@link Data#CONTENT_DIRECTORY} to the raw contact URI. 2589 */ 2590 public static final class Data implements BaseColumns, DataColumns { 2591 /** 2592 * no public constructor since this is a utility class 2593 */ 2594 private Data() { 2595 } 2596 2597 /** 2598 * The directory twig for this sub-table 2599 */ 2600 public static final String CONTENT_DIRECTORY = "data"; 2601 } 2602 2603 /** 2604 * <p> 2605 * A sub-directory of a single raw contact that contains all of its 2606 * {@link ContactsContract.Data} rows. To access this directory append 2607 * {@link RawContacts.Entity#CONTENT_DIRECTORY} to the raw contact URI. See 2608 * {@link RawContactsEntity} for a stand-alone table containing the same 2609 * data. 2610 * </p> 2611 * <p> 2612 * Entity has two ID fields: {@link #_ID} for the raw contact 2613 * and {@link #DATA_ID} for the data rows. 2614 * Entity always contains at least one row, even if there are no 2615 * actual data rows. In this case the {@link #DATA_ID} field will be 2616 * null. 2617 * </p> 2618 * <p> 2619 * Using Entity should be preferred to using two separate queries: 2620 * RawContacts followed by Data. The reason is that Entity reads all 2621 * data for a raw contact in one transaction, so there is no possibility 2622 * of the data changing between the two queries. 2623 */ 2624 public static final class Entity implements BaseColumns, DataColumns { 2625 /** 2626 * no public constructor since this is a utility class 2627 */ 2628 private Entity() { 2629 } 2630 2631 /** 2632 * The directory twig for this sub-table 2633 */ 2634 public static final String CONTENT_DIRECTORY = "entity"; 2635 2636 /** 2637 * The ID of the data row. The value will be null if this raw contact has no 2638 * data rows. 2639 * <P>Type: INTEGER</P> 2640 */ 2641 public static final String DATA_ID = "data_id"; 2642 } 2643 2644 /** 2645 * <p> 2646 * A sub-directory of a single raw contact that contains all of its 2647 * {@link ContactsContract.StreamItems} rows. To access this directory append 2648 * {@link RawContacts.StreamItems#CONTENT_DIRECTORY} to the raw contact URI. See 2649 * {@link ContactsContract.StreamItems} for a stand-alone table containing the 2650 * same data. 2651 * </p> 2652 */ 2653 public static final class StreamItems implements BaseColumns, StreamItemsColumns { 2654 /** 2655 * No public constructor since this is a utility class 2656 */ 2657 private StreamItems() { 2658 } 2659 2660 /** 2661 * The directory twig for this sub-table 2662 */ 2663 public static final String CONTENT_DIRECTORY = "stream_items"; 2664 } 2665 2666 /** 2667 * <p> 2668 * A sub-directory of a single raw contact that represents its primary 2669 * display photo. To access this directory append 2670 * {@link RawContacts.DisplayPhoto#CONTENT_DIRECTORY} to the raw contact URI. 2671 * The resulting URI represents an image file, and should be interacted with 2672 * using ContentResolver.openAssetFileDescriptor. 2673 * <p> 2674 * <p> 2675 * Note that this sub-directory also supports opening the photo as an asset file 2676 * in write mode. Callers can create or replace the primary photo associated 2677 * with this raw contact by opening the asset file and writing the full-size 2678 * photo contents into it. When the file is closed, the image will be parsed, 2679 * sized down if necessary for the full-size display photo and thumbnail 2680 * dimensions, and stored. 2681 * </p> 2682 * <p> 2683 * Usage example: 2684 * <pre> 2685 * public void writeDisplayPhoto(long rawContactId, byte[] photo) { 2686 * Uri rawContactPhotoUri = Uri.withAppendedPath( 2687 * ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId), 2688 * RawContacts.DisplayPhoto.CONTENT_DIRECTORY); 2689 * try { 2690 * AssetFileDescriptor fd = 2691 * getContentResolver().openAssetFileDescriptor(rawContactPhotoUri, "rw"); 2692 * OutputStream os = fd.createOutputStream(); 2693 * os.write(photo); 2694 * os.close(); 2695 * fd.close(); 2696 * } catch (IOException e) { 2697 * // Handle error cases. 2698 * } 2699 * } 2700 * </pre> 2701 * </p> 2702 */ 2703 public static final class DisplayPhoto { 2704 /** 2705 * No public constructor since this is a utility class 2706 */ 2707 private DisplayPhoto() { 2708 } 2709 2710 /** 2711 * The directory twig for this sub-table 2712 */ 2713 public static final String CONTENT_DIRECTORY = "display_photo"; 2714 } 2715 2716 /** 2717 * TODO: javadoc 2718 * @param cursor 2719 * @return 2720 */ 2721 public static EntityIterator newEntityIterator(Cursor cursor) { 2722 return new EntityIteratorImpl(cursor); 2723 } 2724 2725 private static class EntityIteratorImpl extends CursorEntityIterator { 2726 private static final String[] DATA_KEYS = new String[]{ 2727 Data.DATA1, 2728 Data.DATA2, 2729 Data.DATA3, 2730 Data.DATA4, 2731 Data.DATA5, 2732 Data.DATA6, 2733 Data.DATA7, 2734 Data.DATA8, 2735 Data.DATA9, 2736 Data.DATA10, 2737 Data.DATA11, 2738 Data.DATA12, 2739 Data.DATA13, 2740 Data.DATA14, 2741 Data.DATA15, 2742 Data.SYNC1, 2743 Data.SYNC2, 2744 Data.SYNC3, 2745 Data.SYNC4}; 2746 2747 public EntityIteratorImpl(Cursor cursor) { 2748 super(cursor); 2749 } 2750 2751 @Override 2752 public android.content.Entity getEntityAndIncrementCursor(Cursor cursor) 2753 throws RemoteException { 2754 final int columnRawContactId = cursor.getColumnIndexOrThrow(RawContacts._ID); 2755 final long rawContactId = cursor.getLong(columnRawContactId); 2756 2757 // we expect the cursor is already at the row we need to read from 2758 ContentValues cv = new ContentValues(); 2759 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ACCOUNT_NAME); 2760 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ACCOUNT_TYPE); 2761 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, DATA_SET); 2762 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, _ID); 2763 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DIRTY); 2764 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, VERSION); 2765 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SOURCE_ID); 2766 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC1); 2767 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC2); 2768 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC3); 2769 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC4); 2770 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DELETED); 2771 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, CONTACT_ID); 2772 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, STARRED); 2773 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, NAME_VERIFIED); 2774 android.content.Entity contact = new android.content.Entity(cv); 2775 2776 // read data rows until the contact id changes 2777 do { 2778 if (rawContactId != cursor.getLong(columnRawContactId)) { 2779 break; 2780 } 2781 // add the data to to the contact 2782 cv = new ContentValues(); 2783 cv.put(Data._ID, cursor.getLong(cursor.getColumnIndexOrThrow(Entity.DATA_ID))); 2784 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, 2785 Data.RES_PACKAGE); 2786 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, Data.MIMETYPE); 2787 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, Data.IS_PRIMARY); 2788 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, 2789 Data.IS_SUPER_PRIMARY); 2790 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, Data.DATA_VERSION); 2791 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, 2792 CommonDataKinds.GroupMembership.GROUP_SOURCE_ID); 2793 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, 2794 Data.DATA_VERSION); 2795 for (String key : DATA_KEYS) { 2796 final int columnIndex = cursor.getColumnIndexOrThrow(key); 2797 switch (cursor.getType(columnIndex)) { 2798 case Cursor.FIELD_TYPE_NULL: 2799 // don't put anything 2800 break; 2801 case Cursor.FIELD_TYPE_INTEGER: 2802 case Cursor.FIELD_TYPE_FLOAT: 2803 case Cursor.FIELD_TYPE_STRING: 2804 cv.put(key, cursor.getString(columnIndex)); 2805 break; 2806 case Cursor.FIELD_TYPE_BLOB: 2807 cv.put(key, cursor.getBlob(columnIndex)); 2808 break; 2809 default: 2810 throw new IllegalStateException("Invalid or unhandled data type"); 2811 } 2812 } 2813 contact.addSubValue(ContactsContract.Data.CONTENT_URI, cv); 2814 } while (cursor.moveToNext()); 2815 2816 return contact; 2817 } 2818 2819 } 2820 } 2821 2822 /** 2823 * Social status update columns. 2824 * 2825 * @see StatusUpdates 2826 * @see ContactsContract.Data 2827 */ 2828 protected interface StatusColumns { 2829 /** 2830 * Contact's latest presence level. 2831 * <P>Type: INTEGER (one of the values below)</P> 2832 */ 2833 public static final String PRESENCE = "mode"; 2834 2835 /** 2836 * @deprecated use {@link #PRESENCE} 2837 */ 2838 @Deprecated 2839 public static final String PRESENCE_STATUS = PRESENCE; 2840 2841 /** 2842 * An allowed value of {@link #PRESENCE}. 2843 */ 2844 int OFFLINE = 0; 2845 2846 /** 2847 * An allowed value of {@link #PRESENCE}. 2848 */ 2849 int INVISIBLE = 1; 2850 2851 /** 2852 * An allowed value of {@link #PRESENCE}. 2853 */ 2854 int AWAY = 2; 2855 2856 /** 2857 * An allowed value of {@link #PRESENCE}. 2858 */ 2859 int IDLE = 3; 2860 2861 /** 2862 * An allowed value of {@link #PRESENCE}. 2863 */ 2864 int DO_NOT_DISTURB = 4; 2865 2866 /** 2867 * An allowed value of {@link #PRESENCE}. 2868 */ 2869 int AVAILABLE = 5; 2870 2871 /** 2872 * Contact latest status update. 2873 * <p>Type: TEXT</p> 2874 */ 2875 public static final String STATUS = "status"; 2876 2877 /** 2878 * @deprecated use {@link #STATUS} 2879 */ 2880 @Deprecated 2881 public static final String PRESENCE_CUSTOM_STATUS = STATUS; 2882 2883 /** 2884 * The absolute time in milliseconds when the latest status was inserted/updated. 2885 * <p>Type: NUMBER</p> 2886 */ 2887 public static final String STATUS_TIMESTAMP = "status_ts"; 2888 2889 /** 2890 * The package containing resources for this status: label and icon. 2891 * <p>Type: TEXT</p> 2892 */ 2893 public static final String STATUS_RES_PACKAGE = "status_res_package"; 2894 2895 /** 2896 * The resource ID of the label describing the source of the status update, e.g. "Google 2897 * Talk". This resource should be scoped by the {@link #STATUS_RES_PACKAGE}. 2898 * <p>Type: NUMBER</p> 2899 */ 2900 public static final String STATUS_LABEL = "status_label"; 2901 2902 /** 2903 * The resource ID of the icon for the source of the status update. 2904 * This resource should be scoped by the {@link #STATUS_RES_PACKAGE}. 2905 * <p>Type: NUMBER</p> 2906 */ 2907 public static final String STATUS_ICON = "status_icon"; 2908 2909 /** 2910 * Contact's audio/video chat capability level. 2911 * <P>Type: INTEGER (one of the values below)</P> 2912 */ 2913 public static final String CHAT_CAPABILITY = "chat_capability"; 2914 2915 /** 2916 * An allowed flag of {@link #CHAT_CAPABILITY}. Indicates audio-chat capability (microphone 2917 * and speaker) 2918 */ 2919 public static final int CAPABILITY_HAS_VOICE = 1; 2920 2921 /** 2922 * An allowed flag of {@link #CHAT_CAPABILITY}. Indicates that the contact's device can 2923 * display a video feed. 2924 */ 2925 public static final int CAPABILITY_HAS_VIDEO = 2; 2926 2927 /** 2928 * An allowed flag of {@link #CHAT_CAPABILITY}. Indicates that the contact's device has a 2929 * camera that can be used for video chat (e.g. a front-facing camera on a phone). 2930 */ 2931 public static final int CAPABILITY_HAS_CAMERA = 4; 2932 } 2933 2934 /** 2935 * <p> 2936 * Constants for the stream_items table, which contains social stream updates from 2937 * the user's contact list. 2938 * </p> 2939 * <p> 2940 * Only a certain number of stream items will ever be stored under a given raw contact. 2941 * Users of this API can query {@link ContactsContract.StreamItems#CONTENT_LIMIT_URI} to 2942 * determine this limit, and should restrict the number of items inserted in any given 2943 * transaction correspondingly. Insertion of more items beyond the limit will 2944 * automatically lead to deletion of the oldest items, by {@link StreamItems#TIMESTAMP}. 2945 * </p> 2946 * <h3>Operations</h3> 2947 * <dl> 2948 * <dt><b>Insert</b></dt> 2949 * <dd> 2950 * <p>Social stream updates are always associated with a raw contact. There are a couple 2951 * of ways to insert these entries. 2952 * <dl> 2953 * <dt>Via the {@link RawContacts.StreamItems#CONTENT_DIRECTORY} sub-path of a raw contact:</dt> 2954 * <dd> 2955 * <pre> 2956 * ContentValues values = new ContentValues(); 2957 * values.put(StreamItems.TEXT, "Breakfasted at Tiffanys"); 2958 * values.put(StreamItems.TIMESTAMP, timestamp); 2959 * values.put(StreamItems.COMMENTS, "3 people reshared this"); 2960 * Uri streamItemUri = getContentResolver().insert( 2961 * Uri.withAppendedPath(ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId), 2962 * RawContacts.StreamItems.CONTENT_DIRECTORY), values); 2963 * long streamItemId = ContentUris.parseId(streamItemUri); 2964 * </pre> 2965 * </dd> 2966 * <dt>Via the {@link StreamItems#CONTENT_URI} URI:</dt> 2967 * <dd> 2968 * ContentValues values = new ContentValues(); 2969 * values.put(StreamItems.RAW_CONTACT_ID, rawContactId); 2970 * values.put(StreamItems.TEXT, "Breakfasted at Tiffanys"); 2971 * values.put(StreamItems.TIMESTAMP, timestamp); 2972 * values.put(StreamItems.COMMENTS, "3 people reshared this"); 2973 * Uri streamItemUri = getContentResolver().insert(StreamItems.CONTENT_URI, values); 2974 * long streamItemId = ContentUris.parseId(streamItemUri); 2975 * </dd> 2976 * </dl> 2977 * </dd> 2978 * </p> 2979 * <p> 2980 * Once a {@link StreamItems} entry has been inserted, photos associated with that 2981 * social update can be inserted. For example, after one of the insertions above, 2982 * photos could be added to the stream item in one of the following ways: 2983 * <dl> 2984 * <dt>Via a URI including the stream item ID:</dt> 2985 * <dd> 2986 * <pre> 2987 * values.clear(); 2988 * values.put(StreamItemPhotos.SORT_INDEX, 1); 2989 * values.put(StreamItemPhotos.PHOTO, photoData); 2990 * getContentResolver().insert(Uri.withAppendedPath( 2991 * ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId), 2992 * StreamItems.StreamItemPhotos.CONTENT_DIRECTORY), values); 2993 * </pre> 2994 * </dd> 2995 * <dt>Via {@link ContactsContract.StreamItems#CONTENT_PHOTO_URI}</dt> 2996 * <dd> 2997 * <pre> 2998 * values.clear(); 2999 * values.put(StreamItemPhotos.STREAM_ITEM_ID, streamItemId); 3000 * values.put(StreamItemPhotos.SORT_INDEX, 1); 3001 * values.put(StreamItemPhotos.PHOTO, photoData); 3002 * getContentResolver().insert(StreamItems.CONTENT_PHOTO_URI, values); 3003 * </pre> 3004 * Note that this latter form allows the insertion of a stream item and its 3005 * photos in a single transaction, by using {@link ContentProviderOperation} with 3006 * back references to populate the stream item ID in the {@link ContentValues}. 3007 * </dd> 3008 * </dl> 3009 * </p> 3010 * </dd> 3011 * <dt><b>Update</b></dt> 3012 * <dd>Updates can be performed by appending the stream item ID to the 3013 * {@link StreamItems#CONTENT_URI} URI. Only social stream entries that were 3014 * created by the calling package can be updated.</dd> 3015 * <dt><b>Delete</b></dt> 3016 * <dd>Deletes can be performed by appending the stream item ID to the 3017 * {@link StreamItems#CONTENT_URI} URI. Only social stream entries that were 3018 * created by the calling package can be deleted.</dd> 3019 * <dt><b>Query</b></dt> 3020 * <dl> 3021 * <dt>Finding all social stream updates for a given contact</dt> 3022 * <dd>By Contact ID: 3023 * <pre> 3024 * Cursor c = getContentResolver().query(Uri.withAppendedPath( 3025 * ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId), 3026 * Contacts.StreamItems.CONTENT_DIRECTORY), 3027 * null, null, null, null); 3028 * </pre> 3029 * </dd> 3030 * <dd>By lookup key: 3031 * <pre> 3032 * Cursor c = getContentResolver().query(Contacts.CONTENT_URI.buildUpon() 3033 * .appendPath(lookupKey) 3034 * .appendPath(Contacts.StreamItems.CONTENT_DIRECTORY).build(), 3035 * null, null, null, null); 3036 * </pre> 3037 * </dd> 3038 * <dt>Finding all social stream updates for a given raw contact</dt> 3039 * <dd> 3040 * <pre> 3041 * Cursor c = getContentResolver().query(Uri.withAppendedPath( 3042 * ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId), 3043 * RawContacts.StreamItems.CONTENT_DIRECTORY)), 3044 * null, null, null, null); 3045 * </pre> 3046 * </dd> 3047 * <dt>Querying for a specific stream item by ID</dt> 3048 * <dd> 3049 * <pre> 3050 * Cursor c = getContentResolver().query(ContentUris.withAppendedId( 3051 * StreamItems.CONTENT_URI, streamItemId), 3052 * null, null, null, null); 3053 * </pre> 3054 * </dd> 3055 * </dl> 3056 */ 3057 public static final class StreamItems implements BaseColumns, StreamItemsColumns { 3058 /** 3059 * This utility class cannot be instantiated 3060 */ 3061 private StreamItems() { 3062 } 3063 3064 /** 3065 * The content:// style URI for this table, which handles social network stream 3066 * updates for the user's contacts. 3067 */ 3068 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "stream_items"); 3069 3070 /** 3071 * <p> 3072 * A content:// style URI for the photos stored in a sub-table underneath 3073 * stream items. This is only used for inserts, and updates - queries and deletes 3074 * for photos should be performed by appending 3075 * {@link StreamItems.StreamItemPhotos#CONTENT_DIRECTORY} path to URIs for a 3076 * specific stream item. 3077 * </p> 3078 * <p> 3079 * When using this URI, the stream item ID for the photo(s) must be identified 3080 * in the {@link ContentValues} passed in. 3081 * </p> 3082 */ 3083 public static final Uri CONTENT_PHOTO_URI = Uri.withAppendedPath(CONTENT_URI, "photo"); 3084 3085 /** 3086 * This URI allows the caller to query for the maximum number of stream items 3087 * that will be stored under any single raw contact. 3088 */ 3089 public static final Uri CONTENT_LIMIT_URI = 3090 Uri.withAppendedPath(AUTHORITY_URI, "stream_items_limit"); 3091 3092 /** 3093 * The MIME type of a directory of stream items. 3094 */ 3095 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/stream_item"; 3096 3097 /** 3098 * The MIME type of a single stream item. 3099 */ 3100 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/stream_item"; 3101 3102 /** 3103 * Queries to {@link ContactsContract.StreamItems#CONTENT_LIMIT_URI} will 3104 * contain this column, with the value indicating the maximum number of 3105 * stream items that will be stored under any single raw contact. 3106 */ 3107 public static final String MAX_ITEMS = "max_items"; 3108 3109 /** 3110 * <p> 3111 * A sub-directory of a single stream item entry that contains all of its 3112 * photo rows. To access this 3113 * directory append {@link StreamItems.StreamItemPhotos#CONTENT_DIRECTORY} to 3114 * an individual stream item URI. 3115 * </p> 3116 */ 3117 public static final class StreamItemPhotos 3118 implements BaseColumns, StreamItemPhotosColumns { 3119 /** 3120 * No public constructor since this is a utility class 3121 */ 3122 private StreamItemPhotos() { 3123 } 3124 3125 /** 3126 * The directory twig for this sub-table 3127 */ 3128 public static final String CONTENT_DIRECTORY = "photo"; 3129 3130 /** 3131 * The MIME type of a directory of stream item photos. 3132 */ 3133 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/stream_item_photo"; 3134 3135 /** 3136 * The MIME type of a single stream item photo. 3137 */ 3138 public static final String CONTENT_ITEM_TYPE 3139 = "vnd.android.cursor.item/stream_item_photo"; 3140 } 3141 } 3142 3143 /** 3144 * Columns in the StreamItems table. 3145 * 3146 * @see ContactsContract.StreamItems 3147 */ 3148 protected interface StreamItemsColumns { 3149 /** 3150 * A reference to the {@link android.provider.ContactsContract.Contacts#_ID} 3151 * that this stream item belongs to. 3152 * 3153 * <p>Type: INTEGER</p> 3154 * <p>read-only</p> 3155 */ 3156 public static final String CONTACT_ID = "contact_id"; 3157 3158 /** 3159 * A reference to the {@link android.provider.ContactsContract.Contacts#LOOKUP_KEY} 3160 * that this stream item belongs to. 3161 * 3162 * <p>Type: TEXT</p> 3163 * <p>read-only</p> 3164 */ 3165 public static final String CONTACT_LOOKUP_KEY = "contact_lookup"; 3166 3167 /** 3168 * A reference to the {@link RawContacts#_ID} 3169 * that this stream item belongs to. 3170 * <p>Type: INTEGER</p> 3171 */ 3172 public static final String RAW_CONTACT_ID = "raw_contact_id"; 3173 3174 /** 3175 * The package name to use when creating {@link Resources} objects for 3176 * this stream item. This value is only designed for use when building 3177 * user interfaces, and should not be used to infer the owner. 3178 * <P>Type: TEXT</P> 3179 */ 3180 public static final String RES_PACKAGE = "res_package"; 3181 3182 /** 3183 * The account type to which the raw_contact of this item is associated. See 3184 * {@link RawContacts#ACCOUNT_TYPE} 3185 * 3186 * <p>Type: TEXT</p> 3187 * <p>read-only</p> 3188 */ 3189 public static final String ACCOUNT_TYPE = "account_type"; 3190 3191 /** 3192 * The account name to which the raw_contact of this item is associated. See 3193 * {@link RawContacts#ACCOUNT_NAME} 3194 * 3195 * <p>Type: TEXT</p> 3196 * <p>read-only</p> 3197 */ 3198 public static final String ACCOUNT_NAME = "account_name"; 3199 3200 /** 3201 * The data set within the account that the raw_contact of this row belongs to. This allows 3202 * multiple sync adapters for the same account type to distinguish between 3203 * each others' data. 3204 * {@link RawContacts#DATA_SET} 3205 * 3206 * <P>Type: TEXT</P> 3207 * <p>read-only</p> 3208 */ 3209 public static final String DATA_SET = "data_set"; 3210 3211 /** 3212 * The source_id of the raw_contact that this row belongs to. 3213 * {@link RawContacts#SOURCE_ID} 3214 * 3215 * <P>Type: TEXT</P> 3216 * <p>read-only</p> 3217 */ 3218 public static final String RAW_CONTACT_SOURCE_ID = "raw_contact_source_id"; 3219 3220 /** 3221 * The resource name of the icon for the source of the stream item. 3222 * This resource should be scoped by the {@link #RES_PACKAGE}. As this can only reference 3223 * drawables, the "@drawable/" prefix must be omitted. 3224 * <P>Type: TEXT</P> 3225 */ 3226 public static final String RES_ICON = "icon"; 3227 3228 /** 3229 * The resource name of the label describing the source of the status update, e.g. "Google 3230 * Talk". This resource should be scoped by the {@link #RES_PACKAGE}. As this can only 3231 * reference strings, the "@string/" prefix must be omitted. 3232 * <p>Type: TEXT</p> 3233 */ 3234 public static final String RES_LABEL = "label"; 3235 3236 /** 3237 * <P> 3238 * The main textual contents of the item. Typically this is content 3239 * that was posted by the source of this stream item, but it can also 3240 * be a textual representation of an action (e.g. ”Checked in at Joe's”). 3241 * This text is displayed to the user and allows formatting and embedded 3242 * resource images via HTML (as parseable via 3243 * {@link android.text.Html#fromHtml}). 3244 * </P> 3245 * <P> 3246 * Long content may be truncated and/or ellipsized - the exact behavior 3247 * is unspecified, but it should not break tags. 3248 * </P> 3249 * <P>Type: TEXT</P> 3250 */ 3251 public static final String TEXT = "text"; 3252 3253 /** 3254 * The absolute time (milliseconds since epoch) when this stream item was 3255 * inserted/updated. 3256 * <P>Type: NUMBER</P> 3257 */ 3258 public static final String TIMESTAMP = "timestamp"; 3259 3260 /** 3261 * <P> 3262 * Summary information about the stream item, for example to indicate how 3263 * many people have reshared it, how many have liked it, how many thumbs 3264 * up and/or thumbs down it has, what the original source was, etc. 3265 * </P> 3266 * <P> 3267 * This text is displayed to the user and allows simple formatting via 3268 * HTML, in the same manner as {@link #TEXT} allows. 3269 * </P> 3270 * <P> 3271 * Long content may be truncated and/or ellipsized - the exact behavior 3272 * is unspecified, but it should not break tags. 3273 * </P> 3274 * <P>Type: TEXT</P> 3275 */ 3276 public static final String COMMENTS = "comments"; 3277 3278 /** Generic column for use by sync adapters. */ 3279 public static final String SYNC1 = "stream_item_sync1"; 3280 /** Generic column for use by sync adapters. */ 3281 public static final String SYNC2 = "stream_item_sync2"; 3282 /** Generic column for use by sync adapters. */ 3283 public static final String SYNC3 = "stream_item_sync3"; 3284 /** Generic column for use by sync adapters. */ 3285 public static final String SYNC4 = "stream_item_sync4"; 3286 } 3287 3288 /** 3289 * <p> 3290 * Constants for the stream_item_photos table, which contains photos associated with 3291 * social stream updates. 3292 * </p> 3293 * <h3>Operations</h3> 3294 * <dl> 3295 * <dt><b>Insert</b></dt> 3296 * <dd> 3297 * <p>Social stream photo entries are associated with a social stream item. Photos 3298 * can be inserted into a social stream item in a couple of ways: 3299 * <dl> 3300 * <dt> 3301 * Via the {@link StreamItems.StreamItemPhotos#CONTENT_DIRECTORY} sub-path of a 3302 * stream item: 3303 * </dt> 3304 * <dd> 3305 * <pre> 3306 * ContentValues values = new ContentValues(); 3307 * values.put(StreamItemPhotos.SORT_INDEX, 1); 3308 * values.put(StreamItemPhotos.PHOTO, photoData); 3309 * Uri photoUri = getContentResolver().insert(Uri.withAppendedPath( 3310 * ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId) 3311 * StreamItems.StreamItemPhotos#CONTENT_DIRECTORY), values); 3312 * long photoId = ContentUris.parseId(photoUri); 3313 * </pre> 3314 * </dd> 3315 * <dt>Via the {@link ContactsContract.StreamItems#CONTENT_PHOTO_URI} URI:</dt> 3316 * <dd> 3317 * <pre> 3318 * ContentValues values = new ContentValues(); 3319 * values.put(StreamItemPhotos.STREAM_ITEM_ID, streamItemId); 3320 * values.put(StreamItemPhotos.SORT_INDEX, 1); 3321 * values.put(StreamItemPhotos.PHOTO, photoData); 3322 * Uri photoUri = getContentResolver().insert(StreamItems.CONTENT_PHOTO_URI, values); 3323 * long photoId = ContentUris.parseId(photoUri); 3324 * </pre> 3325 * </dd> 3326 * </dl> 3327 * </p> 3328 * </dd> 3329 * <dt><b>Update</b></dt> 3330 * <dd> 3331 * <p>Updates can only be made against a specific {@link StreamItemPhotos} entry, 3332 * identified by both the stream item ID it belongs to and the stream item photo ID. 3333 * This can be specified in two ways. 3334 * <dl> 3335 * <dt>Via the {@link StreamItems.StreamItemPhotos#CONTENT_DIRECTORY} sub-path of a 3336 * stream item: 3337 * </dt> 3338 * <dd> 3339 * <pre> 3340 * ContentValues values = new ContentValues(); 3341 * values.put(StreamItemPhotos.PHOTO, newPhotoData); 3342 * getContentResolver().update( 3343 * ContentUris.withAppendedId( 3344 * Uri.withAppendedPath( 3345 * ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId) 3346 * StreamItems.StreamItemPhotos#CONTENT_DIRECTORY), 3347 * streamItemPhotoId), values, null, null); 3348 * </pre> 3349 * </dd> 3350 * <dt>Via the {@link ContactsContract.StreamItems#CONTENT_PHOTO_URI} URI:</dt> 3351 * <dd> 3352 * <pre> 3353 * ContentValues values = new ContentValues(); 3354 * values.put(StreamItemPhotos.STREAM_ITEM_ID, streamItemId); 3355 * values.put(StreamItemPhotos.PHOTO, newPhotoData); 3356 * getContentResolver().update(StreamItems.CONTENT_PHOTO_URI, values); 3357 * </pre> 3358 * </dd> 3359 * </dl> 3360 * </p> 3361 * </dd> 3362 * <dt><b>Delete</b></dt> 3363 * <dd>Deletes can be made against either a specific photo item in a stream item, or 3364 * against all or a selected subset of photo items under a stream item. 3365 * For example: 3366 * <dl> 3367 * <dt>Deleting a single photo via the 3368 * {@link StreamItems.StreamItemPhotos#CONTENT_DIRECTORY} sub-path of a stream item: 3369 * </dt> 3370 * <dd> 3371 * <pre> 3372 * getContentResolver().delete( 3373 * ContentUris.withAppendedId( 3374 * Uri.withAppendedPath( 3375 * ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId) 3376 * StreamItems.StreamItemPhotos#CONTENT_DIRECTORY), 3377 * streamItemPhotoId), null, null); 3378 * </pre> 3379 * </dd> 3380 * <dt>Deleting all photos under a stream item</dt> 3381 * <dd> 3382 * <pre> 3383 * getContentResolver().delete( 3384 * Uri.withAppendedPath( 3385 * ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId) 3386 * StreamItems.StreamItemPhotos#CONTENT_DIRECTORY), null, null); 3387 * </pre> 3388 * </dd> 3389 * </dl> 3390 * </dd> 3391 * <dt><b>Query</b></dt> 3392 * <dl> 3393 * <dt>Querying for a specific photo in a stream item</dt> 3394 * <dd> 3395 * <pre> 3396 * Cursor c = getContentResolver().query( 3397 * ContentUris.withAppendedId( 3398 * Uri.withAppendedPath( 3399 * ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId) 3400 * StreamItems.StreamItemPhotos#CONTENT_DIRECTORY), 3401 * streamItemPhotoId), null, null, null, null); 3402 * </pre> 3403 * </dd> 3404 * <dt>Querying for all photos in a stream item</dt> 3405 * <dd> 3406 * <pre> 3407 * Cursor c = getContentResolver().query( 3408 * Uri.withAppendedPath( 3409 * ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId) 3410 * StreamItems.StreamItemPhotos#CONTENT_DIRECTORY), 3411 * null, null, null, StreamItemPhotos.SORT_INDEX); 3412 * </pre> 3413 * </dl> 3414 * The record will contain both a {@link StreamItemPhotos#PHOTO_FILE_ID} and a 3415 * {@link StreamItemPhotos#PHOTO_URI}. The {@link StreamItemPhotos#PHOTO_FILE_ID} 3416 * can be used in conjunction with the {@link ContactsContract.DisplayPhoto} API to 3417 * retrieve photo content, or you can open the {@link StreamItemPhotos#PHOTO_URI} as 3418 * an asset file, as follows: 3419 * <pre> 3420 * public InputStream openDisplayPhoto(String photoUri) { 3421 * try { 3422 * AssetFileDescriptor fd = getContentResolver().openAssetFileDescriptor(photoUri, "r"); 3423 * return fd.createInputStream(); 3424 * } catch (IOException e) { 3425 * return null; 3426 * } 3427 * } 3428 * <pre> 3429 * </dd> 3430 * </dl> 3431 */ 3432 public static final class StreamItemPhotos implements BaseColumns, StreamItemPhotosColumns { 3433 /** 3434 * No public constructor since this is a utility class 3435 */ 3436 private StreamItemPhotos() { 3437 } 3438 3439 /** 3440 * <p> 3441 * The binary representation of the photo. Any size photo can be inserted; 3442 * the provider will resize it appropriately for storage and display. 3443 * </p> 3444 * <p> 3445 * This is only intended for use when inserting or updating a stream item photo. 3446 * To retrieve the photo that was stored, open {@link StreamItemPhotos#PHOTO_URI} 3447 * as an asset file. 3448 * </p> 3449 * <P>Type: BLOB</P> 3450 */ 3451 public static final String PHOTO = "photo"; 3452 } 3453 3454 /** 3455 * Columns in the StreamItemPhotos table. 3456 * 3457 * @see ContactsContract.StreamItemPhotos 3458 */ 3459 protected interface StreamItemPhotosColumns { 3460 /** 3461 * A reference to the {@link StreamItems#_ID} this photo is associated with. 3462 * <P>Type: NUMBER</P> 3463 */ 3464 public static final String STREAM_ITEM_ID = "stream_item_id"; 3465 3466 /** 3467 * An integer to use for sort order for photos in the stream item. If not 3468 * specified, the {@link StreamItemPhotos#_ID} will be used for sorting. 3469 * <P>Type: NUMBER</P> 3470 */ 3471 public static final String SORT_INDEX = "sort_index"; 3472 3473 /** 3474 * Photo file ID for the photo. 3475 * See {@link ContactsContract.DisplayPhoto}. 3476 * <P>Type: NUMBER</P> 3477 */ 3478 public static final String PHOTO_FILE_ID = "photo_file_id"; 3479 3480 /** 3481 * URI for retrieving the photo content, automatically populated. Callers 3482 * may retrieve the photo content by opening this URI as an asset file. 3483 * <P>Type: TEXT</P> 3484 */ 3485 public static final String PHOTO_URI = "photo_uri"; 3486 3487 /** Generic column for use by sync adapters. */ 3488 public static final String SYNC1 = "stream_item_photo_sync1"; 3489 /** Generic column for use by sync adapters. */ 3490 public static final String SYNC2 = "stream_item_photo_sync2"; 3491 /** Generic column for use by sync adapters. */ 3492 public static final String SYNC3 = "stream_item_photo_sync3"; 3493 /** Generic column for use by sync adapters. */ 3494 public static final String SYNC4 = "stream_item_photo_sync4"; 3495 } 3496 3497 /** 3498 * <p> 3499 * Constants for the photo files table, which tracks metadata for hi-res photos 3500 * stored in the file system. 3501 * </p> 3502 * 3503 * @hide 3504 */ 3505 public static final class PhotoFiles implements BaseColumns, PhotoFilesColumns { 3506 /** 3507 * No public constructor since this is a utility class 3508 */ 3509 private PhotoFiles() { 3510 } 3511 } 3512 3513 /** 3514 * Columns in the PhotoFiles table. 3515 * 3516 * @see ContactsContract.PhotoFiles 3517 * 3518 * @hide 3519 */ 3520 protected interface PhotoFilesColumns { 3521 3522 /** 3523 * The height, in pixels, of the photo this entry is associated with. 3524 * <P>Type: NUMBER</P> 3525 */ 3526 public static final String HEIGHT = "height"; 3527 3528 /** 3529 * The width, in pixels, of the photo this entry is associated with. 3530 * <P>Type: NUMBER</P> 3531 */ 3532 public static final String WIDTH = "width"; 3533 3534 /** 3535 * The size, in bytes, of the photo stored on disk. 3536 * <P>Type: NUMBER</P> 3537 */ 3538 public static final String FILESIZE = "filesize"; 3539 } 3540 3541 /** 3542 * Columns in the Data table. 3543 * 3544 * @see ContactsContract.Data 3545 */ 3546 protected interface DataColumns { 3547 /** 3548 * The package name to use when creating {@link Resources} objects for 3549 * this data row. This value is only designed for use when building user 3550 * interfaces, and should not be used to infer the owner. 3551 * 3552 * @hide 3553 */ 3554 public static final String RES_PACKAGE = "res_package"; 3555 3556 /** 3557 * The MIME type of the item represented by this row. 3558 */ 3559 public static final String MIMETYPE = "mimetype"; 3560 3561 /** 3562 * A reference to the {@link RawContacts#_ID} 3563 * that this data belongs to. 3564 */ 3565 public static final String RAW_CONTACT_ID = "raw_contact_id"; 3566 3567 /** 3568 * Whether this is the primary entry of its kind for the raw contact it belongs to. 3569 * <P>Type: INTEGER (if set, non-0 means true)</P> 3570 */ 3571 public static final String IS_PRIMARY = "is_primary"; 3572 3573 /** 3574 * Whether this is the primary entry of its kind for the aggregate 3575 * contact it belongs to. Any data record that is "super primary" must 3576 * also be "primary". 3577 * <P>Type: INTEGER (if set, non-0 means true)</P> 3578 */ 3579 public static final String IS_SUPER_PRIMARY = "is_super_primary"; 3580 3581 /** 3582 * The "read-only" flag: "0" by default, "1" if the row cannot be modified or 3583 * deleted except by a sync adapter. See {@link ContactsContract#CALLER_IS_SYNCADAPTER}. 3584 * <P>Type: INTEGER</P> 3585 */ 3586 public static final String IS_READ_ONLY = "is_read_only"; 3587 3588 /** 3589 * The version of this data record. This is a read-only value. The data column is 3590 * guaranteed to not change without the version going up. This value is monotonically 3591 * increasing. 3592 * <P>Type: INTEGER</P> 3593 */ 3594 public static final String DATA_VERSION = "data_version"; 3595 3596 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3597 public static final String DATA1 = "data1"; 3598 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3599 public static final String DATA2 = "data2"; 3600 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3601 public static final String DATA3 = "data3"; 3602 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3603 public static final String DATA4 = "data4"; 3604 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3605 public static final String DATA5 = "data5"; 3606 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3607 public static final String DATA6 = "data6"; 3608 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3609 public static final String DATA7 = "data7"; 3610 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3611 public static final String DATA8 = "data8"; 3612 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3613 public static final String DATA9 = "data9"; 3614 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3615 public static final String DATA10 = "data10"; 3616 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3617 public static final String DATA11 = "data11"; 3618 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3619 public static final String DATA12 = "data12"; 3620 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3621 public static final String DATA13 = "data13"; 3622 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3623 public static final String DATA14 = "data14"; 3624 /** 3625 * Generic data column, the meaning is {@link #MIMETYPE} specific. By convention, 3626 * this field is used to store BLOBs (binary data). 3627 */ 3628 public static final String DATA15 = "data15"; 3629 3630 /** Generic column for use by sync adapters. */ 3631 public static final String SYNC1 = "data_sync1"; 3632 /** Generic column for use by sync adapters. */ 3633 public static final String SYNC2 = "data_sync2"; 3634 /** Generic column for use by sync adapters. */ 3635 public static final String SYNC3 = "data_sync3"; 3636 /** Generic column for use by sync adapters. */ 3637 public static final String SYNC4 = "data_sync4"; 3638 } 3639 3640 /** 3641 * Combines all columns returned by {@link ContactsContract.Data} table queries. 3642 * 3643 * @see ContactsContract.Data 3644 */ 3645 protected interface DataColumnsWithJoins extends BaseColumns, DataColumns, StatusColumns, 3646 RawContactsColumns, ContactsColumns, ContactNameColumns, ContactOptionsColumns, 3647 ContactStatusColumns { 3648 } 3649 3650 /** 3651 * <p> 3652 * Constants for the data table, which contains data points tied to a raw 3653 * contact. Each row of the data table is typically used to store a single 3654 * piece of contact 3655 * information (such as a phone number) and its 3656 * associated metadata (such as whether it is a work or home number). 3657 * </p> 3658 * <h3>Data kinds</h3> 3659 * <p> 3660 * Data is a generic table that can hold any kind of contact data. 3661 * The kind of data stored in a given row is specified by the row's 3662 * {@link #MIMETYPE} value, which determines the meaning of the 3663 * generic columns {@link #DATA1} through 3664 * {@link #DATA15}. 3665 * For example, if the data kind is 3666 * {@link CommonDataKinds.Phone Phone.CONTENT_ITEM_TYPE}, then the column 3667 * {@link #DATA1} stores the 3668 * phone number, but if the data kind is 3669 * {@link CommonDataKinds.Email Email.CONTENT_ITEM_TYPE}, then {@link #DATA1} 3670 * stores the email address. 3671 * Sync adapters and applications can introduce their own data kinds. 3672 * </p> 3673 * <p> 3674 * ContactsContract defines a small number of pre-defined data kinds, e.g. 3675 * {@link CommonDataKinds.Phone}, {@link CommonDataKinds.Email} etc. As a 3676 * convenience, these classes define data kind specific aliases for DATA1 etc. 3677 * For example, {@link CommonDataKinds.Phone Phone.NUMBER} is the same as 3678 * {@link ContactsContract.Data Data.DATA1}. 3679 * </p> 3680 * <p> 3681 * {@link #DATA1} is an indexed column and should be used for the data element that is 3682 * expected to be most frequently used in query selections. For example, in the 3683 * case of a row representing email addresses {@link #DATA1} should probably 3684 * be used for the email address itself, while {@link #DATA2} etc can be 3685 * used for auxiliary information like type of email address. 3686 * <p> 3687 * <p> 3688 * By convention, {@link #DATA15} is used for storing BLOBs (binary data). 3689 * </p> 3690 * <p> 3691 * The sync adapter for a given account type must correctly handle every data type 3692 * used in the corresponding raw contacts. Otherwise it could result in lost or 3693 * corrupted data. 3694 * </p> 3695 * <p> 3696 * Similarly, you should refrain from introducing new kinds of data for an other 3697 * party's account types. For example, if you add a data row for 3698 * "favorite song" to a raw contact owned by a Google account, it will not 3699 * get synced to the server, because the Google sync adapter does not know 3700 * how to handle this data kind. Thus new data kinds are typically 3701 * introduced along with new account types, i.e. new sync adapters. 3702 * </p> 3703 * <h3>Batch operations</h3> 3704 * <p> 3705 * Data rows can be inserted/updated/deleted using the traditional 3706 * {@link ContentResolver#insert}, {@link ContentResolver#update} and 3707 * {@link ContentResolver#delete} methods, however the newer mechanism based 3708 * on a batch of {@link ContentProviderOperation} will prove to be a better 3709 * choice in almost all cases. All operations in a batch are executed in a 3710 * single transaction, which ensures that the phone-side and server-side 3711 * state of a raw contact are always consistent. Also, the batch-based 3712 * approach is far more efficient: not only are the database operations 3713 * faster when executed in a single transaction, but also sending a batch of 3714 * commands to the content provider saves a lot of time on context switching 3715 * between your process and the process in which the content provider runs. 3716 * </p> 3717 * <p> 3718 * The flip side of using batched operations is that a large batch may lock 3719 * up the database for a long time preventing other applications from 3720 * accessing data and potentially causing ANRs ("Application Not Responding" 3721 * dialogs.) 3722 * </p> 3723 * <p> 3724 * To avoid such lockups of the database, make sure to insert "yield points" 3725 * in the batch. A yield point indicates to the content provider that before 3726 * executing the next operation it can commit the changes that have already 3727 * been made, yield to other requests, open another transaction and continue 3728 * processing operations. A yield point will not automatically commit the 3729 * transaction, but only if there is another request waiting on the 3730 * database. Normally a sync adapter should insert a yield point at the 3731 * beginning of each raw contact operation sequence in the batch. See 3732 * {@link ContentProviderOperation.Builder#withYieldAllowed(boolean)}. 3733 * </p> 3734 * <h3>Operations</h3> 3735 * <dl> 3736 * <dt><b>Insert</b></dt> 3737 * <dd> 3738 * <p> 3739 * An individual data row can be inserted using the traditional 3740 * {@link ContentResolver#insert(Uri, ContentValues)} method. Multiple rows 3741 * should always be inserted as a batch. 3742 * </p> 3743 * <p> 3744 * An example of a traditional insert: 3745 * <pre> 3746 * ContentValues values = new ContentValues(); 3747 * values.put(Data.RAW_CONTACT_ID, rawContactId); 3748 * values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE); 3749 * values.put(Phone.NUMBER, "1-800-GOOG-411"); 3750 * values.put(Phone.TYPE, Phone.TYPE_CUSTOM); 3751 * values.put(Phone.LABEL, "free directory assistance"); 3752 * Uri dataUri = getContentResolver().insert(Data.CONTENT_URI, values); 3753 * </pre> 3754 * <p> 3755 * The same done using ContentProviderOperations: 3756 * <pre> 3757 * ArrayList<ContentProviderOperation> ops = 3758 * new ArrayList<ContentProviderOperation>(); 3759 * 3760 * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI) 3761 * .withValue(Data.RAW_CONTACT_ID, rawContactId) 3762 * .withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE) 3763 * .withValue(Phone.NUMBER, "1-800-GOOG-411") 3764 * .withValue(Phone.TYPE, Phone.TYPE_CUSTOM) 3765 * .withValue(Phone.LABEL, "free directory assistance") 3766 * .build()); 3767 * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); 3768 * </pre> 3769 * </p> 3770 * <dt><b>Update</b></dt> 3771 * <dd> 3772 * <p> 3773 * Just as with insert, update can be done incrementally or as a batch, 3774 * the batch mode being the preferred method: 3775 * <pre> 3776 * ArrayList<ContentProviderOperation> ops = 3777 * new ArrayList<ContentProviderOperation>(); 3778 * 3779 * ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI) 3780 * .withSelection(Data._ID + "=?", new String[]{String.valueOf(dataId)}) 3781 * .withValue(Email.DATA, "somebody@android.com") 3782 * .build()); 3783 * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); 3784 * </pre> 3785 * </p> 3786 * </dd> 3787 * <dt><b>Delete</b></dt> 3788 * <dd> 3789 * <p> 3790 * Just as with insert and update, deletion can be done either using the 3791 * {@link ContentResolver#delete} method or using a ContentProviderOperation: 3792 * <pre> 3793 * ArrayList<ContentProviderOperation> ops = 3794 * new ArrayList<ContentProviderOperation>(); 3795 * 3796 * ops.add(ContentProviderOperation.newDelete(Data.CONTENT_URI) 3797 * .withSelection(Data._ID + "=?", new String[]{String.valueOf(dataId)}) 3798 * .build()); 3799 * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); 3800 * </pre> 3801 * </p> 3802 * </dd> 3803 * <dt><b>Query</b></dt> 3804 * <dd> 3805 * <p> 3806 * <dl> 3807 * <dt>Finding all Data of a given type for a given contact</dt> 3808 * <dd> 3809 * <pre> 3810 * Cursor c = getContentResolver().query(Data.CONTENT_URI, 3811 * new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL}, 3812 * Data.CONTACT_ID + "=?" + " AND " 3813 * + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'", 3814 * new String[] {String.valueOf(contactId)}, null); 3815 * </pre> 3816 * </p> 3817 * <p> 3818 * </dd> 3819 * <dt>Finding all Data of a given type for a given raw contact</dt> 3820 * <dd> 3821 * <pre> 3822 * Cursor c = getContentResolver().query(Data.CONTENT_URI, 3823 * new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL}, 3824 * Data.RAW_CONTACT_ID + "=?" + " AND " 3825 * + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'", 3826 * new String[] {String.valueOf(rawContactId)}, null); 3827 * </pre> 3828 * </dd> 3829 * <dt>Finding all Data for a given raw contact</dt> 3830 * <dd> 3831 * Most sync adapters will want to read all data rows for a raw contact 3832 * along with the raw contact itself. For that you should use the 3833 * {@link RawContactsEntity}. See also {@link RawContacts}. 3834 * </dd> 3835 * </dl> 3836 * </p> 3837 * </dd> 3838 * </dl> 3839 * <h2>Columns</h2> 3840 * <p> 3841 * Many columns are available via a {@link Data#CONTENT_URI} query. For best performance you 3842 * should explicitly specify a projection to only those columns that you need. 3843 * </p> 3844 * <table class="jd-sumtable"> 3845 * <tr> 3846 * <th colspan='4'>Data</th> 3847 * </tr> 3848 * <tr> 3849 * <td style="width: 7em;">long</td> 3850 * <td style="width: 20em;">{@link #_ID}</td> 3851 * <td style="width: 5em;">read-only</td> 3852 * <td>Row ID. Sync adapter should try to preserve row IDs during updates. In other words, 3853 * it would be a bad idea to delete and reinsert a data row. A sync adapter should 3854 * always do an update instead.</td> 3855 * </tr> 3856 * <tr> 3857 * <td>String</td> 3858 * <td>{@link #MIMETYPE}</td> 3859 * <td>read/write-once</td> 3860 * <td> 3861 * <p>The MIME type of the item represented by this row. Examples of common 3862 * MIME types are: 3863 * <ul> 3864 * <li>{@link CommonDataKinds.StructuredName StructuredName.CONTENT_ITEM_TYPE}</li> 3865 * <li>{@link CommonDataKinds.Phone Phone.CONTENT_ITEM_TYPE}</li> 3866 * <li>{@link CommonDataKinds.Email Email.CONTENT_ITEM_TYPE}</li> 3867 * <li>{@link CommonDataKinds.Photo Photo.CONTENT_ITEM_TYPE}</li> 3868 * <li>{@link CommonDataKinds.Organization Organization.CONTENT_ITEM_TYPE}</li> 3869 * <li>{@link CommonDataKinds.Im Im.CONTENT_ITEM_TYPE}</li> 3870 * <li>{@link CommonDataKinds.Nickname Nickname.CONTENT_ITEM_TYPE}</li> 3871 * <li>{@link CommonDataKinds.Note Note.CONTENT_ITEM_TYPE}</li> 3872 * <li>{@link CommonDataKinds.StructuredPostal StructuredPostal.CONTENT_ITEM_TYPE}</li> 3873 * <li>{@link CommonDataKinds.GroupMembership GroupMembership.CONTENT_ITEM_TYPE}</li> 3874 * <li>{@link CommonDataKinds.Website Website.CONTENT_ITEM_TYPE}</li> 3875 * <li>{@link CommonDataKinds.Event Event.CONTENT_ITEM_TYPE}</li> 3876 * <li>{@link CommonDataKinds.Relation Relation.CONTENT_ITEM_TYPE}</li> 3877 * <li>{@link CommonDataKinds.SipAddress SipAddress.CONTENT_ITEM_TYPE}</li> 3878 * </ul> 3879 * </p> 3880 * </td> 3881 * </tr> 3882 * <tr> 3883 * <td>long</td> 3884 * <td>{@link #RAW_CONTACT_ID}</td> 3885 * <td>read/write-once</td> 3886 * <td>The id of the row in the {@link RawContacts} table that this data belongs to.</td> 3887 * </tr> 3888 * <tr> 3889 * <td>int</td> 3890 * <td>{@link #IS_PRIMARY}</td> 3891 * <td>read/write</td> 3892 * <td>Whether this is the primary entry of its kind for the raw contact it belongs to. 3893 * "1" if true, "0" if false. 3894 * </td> 3895 * </tr> 3896 * <tr> 3897 * <td>int</td> 3898 * <td>{@link #IS_SUPER_PRIMARY}</td> 3899 * <td>read/write</td> 3900 * <td>Whether this is the primary entry of its kind for the aggregate 3901 * contact it belongs to. Any data record that is "super primary" must 3902 * also be "primary". For example, the super-primary entry may be 3903 * interpreted as the default contact value of its kind (for example, 3904 * the default phone number to use for the contact).</td> 3905 * </tr> 3906 * <tr> 3907 * <td>int</td> 3908 * <td>{@link #DATA_VERSION}</td> 3909 * <td>read-only</td> 3910 * <td>The version of this data record. Whenever the data row changes 3911 * the version goes up. This value is monotonically increasing.</td> 3912 * </tr> 3913 * <tr> 3914 * <td>Any type</td> 3915 * <td> 3916 * {@link #DATA1}<br> 3917 * {@link #DATA2}<br> 3918 * {@link #DATA3}<br> 3919 * {@link #DATA4}<br> 3920 * {@link #DATA5}<br> 3921 * {@link #DATA6}<br> 3922 * {@link #DATA7}<br> 3923 * {@link #DATA8}<br> 3924 * {@link #DATA9}<br> 3925 * {@link #DATA10}<br> 3926 * {@link #DATA11}<br> 3927 * {@link #DATA12}<br> 3928 * {@link #DATA13}<br> 3929 * {@link #DATA14}<br> 3930 * {@link #DATA15} 3931 * </td> 3932 * <td>read/write</td> 3933 * <td> 3934 * <p> 3935 * Generic data columns. The meaning of each column is determined by the 3936 * {@link #MIMETYPE}. By convention, {@link #DATA15} is used for storing 3937 * BLOBs (binary data). 3938 * </p> 3939 * <p> 3940 * Data columns whose meaning is not explicitly defined for a given MIMETYPE 3941 * should not be used. There is no guarantee that any sync adapter will 3942 * preserve them. Sync adapters themselves should not use such columns either, 3943 * but should instead use {@link #SYNC1}-{@link #SYNC4}. 3944 * </p> 3945 * </td> 3946 * </tr> 3947 * <tr> 3948 * <td>Any type</td> 3949 * <td> 3950 * {@link #SYNC1}<br> 3951 * {@link #SYNC2}<br> 3952 * {@link #SYNC3}<br> 3953 * {@link #SYNC4} 3954 * </td> 3955 * <td>read/write</td> 3956 * <td>Generic columns for use by sync adapters. For example, a Photo row 3957 * may store the image URL in SYNC1, a status (not loaded, loading, loaded, error) 3958 * in SYNC2, server-side version number in SYNC3 and error code in SYNC4.</td> 3959 * </tr> 3960 * </table> 3961 * 3962 * <p> 3963 * Some columns from the most recent associated status update are also available 3964 * through an implicit join. 3965 * </p> 3966 * <table class="jd-sumtable"> 3967 * <tr> 3968 * <th colspan='4'>Join with {@link StatusUpdates}</th> 3969 * </tr> 3970 * <tr> 3971 * <td style="width: 7em;">int</td> 3972 * <td style="width: 20em;">{@link #PRESENCE}</td> 3973 * <td style="width: 5em;">read-only</td> 3974 * <td>IM presence status linked to this data row. Compare with 3975 * {@link #CONTACT_PRESENCE}, which contains the contact's presence across 3976 * all IM rows. See {@link StatusUpdates} for individual status definitions. 3977 * The provider may choose not to store this value 3978 * in persistent storage. The expectation is that presence status will be 3979 * updated on a regular basic. 3980 * </td> 3981 * </tr> 3982 * <tr> 3983 * <td>String</td> 3984 * <td>{@link #STATUS}</td> 3985 * <td>read-only</td> 3986 * <td>Latest status update linked with this data row.</td> 3987 * </tr> 3988 * <tr> 3989 * <td>long</td> 3990 * <td>{@link #STATUS_TIMESTAMP}</td> 3991 * <td>read-only</td> 3992 * <td>The absolute time in milliseconds when the latest status was 3993 * inserted/updated for this data row.</td> 3994 * </tr> 3995 * <tr> 3996 * <td>String</td> 3997 * <td>{@link #STATUS_RES_PACKAGE}</td> 3998 * <td>read-only</td> 3999 * <td>The package containing resources for this status: label and icon.</td> 4000 * </tr> 4001 * <tr> 4002 * <td>long</td> 4003 * <td>{@link #STATUS_LABEL}</td> 4004 * <td>read-only</td> 4005 * <td>The resource ID of the label describing the source of status update linked 4006 * to this data row. This resource is scoped by the {@link #STATUS_RES_PACKAGE}.</td> 4007 * </tr> 4008 * <tr> 4009 * <td>long</td> 4010 * <td>{@link #STATUS_ICON}</td> 4011 * <td>read-only</td> 4012 * <td>The resource ID of the icon for the source of the status update linked 4013 * to this data row. This resource is scoped by the {@link #STATUS_RES_PACKAGE}.</td> 4014 * </tr> 4015 * </table> 4016 * 4017 * <p> 4018 * Some columns from the associated raw contact are also available through an 4019 * implicit join. The other columns are excluded as uninteresting in this 4020 * context. 4021 * </p> 4022 * 4023 * <table class="jd-sumtable"> 4024 * <tr> 4025 * <th colspan='4'>Join with {@link ContactsContract.RawContacts}</th> 4026 * </tr> 4027 * <tr> 4028 * <td style="width: 7em;">long</td> 4029 * <td style="width: 20em;">{@link #CONTACT_ID}</td> 4030 * <td style="width: 5em;">read-only</td> 4031 * <td>The id of the row in the {@link Contacts} table that this data belongs 4032 * to.</td> 4033 * </tr> 4034 * <tr> 4035 * <td>int</td> 4036 * <td>{@link #AGGREGATION_MODE}</td> 4037 * <td>read-only</td> 4038 * <td>See {@link RawContacts}.</td> 4039 * </tr> 4040 * <tr> 4041 * <td>int</td> 4042 * <td>{@link #DELETED}</td> 4043 * <td>read-only</td> 4044 * <td>See {@link RawContacts}.</td> 4045 * </tr> 4046 * </table> 4047 * 4048 * <p> 4049 * The ID column for the associated aggregated contact table 4050 * {@link ContactsContract.Contacts} is available 4051 * via the implicit join to the {@link RawContacts} table, see above. 4052 * The remaining columns from this table are also 4053 * available, through an implicit join. This 4054 * facilitates lookup by 4055 * the value of a single data element, such as the email address. 4056 * </p> 4057 * 4058 * <table class="jd-sumtable"> 4059 * <tr> 4060 * <th colspan='4'>Join with {@link ContactsContract.Contacts}</th> 4061 * </tr> 4062 * <tr> 4063 * <td style="width: 7em;">String</td> 4064 * <td style="width: 20em;">{@link #LOOKUP_KEY}</td> 4065 * <td style="width: 5em;">read-only</td> 4066 * <td>See {@link ContactsContract.Contacts}</td> 4067 * </tr> 4068 * <tr> 4069 * <td>String</td> 4070 * <td>{@link #DISPLAY_NAME}</td> 4071 * <td>read-only</td> 4072 * <td>See {@link ContactsContract.Contacts}</td> 4073 * </tr> 4074 * <tr> 4075 * <td>long</td> 4076 * <td>{@link #PHOTO_ID}</td> 4077 * <td>read-only</td> 4078 * <td>See {@link ContactsContract.Contacts}.</td> 4079 * </tr> 4080 * <tr> 4081 * <td>int</td> 4082 * <td>{@link #IN_VISIBLE_GROUP}</td> 4083 * <td>read-only</td> 4084 * <td>See {@link ContactsContract.Contacts}.</td> 4085 * </tr> 4086 * <tr> 4087 * <td>int</td> 4088 * <td>{@link #HAS_PHONE_NUMBER}</td> 4089 * <td>read-only</td> 4090 * <td>See {@link ContactsContract.Contacts}.</td> 4091 * </tr> 4092 * <tr> 4093 * <td>int</td> 4094 * <td>{@link #TIMES_CONTACTED}</td> 4095 * <td>read-only</td> 4096 * <td>See {@link ContactsContract.Contacts}.</td> 4097 * </tr> 4098 * <tr> 4099 * <td>long</td> 4100 * <td>{@link #LAST_TIME_CONTACTED}</td> 4101 * <td>read-only</td> 4102 * <td>See {@link ContactsContract.Contacts}.</td> 4103 * </tr> 4104 * <tr> 4105 * <td>int</td> 4106 * <td>{@link #STARRED}</td> 4107 * <td>read-only</td> 4108 * <td>See {@link ContactsContract.Contacts}.</td> 4109 * </tr> 4110 * <tr> 4111 * <td>String</td> 4112 * <td>{@link #CUSTOM_RINGTONE}</td> 4113 * <td>read-only</td> 4114 * <td>See {@link ContactsContract.Contacts}.</td> 4115 * </tr> 4116 * <tr> 4117 * <td>int</td> 4118 * <td>{@link #SEND_TO_VOICEMAIL}</td> 4119 * <td>read-only</td> 4120 * <td>See {@link ContactsContract.Contacts}.</td> 4121 * </tr> 4122 * <tr> 4123 * <td>int</td> 4124 * <td>{@link #CONTACT_PRESENCE}</td> 4125 * <td>read-only</td> 4126 * <td>See {@link ContactsContract.Contacts}.</td> 4127 * </tr> 4128 * <tr> 4129 * <td>String</td> 4130 * <td>{@link #CONTACT_STATUS}</td> 4131 * <td>read-only</td> 4132 * <td>See {@link ContactsContract.Contacts}.</td> 4133 * </tr> 4134 * <tr> 4135 * <td>long</td> 4136 * <td>{@link #CONTACT_STATUS_TIMESTAMP}</td> 4137 * <td>read-only</td> 4138 * <td>See {@link ContactsContract.Contacts}.</td> 4139 * </tr> 4140 * <tr> 4141 * <td>String</td> 4142 * <td>{@link #CONTACT_STATUS_RES_PACKAGE}</td> 4143 * <td>read-only</td> 4144 * <td>See {@link ContactsContract.Contacts}.</td> 4145 * </tr> 4146 * <tr> 4147 * <td>long</td> 4148 * <td>{@link #CONTACT_STATUS_LABEL}</td> 4149 * <td>read-only</td> 4150 * <td>See {@link ContactsContract.Contacts}.</td> 4151 * </tr> 4152 * <tr> 4153 * <td>long</td> 4154 * <td>{@link #CONTACT_STATUS_ICON}</td> 4155 * <td>read-only</td> 4156 * <td>See {@link ContactsContract.Contacts}.</td> 4157 * </tr> 4158 * </table> 4159 */ 4160 public final static class Data implements DataColumnsWithJoins { 4161 /** 4162 * This utility class cannot be instantiated 4163 */ 4164 private Data() {} 4165 4166 /** 4167 * The content:// style URI for this table, which requests a directory 4168 * of data rows matching the selection criteria. 4169 */ 4170 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "data"); 4171 4172 /** 4173 * The MIME type of the results from {@link #CONTENT_URI}. 4174 */ 4175 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/data"; 4176 4177 /** 4178 * <p> 4179 * Build a {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI} 4180 * style {@link Uri} for the parent {@link android.provider.ContactsContract.Contacts} 4181 * entry of the given {@link ContactsContract.Data} entry. 4182 * </p> 4183 * <p> 4184 * Returns the Uri for the contact in the first entry returned by 4185 * {@link ContentResolver#query(Uri, String[], String, String[], String)} 4186 * for the provided {@code dataUri}. If the query returns null or empty 4187 * results, silently returns null. 4188 * </p> 4189 */ 4190 public static Uri getContactLookupUri(ContentResolver resolver, Uri dataUri) { 4191 final Cursor cursor = resolver.query(dataUri, new String[] { 4192 RawContacts.CONTACT_ID, Contacts.LOOKUP_KEY 4193 }, null, null, null); 4194 4195 Uri lookupUri = null; 4196 try { 4197 if (cursor != null && cursor.moveToFirst()) { 4198 final long contactId = cursor.getLong(0); 4199 final String lookupKey = cursor.getString(1); 4200 return Contacts.getLookupUri(contactId, lookupKey); 4201 } 4202 } finally { 4203 if (cursor != null) cursor.close(); 4204 } 4205 return lookupUri; 4206 } 4207 } 4208 4209 /** 4210 * <p> 4211 * Constants for the raw contacts entities table, which can be thought of as 4212 * an outer join of the raw_contacts table with the data table. It is a strictly 4213 * read-only table. 4214 * </p> 4215 * <p> 4216 * If a raw contact has data rows, the RawContactsEntity cursor will contain 4217 * a one row for each data row. If the raw contact has no data rows, the 4218 * cursor will still contain one row with the raw contact-level information 4219 * and nulls for data columns. 4220 * 4221 * <pre> 4222 * Uri entityUri = ContentUris.withAppendedId(RawContactsEntity.CONTENT_URI, rawContactId); 4223 * Cursor c = getContentResolver().query(entityUri, 4224 * new String[]{ 4225 * RawContactsEntity.SOURCE_ID, 4226 * RawContactsEntity.DATA_ID, 4227 * RawContactsEntity.MIMETYPE, 4228 * RawContactsEntity.DATA1 4229 * }, null, null, null); 4230 * try { 4231 * while (c.moveToNext()) { 4232 * String sourceId = c.getString(0); 4233 * if (!c.isNull(1)) { 4234 * String mimeType = c.getString(2); 4235 * String data = c.getString(3); 4236 * ... 4237 * } 4238 * } 4239 * } finally { 4240 * c.close(); 4241 * } 4242 * </pre> 4243 * 4244 * <h3>Columns</h3> 4245 * RawContactsEntity has a combination of RawContact and Data columns. 4246 * 4247 * <table class="jd-sumtable"> 4248 * <tr> 4249 * <th colspan='4'>RawContacts</th> 4250 * </tr> 4251 * <tr> 4252 * <td style="width: 7em;">long</td> 4253 * <td style="width: 20em;">{@link #_ID}</td> 4254 * <td style="width: 5em;">read-only</td> 4255 * <td>Raw contact row ID. See {@link RawContacts}.</td> 4256 * </tr> 4257 * <tr> 4258 * <td>long</td> 4259 * <td>{@link #CONTACT_ID}</td> 4260 * <td>read-only</td> 4261 * <td>See {@link RawContacts}.</td> 4262 * </tr> 4263 * <tr> 4264 * <td>int</td> 4265 * <td>{@link #AGGREGATION_MODE}</td> 4266 * <td>read-only</td> 4267 * <td>See {@link RawContacts}.</td> 4268 * </tr> 4269 * <tr> 4270 * <td>int</td> 4271 * <td>{@link #DELETED}</td> 4272 * <td>read-only</td> 4273 * <td>See {@link RawContacts}.</td> 4274 * </tr> 4275 * </table> 4276 * 4277 * <table class="jd-sumtable"> 4278 * <tr> 4279 * <th colspan='4'>Data</th> 4280 * </tr> 4281 * <tr> 4282 * <td style="width: 7em;">long</td> 4283 * <td style="width: 20em;">{@link #DATA_ID}</td> 4284 * <td style="width: 5em;">read-only</td> 4285 * <td>Data row ID. It will be null if the raw contact has no data rows.</td> 4286 * </tr> 4287 * <tr> 4288 * <td>String</td> 4289 * <td>{@link #MIMETYPE}</td> 4290 * <td>read-only</td> 4291 * <td>See {@link ContactsContract.Data}.</td> 4292 * </tr> 4293 * <tr> 4294 * <td>int</td> 4295 * <td>{@link #IS_PRIMARY}</td> 4296 * <td>read-only</td> 4297 * <td>See {@link ContactsContract.Data}.</td> 4298 * </tr> 4299 * <tr> 4300 * <td>int</td> 4301 * <td>{@link #IS_SUPER_PRIMARY}</td> 4302 * <td>read-only</td> 4303 * <td>See {@link ContactsContract.Data}.</td> 4304 * </tr> 4305 * <tr> 4306 * <td>int</td> 4307 * <td>{@link #DATA_VERSION}</td> 4308 * <td>read-only</td> 4309 * <td>See {@link ContactsContract.Data}.</td> 4310 * </tr> 4311 * <tr> 4312 * <td>Any type</td> 4313 * <td> 4314 * {@link #DATA1}<br> 4315 * {@link #DATA2}<br> 4316 * {@link #DATA3}<br> 4317 * {@link #DATA4}<br> 4318 * {@link #DATA5}<br> 4319 * {@link #DATA6}<br> 4320 * {@link #DATA7}<br> 4321 * {@link #DATA8}<br> 4322 * {@link #DATA9}<br> 4323 * {@link #DATA10}<br> 4324 * {@link #DATA11}<br> 4325 * {@link #DATA12}<br> 4326 * {@link #DATA13}<br> 4327 * {@link #DATA14}<br> 4328 * {@link #DATA15} 4329 * </td> 4330 * <td>read-only</td> 4331 * <td>See {@link ContactsContract.Data}.</td> 4332 * </tr> 4333 * <tr> 4334 * <td>Any type</td> 4335 * <td> 4336 * {@link #SYNC1}<br> 4337 * {@link #SYNC2}<br> 4338 * {@link #SYNC3}<br> 4339 * {@link #SYNC4} 4340 * </td> 4341 * <td>read-only</td> 4342 * <td>See {@link ContactsContract.Data}.</td> 4343 * </tr> 4344 * </table> 4345 */ 4346 public final static class RawContactsEntity 4347 implements BaseColumns, DataColumns, RawContactsColumns { 4348 /** 4349 * This utility class cannot be instantiated 4350 */ 4351 private RawContactsEntity() {} 4352 4353 /** 4354 * The content:// style URI for this table 4355 */ 4356 public static final Uri CONTENT_URI = 4357 Uri.withAppendedPath(AUTHORITY_URI, "raw_contact_entities"); 4358 4359 /** 4360 * The MIME type of {@link #CONTENT_URI} providing a directory of raw contact entities. 4361 */ 4362 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/raw_contact_entity"; 4363 4364 /** 4365 * If {@link #FOR_EXPORT_ONLY} is explicitly set to "1", returned Cursor toward 4366 * Data.CONTENT_URI contains only exportable data. 4367 * 4368 * This flag is useful (currently) only for vCard exporter in Contacts app, which 4369 * needs to exclude "un-exportable" data from available data to export, while 4370 * Contacts app itself has priviledge to access all data including "un-expotable" 4371 * ones and providers return all of them regardless of the callers' intention. 4372 * <P>Type: INTEGER</p> 4373 * 4374 * @hide Maybe available only in Eclair and not really ready for public use. 4375 * TODO: remove, or implement this feature completely. As of now (Eclair), 4376 * we only use this flag in queryEntities(), not query(). 4377 */ 4378 public static final String FOR_EXPORT_ONLY = "for_export_only"; 4379 4380 /** 4381 * The ID of the data column. The value will be null if this raw contact has no data rows. 4382 * <P>Type: INTEGER</P> 4383 */ 4384 public static final String DATA_ID = "data_id"; 4385 } 4386 4387 /** 4388 * @see PhoneLookup 4389 */ 4390 protected interface PhoneLookupColumns { 4391 /** 4392 * The phone number as the user entered it. 4393 * <P>Type: TEXT</P> 4394 */ 4395 public static final String NUMBER = "number"; 4396 4397 /** 4398 * The type of phone number, for example Home or Work. 4399 * <P>Type: INTEGER</P> 4400 */ 4401 public static final String TYPE = "type"; 4402 4403 /** 4404 * The user defined label for the phone number. 4405 * <P>Type: TEXT</P> 4406 */ 4407 public static final String LABEL = "label"; 4408 4409 /** 4410 * The phone number's E164 representation. 4411 * <P>Type: TEXT</P> 4412 * 4413 * @hide 4414 */ 4415 public static final String NORMALIZED_NUMBER = "normalized_number"; 4416 } 4417 4418 /** 4419 * A table that represents the result of looking up a phone number, for 4420 * example for caller ID. To perform a lookup you must append the number you 4421 * want to find to {@link #CONTENT_FILTER_URI}. This query is highly 4422 * optimized. 4423 * <pre> 4424 * Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)); 4425 * resolver.query(uri, new String[]{PhoneLookup.DISPLAY_NAME,... 4426 * </pre> 4427 * 4428 * <h3>Columns</h3> 4429 * 4430 * <table class="jd-sumtable"> 4431 * <tr> 4432 * <th colspan='4'>PhoneLookup</th> 4433 * </tr> 4434 * <tr> 4435 * <td>String</td> 4436 * <td>{@link #NUMBER}</td> 4437 * <td>read-only</td> 4438 * <td>Phone number.</td> 4439 * </tr> 4440 * <tr> 4441 * <td>String</td> 4442 * <td>{@link #TYPE}</td> 4443 * <td>read-only</td> 4444 * <td>Phone number type. See {@link CommonDataKinds.Phone}.</td> 4445 * </tr> 4446 * <tr> 4447 * <td>String</td> 4448 * <td>{@link #LABEL}</td> 4449 * <td>read-only</td> 4450 * <td>Custom label for the phone number. See {@link CommonDataKinds.Phone}.</td> 4451 * </tr> 4452 * </table> 4453 * <p> 4454 * Columns from the Contacts table are also available through a join. 4455 * </p> 4456 * <table class="jd-sumtable"> 4457 * <tr> 4458 * <th colspan='4'>Join with {@link Contacts}</th> 4459 * </tr> 4460 * <tr> 4461 * <td>long</td> 4462 * <td>{@link #_ID}</td> 4463 * <td>read-only</td> 4464 * <td>Contact ID.</td> 4465 * </tr> 4466 * <tr> 4467 * <td>String</td> 4468 * <td>{@link #LOOKUP_KEY}</td> 4469 * <td>read-only</td> 4470 * <td>See {@link ContactsContract.Contacts}</td> 4471 * </tr> 4472 * <tr> 4473 * <td>String</td> 4474 * <td>{@link #DISPLAY_NAME}</td> 4475 * <td>read-only</td> 4476 * <td>See {@link ContactsContract.Contacts}</td> 4477 * </tr> 4478 * <tr> 4479 * <td>long</td> 4480 * <td>{@link #PHOTO_ID}</td> 4481 * <td>read-only</td> 4482 * <td>See {@link ContactsContract.Contacts}.</td> 4483 * </tr> 4484 * <tr> 4485 * <td>int</td> 4486 * <td>{@link #IN_VISIBLE_GROUP}</td> 4487 * <td>read-only</td> 4488 * <td>See {@link ContactsContract.Contacts}.</td> 4489 * </tr> 4490 * <tr> 4491 * <td>int</td> 4492 * <td>{@link #HAS_PHONE_NUMBER}</td> 4493 * <td>read-only</td> 4494 * <td>See {@link ContactsContract.Contacts}.</td> 4495 * </tr> 4496 * <tr> 4497 * <td>int</td> 4498 * <td>{@link #TIMES_CONTACTED}</td> 4499 * <td>read-only</td> 4500 * <td>See {@link ContactsContract.Contacts}.</td> 4501 * </tr> 4502 * <tr> 4503 * <td>long</td> 4504 * <td>{@link #LAST_TIME_CONTACTED}</td> 4505 * <td>read-only</td> 4506 * <td>See {@link ContactsContract.Contacts}.</td> 4507 * </tr> 4508 * <tr> 4509 * <td>int</td> 4510 * <td>{@link #STARRED}</td> 4511 * <td>read-only</td> 4512 * <td>See {@link ContactsContract.Contacts}.</td> 4513 * </tr> 4514 * <tr> 4515 * <td>String</td> 4516 * <td>{@link #CUSTOM_RINGTONE}</td> 4517 * <td>read-only</td> 4518 * <td>See {@link ContactsContract.Contacts}.</td> 4519 * </tr> 4520 * <tr> 4521 * <td>int</td> 4522 * <td>{@link #SEND_TO_VOICEMAIL}</td> 4523 * <td>read-only</td> 4524 * <td>See {@link ContactsContract.Contacts}.</td> 4525 * </tr> 4526 * </table> 4527 */ 4528 public static final class PhoneLookup implements BaseColumns, PhoneLookupColumns, 4529 ContactsColumns, ContactOptionsColumns { 4530 /** 4531 * This utility class cannot be instantiated 4532 */ 4533 private PhoneLookup() {} 4534 4535 /** 4536 * The content:// style URI for this table. Append the phone number you want to lookup 4537 * to this URI and query it to perform a lookup. For example: 4538 * <pre> 4539 * Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_URI, Uri.encode(phoneNumber)); 4540 * </pre> 4541 */ 4542 public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(AUTHORITY_URI, 4543 "phone_lookup"); 4544 4545 /** 4546 * The MIME type of {@link #CONTENT_FILTER_URI} providing a directory of phone lookup rows. 4547 * 4548 * @hide 4549 */ 4550 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/phone_lookup"; 4551 } 4552 4553 /** 4554 * Additional data mixed in with {@link StatusColumns} to link 4555 * back to specific {@link ContactsContract.Data#_ID} entries. 4556 * 4557 * @see StatusUpdates 4558 */ 4559 protected interface PresenceColumns { 4560 4561 /** 4562 * Reference to the {@link Data#_ID} entry that owns this presence. 4563 * <P>Type: INTEGER</P> 4564 */ 4565 public static final String DATA_ID = "presence_data_id"; 4566 4567 /** 4568 * See {@link CommonDataKinds.Im} for a list of defined protocol constants. 4569 * <p>Type: NUMBER</p> 4570 */ 4571 public static final String PROTOCOL = "protocol"; 4572 4573 /** 4574 * Name of the custom protocol. Should be supplied along with the {@link #PROTOCOL} value 4575 * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}. Should be null or 4576 * omitted if {@link #PROTOCOL} value is not 4577 * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}. 4578 * 4579 * <p>Type: NUMBER</p> 4580 */ 4581 public static final String CUSTOM_PROTOCOL = "custom_protocol"; 4582 4583 /** 4584 * The IM handle the presence item is for. The handle is scoped to 4585 * {@link #PROTOCOL}. 4586 * <P>Type: TEXT</P> 4587 */ 4588 public static final String IM_HANDLE = "im_handle"; 4589 4590 /** 4591 * The IM account for the local user that the presence data came from. 4592 * <P>Type: TEXT</P> 4593 */ 4594 public static final String IM_ACCOUNT = "im_account"; 4595 } 4596 4597 /** 4598 * <p> 4599 * A status update is linked to a {@link ContactsContract.Data} row and captures 4600 * the user's latest status update via the corresponding source, e.g. 4601 * "Having lunch" via "Google Talk". 4602 * </p> 4603 * <p> 4604 * There are two ways a status update can be inserted: by explicitly linking 4605 * it to a Data row using {@link #DATA_ID} or indirectly linking it to a data row 4606 * using a combination of {@link #PROTOCOL} (or {@link #CUSTOM_PROTOCOL}) and 4607 * {@link #IM_HANDLE}. There is no difference between insert and update, you can use 4608 * either. 4609 * </p> 4610 * <p> 4611 * Inserting or updating a status update for the user's profile requires either using 4612 * the {@link #DATA_ID} to identify the data row to attach the update to, or 4613 * {@link StatusUpdates#PROFILE_CONTENT_URI} to ensure that the change is scoped to the 4614 * profile. 4615 * </p> 4616 * <p> 4617 * You cannot use {@link ContentResolver#update} to change a status, but 4618 * {@link ContentResolver#insert} will replace the latests status if it already 4619 * exists. 4620 * </p> 4621 * <p> 4622 * Use {@link ContentResolver#bulkInsert(Uri, ContentValues[])} to insert/update statuses 4623 * for multiple contacts at once. 4624 * </p> 4625 * 4626 * <h3>Columns</h3> 4627 * <table class="jd-sumtable"> 4628 * <tr> 4629 * <th colspan='4'>StatusUpdates</th> 4630 * </tr> 4631 * <tr> 4632 * <td>long</td> 4633 * <td>{@link #DATA_ID}</td> 4634 * <td>read/write</td> 4635 * <td>Reference to the {@link Data#_ID} entry that owns this presence. If this 4636 * field is <i>not</i> specified, the provider will attempt to find a data row 4637 * that matches the {@link #PROTOCOL} (or {@link #CUSTOM_PROTOCOL}) and 4638 * {@link #IM_HANDLE} columns. 4639 * </td> 4640 * </tr> 4641 * <tr> 4642 * <td>long</td> 4643 * <td>{@link #PROTOCOL}</td> 4644 * <td>read/write</td> 4645 * <td>See {@link CommonDataKinds.Im} for a list of defined protocol constants.</td> 4646 * </tr> 4647 * <tr> 4648 * <td>String</td> 4649 * <td>{@link #CUSTOM_PROTOCOL}</td> 4650 * <td>read/write</td> 4651 * <td>Name of the custom protocol. Should be supplied along with the {@link #PROTOCOL} value 4652 * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}. Should be null or 4653 * omitted if {@link #PROTOCOL} value is not 4654 * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.</td> 4655 * </tr> 4656 * <tr> 4657 * <td>String</td> 4658 * <td>{@link #IM_HANDLE}</td> 4659 * <td>read/write</td> 4660 * <td> The IM handle the presence item is for. The handle is scoped to 4661 * {@link #PROTOCOL}.</td> 4662 * </tr> 4663 * <tr> 4664 * <td>String</td> 4665 * <td>{@link #IM_ACCOUNT}</td> 4666 * <td>read/write</td> 4667 * <td>The IM account for the local user that the presence data came from.</td> 4668 * </tr> 4669 * <tr> 4670 * <td>int</td> 4671 * <td>{@link #PRESENCE}</td> 4672 * <td>read/write</td> 4673 * <td>Contact IM presence status. The allowed values are: 4674 * <p> 4675 * <ul> 4676 * <li>{@link #OFFLINE}</li> 4677 * <li>{@link #INVISIBLE}</li> 4678 * <li>{@link #AWAY}</li> 4679 * <li>{@link #IDLE}</li> 4680 * <li>{@link #DO_NOT_DISTURB}</li> 4681 * <li>{@link #AVAILABLE}</li> 4682 * </ul> 4683 * </p> 4684 * <p> 4685 * Since presence status is inherently volatile, the content provider 4686 * may choose not to store this field in long-term storage. 4687 * </p> 4688 * </td> 4689 * </tr> 4690 * <tr> 4691 * <td>int</td> 4692 * <td>{@link #CHAT_CAPABILITY}</td> 4693 * <td>read/write</td> 4694 * <td>Contact IM chat compatibility value. The allowed values combinations of the following 4695 * flags. If None of these flags is set, the device can only do text messaging. 4696 * <p> 4697 * <ul> 4698 * <li>{@link #CAPABILITY_HAS_VIDEO}</li> 4699 * <li>{@link #CAPABILITY_HAS_VOICE}</li> 4700 * <li>{@link #CAPABILITY_HAS_CAMERA}</li> 4701 * </ul> 4702 * </p> 4703 * <p> 4704 * Since chat compatibility is inherently volatile as the contact's availability moves from 4705 * one device to another, the content provider may choose not to store this field in long-term 4706 * storage. 4707 * </p> 4708 * </td> 4709 * </tr> 4710 * <tr> 4711 * <td>String</td> 4712 * <td>{@link #STATUS}</td> 4713 * <td>read/write</td> 4714 * <td>Contact's latest status update, e.g. "having toast for breakfast"</td> 4715 * </tr> 4716 * <tr> 4717 * <td>long</td> 4718 * <td>{@link #STATUS_TIMESTAMP}</td> 4719 * <td>read/write</td> 4720 * <td>The absolute time in milliseconds when the status was 4721 * entered by the user. If this value is not provided, the provider will follow 4722 * this logic: if there was no prior status update, the value will be left as null. 4723 * If there was a prior status update, the provider will default this field 4724 * to the current time.</td> 4725 * </tr> 4726 * <tr> 4727 * <td>String</td> 4728 * <td>{@link #STATUS_RES_PACKAGE}</td> 4729 * <td>read/write</td> 4730 * <td> The package containing resources for this status: label and icon.</td> 4731 * </tr> 4732 * <tr> 4733 * <td>long</td> 4734 * <td>{@link #STATUS_LABEL}</td> 4735 * <td>read/write</td> 4736 * <td>The resource ID of the label describing the source of contact status, 4737 * e.g. "Google Talk". This resource is scoped by the 4738 * {@link #STATUS_RES_PACKAGE}.</td> 4739 * </tr> 4740 * <tr> 4741 * <td>long</td> 4742 * <td>{@link #STATUS_ICON}</td> 4743 * <td>read/write</td> 4744 * <td>The resource ID of the icon for the source of contact status. This 4745 * resource is scoped by the {@link #STATUS_RES_PACKAGE}.</td> 4746 * </tr> 4747 * </table> 4748 */ 4749 public static class StatusUpdates implements StatusColumns, PresenceColumns { 4750 4751 /** 4752 * This utility class cannot be instantiated 4753 */ 4754 private StatusUpdates() {} 4755 4756 /** 4757 * The content:// style URI for this table 4758 */ 4759 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "status_updates"); 4760 4761 /** 4762 * The content:// style URI for this table, specific to the user's profile. 4763 */ 4764 public static final Uri PROFILE_CONTENT_URI = 4765 Uri.withAppendedPath(Profile.CONTENT_URI, "status_updates"); 4766 4767 /** 4768 * Gets the resource ID for the proper presence icon. 4769 * 4770 * @param status the status to get the icon for 4771 * @return the resource ID for the proper presence icon 4772 */ 4773 public static final int getPresenceIconResourceId(int status) { 4774 switch (status) { 4775 case AVAILABLE: 4776 return android.R.drawable.presence_online; 4777 case IDLE: 4778 case AWAY: 4779 return android.R.drawable.presence_away; 4780 case DO_NOT_DISTURB: 4781 return android.R.drawable.presence_busy; 4782 case INVISIBLE: 4783 return android.R.drawable.presence_invisible; 4784 case OFFLINE: 4785 default: 4786 return android.R.drawable.presence_offline; 4787 } 4788 } 4789 4790 /** 4791 * Returns the precedence of the status code the higher number being the higher precedence. 4792 * 4793 * @param status The status code. 4794 * @return An integer representing the precedence, 0 being the lowest. 4795 */ 4796 public static final int getPresencePrecedence(int status) { 4797 // Keep this function here incase we want to enforce a different precedence than the 4798 // natural order of the status constants. 4799 return status; 4800 } 4801 4802 /** 4803 * The MIME type of {@link #CONTENT_URI} providing a directory of 4804 * status update details. 4805 */ 4806 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/status-update"; 4807 4808 /** 4809 * The MIME type of a {@link #CONTENT_URI} subdirectory of a single 4810 * status update detail. 4811 */ 4812 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/status-update"; 4813 } 4814 4815 /** 4816 * @deprecated This old name was never meant to be made public. Do not use. 4817 */ 4818 @Deprecated 4819 public static final class Presence extends StatusUpdates { 4820 4821 } 4822 4823 /** 4824 * Additional column returned by the {@link Contacts#CONTENT_FILTER_URI} providing the 4825 * explanation of why the filter matched the contact. Specifically, it contains the 4826 * data elements that matched the query. The overall number of words in the snippet 4827 * can be capped. 4828 * 4829 * @hide 4830 */ 4831 public static class SearchSnippetColumns { 4832 4833 /** 4834 * The search snippet constructed according to the SQLite rules, see 4835 * http://www.sqlite.org/fts3.html#snippet 4836 * <p> 4837 * The snippet may contain (parts of) several data elements comprising 4838 * the contact. 4839 * 4840 * @hide 4841 */ 4842 public static final String SNIPPET = "snippet"; 4843 4844 4845 /** 4846 * Comma-separated parameters for the generation of the snippet: 4847 * <ul> 4848 * <li>The "start match" text. Default is <b></li> 4849 * <li>The "end match" text. Default is </b></li> 4850 * <li>The "ellipsis" text. Default is <b>...</b></li> 4851 * <li>Maximum number of tokens to include in the snippet. Can be either 4852 * a positive or a negative number: A positive number indicates how many 4853 * tokens can be returned in total. A negative number indicates how many 4854 * tokens can be returned per occurrence of the search terms.</li> 4855 * </ul> 4856 * 4857 * @hide 4858 */ 4859 public static final String SNIPPET_ARGS_PARAM_KEY = "snippet_args"; 4860 } 4861 4862 /** 4863 * Container for definitions of common data types stored in the {@link ContactsContract.Data} 4864 * table. 4865 */ 4866 public static final class CommonDataKinds { 4867 /** 4868 * This utility class cannot be instantiated 4869 */ 4870 private CommonDataKinds() {} 4871 4872 /** 4873 * The {@link Data#RES_PACKAGE} value for common data that should be 4874 * shown using a default style. 4875 * 4876 * @hide RES_PACKAGE is hidden 4877 */ 4878 public static final String PACKAGE_COMMON = "common"; 4879 4880 /** 4881 * The base types that all "Typed" data kinds support. 4882 */ 4883 public interface BaseTypes { 4884 /** 4885 * A custom type. The custom label should be supplied by user. 4886 */ 4887 public static int TYPE_CUSTOM = 0; 4888 } 4889 4890 /** 4891 * Columns common across the specific types. 4892 */ 4893 protected interface CommonColumns extends BaseTypes { 4894 /** 4895 * The data for the contact method. 4896 * <P>Type: TEXT</P> 4897 */ 4898 public static final String DATA = DataColumns.DATA1; 4899 4900 /** 4901 * The type of data, for example Home or Work. 4902 * <P>Type: INTEGER</P> 4903 */ 4904 public static final String TYPE = DataColumns.DATA2; 4905 4906 /** 4907 * The user defined label for the the contact method. 4908 * <P>Type: TEXT</P> 4909 */ 4910 public static final String LABEL = DataColumns.DATA3; 4911 } 4912 4913 /** 4914 * A data kind representing the contact's proper name. You can use all 4915 * columns defined for {@link ContactsContract.Data} as well as the following aliases. 4916 * 4917 * <h2>Column aliases</h2> 4918 * <table class="jd-sumtable"> 4919 * <tr> 4920 * <th>Type</th><th>Alias</th><th colspan='2'>Data column</th> 4921 * </tr> 4922 * <tr> 4923 * <td>String</td> 4924 * <td>{@link #DISPLAY_NAME}</td> 4925 * <td>{@link #DATA1}</td> 4926 * <td></td> 4927 * </tr> 4928 * <tr> 4929 * <td>String</td> 4930 * <td>{@link #GIVEN_NAME}</td> 4931 * <td>{@link #DATA2}</td> 4932 * <td></td> 4933 * </tr> 4934 * <tr> 4935 * <td>String</td> 4936 * <td>{@link #FAMILY_NAME}</td> 4937 * <td>{@link #DATA3}</td> 4938 * <td></td> 4939 * </tr> 4940 * <tr> 4941 * <td>String</td> 4942 * <td>{@link #PREFIX}</td> 4943 * <td>{@link #DATA4}</td> 4944 * <td>Common prefixes in English names are "Mr", "Ms", "Dr" etc.</td> 4945 * </tr> 4946 * <tr> 4947 * <td>String</td> 4948 * <td>{@link #MIDDLE_NAME}</td> 4949 * <td>{@link #DATA5}</td> 4950 * <td></td> 4951 * </tr> 4952 * <tr> 4953 * <td>String</td> 4954 * <td>{@link #SUFFIX}</td> 4955 * <td>{@link #DATA6}</td> 4956 * <td>Common suffixes in English names are "Sr", "Jr", "III" etc.</td> 4957 * </tr> 4958 * <tr> 4959 * <td>String</td> 4960 * <td>{@link #PHONETIC_GIVEN_NAME}</td> 4961 * <td>{@link #DATA7}</td> 4962 * <td>Used for phonetic spelling of the name, e.g. Pinyin, Katakana, Hiragana</td> 4963 * </tr> 4964 * <tr> 4965 * <td>String</td> 4966 * <td>{@link #PHONETIC_MIDDLE_NAME}</td> 4967 * <td>{@link #DATA8}</td> 4968 * <td></td> 4969 * </tr> 4970 * <tr> 4971 * <td>String</td> 4972 * <td>{@link #PHONETIC_FAMILY_NAME}</td> 4973 * <td>{@link #DATA9}</td> 4974 * <td></td> 4975 * </tr> 4976 * </table> 4977 */ 4978 public static final class StructuredName implements DataColumnsWithJoins { 4979 /** 4980 * This utility class cannot be instantiated 4981 */ 4982 private StructuredName() {} 4983 4984 /** MIME type used when storing this in data table. */ 4985 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/name"; 4986 4987 /** 4988 * The name that should be used to display the contact. 4989 * <i>Unstructured component of the name should be consistent with 4990 * its structured representation.</i> 4991 * <p> 4992 * Type: TEXT 4993 */ 4994 public static final String DISPLAY_NAME = DATA1; 4995 4996 /** 4997 * The given name for the contact. 4998 * <P>Type: TEXT</P> 4999 */ 5000 public static final String GIVEN_NAME = DATA2; 5001 5002 /** 5003 * The family name for the contact. 5004 * <P>Type: TEXT</P> 5005 */ 5006 public static final String FAMILY_NAME = DATA3; 5007 5008 /** 5009 * The contact's honorific prefix, e.g. "Sir" 5010 * <P>Type: TEXT</P> 5011 */ 5012 public static final String PREFIX = DATA4; 5013 5014 /** 5015 * The contact's middle name 5016 * <P>Type: TEXT</P> 5017 */ 5018 public static final String MIDDLE_NAME = DATA5; 5019 5020 /** 5021 * The contact's honorific suffix, e.g. "Jr" 5022 */ 5023 public static final String SUFFIX = DATA6; 5024 5025 /** 5026 * The phonetic version of the given name for the contact. 5027 * <P>Type: TEXT</P> 5028 */ 5029 public static final String PHONETIC_GIVEN_NAME = DATA7; 5030 5031 /** 5032 * The phonetic version of the additional name for the contact. 5033 * <P>Type: TEXT</P> 5034 */ 5035 public static final String PHONETIC_MIDDLE_NAME = DATA8; 5036 5037 /** 5038 * The phonetic version of the family name for the contact. 5039 * <P>Type: TEXT</P> 5040 */ 5041 public static final String PHONETIC_FAMILY_NAME = DATA9; 5042 5043 /** 5044 * The style used for combining given/middle/family name into a full name. 5045 * See {@link ContactsContract.FullNameStyle}. 5046 * 5047 * @hide 5048 */ 5049 public static final String FULL_NAME_STYLE = DATA10; 5050 5051 /** 5052 * The alphabet used for capturing the phonetic name. 5053 * See ContactsContract.PhoneticNameStyle. 5054 * @hide 5055 */ 5056 public static final String PHONETIC_NAME_STYLE = DATA11; 5057 } 5058 5059 /** 5060 * <p>A data kind representing the contact's nickname. For example, for 5061 * Bob Parr ("Mr. Incredible"): 5062 * <pre> 5063 * ArrayList<ContentProviderOperation> ops = 5064 * new ArrayList<ContentProviderOperation>(); 5065 * 5066 * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI) 5067 * .withValue(Data.RAW_CONTACT_ID, rawContactId) 5068 * .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE) 5069 * .withValue(StructuredName.DISPLAY_NAME, "Bob Parr") 5070 * .build()); 5071 * 5072 * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI) 5073 * .withValue(Data.RAW_CONTACT_ID, rawContactId) 5074 * .withValue(Data.MIMETYPE, Nickname.CONTENT_ITEM_TYPE) 5075 * .withValue(Nickname.NAME, "Mr. Incredible") 5076 * .withValue(Nickname.TYPE, Nickname.TYPE_CUSTOM) 5077 * .withValue(Nickname.LABEL, "Superhero") 5078 * .build()); 5079 * 5080 * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); 5081 * </pre> 5082 * </p> 5083 * <p> 5084 * You can use all columns defined for {@link ContactsContract.Data} as well as the 5085 * following aliases. 5086 * </p> 5087 * 5088 * <h2>Column aliases</h2> 5089 * <table class="jd-sumtable"> 5090 * <tr> 5091 * <th>Type</th><th>Alias</th><th colspan='2'>Data column</th> 5092 * </tr> 5093 * <tr> 5094 * <td>String</td> 5095 * <td>{@link #NAME}</td> 5096 * <td>{@link #DATA1}</td> 5097 * <td></td> 5098 * </tr> 5099 * <tr> 5100 * <td>int</td> 5101 * <td>{@link #TYPE}</td> 5102 * <td>{@link #DATA2}</td> 5103 * <td> 5104 * Allowed values are: 5105 * <p> 5106 * <ul> 5107 * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li> 5108 * <li>{@link #TYPE_DEFAULT}</li> 5109 * <li>{@link #TYPE_OTHER_NAME}</li> 5110 * <li>{@link #TYPE_MAIDEN_NAME}</li> 5111 * <li>{@link #TYPE_SHORT_NAME}</li> 5112 * <li>{@link #TYPE_INITIALS}</li> 5113 * </ul> 5114 * </p> 5115 * </td> 5116 * </tr> 5117 * <tr> 5118 * <td>String</td> 5119 * <td>{@link #LABEL}</td> 5120 * <td>{@link #DATA3}</td> 5121 * <td></td> 5122 * </tr> 5123 * </table> 5124 */ 5125 public static final class Nickname implements DataColumnsWithJoins, CommonColumns { 5126 /** 5127 * This utility class cannot be instantiated 5128 */ 5129 private Nickname() {} 5130 5131 /** MIME type used when storing this in data table. */ 5132 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/nickname"; 5133 5134 public static final int TYPE_DEFAULT = 1; 5135 public static final int TYPE_OTHER_NAME = 2; 5136 public static final int TYPE_MAIDEN_NAME = 3; 5137 /** @deprecated Use TYPE_MAIDEN_NAME instead. */ 5138 @Deprecated 5139 public static final int TYPE_MAINDEN_NAME = 3; 5140 public static final int TYPE_SHORT_NAME = 4; 5141 public static final int TYPE_INITIALS = 5; 5142 5143 /** 5144 * The name itself 5145 */ 5146 public static final String NAME = DATA; 5147 } 5148 5149 /** 5150 * <p> 5151 * A data kind representing a telephone number. 5152 * </p> 5153 * <p> 5154 * You can use all columns defined for {@link ContactsContract.Data} as 5155 * well as the following aliases. 5156 * </p> 5157 * <h2>Column aliases</h2> 5158 * <table class="jd-sumtable"> 5159 * <tr> 5160 * <th>Type</th> 5161 * <th>Alias</th><th colspan='2'>Data column</th> 5162 * </tr> 5163 * <tr> 5164 * <td>String</td> 5165 * <td>{@link #NUMBER}</td> 5166 * <td>{@link #DATA1}</td> 5167 * <td></td> 5168 * </tr> 5169 * <tr> 5170 * <td>int</td> 5171 * <td>{@link #TYPE}</td> 5172 * <td>{@link #DATA2}</td> 5173 * <td>Allowed values are: 5174 * <p> 5175 * <ul> 5176 * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li> 5177 * <li>{@link #TYPE_HOME}</li> 5178 * <li>{@link #TYPE_MOBILE}</li> 5179 * <li>{@link #TYPE_WORK}</li> 5180 * <li>{@link #TYPE_FAX_WORK}</li> 5181 * <li>{@link #TYPE_FAX_HOME}</li> 5182 * <li>{@link #TYPE_PAGER}</li> 5183 * <li>{@link #TYPE_OTHER}</li> 5184 * <li>{@link #TYPE_CALLBACK}</li> 5185 * <li>{@link #TYPE_CAR}</li> 5186 * <li>{@link #TYPE_COMPANY_MAIN}</li> 5187 * <li>{@link #TYPE_ISDN}</li> 5188 * <li>{@link #TYPE_MAIN}</li> 5189 * <li>{@link #TYPE_OTHER_FAX}</li> 5190 * <li>{@link #TYPE_RADIO}</li> 5191 * <li>{@link #TYPE_TELEX}</li> 5192 * <li>{@link #TYPE_TTY_TDD}</li> 5193 * <li>{@link #TYPE_WORK_MOBILE}</li> 5194 * <li>{@link #TYPE_WORK_PAGER}</li> 5195 * <li>{@link #TYPE_ASSISTANT}</li> 5196 * <li>{@link #TYPE_MMS}</li> 5197 * </ul> 5198 * </p> 5199 * </td> 5200 * </tr> 5201 * <tr> 5202 * <td>String</td> 5203 * <td>{@link #LABEL}</td> 5204 * <td>{@link #DATA3}</td> 5205 * <td></td> 5206 * </tr> 5207 * </table> 5208 */ 5209 public static final class Phone implements DataColumnsWithJoins, CommonColumns { 5210 /** 5211 * This utility class cannot be instantiated 5212 */ 5213 private Phone() {} 5214 5215 /** MIME type used when storing this in data table. */ 5216 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/phone_v2"; 5217 5218 /** 5219 * The MIME type of {@link #CONTENT_URI} providing a directory of 5220 * phones. 5221 */ 5222 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/phone_v2"; 5223 5224 /** 5225 * The content:// style URI for all data records of the 5226 * {@link #CONTENT_ITEM_TYPE} MIME type, combined with the 5227 * associated raw contact and aggregate contact data. 5228 */ 5229 public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI, 5230 "phones"); 5231 5232 /** 5233 * The content:// style URL for phone lookup using a filter. The filter returns 5234 * records of MIME type {@link #CONTENT_ITEM_TYPE}. The filter is applied 5235 * to display names as well as phone numbers. The filter argument should be passed 5236 * as an additional path segment after this URI. 5237 */ 5238 public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI, 5239 "filter"); 5240 5241 public static final int TYPE_HOME = 1; 5242 public static final int TYPE_MOBILE = 2; 5243 public static final int TYPE_WORK = 3; 5244 public static final int TYPE_FAX_WORK = 4; 5245 public static final int TYPE_FAX_HOME = 5; 5246 public static final int TYPE_PAGER = 6; 5247 public static final int TYPE_OTHER = 7; 5248 public static final int TYPE_CALLBACK = 8; 5249 public static final int TYPE_CAR = 9; 5250 public static final int TYPE_COMPANY_MAIN = 10; 5251 public static final int TYPE_ISDN = 11; 5252 public static final int TYPE_MAIN = 12; 5253 public static final int TYPE_OTHER_FAX = 13; 5254 public static final int TYPE_RADIO = 14; 5255 public static final int TYPE_TELEX = 15; 5256 public static final int TYPE_TTY_TDD = 16; 5257 public static final int TYPE_WORK_MOBILE = 17; 5258 public static final int TYPE_WORK_PAGER = 18; 5259 public static final int TYPE_ASSISTANT = 19; 5260 public static final int TYPE_MMS = 20; 5261 5262 /** 5263 * The phone number as the user entered it. 5264 * <P>Type: TEXT</P> 5265 */ 5266 public static final String NUMBER = DATA; 5267 5268 /** 5269 * The phone number's E164 representation. 5270 * <P>Type: TEXT</P> 5271 * 5272 * @hide 5273 */ 5274 public static final String NORMALIZED_NUMBER = DATA4; 5275 5276 /** 5277 * @deprecated use {@link #getTypeLabel(Resources, int, CharSequence)} instead. 5278 * @hide 5279 */ 5280 @Deprecated 5281 public static final CharSequence getDisplayLabel(Context context, int type, 5282 CharSequence label, CharSequence[] labelArray) { 5283 return getTypeLabel(context.getResources(), type, label); 5284 } 5285 5286 /** 5287 * @deprecated use {@link #getTypeLabel(Resources, int, CharSequence)} instead. 5288 * @hide 5289 */ 5290 @Deprecated 5291 public static final CharSequence getDisplayLabel(Context context, int type, 5292 CharSequence label) { 5293 return getTypeLabel(context.getResources(), type, label); 5294 } 5295 5296 /** 5297 * Return the string resource that best describes the given 5298 * {@link #TYPE}. Will always return a valid resource. 5299 */ 5300 public static final int getTypeLabelResource(int type) { 5301 switch (type) { 5302 case TYPE_HOME: return com.android.internal.R.string.phoneTypeHome; 5303 case TYPE_MOBILE: return com.android.internal.R.string.phoneTypeMobile; 5304 case TYPE_WORK: return com.android.internal.R.string.phoneTypeWork; 5305 case TYPE_FAX_WORK: return com.android.internal.R.string.phoneTypeFaxWork; 5306 case TYPE_FAX_HOME: return com.android.internal.R.string.phoneTypeFaxHome; 5307 case TYPE_PAGER: return com.android.internal.R.string.phoneTypePager; 5308 case TYPE_OTHER: return com.android.internal.R.string.phoneTypeOther; 5309 case TYPE_CALLBACK: return com.android.internal.R.string.phoneTypeCallback; 5310 case TYPE_CAR: return com.android.internal.R.string.phoneTypeCar; 5311 case TYPE_COMPANY_MAIN: return com.android.internal.R.string.phoneTypeCompanyMain; 5312 case TYPE_ISDN: return com.android.internal.R.string.phoneTypeIsdn; 5313 case TYPE_MAIN: return com.android.internal.R.string.phoneTypeMain; 5314 case TYPE_OTHER_FAX: return com.android.internal.R.string.phoneTypeOtherFax; 5315 case TYPE_RADIO: return com.android.internal.R.string.phoneTypeRadio; 5316 case TYPE_TELEX: return com.android.internal.R.string.phoneTypeTelex; 5317 case TYPE_TTY_TDD: return com.android.internal.R.string.phoneTypeTtyTdd; 5318 case TYPE_WORK_MOBILE: return com.android.internal.R.string.phoneTypeWorkMobile; 5319 case TYPE_WORK_PAGER: return com.android.internal.R.string.phoneTypeWorkPager; 5320 case TYPE_ASSISTANT: return com.android.internal.R.string.phoneTypeAssistant; 5321 case TYPE_MMS: return com.android.internal.R.string.phoneTypeMms; 5322 default: return com.android.internal.R.string.phoneTypeCustom; 5323 } 5324 } 5325 5326 /** 5327 * Return a {@link CharSequence} that best describes the given type, 5328 * possibly substituting the given {@link #LABEL} value 5329 * for {@link #TYPE_CUSTOM}. 5330 */ 5331 public static final CharSequence getTypeLabel(Resources res, int type, 5332 CharSequence label) { 5333 if ((type == TYPE_CUSTOM || type == TYPE_ASSISTANT) && !TextUtils.isEmpty(label)) { 5334 return label; 5335 } else { 5336 final int labelRes = getTypeLabelResource(type); 5337 return res.getText(labelRes); 5338 } 5339 } 5340 } 5341 5342 /** 5343 * <p> 5344 * A data kind representing an email address. 5345 * </p> 5346 * <p> 5347 * You can use all columns defined for {@link ContactsContract.Data} as 5348 * well as the following aliases. 5349 * </p> 5350 * <h2>Column aliases</h2> 5351 * <table class="jd-sumtable"> 5352 * <tr> 5353 * <th>Type</th> 5354 * <th>Alias</th><th colspan='2'>Data column</th> 5355 * </tr> 5356 * <tr> 5357 * <td>String</td> 5358 * <td>{@link #ADDRESS}</td> 5359 * <td>{@link #DATA1}</td> 5360 * <td>Email address itself.</td> 5361 * </tr> 5362 * <tr> 5363 * <td>int</td> 5364 * <td>{@link #TYPE}</td> 5365 * <td>{@link #DATA2}</td> 5366 * <td>Allowed values are: 5367 * <p> 5368 * <ul> 5369 * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li> 5370 * <li>{@link #TYPE_HOME}</li> 5371 * <li>{@link #TYPE_WORK}</li> 5372 * <li>{@link #TYPE_OTHER}</li> 5373 * <li>{@link #TYPE_MOBILE}</li> 5374 * </ul> 5375 * </p> 5376 * </td> 5377 * </tr> 5378 * <tr> 5379 * <td>String</td> 5380 * <td>{@link #LABEL}</td> 5381 * <td>{@link #DATA3}</td> 5382 * <td></td> 5383 * </tr> 5384 * </table> 5385 */ 5386 public static final class Email implements DataColumnsWithJoins, CommonColumns { 5387 /** 5388 * This utility class cannot be instantiated 5389 */ 5390 private Email() {} 5391 5392 /** MIME type used when storing this in data table. */ 5393 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/email_v2"; 5394 5395 /** 5396 * The MIME type of {@link #CONTENT_URI} providing a directory of email addresses. 5397 */ 5398 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/email_v2"; 5399 5400 /** 5401 * The content:// style URI for all data records of the 5402 * {@link #CONTENT_ITEM_TYPE} MIME type, combined with the 5403 * associated raw contact and aggregate contact data. 5404 */ 5405 public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI, 5406 "emails"); 5407 5408 /** 5409 * <p> 5410 * The content:// style URL for looking up data rows by email address. The 5411 * lookup argument, an email address, should be passed as an additional path segment 5412 * after this URI. 5413 * </p> 5414 * <p>Example: 5415 * <pre> 5416 * Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(email)); 5417 * Cursor c = getContentResolver().query(uri, 5418 * new String[]{Email.CONTACT_ID, Email.DISPLAY_NAME, Email.DATA}, 5419 * null, null, null); 5420 * </pre> 5421 * </p> 5422 */ 5423 public static final Uri CONTENT_LOOKUP_URI = Uri.withAppendedPath(CONTENT_URI, 5424 "lookup"); 5425 5426 /** 5427 * <p> 5428 * The content:// style URL for email lookup using a filter. The filter returns 5429 * records of MIME type {@link #CONTENT_ITEM_TYPE}. The filter is applied 5430 * to display names as well as email addresses. The filter argument should be passed 5431 * as an additional path segment after this URI. 5432 * </p> 5433 * <p>The query in the following example will return "Robert Parr (bob@incredibles.com)" 5434 * as well as "Bob Parr (incredible@android.com)". 5435 * <pre> 5436 * Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode("bob")); 5437 * Cursor c = getContentResolver().query(uri, 5438 * new String[]{Email.DISPLAY_NAME, Email.DATA}, 5439 * null, null, null); 5440 * </pre> 5441 * </p> 5442 */ 5443 public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI, 5444 "filter"); 5445 5446 /** 5447 * The email address. 5448 * <P>Type: TEXT</P> 5449 */ 5450 public static final String ADDRESS = DATA1; 5451 5452 public static final int TYPE_HOME = 1; 5453 public static final int TYPE_WORK = 2; 5454 public static final int TYPE_OTHER = 3; 5455 public static final int TYPE_MOBILE = 4; 5456 5457 /** 5458 * The display name for the email address 5459 * <P>Type: TEXT</P> 5460 */ 5461 public static final String DISPLAY_NAME = DATA4; 5462 5463 /** 5464 * Return the string resource that best describes the given 5465 * {@link #TYPE}. Will always return a valid resource. 5466 */ 5467 public static final int getTypeLabelResource(int type) { 5468 switch (type) { 5469 case TYPE_HOME: return com.android.internal.R.string.emailTypeHome; 5470 case TYPE_WORK: return com.android.internal.R.string.emailTypeWork; 5471 case TYPE_OTHER: return com.android.internal.R.string.emailTypeOther; 5472 case TYPE_MOBILE: return com.android.internal.R.string.emailTypeMobile; 5473 default: return com.android.internal.R.string.emailTypeCustom; 5474 } 5475 } 5476 5477 /** 5478 * Return a {@link CharSequence} that best describes the given type, 5479 * possibly substituting the given {@link #LABEL} value 5480 * for {@link #TYPE_CUSTOM}. 5481 */ 5482 public static final CharSequence getTypeLabel(Resources res, int type, 5483 CharSequence label) { 5484 if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) { 5485 return label; 5486 } else { 5487 final int labelRes = getTypeLabelResource(type); 5488 return res.getText(labelRes); 5489 } 5490 } 5491 } 5492 5493 /** 5494 * <p> 5495 * A data kind representing a postal addresses. 5496 * </p> 5497 * <p> 5498 * You can use all columns defined for {@link ContactsContract.Data} as 5499 * well as the following aliases. 5500 * </p> 5501 * <h2>Column aliases</h2> 5502 * <table class="jd-sumtable"> 5503 * <tr> 5504 * <th>Type</th> 5505 * <th>Alias</th><th colspan='2'>Data column</th> 5506 * </tr> 5507 * <tr> 5508 * <td>String</td> 5509 * <td>{@link #FORMATTED_ADDRESS}</td> 5510 * <td>{@link #DATA1}</td> 5511 * <td></td> 5512 * </tr> 5513 * <tr> 5514 * <td>int</td> 5515 * <td>{@link #TYPE}</td> 5516 * <td>{@link #DATA2}</td> 5517 * <td>Allowed values are: 5518 * <p> 5519 * <ul> 5520 * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li> 5521 * <li>{@link #TYPE_HOME}</li> 5522 * <li>{@link #TYPE_WORK}</li> 5523 * <li>{@link #TYPE_OTHER}</li> 5524 * </ul> 5525 * </p> 5526 * </td> 5527 * </tr> 5528 * <tr> 5529 * <td>String</td> 5530 * <td>{@link #LABEL}</td> 5531 * <td>{@link #DATA3}</td> 5532 * <td></td> 5533 * </tr> 5534 * <tr> 5535 * <td>String</td> 5536 * <td>{@link #STREET}</td> 5537 * <td>{@link #DATA4}</td> 5538 * <td></td> 5539 * </tr> 5540 * <tr> 5541 * <td>String</td> 5542 * <td>{@link #POBOX}</td> 5543 * <td>{@link #DATA5}</td> 5544 * <td>Post Office Box number</td> 5545 * </tr> 5546 * <tr> 5547 * <td>String</td> 5548 * <td>{@link #NEIGHBORHOOD}</td> 5549 * <td>{@link #DATA6}</td> 5550 * <td></td> 5551 * </tr> 5552 * <tr> 5553 * <td>String</td> 5554 * <td>{@link #CITY}</td> 5555 * <td>{@link #DATA7}</td> 5556 * <td></td> 5557 * </tr> 5558 * <tr> 5559 * <td>String</td> 5560 * <td>{@link #REGION}</td> 5561 * <td>{@link #DATA8}</td> 5562 * <td></td> 5563 * </tr> 5564 * <tr> 5565 * <td>String</td> 5566 * <td>{@link #POSTCODE}</td> 5567 * <td>{@link #DATA9}</td> 5568 * <td></td> 5569 * </tr> 5570 * <tr> 5571 * <td>String</td> 5572 * <td>{@link #COUNTRY}</td> 5573 * <td>{@link #DATA10}</td> 5574 * <td></td> 5575 * </tr> 5576 * </table> 5577 */ 5578 public static final class StructuredPostal implements DataColumnsWithJoins, CommonColumns { 5579 /** 5580 * This utility class cannot be instantiated 5581 */ 5582 private StructuredPostal() { 5583 } 5584 5585 /** MIME type used when storing this in data table. */ 5586 public static final String CONTENT_ITEM_TYPE = 5587 "vnd.android.cursor.item/postal-address_v2"; 5588 5589 /** 5590 * The MIME type of {@link #CONTENT_URI} providing a directory of 5591 * postal addresses. 5592 */ 5593 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/postal-address_v2"; 5594 5595 /** 5596 * The content:// style URI for all data records of the 5597 * {@link StructuredPostal#CONTENT_ITEM_TYPE} MIME type. 5598 */ 5599 public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI, 5600 "postals"); 5601 5602 public static final int TYPE_HOME = 1; 5603 public static final int TYPE_WORK = 2; 5604 public static final int TYPE_OTHER = 3; 5605 5606 /** 5607 * The full, unstructured postal address. <i>This field must be 5608 * consistent with any structured data.</i> 5609 * <p> 5610 * Type: TEXT 5611 */ 5612 public static final String FORMATTED_ADDRESS = DATA; 5613 5614 /** 5615 * Can be street, avenue, road, etc. This element also includes the 5616 * house number and room/apartment/flat/floor number. 5617 * <p> 5618 * Type: TEXT 5619 */ 5620 public static final String STREET = DATA4; 5621 5622 /** 5623 * Covers actual P.O. boxes, drawers, locked bags, etc. This is 5624 * usually but not always mutually exclusive with street. 5625 * <p> 5626 * Type: TEXT 5627 */ 5628 public static final String POBOX = DATA5; 5629 5630 /** 5631 * This is used to disambiguate a street address when a city 5632 * contains more than one street with the same name, or to specify a 5633 * small place whose mail is routed through a larger postal town. In 5634 * China it could be a county or a minor city. 5635 * <p> 5636 * Type: TEXT 5637 */ 5638 public static final String NEIGHBORHOOD = DATA6; 5639 5640 /** 5641 * Can be city, village, town, borough, etc. This is the postal town 5642 * and not necessarily the place of residence or place of business. 5643 * <p> 5644 * Type: TEXT 5645 */ 5646 public static final String CITY = DATA7; 5647 5648 /** 5649 * A state, province, county (in Ireland), Land (in Germany), 5650 * departement (in France), etc. 5651 * <p> 5652 * Type: TEXT 5653 */ 5654 public static final String REGION = DATA8; 5655 5656 /** 5657 * Postal code. Usually country-wide, but sometimes specific to the 5658 * city (e.g. "2" in "Dublin 2, Ireland" addresses). 5659 * <p> 5660 * Type: TEXT 5661 */ 5662 public static final String POSTCODE = DATA9; 5663 5664 /** 5665 * The name or code of the country. 5666 * <p> 5667 * Type: TEXT 5668 */ 5669 public static final String COUNTRY = DATA10; 5670 5671 /** 5672 * Return the string resource that best describes the given 5673 * {@link #TYPE}. Will always return a valid resource. 5674 */ 5675 public static final int getTypeLabelResource(int type) { 5676 switch (type) { 5677 case TYPE_HOME: return com.android.internal.R.string.postalTypeHome; 5678 case TYPE_WORK: return com.android.internal.R.string.postalTypeWork; 5679 case TYPE_OTHER: return com.android.internal.R.string.postalTypeOther; 5680 default: return com.android.internal.R.string.postalTypeCustom; 5681 } 5682 } 5683 5684 /** 5685 * Return a {@link CharSequence} that best describes the given type, 5686 * possibly substituting the given {@link #LABEL} value 5687 * for {@link #TYPE_CUSTOM}. 5688 */ 5689 public static final CharSequence getTypeLabel(Resources res, int type, 5690 CharSequence label) { 5691 if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) { 5692 return label; 5693 } else { 5694 final int labelRes = getTypeLabelResource(type); 5695 return res.getText(labelRes); 5696 } 5697 } 5698 } 5699 5700 /** 5701 * <p> 5702 * A data kind representing an IM address 5703 * </p> 5704 * <p> 5705 * You can use all columns defined for {@link ContactsContract.Data} as 5706 * well as the following aliases. 5707 * </p> 5708 * <h2>Column aliases</h2> 5709 * <table class="jd-sumtable"> 5710 * <tr> 5711 * <th>Type</th> 5712 * <th>Alias</th><th colspan='2'>Data column</th> 5713 * </tr> 5714 * <tr> 5715 * <td>String</td> 5716 * <td>{@link #DATA}</td> 5717 * <td>{@link #DATA1}</td> 5718 * <td></td> 5719 * </tr> 5720 * <tr> 5721 * <td>int</td> 5722 * <td>{@link #TYPE}</td> 5723 * <td>{@link #DATA2}</td> 5724 * <td>Allowed values are: 5725 * <p> 5726 * <ul> 5727 * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li> 5728 * <li>{@link #TYPE_HOME}</li> 5729 * <li>{@link #TYPE_WORK}</li> 5730 * <li>{@link #TYPE_OTHER}</li> 5731 * </ul> 5732 * </p> 5733 * </td> 5734 * </tr> 5735 * <tr> 5736 * <td>String</td> 5737 * <td>{@link #LABEL}</td> 5738 * <td>{@link #DATA3}</td> 5739 * <td></td> 5740 * </tr> 5741 * <tr> 5742 * <td>String</td> 5743 * <td>{@link #PROTOCOL}</td> 5744 * <td>{@link #DATA5}</td> 5745 * <td> 5746 * <p> 5747 * Allowed values: 5748 * <ul> 5749 * <li>{@link #PROTOCOL_CUSTOM}. Also provide the actual protocol name 5750 * as {@link #CUSTOM_PROTOCOL}.</li> 5751 * <li>{@link #PROTOCOL_AIM}</li> 5752 * <li>{@link #PROTOCOL_MSN}</li> 5753 * <li>{@link #PROTOCOL_YAHOO}</li> 5754 * <li>{@link #PROTOCOL_SKYPE}</li> 5755 * <li>{@link #PROTOCOL_QQ}</li> 5756 * <li>{@link #PROTOCOL_GOOGLE_TALK}</li> 5757 * <li>{@link #PROTOCOL_ICQ}</li> 5758 * <li>{@link #PROTOCOL_JABBER}</li> 5759 * <li>{@link #PROTOCOL_NETMEETING}</li> 5760 * </ul> 5761 * </p> 5762 * </td> 5763 * </tr> 5764 * <tr> 5765 * <td>String</td> 5766 * <td>{@link #CUSTOM_PROTOCOL}</td> 5767 * <td>{@link #DATA6}</td> 5768 * <td></td> 5769 * </tr> 5770 * </table> 5771 */ 5772 public static final class Im implements DataColumnsWithJoins, CommonColumns { 5773 /** 5774 * This utility class cannot be instantiated 5775 */ 5776 private Im() {} 5777 5778 /** MIME type used when storing this in data table. */ 5779 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/im"; 5780 5781 public static final int TYPE_HOME = 1; 5782 public static final int TYPE_WORK = 2; 5783 public static final int TYPE_OTHER = 3; 5784 5785 /** 5786 * This column should be populated with one of the defined 5787 * constants, e.g. {@link #PROTOCOL_YAHOO}. If the value of this 5788 * column is {@link #PROTOCOL_CUSTOM}, the {@link #CUSTOM_PROTOCOL} 5789 * should contain the name of the custom protocol. 5790 */ 5791 public static final String PROTOCOL = DATA5; 5792 5793 public static final String CUSTOM_PROTOCOL = DATA6; 5794 5795 /* 5796 * The predefined IM protocol types. 5797 */ 5798 public static final int PROTOCOL_CUSTOM = -1; 5799 public static final int PROTOCOL_AIM = 0; 5800 public static final int PROTOCOL_MSN = 1; 5801 public static final int PROTOCOL_YAHOO = 2; 5802 public static final int PROTOCOL_SKYPE = 3; 5803 public static final int PROTOCOL_QQ = 4; 5804 public static final int PROTOCOL_GOOGLE_TALK = 5; 5805 public static final int PROTOCOL_ICQ = 6; 5806 public static final int PROTOCOL_JABBER = 7; 5807 public static final int PROTOCOL_NETMEETING = 8; 5808 5809 /** 5810 * Return the string resource that best describes the given 5811 * {@link #TYPE}. Will always return a valid resource. 5812 */ 5813 public static final int getTypeLabelResource(int type) { 5814 switch (type) { 5815 case TYPE_HOME: return com.android.internal.R.string.imTypeHome; 5816 case TYPE_WORK: return com.android.internal.R.string.imTypeWork; 5817 case TYPE_OTHER: return com.android.internal.R.string.imTypeOther; 5818 default: return com.android.internal.R.string.imTypeCustom; 5819 } 5820 } 5821 5822 /** 5823 * Return a {@link CharSequence} that best describes the given type, 5824 * possibly substituting the given {@link #LABEL} value 5825 * for {@link #TYPE_CUSTOM}. 5826 */ 5827 public static final CharSequence getTypeLabel(Resources res, int type, 5828 CharSequence label) { 5829 if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) { 5830 return label; 5831 } else { 5832 final int labelRes = getTypeLabelResource(type); 5833 return res.getText(labelRes); 5834 } 5835 } 5836 5837 /** 5838 * Return the string resource that best describes the given 5839 * {@link #PROTOCOL}. Will always return a valid resource. 5840 */ 5841 public static final int getProtocolLabelResource(int type) { 5842 switch (type) { 5843 case PROTOCOL_AIM: return com.android.internal.R.string.imProtocolAim; 5844 case PROTOCOL_MSN: return com.android.internal.R.string.imProtocolMsn; 5845 case PROTOCOL_YAHOO: return com.android.internal.R.string.imProtocolYahoo; 5846 case PROTOCOL_SKYPE: return com.android.internal.R.string.imProtocolSkype; 5847 case PROTOCOL_QQ: return com.android.internal.R.string.imProtocolQq; 5848 case PROTOCOL_GOOGLE_TALK: return com.android.internal.R.string.imProtocolGoogleTalk; 5849 case PROTOCOL_ICQ: return com.android.internal.R.string.imProtocolIcq; 5850 case PROTOCOL_JABBER: return com.android.internal.R.string.imProtocolJabber; 5851 case PROTOCOL_NETMEETING: return com.android.internal.R.string.imProtocolNetMeeting; 5852 default: return com.android.internal.R.string.imProtocolCustom; 5853 } 5854 } 5855 5856 /** 5857 * Return a {@link CharSequence} that best describes the given 5858 * protocol, possibly substituting the given 5859 * {@link #CUSTOM_PROTOCOL} value for {@link #PROTOCOL_CUSTOM}. 5860 */ 5861 public static final CharSequence getProtocolLabel(Resources res, int type, 5862 CharSequence label) { 5863 if (type == PROTOCOL_CUSTOM && !TextUtils.isEmpty(label)) { 5864 return label; 5865 } else { 5866 final int labelRes = getProtocolLabelResource(type); 5867 return res.getText(labelRes); 5868 } 5869 } 5870 } 5871 5872 /** 5873 * <p> 5874 * A data kind representing an organization. 5875 * </p> 5876 * <p> 5877 * You can use all columns defined for {@link ContactsContract.Data} as 5878 * well as the following aliases. 5879 * </p> 5880 * <h2>Column aliases</h2> 5881 * <table class="jd-sumtable"> 5882 * <tr> 5883 * <th>Type</th> 5884 * <th>Alias</th><th colspan='2'>Data column</th> 5885 * </tr> 5886 * <tr> 5887 * <td>String</td> 5888 * <td>{@link #COMPANY}</td> 5889 * <td>{@link #DATA1}</td> 5890 * <td></td> 5891 * </tr> 5892 * <tr> 5893 * <td>int</td> 5894 * <td>{@link #TYPE}</td> 5895 * <td>{@link #DATA2}</td> 5896 * <td>Allowed values are: 5897 * <p> 5898 * <ul> 5899 * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li> 5900 * <li>{@link #TYPE_WORK}</li> 5901 * <li>{@link #TYPE_OTHER}</li> 5902 * </ul> 5903 * </p> 5904 * </td> 5905 * </tr> 5906 * <tr> 5907 * <td>String</td> 5908 * <td>{@link #LABEL}</td> 5909 * <td>{@link #DATA3}</td> 5910 * <td></td> 5911 * </tr> 5912 * <tr> 5913 * <td>String</td> 5914 * <td>{@link #TITLE}</td> 5915 * <td>{@link #DATA4}</td> 5916 * <td></td> 5917 * </tr> 5918 * <tr> 5919 * <td>String</td> 5920 * <td>{@link #DEPARTMENT}</td> 5921 * <td>{@link #DATA5}</td> 5922 * <td></td> 5923 * </tr> 5924 * <tr> 5925 * <td>String</td> 5926 * <td>{@link #JOB_DESCRIPTION}</td> 5927 * <td>{@link #DATA6}</td> 5928 * <td></td> 5929 * </tr> 5930 * <tr> 5931 * <td>String</td> 5932 * <td>{@link #SYMBOL}</td> 5933 * <td>{@link #DATA7}</td> 5934 * <td></td> 5935 * </tr> 5936 * <tr> 5937 * <td>String</td> 5938 * <td>{@link #PHONETIC_NAME}</td> 5939 * <td>{@link #DATA8}</td> 5940 * <td></td> 5941 * </tr> 5942 * <tr> 5943 * <td>String</td> 5944 * <td>{@link #OFFICE_LOCATION}</td> 5945 * <td>{@link #DATA9}</td> 5946 * <td></td> 5947 * </tr> 5948 * <tr> 5949 * <td>String</td> 5950 * <td>PHONETIC_NAME_STYLE</td> 5951 * <td>{@link #DATA10}</td> 5952 * <td></td> 5953 * </tr> 5954 * </table> 5955 */ 5956 public static final class Organization implements DataColumnsWithJoins, CommonColumns { 5957 /** 5958 * This utility class cannot be instantiated 5959 */ 5960 private Organization() {} 5961 5962 /** MIME type used when storing this in data table. */ 5963 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/organization"; 5964 5965 public static final int TYPE_WORK = 1; 5966 public static final int TYPE_OTHER = 2; 5967 5968 /** 5969 * The company as the user entered it. 5970 * <P>Type: TEXT</P> 5971 */ 5972 public static final String COMPANY = DATA; 5973 5974 /** 5975 * The position title at this company as the user entered it. 5976 * <P>Type: TEXT</P> 5977 */ 5978 public static final String TITLE = DATA4; 5979 5980 /** 5981 * The department at this company as the user entered it. 5982 * <P>Type: TEXT</P> 5983 */ 5984 public static final String DEPARTMENT = DATA5; 5985 5986 /** 5987 * The job description at this company as the user entered it. 5988 * <P>Type: TEXT</P> 5989 */ 5990 public static final String JOB_DESCRIPTION = DATA6; 5991 5992 /** 5993 * The symbol of this company as the user entered it. 5994 * <P>Type: TEXT</P> 5995 */ 5996 public static final String SYMBOL = DATA7; 5997 5998 /** 5999 * The phonetic name of this company as the user entered it. 6000 * <P>Type: TEXT</P> 6001 */ 6002 public static final String PHONETIC_NAME = DATA8; 6003 6004 /** 6005 * The office location of this organization. 6006 * <P>Type: TEXT</P> 6007 */ 6008 public static final String OFFICE_LOCATION = DATA9; 6009 6010 /** 6011 * The alphabet used for capturing the phonetic name. 6012 * See {@link ContactsContract.PhoneticNameStyle}. 6013 * @hide 6014 */ 6015 public static final String PHONETIC_NAME_STYLE = DATA10; 6016 6017 /** 6018 * Return the string resource that best describes the given 6019 * {@link #TYPE}. Will always return a valid resource. 6020 */ 6021 public static final int getTypeLabelResource(int type) { 6022 switch (type) { 6023 case TYPE_WORK: return com.android.internal.R.string.orgTypeWork; 6024 case TYPE_OTHER: return com.android.internal.R.string.orgTypeOther; 6025 default: return com.android.internal.R.string.orgTypeCustom; 6026 } 6027 } 6028 6029 /** 6030 * Return a {@link CharSequence} that best describes the given type, 6031 * possibly substituting the given {@link #LABEL} value 6032 * for {@link #TYPE_CUSTOM}. 6033 */ 6034 public static final CharSequence getTypeLabel(Resources res, int type, 6035 CharSequence label) { 6036 if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) { 6037 return label; 6038 } else { 6039 final int labelRes = getTypeLabelResource(type); 6040 return res.getText(labelRes); 6041 } 6042 } 6043 } 6044 6045 /** 6046 * <p> 6047 * A data kind representing a relation. 6048 * </p> 6049 * <p> 6050 * You can use all columns defined for {@link ContactsContract.Data} as 6051 * well as the following aliases. 6052 * </p> 6053 * <h2>Column aliases</h2> 6054 * <table class="jd-sumtable"> 6055 * <tr> 6056 * <th>Type</th> 6057 * <th>Alias</th><th colspan='2'>Data column</th> 6058 * </tr> 6059 * <tr> 6060 * <td>String</td> 6061 * <td>{@link #NAME}</td> 6062 * <td>{@link #DATA1}</td> 6063 * <td></td> 6064 * </tr> 6065 * <tr> 6066 * <td>int</td> 6067 * <td>{@link #TYPE}</td> 6068 * <td>{@link #DATA2}</td> 6069 * <td>Allowed values are: 6070 * <p> 6071 * <ul> 6072 * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li> 6073 * <li>{@link #TYPE_ASSISTANT}</li> 6074 * <li>{@link #TYPE_BROTHER}</li> 6075 * <li>{@link #TYPE_CHILD}</li> 6076 * <li>{@link #TYPE_DOMESTIC_PARTNER}</li> 6077 * <li>{@link #TYPE_FATHER}</li> 6078 * <li>{@link #TYPE_FRIEND}</li> 6079 * <li>{@link #TYPE_MANAGER}</li> 6080 * <li>{@link #TYPE_MOTHER}</li> 6081 * <li>{@link #TYPE_PARENT}</li> 6082 * <li>{@link #TYPE_PARTNER}</li> 6083 * <li>{@link #TYPE_REFERRED_BY}</li> 6084 * <li>{@link #TYPE_RELATIVE}</li> 6085 * <li>{@link #TYPE_SISTER}</li> 6086 * <li>{@link #TYPE_SPOUSE}</li> 6087 * </ul> 6088 * </p> 6089 * </td> 6090 * </tr> 6091 * <tr> 6092 * <td>String</td> 6093 * <td>{@link #LABEL}</td> 6094 * <td>{@link #DATA3}</td> 6095 * <td></td> 6096 * </tr> 6097 * </table> 6098 */ 6099 public static final class Relation implements DataColumnsWithJoins, CommonColumns { 6100 /** 6101 * This utility class cannot be instantiated 6102 */ 6103 private Relation() {} 6104 6105 /** MIME type used when storing this in data table. */ 6106 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/relation"; 6107 6108 public static final int TYPE_ASSISTANT = 1; 6109 public static final int TYPE_BROTHER = 2; 6110 public static final int TYPE_CHILD = 3; 6111 public static final int TYPE_DOMESTIC_PARTNER = 4; 6112 public static final int TYPE_FATHER = 5; 6113 public static final int TYPE_FRIEND = 6; 6114 public static final int TYPE_MANAGER = 7; 6115 public static final int TYPE_MOTHER = 8; 6116 public static final int TYPE_PARENT = 9; 6117 public static final int TYPE_PARTNER = 10; 6118 public static final int TYPE_REFERRED_BY = 11; 6119 public static final int TYPE_RELATIVE = 12; 6120 public static final int TYPE_SISTER = 13; 6121 public static final int TYPE_SPOUSE = 14; 6122 6123 /** 6124 * The name of the relative as the user entered it. 6125 * <P>Type: TEXT</P> 6126 */ 6127 public static final String NAME = DATA; 6128 6129 /** 6130 * Return the string resource that best describes the given 6131 * {@link #TYPE}. Will always return a valid resource. 6132 */ 6133 public static final int getTypeLabelResource(int type) { 6134 switch (type) { 6135 case TYPE_ASSISTANT: return com.android.internal.R.string.relationTypeAssistant; 6136 case TYPE_BROTHER: return com.android.internal.R.string.relationTypeBrother; 6137 case TYPE_CHILD: return com.android.internal.R.string.relationTypeChild; 6138 case TYPE_DOMESTIC_PARTNER: 6139 return com.android.internal.R.string.relationTypeDomesticPartner; 6140 case TYPE_FATHER: return com.android.internal.R.string.relationTypeFather; 6141 case TYPE_FRIEND: return com.android.internal.R.string.relationTypeFriend; 6142 case TYPE_MANAGER: return com.android.internal.R.string.relationTypeManager; 6143 case TYPE_MOTHER: return com.android.internal.R.string.relationTypeMother; 6144 case TYPE_PARENT: return com.android.internal.R.string.relationTypeParent; 6145 case TYPE_PARTNER: return com.android.internal.R.string.relationTypePartner; 6146 case TYPE_REFERRED_BY: 6147 return com.android.internal.R.string.relationTypeReferredBy; 6148 case TYPE_RELATIVE: return com.android.internal.R.string.relationTypeRelative; 6149 case TYPE_SISTER: return com.android.internal.R.string.relationTypeSister; 6150 case TYPE_SPOUSE: return com.android.internal.R.string.relationTypeSpouse; 6151 default: return com.android.internal.R.string.orgTypeCustom; 6152 } 6153 } 6154 6155 /** 6156 * Return a {@link CharSequence} that best describes the given type, 6157 * possibly substituting the given {@link #LABEL} value 6158 * for {@link #TYPE_CUSTOM}. 6159 */ 6160 public static final CharSequence getTypeLabel(Resources res, int type, 6161 CharSequence label) { 6162 if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) { 6163 return label; 6164 } else { 6165 final int labelRes = getTypeLabelResource(type); 6166 return res.getText(labelRes); 6167 } 6168 } 6169 } 6170 6171 /** 6172 * <p> 6173 * A data kind representing an event. 6174 * </p> 6175 * <p> 6176 * You can use all columns defined for {@link ContactsContract.Data} as 6177 * well as the following aliases. 6178 * </p> 6179 * <h2>Column aliases</h2> 6180 * <table class="jd-sumtable"> 6181 * <tr> 6182 * <th>Type</th> 6183 * <th>Alias</th><th colspan='2'>Data column</th> 6184 * </tr> 6185 * <tr> 6186 * <td>String</td> 6187 * <td>{@link #START_DATE}</td> 6188 * <td>{@link #DATA1}</td> 6189 * <td></td> 6190 * </tr> 6191 * <tr> 6192 * <td>int</td> 6193 * <td>{@link #TYPE}</td> 6194 * <td>{@link #DATA2}</td> 6195 * <td>Allowed values are: 6196 * <p> 6197 * <ul> 6198 * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li> 6199 * <li>{@link #TYPE_ANNIVERSARY}</li> 6200 * <li>{@link #TYPE_OTHER}</li> 6201 * <li>{@link #TYPE_BIRTHDAY}</li> 6202 * </ul> 6203 * </p> 6204 * </td> 6205 * </tr> 6206 * <tr> 6207 * <td>String</td> 6208 * <td>{@link #LABEL}</td> 6209 * <td>{@link #DATA3}</td> 6210 * <td></td> 6211 * </tr> 6212 * </table> 6213 */ 6214 public static final class Event implements DataColumnsWithJoins, CommonColumns { 6215 /** 6216 * This utility class cannot be instantiated 6217 */ 6218 private Event() {} 6219 6220 /** MIME type used when storing this in data table. */ 6221 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact_event"; 6222 6223 public static final int TYPE_ANNIVERSARY = 1; 6224 public static final int TYPE_OTHER = 2; 6225 public static final int TYPE_BIRTHDAY = 3; 6226 6227 /** 6228 * The event start date as the user entered it. 6229 * <P>Type: TEXT</P> 6230 */ 6231 public static final String START_DATE = DATA; 6232 6233 /** 6234 * Return the string resource that best describes the given 6235 * {@link #TYPE}. Will always return a valid resource. 6236 */ 6237 public static int getTypeResource(Integer type) { 6238 if (type == null) { 6239 return com.android.internal.R.string.eventTypeOther; 6240 } 6241 switch (type) { 6242 case TYPE_ANNIVERSARY: 6243 return com.android.internal.R.string.eventTypeAnniversary; 6244 case TYPE_BIRTHDAY: return com.android.internal.R.string.eventTypeBirthday; 6245 case TYPE_OTHER: return com.android.internal.R.string.eventTypeOther; 6246 default: return com.android.internal.R.string.eventTypeCustom; 6247 } 6248 } 6249 } 6250 6251 /** 6252 * <p> 6253 * A data kind representing a photo for the contact. 6254 * </p> 6255 * <p> 6256 * Some sync adapters will choose to download photos in a separate 6257 * pass. A common pattern is to use columns {@link ContactsContract.Data#SYNC1} 6258 * through {@link ContactsContract.Data#SYNC4} to store temporary 6259 * data, e.g. the image URL or ID, state of download, server-side version 6260 * of the image. It is allowed for the {@link #PHOTO} to be null. 6261 * </p> 6262 * <p> 6263 * You can use all columns defined for {@link ContactsContract.Data} as 6264 * well as the following aliases. 6265 * </p> 6266 * <h2>Column aliases</h2> 6267 * <table class="jd-sumtable"> 6268 * <tr> 6269 * <th>Type</th> 6270 * <th>Alias</th><th colspan='2'>Data column</th> 6271 * </tr> 6272 * <tr> 6273 * <td>NUMBER</td> 6274 * <td>{@link #PHOTO_FILE_ID}</td> 6275 * <td>{@link #DATA14}</td> 6276 * <td>ID of the hi-res photo file.</td> 6277 * </tr> 6278 * <tr> 6279 * <td>BLOB</td> 6280 * <td>{@link #PHOTO}</td> 6281 * <td>{@link #DATA15}</td> 6282 * <td>By convention, binary data is stored in DATA15. The thumbnail of the 6283 * photo is stored in this column.</td> 6284 * </tr> 6285 * </table> 6286 */ 6287 public static final class Photo implements DataColumnsWithJoins { 6288 /** 6289 * This utility class cannot be instantiated 6290 */ 6291 private Photo() {} 6292 6293 /** MIME type used when storing this in data table. */ 6294 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/photo"; 6295 6296 /** 6297 * Photo file ID for the display photo of the raw contact. 6298 * See {@link ContactsContract.DisplayPhoto}. 6299 * <p> 6300 * Type: NUMBER 6301 */ 6302 public static final String PHOTO_FILE_ID = DATA14; 6303 6304 /** 6305 * Thumbnail photo of the raw contact. This is the raw bytes of an image 6306 * that could be inflated using {@link android.graphics.BitmapFactory}. 6307 * <p> 6308 * Type: BLOB 6309 */ 6310 public static final String PHOTO = DATA15; 6311 } 6312 6313 /** 6314 * <p> 6315 * Notes about the contact. 6316 * </p> 6317 * <p> 6318 * You can use all columns defined for {@link ContactsContract.Data} as 6319 * well as the following aliases. 6320 * </p> 6321 * <h2>Column aliases</h2> 6322 * <table class="jd-sumtable"> 6323 * <tr> 6324 * <th>Type</th> 6325 * <th>Alias</th><th colspan='2'>Data column</th> 6326 * </tr> 6327 * <tr> 6328 * <td>String</td> 6329 * <td>{@link #NOTE}</td> 6330 * <td>{@link #DATA1}</td> 6331 * <td></td> 6332 * </tr> 6333 * </table> 6334 */ 6335 public static final class Note implements DataColumnsWithJoins { 6336 /** 6337 * This utility class cannot be instantiated 6338 */ 6339 private Note() {} 6340 6341 /** MIME type used when storing this in data table. */ 6342 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/note"; 6343 6344 /** 6345 * The note text. 6346 * <P>Type: TEXT</P> 6347 */ 6348 public static final String NOTE = DATA1; 6349 } 6350 6351 /** 6352 * <p> 6353 * Group Membership. 6354 * </p> 6355 * <p> 6356 * You can use all columns defined for {@link ContactsContract.Data} as 6357 * well as the following aliases. 6358 * </p> 6359 * <h2>Column aliases</h2> 6360 * <table class="jd-sumtable"> 6361 * <tr> 6362 * <th>Type</th> 6363 * <th>Alias</th><th colspan='2'>Data column</th> 6364 * </tr> 6365 * <tr> 6366 * <td>long</td> 6367 * <td>{@link #GROUP_ROW_ID}</td> 6368 * <td>{@link #DATA1}</td> 6369 * <td></td> 6370 * </tr> 6371 * <tr> 6372 * <td>String</td> 6373 * <td>{@link #GROUP_SOURCE_ID}</td> 6374 * <td>none</td> 6375 * <td> 6376 * <p> 6377 * The sourceid of the group that this group membership refers to. 6378 * Exactly one of this or {@link #GROUP_ROW_ID} must be set when 6379 * inserting a row. 6380 * </p> 6381 * <p> 6382 * If this field is specified, the provider will first try to 6383 * look up a group with this {@link Groups Groups.SOURCE_ID}. If such a group 6384 * is found, it will use the corresponding row id. If the group is not 6385 * found, it will create one. 6386 * </td> 6387 * </tr> 6388 * </table> 6389 */ 6390 public static final class GroupMembership implements DataColumnsWithJoins { 6391 /** 6392 * This utility class cannot be instantiated 6393 */ 6394 private GroupMembership() {} 6395 6396 /** MIME type used when storing this in data table. */ 6397 public static final String CONTENT_ITEM_TYPE = 6398 "vnd.android.cursor.item/group_membership"; 6399 6400 /** 6401 * The row id of the group that this group membership refers to. Exactly one of 6402 * this or {@link #GROUP_SOURCE_ID} must be set when inserting a row. 6403 * <P>Type: INTEGER</P> 6404 */ 6405 public static final String GROUP_ROW_ID = DATA1; 6406 6407 /** 6408 * The sourceid of the group that this group membership refers to. Exactly one of 6409 * this or {@link #GROUP_ROW_ID} must be set when inserting a row. 6410 * <P>Type: TEXT</P> 6411 */ 6412 public static final String GROUP_SOURCE_ID = "group_sourceid"; 6413 } 6414 6415 /** 6416 * <p> 6417 * A data kind representing a website related to the contact. 6418 * </p> 6419 * <p> 6420 * You can use all columns defined for {@link ContactsContract.Data} as 6421 * well as the following aliases. 6422 * </p> 6423 * <h2>Column aliases</h2> 6424 * <table class="jd-sumtable"> 6425 * <tr> 6426 * <th>Type</th> 6427 * <th>Alias</th><th colspan='2'>Data column</th> 6428 * </tr> 6429 * <tr> 6430 * <td>String</td> 6431 * <td>{@link #URL}</td> 6432 * <td>{@link #DATA1}</td> 6433 * <td></td> 6434 * </tr> 6435 * <tr> 6436 * <td>int</td> 6437 * <td>{@link #TYPE}</td> 6438 * <td>{@link #DATA2}</td> 6439 * <td>Allowed values are: 6440 * <p> 6441 * <ul> 6442 * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li> 6443 * <li>{@link #TYPE_HOMEPAGE}</li> 6444 * <li>{@link #TYPE_BLOG}</li> 6445 * <li>{@link #TYPE_PROFILE}</li> 6446 * <li>{@link #TYPE_HOME}</li> 6447 * <li>{@link #TYPE_WORK}</li> 6448 * <li>{@link #TYPE_FTP}</li> 6449 * <li>{@link #TYPE_OTHER}</li> 6450 * </ul> 6451 * </p> 6452 * </td> 6453 * </tr> 6454 * <tr> 6455 * <td>String</td> 6456 * <td>{@link #LABEL}</td> 6457 * <td>{@link #DATA3}</td> 6458 * <td></td> 6459 * </tr> 6460 * </table> 6461 */ 6462 public static final class Website implements DataColumnsWithJoins, CommonColumns { 6463 /** 6464 * This utility class cannot be instantiated 6465 */ 6466 private Website() {} 6467 6468 /** MIME type used when storing this in data table. */ 6469 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/website"; 6470 6471 public static final int TYPE_HOMEPAGE = 1; 6472 public static final int TYPE_BLOG = 2; 6473 public static final int TYPE_PROFILE = 3; 6474 public static final int TYPE_HOME = 4; 6475 public static final int TYPE_WORK = 5; 6476 public static final int TYPE_FTP = 6; 6477 public static final int TYPE_OTHER = 7; 6478 6479 /** 6480 * The website URL string. 6481 * <P>Type: TEXT</P> 6482 */ 6483 public static final String URL = DATA; 6484 } 6485 6486 /** 6487 * <p> 6488 * A data kind representing a SIP address for the contact. 6489 * </p> 6490 * <p> 6491 * You can use all columns defined for {@link ContactsContract.Data} as 6492 * well as the following aliases. 6493 * </p> 6494 * <h2>Column aliases</h2> 6495 * <table class="jd-sumtable"> 6496 * <tr> 6497 * <th>Type</th> 6498 * <th>Alias</th><th colspan='2'>Data column</th> 6499 * </tr> 6500 * <tr> 6501 * <td>String</td> 6502 * <td>{@link #SIP_ADDRESS}</td> 6503 * <td>{@link #DATA1}</td> 6504 * <td></td> 6505 * </tr> 6506 * <tr> 6507 * <td>int</td> 6508 * <td>{@link #TYPE}</td> 6509 * <td>{@link #DATA2}</td> 6510 * <td>Allowed values are: 6511 * <p> 6512 * <ul> 6513 * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li> 6514 * <li>{@link #TYPE_HOME}</li> 6515 * <li>{@link #TYPE_WORK}</li> 6516 * <li>{@link #TYPE_OTHER}</li> 6517 * </ul> 6518 * </p> 6519 * </td> 6520 * </tr> 6521 * <tr> 6522 * <td>String</td> 6523 * <td>{@link #LABEL}</td> 6524 * <td>{@link #DATA3}</td> 6525 * <td></td> 6526 * </tr> 6527 * </table> 6528 */ 6529 public static final class SipAddress implements DataColumnsWithJoins, CommonColumns { 6530 /** 6531 * This utility class cannot be instantiated 6532 */ 6533 private SipAddress() {} 6534 6535 /** MIME type used when storing this in data table. */ 6536 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/sip_address"; 6537 6538 public static final int TYPE_HOME = 1; 6539 public static final int TYPE_WORK = 2; 6540 public static final int TYPE_OTHER = 3; 6541 6542 /** 6543 * The SIP address. 6544 * <P>Type: TEXT</P> 6545 */ 6546 public static final String SIP_ADDRESS = DATA1; 6547 // ...and TYPE and LABEL come from the CommonColumns interface. 6548 6549 /** 6550 * Return the string resource that best describes the given 6551 * {@link #TYPE}. Will always return a valid resource. 6552 */ 6553 public static final int getTypeLabelResource(int type) { 6554 switch (type) { 6555 case TYPE_HOME: return com.android.internal.R.string.sipAddressTypeHome; 6556 case TYPE_WORK: return com.android.internal.R.string.sipAddressTypeWork; 6557 case TYPE_OTHER: return com.android.internal.R.string.sipAddressTypeOther; 6558 default: return com.android.internal.R.string.sipAddressTypeCustom; 6559 } 6560 } 6561 6562 /** 6563 * Return a {@link CharSequence} that best describes the given type, 6564 * possibly substituting the given {@link #LABEL} value 6565 * for {@link #TYPE_CUSTOM}. 6566 */ 6567 public static final CharSequence getTypeLabel(Resources res, int type, 6568 CharSequence label) { 6569 if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) { 6570 return label; 6571 } else { 6572 final int labelRes = getTypeLabelResource(type); 6573 return res.getText(labelRes); 6574 } 6575 } 6576 } 6577 6578 /** 6579 * A data kind representing an Identity related to the contact. 6580 * <p> 6581 * This can be used as a signal by the aggregator to combine raw contacts into 6582 * contacts, e.g. if two contacts have Identity rows with 6583 * the same NAMESPACE and IDENTITY values the aggregator can know that they refer 6584 * to the same person. 6585 * </p> 6586 */ 6587 public static final class Identity implements DataColumnsWithJoins { 6588 /** 6589 * This utility class cannot be instantiated 6590 */ 6591 private Identity() {} 6592 6593 /** MIME type used when storing this in data table. */ 6594 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/identity"; 6595 6596 /** 6597 * The identity string. 6598 * <P>Type: TEXT</P> 6599 */ 6600 public static final String IDENTITY = DataColumns.DATA1; 6601 6602 /** 6603 * The namespace of the identity string, e.g. "com.google" 6604 * <P>Type: TEXT</P> 6605 */ 6606 public static final String NAMESPACE = DataColumns.DATA2; 6607 } 6608 } 6609 6610 /** 6611 * @see Groups 6612 */ 6613 protected interface GroupsColumns { 6614 /** 6615 * The data set within the account that this group belongs to. This allows 6616 * multiple sync adapters for the same account type to distinguish between 6617 * each others' group data. 6618 * 6619 * This is empty by default, and is completely optional. It only needs to 6620 * be populated if multiple sync adapters are entering distinct group data 6621 * for the same account type and account name. 6622 * <P>Type: TEXT</P> 6623 */ 6624 public static final String DATA_SET = "data_set"; 6625 6626 /** 6627 * A concatenation of the account type and data set (delimited by a forward 6628 * slash) - if the data set is empty, this will be the same as the account 6629 * type. For applications that need to be aware of the data set, this can 6630 * be used instead of account type to distinguish sets of data. This is 6631 * never intended to be used for specifying accounts. 6632 * @hide 6633 */ 6634 public static final String ACCOUNT_TYPE_AND_DATA_SET = "account_type_and_data_set"; 6635 6636 /** 6637 * The display title of this group. 6638 * <p> 6639 * Type: TEXT 6640 */ 6641 public static final String TITLE = "title"; 6642 6643 /** 6644 * The package name to use when creating {@link Resources} objects for 6645 * this group. This value is only designed for use when building user 6646 * interfaces, and should not be used to infer the owner. 6647 * 6648 * @hide 6649 */ 6650 public static final String RES_PACKAGE = "res_package"; 6651 6652 /** 6653 * The display title of this group to load as a resource from 6654 * {@link #RES_PACKAGE}, which may be localized. 6655 * <P>Type: TEXT</P> 6656 * 6657 * @hide 6658 */ 6659 public static final String TITLE_RES = "title_res"; 6660 6661 /** 6662 * Notes about the group. 6663 * <p> 6664 * Type: TEXT 6665 */ 6666 public static final String NOTES = "notes"; 6667 6668 /** 6669 * The ID of this group if it is a System Group, i.e. a group that has a special meaning 6670 * to the sync adapter, null otherwise. 6671 * <P>Type: TEXT</P> 6672 */ 6673 public static final String SYSTEM_ID = "system_id"; 6674 6675 /** 6676 * The total number of {@link Contacts} that have 6677 * {@link CommonDataKinds.GroupMembership} in this group. Read-only value that is only 6678 * present when querying {@link Groups#CONTENT_SUMMARY_URI}. 6679 * <p> 6680 * Type: INTEGER 6681 */ 6682 public static final String SUMMARY_COUNT = "summ_count"; 6683 6684 /** 6685 * A boolean query parameter that can be used with {@link Groups#CONTENT_SUMMARY_URI}. 6686 * It will additionally return {@link #SUMMARY_GROUP_COUNT_PER_ACCOUNT}. 6687 * 6688 * @hide 6689 */ 6690 public static final String PARAM_RETURN_GROUP_COUNT_PER_ACCOUNT = 6691 "return_group_count_per_account"; 6692 6693 /** 6694 * The total number of groups of the account that a group belongs to. 6695 * This column is available only when the parameter 6696 * {@link #PARAM_RETURN_GROUP_COUNT_PER_ACCOUNT} is specified in 6697 * {@link Groups#CONTENT_SUMMARY_URI}. 6698 * 6699 * For example, when the account "A" has two groups "group1" and "group2", and the account 6700 * "B" has a group "group3", the rows for "group1" and "group2" return "2" and the row for 6701 * "group3" returns "1" for this column. 6702 * 6703 * Note: This counts only non-favorites, non-auto-add, and not deleted groups. 6704 * 6705 * Type: INTEGER 6706 * @hide 6707 */ 6708 public static final String SUMMARY_GROUP_COUNT_PER_ACCOUNT = "group_count_per_account"; 6709 6710 /** 6711 * The total number of {@link Contacts} that have both 6712 * {@link CommonDataKinds.GroupMembership} in this group, and also have phone numbers. 6713 * Read-only value that is only present when querying 6714 * {@link Groups#CONTENT_SUMMARY_URI}. 6715 * <p> 6716 * Type: INTEGER 6717 */ 6718 public static final String SUMMARY_WITH_PHONES = "summ_phones"; 6719 6720 /** 6721 * Flag indicating if the contacts belonging to this group should be 6722 * visible in any user interface. 6723 * <p> 6724 * Type: INTEGER (boolean) 6725 */ 6726 public static final String GROUP_VISIBLE = "group_visible"; 6727 6728 /** 6729 * The "deleted" flag: "0" by default, "1" if the row has been marked 6730 * for deletion. When {@link android.content.ContentResolver#delete} is 6731 * called on a group, it is marked for deletion. The sync adaptor 6732 * deletes the group on the server and then calls ContactResolver.delete 6733 * once more, this time setting the the 6734 * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to 6735 * finalize the data removal. 6736 * <P>Type: INTEGER</P> 6737 */ 6738 public static final String DELETED = "deleted"; 6739 6740 /** 6741 * Whether this group should be synced if the SYNC_EVERYTHING settings 6742 * is false for this group's account. 6743 * <p> 6744 * Type: INTEGER (boolean) 6745 */ 6746 public static final String SHOULD_SYNC = "should_sync"; 6747 6748 /** 6749 * Any newly created contacts will automatically be added to groups that have this 6750 * flag set to true. 6751 * <p> 6752 * Type: INTEGER (boolean) 6753 */ 6754 public static final String AUTO_ADD = "auto_add"; 6755 6756 /** 6757 * When a contacts is marked as a favorites it will be automatically added 6758 * to the groups that have this flag set, and when it is removed from favorites 6759 * it will be removed from these groups. 6760 * <p> 6761 * Type: INTEGER (boolean) 6762 */ 6763 public static final String FAVORITES = "favorites"; 6764 6765 /** 6766 * The "read-only" flag: "0" by default, "1" if the row cannot be modified or 6767 * deleted except by a sync adapter. See {@link ContactsContract#CALLER_IS_SYNCADAPTER}. 6768 * <P>Type: INTEGER</P> 6769 */ 6770 public static final String GROUP_IS_READ_ONLY = "group_is_read_only"; 6771 } 6772 6773 /** 6774 * Constants for the groups table. Only per-account groups are supported. 6775 * <h2>Columns</h2> 6776 * <table class="jd-sumtable"> 6777 * <tr> 6778 * <th colspan='4'>Groups</th> 6779 * </tr> 6780 * <tr> 6781 * <td>long</td> 6782 * <td>{@link #_ID}</td> 6783 * <td>read-only</td> 6784 * <td>Row ID. Sync adapter should try to preserve row IDs during updates. 6785 * In other words, it would be a really bad idea to delete and reinsert a 6786 * group. A sync adapter should always do an update instead.</td> 6787 * </tr> 6788 # <tr> 6789 * <td>String</td> 6790 * <td>{@link #DATA_SET}</td> 6791 * <td>read/write-once</td> 6792 * <td> 6793 * <p> 6794 * The data set within the account that this group belongs to. This allows 6795 * multiple sync adapters for the same account type to distinguish between 6796 * each others' group data. The combination of {@link #ACCOUNT_TYPE}, 6797 * {@link #ACCOUNT_NAME}, and {@link #DATA_SET} identifies a set of data 6798 * that is associated with a single sync adapter. 6799 * </p> 6800 * <p> 6801 * This is empty by default, and is completely optional. It only needs to 6802 * be populated if multiple sync adapters are entering distinct data for 6803 * the same account type and account name. 6804 * </p> 6805 * <p> 6806 * It should be set at the time the group is inserted and never changed 6807 * afterwards. 6808 * </p> 6809 * </td> 6810 * </tr> 6811 * <tr> 6812 * <td>String</td> 6813 * <td>{@link #TITLE}</td> 6814 * <td>read/write</td> 6815 * <td>The display title of this group.</td> 6816 * </tr> 6817 * <tr> 6818 * <td>String</td> 6819 * <td>{@link #NOTES}</td> 6820 * <td>read/write</td> 6821 * <td>Notes about the group.</td> 6822 * </tr> 6823 * <tr> 6824 * <td>String</td> 6825 * <td>{@link #SYSTEM_ID}</td> 6826 * <td>read/write</td> 6827 * <td>The ID of this group if it is a System Group, i.e. a group that has a 6828 * special meaning to the sync adapter, null otherwise.</td> 6829 * </tr> 6830 * <tr> 6831 * <td>int</td> 6832 * <td>{@link #SUMMARY_COUNT}</td> 6833 * <td>read-only</td> 6834 * <td>The total number of {@link Contacts} that have 6835 * {@link CommonDataKinds.GroupMembership} in this group. Read-only value 6836 * that is only present when querying {@link Groups#CONTENT_SUMMARY_URI}.</td> 6837 * </tr> 6838 * <tr> 6839 * <td>int</td> 6840 * <td>{@link #SUMMARY_WITH_PHONES}</td> 6841 * <td>read-only</td> 6842 * <td>The total number of {@link Contacts} that have both 6843 * {@link CommonDataKinds.GroupMembership} in this group, and also have 6844 * phone numbers. Read-only value that is only present when querying 6845 * {@link Groups#CONTENT_SUMMARY_URI}.</td> 6846 * </tr> 6847 * <tr> 6848 * <td>int</td> 6849 * <td>{@link #GROUP_VISIBLE}</td> 6850 * <td>read-only</td> 6851 * <td>Flag indicating if the contacts belonging to this group should be 6852 * visible in any user interface. Allowed values: 0 and 1.</td> 6853 * </tr> 6854 * <tr> 6855 * <td>int</td> 6856 * <td>{@link #DELETED}</td> 6857 * <td>read/write</td> 6858 * <td>The "deleted" flag: "0" by default, "1" if the row has been marked 6859 * for deletion. When {@link android.content.ContentResolver#delete} is 6860 * called on a group, it is marked for deletion. The sync adaptor deletes 6861 * the group on the server and then calls ContactResolver.delete once more, 6862 * this time setting the the {@link ContactsContract#CALLER_IS_SYNCADAPTER} 6863 * query parameter to finalize the data removal.</td> 6864 * </tr> 6865 * <tr> 6866 * <td>int</td> 6867 * <td>{@link #SHOULD_SYNC}</td> 6868 * <td>read/write</td> 6869 * <td>Whether this group should be synced if the SYNC_EVERYTHING settings 6870 * is false for this group's account.</td> 6871 * </tr> 6872 * </table> 6873 */ 6874 public static final class Groups implements BaseColumns, GroupsColumns, SyncColumns { 6875 /** 6876 * This utility class cannot be instantiated 6877 */ 6878 private Groups() { 6879 } 6880 6881 /** 6882 * The content:// style URI for this table 6883 */ 6884 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "groups"); 6885 6886 /** 6887 * The content:// style URI for this table joined with details data from 6888 * {@link ContactsContract.Data}. 6889 */ 6890 public static final Uri CONTENT_SUMMARY_URI = Uri.withAppendedPath(AUTHORITY_URI, 6891 "groups_summary"); 6892 6893 /** 6894 * The MIME type of a directory of groups. 6895 */ 6896 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/group"; 6897 6898 /** 6899 * The MIME type of a single group. 6900 */ 6901 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/group"; 6902 6903 public static EntityIterator newEntityIterator(Cursor cursor) { 6904 return new EntityIteratorImpl(cursor); 6905 } 6906 6907 private static class EntityIteratorImpl extends CursorEntityIterator { 6908 public EntityIteratorImpl(Cursor cursor) { 6909 super(cursor); 6910 } 6911 6912 @Override 6913 public Entity getEntityAndIncrementCursor(Cursor cursor) throws RemoteException { 6914 // we expect the cursor is already at the row we need to read from 6915 final ContentValues values = new ContentValues(); 6916 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, _ID); 6917 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, ACCOUNT_NAME); 6918 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, ACCOUNT_TYPE); 6919 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, DIRTY); 6920 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, VERSION); 6921 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SOURCE_ID); 6922 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, RES_PACKAGE); 6923 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, TITLE); 6924 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, TITLE_RES); 6925 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, GROUP_VISIBLE); 6926 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC1); 6927 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC2); 6928 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC3); 6929 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC4); 6930 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYSTEM_ID); 6931 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, DELETED); 6932 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, NOTES); 6933 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SHOULD_SYNC); 6934 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, FAVORITES); 6935 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, AUTO_ADD); 6936 cursor.moveToNext(); 6937 return new Entity(values); 6938 } 6939 } 6940 } 6941 6942 /** 6943 * <p> 6944 * Constants for the contact aggregation exceptions table, which contains 6945 * aggregation rules overriding those used by automatic aggregation. This 6946 * type only supports query and update. Neither insert nor delete are 6947 * supported. 6948 * </p> 6949 * <h2>Columns</h2> 6950 * <table class="jd-sumtable"> 6951 * <tr> 6952 * <th colspan='4'>AggregationExceptions</th> 6953 * </tr> 6954 * <tr> 6955 * <td>int</td> 6956 * <td>{@link #TYPE}</td> 6957 * <td>read/write</td> 6958 * <td>The type of exception: {@link #TYPE_KEEP_TOGETHER}, 6959 * {@link #TYPE_KEEP_SEPARATE} or {@link #TYPE_AUTOMATIC}.</td> 6960 * </tr> 6961 * <tr> 6962 * <td>long</td> 6963 * <td>{@link #RAW_CONTACT_ID1}</td> 6964 * <td>read/write</td> 6965 * <td>A reference to the {@link RawContacts#_ID} of the raw contact that 6966 * the rule applies to.</td> 6967 * </tr> 6968 * <tr> 6969 * <td>long</td> 6970 * <td>{@link #RAW_CONTACT_ID2}</td> 6971 * <td>read/write</td> 6972 * <td>A reference to the other {@link RawContacts#_ID} of the raw contact 6973 * that the rule applies to.</td> 6974 * </tr> 6975 * </table> 6976 */ 6977 public static final class AggregationExceptions implements BaseColumns { 6978 /** 6979 * This utility class cannot be instantiated 6980 */ 6981 private AggregationExceptions() {} 6982 6983 /** 6984 * The content:// style URI for this table 6985 */ 6986 public static final Uri CONTENT_URI = 6987 Uri.withAppendedPath(AUTHORITY_URI, "aggregation_exceptions"); 6988 6989 /** 6990 * The MIME type of {@link #CONTENT_URI} providing a directory of data. 6991 */ 6992 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/aggregation_exception"; 6993 6994 /** 6995 * The MIME type of a {@link #CONTENT_URI} subdirectory of an aggregation exception 6996 */ 6997 public static final String CONTENT_ITEM_TYPE = 6998 "vnd.android.cursor.item/aggregation_exception"; 6999 7000 /** 7001 * The type of exception: {@link #TYPE_KEEP_TOGETHER}, {@link #TYPE_KEEP_SEPARATE} or 7002 * {@link #TYPE_AUTOMATIC}. 7003 * 7004 * <P>Type: INTEGER</P> 7005 */ 7006 public static final String TYPE = "type"; 7007 7008 /** 7009 * Allows the provider to automatically decide whether the specified raw contacts should 7010 * be included in the same aggregate contact or not. 7011 */ 7012 public static final int TYPE_AUTOMATIC = 0; 7013 7014 /** 7015 * Makes sure that the specified raw contacts are included in the same 7016 * aggregate contact. 7017 */ 7018 public static final int TYPE_KEEP_TOGETHER = 1; 7019 7020 /** 7021 * Makes sure that the specified raw contacts are NOT included in the same 7022 * aggregate contact. 7023 */ 7024 public static final int TYPE_KEEP_SEPARATE = 2; 7025 7026 /** 7027 * A reference to the {@link RawContacts#_ID} of the raw contact that the rule applies to. 7028 */ 7029 public static final String RAW_CONTACT_ID1 = "raw_contact_id1"; 7030 7031 /** 7032 * A reference to the other {@link RawContacts#_ID} of the raw contact that the rule 7033 * applies to. 7034 */ 7035 public static final String RAW_CONTACT_ID2 = "raw_contact_id2"; 7036 } 7037 7038 /** 7039 * @see Settings 7040 */ 7041 protected interface SettingsColumns { 7042 /** 7043 * The name of the account instance to which this row belongs. 7044 * <P>Type: TEXT</P> 7045 */ 7046 public static final String ACCOUNT_NAME = "account_name"; 7047 7048 /** 7049 * The type of account to which this row belongs, which when paired with 7050 * {@link #ACCOUNT_NAME} identifies a specific account. 7051 * <P>Type: TEXT</P> 7052 */ 7053 public static final String ACCOUNT_TYPE = "account_type"; 7054 7055 /** 7056 * Depending on the mode defined by the sync-adapter, this flag controls 7057 * the top-level sync behavior for this data source. 7058 * <p> 7059 * Type: INTEGER (boolean) 7060 */ 7061 public static final String SHOULD_SYNC = "should_sync"; 7062 7063 /** 7064 * Flag indicating if contacts without any {@link CommonDataKinds.GroupMembership} 7065 * entries should be visible in any user interface. 7066 * <p> 7067 * Type: INTEGER (boolean) 7068 */ 7069 public static final String UNGROUPED_VISIBLE = "ungrouped_visible"; 7070 7071 /** 7072 * Read-only flag indicating if this {@link #SHOULD_SYNC} or any 7073 * {@link Groups#SHOULD_SYNC} under this account have been marked as 7074 * unsynced. 7075 */ 7076 public static final String ANY_UNSYNCED = "any_unsynced"; 7077 7078 /** 7079 * Read-only count of {@link Contacts} from a specific source that have 7080 * no {@link CommonDataKinds.GroupMembership} entries. 7081 * <p> 7082 * Type: INTEGER 7083 */ 7084 public static final String UNGROUPED_COUNT = "summ_count"; 7085 7086 /** 7087 * Read-only count of {@link Contacts} from a specific source that have 7088 * no {@link CommonDataKinds.GroupMembership} entries, and also have phone numbers. 7089 * <p> 7090 * Type: INTEGER 7091 */ 7092 public static final String UNGROUPED_WITH_PHONES = "summ_phones"; 7093 } 7094 7095 /** 7096 * <p> 7097 * Contacts-specific settings for various {@link Account}'s. 7098 * </p> 7099 * <h2>Columns</h2> 7100 * <table class="jd-sumtable"> 7101 * <tr> 7102 * <th colspan='4'>Settings</th> 7103 * </tr> 7104 * <tr> 7105 * <td>String</td> 7106 * <td>{@link #ACCOUNT_NAME}</td> 7107 * <td>read/write-once</td> 7108 * <td>The name of the account instance to which this row belongs.</td> 7109 * </tr> 7110 * <tr> 7111 * <td>String</td> 7112 * <td>{@link #ACCOUNT_TYPE}</td> 7113 * <td>read/write-once</td> 7114 * <td>The type of account to which this row belongs, which when paired with 7115 * {@link #ACCOUNT_NAME} identifies a specific account.</td> 7116 * </tr> 7117 * <tr> 7118 * <td>int</td> 7119 * <td>{@link #SHOULD_SYNC}</td> 7120 * <td>read/write</td> 7121 * <td>Depending on the mode defined by the sync-adapter, this flag controls 7122 * the top-level sync behavior for this data source.</td> 7123 * </tr> 7124 * <tr> 7125 * <td>int</td> 7126 * <td>{@link #UNGROUPED_VISIBLE}</td> 7127 * <td>read/write</td> 7128 * <td>Flag indicating if contacts without any 7129 * {@link CommonDataKinds.GroupMembership} entries should be visible in any 7130 * user interface.</td> 7131 * </tr> 7132 * <tr> 7133 * <td>int</td> 7134 * <td>{@link #ANY_UNSYNCED}</td> 7135 * <td>read-only</td> 7136 * <td>Read-only flag indicating if this {@link #SHOULD_SYNC} or any 7137 * {@link Groups#SHOULD_SYNC} under this account have been marked as 7138 * unsynced.</td> 7139 * </tr> 7140 * <tr> 7141 * <td>int</td> 7142 * <td>{@link #UNGROUPED_COUNT}</td> 7143 * <td>read-only</td> 7144 * <td>Read-only count of {@link Contacts} from a specific source that have 7145 * no {@link CommonDataKinds.GroupMembership} entries.</td> 7146 * </tr> 7147 * <tr> 7148 * <td>int</td> 7149 * <td>{@link #UNGROUPED_WITH_PHONES}</td> 7150 * <td>read-only</td> 7151 * <td>Read-only count of {@link Contacts} from a specific source that have 7152 * no {@link CommonDataKinds.GroupMembership} entries, and also have phone 7153 * numbers.</td> 7154 * </tr> 7155 * </table> 7156 */ 7157 public static final class Settings implements SettingsColumns { 7158 /** 7159 * This utility class cannot be instantiated 7160 */ 7161 private Settings() { 7162 } 7163 7164 /** 7165 * The content:// style URI for this table 7166 */ 7167 public static final Uri CONTENT_URI = 7168 Uri.withAppendedPath(AUTHORITY_URI, "settings"); 7169 7170 /** 7171 * The MIME-type of {@link #CONTENT_URI} providing a directory of 7172 * settings. 7173 */ 7174 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/setting"; 7175 7176 /** 7177 * The MIME-type of {@link #CONTENT_URI} providing a single setting. 7178 */ 7179 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/setting"; 7180 } 7181 7182 /** 7183 * Private API for inquiring about the general status of the provider. 7184 * 7185 * @hide 7186 */ 7187 public static final class ProviderStatus { 7188 7189 /** 7190 * Not instantiable. 7191 */ 7192 private ProviderStatus() { 7193 } 7194 7195 /** 7196 * The content:// style URI for this table. Requests to this URI can be 7197 * performed on the UI thread because they are always unblocking. 7198 * 7199 * @hide 7200 */ 7201 public static final Uri CONTENT_URI = 7202 Uri.withAppendedPath(AUTHORITY_URI, "provider_status"); 7203 7204 /** 7205 * The MIME-type of {@link #CONTENT_URI} providing a directory of 7206 * settings. 7207 * 7208 * @hide 7209 */ 7210 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/provider_status"; 7211 7212 /** 7213 * An integer representing the current status of the provider. 7214 * 7215 * @hide 7216 */ 7217 public static final String STATUS = "status"; 7218 7219 /** 7220 * Default status of the provider. 7221 * 7222 * @hide 7223 */ 7224 public static final int STATUS_NORMAL = 0; 7225 7226 /** 7227 * The status used when the provider is in the process of upgrading. Contacts 7228 * are temporarily unaccessible. 7229 * 7230 * @hide 7231 */ 7232 public static final int STATUS_UPGRADING = 1; 7233 7234 /** 7235 * The status used if the provider was in the process of upgrading but ran 7236 * out of storage. The DATA1 column will contain the estimated amount of 7237 * storage required (in bytes). Update status to STATUS_NORMAL to force 7238 * the provider to retry the upgrade. 7239 * 7240 * @hide 7241 */ 7242 public static final int STATUS_UPGRADE_OUT_OF_MEMORY = 2; 7243 7244 /** 7245 * The status used during a locale change. 7246 * 7247 * @hide 7248 */ 7249 public static final int STATUS_CHANGING_LOCALE = 3; 7250 7251 /** 7252 * The status that indicates that there are no accounts and no contacts 7253 * on the device. 7254 * 7255 * @hide 7256 */ 7257 public static final int STATUS_NO_ACCOUNTS_NO_CONTACTS = 4; 7258 7259 /** 7260 * Additional data associated with the status. 7261 * 7262 * @hide 7263 */ 7264 public static final String DATA1 = "data1"; 7265 } 7266 7267 /** 7268 * <p> 7269 * API allowing applications to send usage information for each {@link Data} row to the 7270 * Contacts Provider. 7271 * </p> 7272 * <p> 7273 * With the feedback, Contacts Provider may return more contextually appropriate results for 7274 * Data listing, typically supplied with 7275 * {@link ContactsContract.Contacts#CONTENT_FILTER_URI}, 7276 * {@link ContactsContract.CommonDataKinds.Email#CONTENT_FILTER_URI}, 7277 * {@link ContactsContract.CommonDataKinds.Phone#CONTENT_FILTER_URI}, and users can benefit 7278 * from better ranked (sorted) lists in applications that show auto-complete list. 7279 * </p> 7280 * <p> 7281 * There is no guarantee for how this feedback is used, or even whether it is used at all. 7282 * The ranking algorithm will make best efforts to use the feedback data, but the exact 7283 * implementation, the storage data structures as well as the resulting sort order is device 7284 * and version specific and can change over time. 7285 * </p> 7286 * <p> 7287 * When updating usage information, users of this API need to use 7288 * {@link ContentResolver#update(Uri, ContentValues, String, String[])} with a Uri constructed 7289 * from {@link DataUsageFeedback#FEEDBACK_URI}. The Uri must contain one or more data id(s) as 7290 * its last path. They also need to append a query parameter to the Uri, to specify the type of 7291 * the communication, which enables the Contacts Provider to differentiate between kinds of 7292 * interactions using the same contact data field (for example a phone number can be used to 7293 * make phone calls or send SMS). 7294 * </p> 7295 * <p> 7296 * Selection and selectionArgs are ignored and must be set to null. To get data ids, 7297 * you may need to call {@link ContentResolver#query(Uri, String[], String, String[], String)} 7298 * toward {@link Data#CONTENT_URI}. 7299 * </p> 7300 * <p> 7301 * {@link ContentResolver#update(Uri, ContentValues, String, String[])} returns a positive 7302 * integer when successful, and returns 0 if no contact with that id was found. 7303 * </p> 7304 * <p> 7305 * Example: 7306 * <pre> 7307 * Uri uri = DataUsageFeedback.FEEDBACK_URI.buildUpon() 7308 * .appendPath(TextUtils.join(",", dataIds)) 7309 * .appendQueryParameter(DataUsageFeedback.USAGE_TYPE, 7310 * DataUsageFeedback.USAGE_TYPE_CALL) 7311 * .build(); 7312 * boolean successful = resolver.update(uri, new ContentValues(), null, null) > 0; 7313 * </pre> 7314 * </p> 7315 */ 7316 public static final class DataUsageFeedback { 7317 7318 /** 7319 * The content:// style URI for sending usage feedback. 7320 * Must be used with {@link ContentResolver#update(Uri, ContentValues, String, String[])}. 7321 */ 7322 public static final Uri FEEDBACK_URI = 7323 Uri.withAppendedPath(Data.CONTENT_URI, "usagefeedback"); 7324 7325 /** 7326 * <p> 7327 * Name for query parameter specifying the type of data usage. 7328 * </p> 7329 */ 7330 public static final String USAGE_TYPE = "type"; 7331 7332 /** 7333 * <p> 7334 * Type of usage for voice interaction, which includes phone call, voice chat, and 7335 * video chat. 7336 * </p> 7337 */ 7338 public static final String USAGE_TYPE_CALL = "call"; 7339 7340 /** 7341 * <p> 7342 * Type of usage for text interaction involving longer messages, which includes email. 7343 * </p> 7344 */ 7345 public static final String USAGE_TYPE_LONG_TEXT = "long_text"; 7346 7347 /** 7348 * <p> 7349 * Type of usage for text interaction involving shorter messages, which includes SMS, 7350 * text chat with email addresses. 7351 * </p> 7352 */ 7353 public static final String USAGE_TYPE_SHORT_TEXT = "short_text"; 7354 } 7355 7356 /** 7357 * Helper methods to display QuickContact dialogs that allow users to pivot on 7358 * a specific {@link Contacts} entry. 7359 */ 7360 public static final class QuickContact { 7361 /** 7362 * Action used to trigger person pivot dialog. 7363 * @hide 7364 */ 7365 public static final String ACTION_QUICK_CONTACT = 7366 "com.android.contacts.action.QUICK_CONTACT"; 7367 7368 /** 7369 * Extra used to specify pivot dialog location in screen coordinates. 7370 * @deprecated Use {@link Intent#setSourceBounds(Rect)} instead. 7371 * @hide 7372 */ 7373 @Deprecated 7374 public static final String EXTRA_TARGET_RECT = "target_rect"; 7375 7376 /** 7377 * Extra used to specify size of pivot dialog. 7378 * @hide 7379 */ 7380 public static final String EXTRA_MODE = "mode"; 7381 7382 /** 7383 * Extra used to indicate a list of specific MIME-types to exclude and 7384 * not display. Stored as a {@link String} array. 7385 * @hide 7386 */ 7387 public static final String EXTRA_EXCLUDE_MIMES = "exclude_mimes"; 7388 7389 /** 7390 * Small QuickContact mode, usually presented with minimal actions. 7391 */ 7392 public static final int MODE_SMALL = 1; 7393 7394 /** 7395 * Medium QuickContact mode, includes actions and light summary describing 7396 * the {@link Contacts} entry being shown. This may include social 7397 * status and presence details. 7398 */ 7399 public static final int MODE_MEDIUM = 2; 7400 7401 /** 7402 * Large QuickContact mode, includes actions and larger, card-like summary 7403 * of the {@link Contacts} entry being shown. This may include detailed 7404 * information, such as a photo. 7405 */ 7406 public static final int MODE_LARGE = 3; 7407 7408 /** 7409 * Trigger a dialog that lists the various methods of interacting with 7410 * the requested {@link Contacts} entry. This may be based on available 7411 * {@link ContactsContract.Data} rows under that contact, and may also 7412 * include social status and presence details. 7413 * 7414 * @param context The parent {@link Context} that may be used as the 7415 * parent for this dialog. 7416 * @param target Specific {@link View} from your layout that this dialog 7417 * should be centered around. In particular, if the dialog 7418 * has a "callout" arrow, it will be pointed and centered 7419 * around this {@link View}. 7420 * @param lookupUri A {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style 7421 * {@link Uri} that describes a specific contact to feature 7422 * in this dialog. 7423 * @param mode Any of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or 7424 * {@link #MODE_LARGE}, indicating the desired dialog size, 7425 * when supported. 7426 * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types 7427 * to exclude when showing this dialog. For example, when 7428 * already viewing the contact details card, this can be used 7429 * to omit the details entry from the dialog. 7430 */ 7431 public static void showQuickContact(Context context, View target, Uri lookupUri, int mode, 7432 String[] excludeMimes) { 7433 // Find location and bounds of target view, adjusting based on the 7434 // assumed local density. 7435 final float appScale = context.getResources().getCompatibilityInfo().applicationScale; 7436 final int[] pos = new int[2]; 7437 target.getLocationOnScreen(pos); 7438 7439 final Rect rect = new Rect(); 7440 rect.left = (int) (pos[0] * appScale + 0.5f); 7441 rect.top = (int) (pos[1] * appScale + 0.5f); 7442 rect.right = (int) ((pos[0] + target.getWidth()) * appScale + 0.5f); 7443 rect.bottom = (int) ((pos[1] + target.getHeight()) * appScale + 0.5f); 7444 7445 // Trigger with obtained rectangle 7446 showQuickContact(context, rect, lookupUri, mode, excludeMimes); 7447 } 7448 7449 /** 7450 * Trigger a dialog that lists the various methods of interacting with 7451 * the requested {@link Contacts} entry. This may be based on available 7452 * {@link ContactsContract.Data} rows under that contact, and may also 7453 * include social status and presence details. 7454 * 7455 * @param context The parent {@link Context} that may be used as the 7456 * parent for this dialog. 7457 * @param target Specific {@link Rect} that this dialog should be 7458 * centered around, in screen coordinates. In particular, if 7459 * the dialog has a "callout" arrow, it will be pointed and 7460 * centered around this {@link Rect}. If you are running at a 7461 * non-native density, you need to manually adjust using 7462 * {@link DisplayMetrics#density} before calling. 7463 * @param lookupUri A 7464 * {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style 7465 * {@link Uri} that describes a specific contact to feature 7466 * in this dialog. 7467 * @param mode Any of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or 7468 * {@link #MODE_LARGE}, indicating the desired dialog size, 7469 * when supported. 7470 * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types 7471 * to exclude when showing this dialog. For example, when 7472 * already viewing the contact details card, this can be used 7473 * to omit the details entry from the dialog. 7474 */ 7475 public static void showQuickContact(Context context, Rect target, Uri lookupUri, int mode, 7476 String[] excludeMimes) { 7477 // Launch pivot dialog through intent for now 7478 final Intent intent = new Intent(ACTION_QUICK_CONTACT); 7479 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP 7480 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 7481 7482 intent.setData(lookupUri); 7483 intent.setSourceBounds(target); 7484 intent.putExtra(EXTRA_MODE, mode); 7485 intent.putExtra(EXTRA_EXCLUDE_MIMES, excludeMimes); 7486 context.startActivity(intent); 7487 } 7488 } 7489 7490 /** 7491 * Helper class for accessing full-size photos by photo file ID. 7492 * <p> 7493 * Usage example: 7494 * <dl> 7495 * <dt>Retrieving a full-size photo by photo file ID (see 7496 * {@link ContactsContract.ContactsColumns#PHOTO_FILE_ID}) 7497 * </dt> 7498 * <dd> 7499 * <pre> 7500 * public InputStream openDisplayPhoto(long photoFileId) { 7501 * Uri displayPhotoUri = ContentUris.withAppendedId(DisplayPhoto.CONTENT_URI, photoKey); 7502 * try { 7503 * AssetFileDescriptor fd = getContentResolver().openAssetFileDescriptor( 7504 * displayPhotoUri, "r"); 7505 * return fd.createInputStream(); 7506 * } catch (IOException e) { 7507 * return null; 7508 * } 7509 * } 7510 * </pre> 7511 * </dd> 7512 * </dl> 7513 * </p> 7514 */ 7515 public static final class DisplayPhoto { 7516 /** 7517 * no public constructor since this is a utility class 7518 */ 7519 private DisplayPhoto() {} 7520 7521 /** 7522 * The content:// style URI for this class, which allows access to full-size photos, 7523 * given a key. 7524 */ 7525 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "display_photo"); 7526 7527 /** 7528 * This URI allows the caller to query for the maximum dimensions of a display photo 7529 * or thumbnail. Requests to this URI can be performed on the UI thread because 7530 * they are always unblocking. 7531 */ 7532 public static final Uri CONTENT_MAX_DIMENSIONS_URI = 7533 Uri.withAppendedPath(AUTHORITY_URI, "photo_dimensions"); 7534 7535 /** 7536 * Queries to {@link ContactsContract.DisplayPhoto#CONTENT_MAX_DIMENSIONS_URI} will 7537 * contain this column, populated with the maximum height and width (in pixels) 7538 * that will be stored for a display photo. Larger photos will be down-sized to 7539 * fit within a square of this many pixels. 7540 */ 7541 public static final String DISPLAY_MAX_DIM = "display_max_dim"; 7542 7543 /** 7544 * Queries to {@link ContactsContract.DisplayPhoto#CONTENT_MAX_DIMENSIONS_URI} will 7545 * contain this column, populated with the height and width (in pixels) for photo 7546 * thumbnails. 7547 */ 7548 public static final String THUMBNAIL_MAX_DIM = "thumbnail_max_dim"; 7549 } 7550 7551 /** 7552 * Contains helper classes used to create or manage {@link android.content.Intent Intents} 7553 * that involve contacts. 7554 */ 7555 public static final class Intents { 7556 /** 7557 * This is the intent that is fired when a search suggestion is clicked on. 7558 */ 7559 public static final String SEARCH_SUGGESTION_CLICKED = 7560 "android.provider.Contacts.SEARCH_SUGGESTION_CLICKED"; 7561 7562 /** 7563 * This is the intent that is fired when a search suggestion for dialing a number 7564 * is clicked on. 7565 */ 7566 public static final String SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED = 7567 "android.provider.Contacts.SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED"; 7568 7569 /** 7570 * This is the intent that is fired when a search suggestion for creating a contact 7571 * is clicked on. 7572 */ 7573 public static final String SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED = 7574 "android.provider.Contacts.SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED"; 7575 7576 /** 7577 * Starts an Activity that lets the user pick a contact to attach an image to. 7578 * After picking the contact it launches the image cropper in face detection mode. 7579 */ 7580 public static final String ATTACH_IMAGE = 7581 "com.android.contacts.action.ATTACH_IMAGE"; 7582 7583 /** 7584 * This is the intent that is fired when the user clicks the "invite to the network" button 7585 * on a contact. Only sent to an activity which is explicitly registered by a contact 7586 * provider which supports the "invite to the network" feature. 7587 * <p> 7588 * {@link Intent#getData()} contains the lookup URI for the contact. 7589 */ 7590 public static final String INVITE_CONTACT = 7591 "com.android.contacts.action.INVITE_CONTACT"; 7592 7593 /** 7594 * Takes as input a data URI with a mailto: or tel: scheme. If a single 7595 * contact exists with the given data it will be shown. If no contact 7596 * exists, a dialog will ask the user if they want to create a new 7597 * contact with the provided details filled in. If multiple contacts 7598 * share the data the user will be prompted to pick which contact they 7599 * want to view. 7600 * <p> 7601 * For <code>mailto:</code> URIs, the scheme specific portion must be a 7602 * raw email address, such as one built using 7603 * {@link Uri#fromParts(String, String, String)}. 7604 * <p> 7605 * For <code>tel:</code> URIs, the scheme specific portion is compared 7606 * to existing numbers using the standard caller ID lookup algorithm. 7607 * The number must be properly encoded, for example using 7608 * {@link Uri#fromParts(String, String, String)}. 7609 * <p> 7610 * Any extras from the {@link Insert} class will be passed along to the 7611 * create activity if there are no contacts to show. 7612 * <p> 7613 * Passing true for the {@link #EXTRA_FORCE_CREATE} extra will skip 7614 * prompting the user when the contact doesn't exist. 7615 */ 7616 public static final String SHOW_OR_CREATE_CONTACT = 7617 "com.android.contacts.action.SHOW_OR_CREATE_CONTACT"; 7618 7619 /** 7620 * Starts an Activity that lets the user select the multiple phones from a 7621 * list of phone numbers which come from the contacts or 7622 * {@link #EXTRA_PHONE_URIS}. 7623 * <p> 7624 * The phone numbers being passed in through {@link #EXTRA_PHONE_URIS} 7625 * could belong to the contacts or not, and will be selected by default. 7626 * <p> 7627 * The user's selection will be returned from 7628 * {@link android.app.Activity#onActivityResult(int, int, android.content.Intent)} 7629 * if the resultCode is 7630 * {@link android.app.Activity#RESULT_OK}, the array of picked phone 7631 * numbers are in the Intent's 7632 * {@link #EXTRA_PHONE_URIS}; otherwise, the 7633 * {@link android.app.Activity#RESULT_CANCELED} is returned if the user 7634 * left the Activity without changing the selection. 7635 * 7636 * @hide 7637 */ 7638 public static final String ACTION_GET_MULTIPLE_PHONES = 7639 "com.android.contacts.action.GET_MULTIPLE_PHONES"; 7640 7641 /** 7642 * Used with {@link #SHOW_OR_CREATE_CONTACT} to force creating a new 7643 * contact if no matching contact found. Otherwise, default behavior is 7644 * to prompt user with dialog before creating. 7645 * <p> 7646 * Type: BOOLEAN 7647 */ 7648 public static final String EXTRA_FORCE_CREATE = 7649 "com.android.contacts.action.FORCE_CREATE"; 7650 7651 /** 7652 * Used with {@link #SHOW_OR_CREATE_CONTACT} to specify an exact 7653 * description to be shown when prompting user about creating a new 7654 * contact. 7655 * <p> 7656 * Type: STRING 7657 */ 7658 public static final String EXTRA_CREATE_DESCRIPTION = 7659 "com.android.contacts.action.CREATE_DESCRIPTION"; 7660 7661 /** 7662 * Used with {@link #ACTION_GET_MULTIPLE_PHONES} as the input or output value. 7663 * <p> 7664 * The phone numbers want to be picked by default should be passed in as 7665 * input value. These phone numbers could belong to the contacts or not. 7666 * <p> 7667 * The phone numbers which were picked by the user are returned as output 7668 * value. 7669 * <p> 7670 * Type: array of URIs, the tel URI is used for the phone numbers which don't 7671 * belong to any contact, the content URI is used for phone id in contacts. 7672 * 7673 * @hide 7674 */ 7675 public static final String EXTRA_PHONE_URIS = 7676 "com.android.contacts.extra.PHONE_URIS"; 7677 7678 /** 7679 * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a 7680 * dialog location using screen coordinates. When not specified, the 7681 * dialog will be centered. 7682 * 7683 * @hide 7684 */ 7685 @Deprecated 7686 public static final String EXTRA_TARGET_RECT = "target_rect"; 7687 7688 /** 7689 * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a 7690 * desired dialog style, usually a variation on size. One of 7691 * {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or {@link #MODE_LARGE}. 7692 * 7693 * @hide 7694 */ 7695 @Deprecated 7696 public static final String EXTRA_MODE = "mode"; 7697 7698 /** 7699 * Value for {@link #EXTRA_MODE} to show a small-sized dialog. 7700 * 7701 * @hide 7702 */ 7703 @Deprecated 7704 public static final int MODE_SMALL = 1; 7705 7706 /** 7707 * Value for {@link #EXTRA_MODE} to show a medium-sized dialog. 7708 * 7709 * @hide 7710 */ 7711 @Deprecated 7712 public static final int MODE_MEDIUM = 2; 7713 7714 /** 7715 * Value for {@link #EXTRA_MODE} to show a large-sized dialog. 7716 * 7717 * @hide 7718 */ 7719 @Deprecated 7720 public static final int MODE_LARGE = 3; 7721 7722 /** 7723 * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to indicate 7724 * a list of specific MIME-types to exclude and not display. Stored as a 7725 * {@link String} array. 7726 * 7727 * @hide 7728 */ 7729 @Deprecated 7730 public static final String EXTRA_EXCLUDE_MIMES = "exclude_mimes"; 7731 7732 /** 7733 * Intents related to the Contacts app UI. 7734 * 7735 * @hide 7736 */ 7737 public static final class UI { 7738 /** 7739 * The action for the default contacts list tab. 7740 */ 7741 public static final String LIST_DEFAULT = 7742 "com.android.contacts.action.LIST_DEFAULT"; 7743 7744 /** 7745 * The action for the contacts list tab. 7746 */ 7747 public static final String LIST_GROUP_ACTION = 7748 "com.android.contacts.action.LIST_GROUP"; 7749 7750 /** 7751 * When in LIST_GROUP_ACTION mode, this is the group to display. 7752 */ 7753 public static final String GROUP_NAME_EXTRA_KEY = "com.android.contacts.extra.GROUP"; 7754 7755 /** 7756 * The action for the all contacts list tab. 7757 */ 7758 public static final String LIST_ALL_CONTACTS_ACTION = 7759 "com.android.contacts.action.LIST_ALL_CONTACTS"; 7760 7761 /** 7762 * The action for the contacts with phone numbers list tab. 7763 */ 7764 public static final String LIST_CONTACTS_WITH_PHONES_ACTION = 7765 "com.android.contacts.action.LIST_CONTACTS_WITH_PHONES"; 7766 7767 /** 7768 * The action for the starred contacts list tab. 7769 */ 7770 public static final String LIST_STARRED_ACTION = 7771 "com.android.contacts.action.LIST_STARRED"; 7772 7773 /** 7774 * The action for the frequent contacts list tab. 7775 */ 7776 public static final String LIST_FREQUENT_ACTION = 7777 "com.android.contacts.action.LIST_FREQUENT"; 7778 7779 /** 7780 * The action for the "strequent" contacts list tab. It first lists the starred 7781 * contacts in alphabetical order and then the frequent contacts in descending 7782 * order of the number of times they have been contacted. 7783 */ 7784 public static final String LIST_STREQUENT_ACTION = 7785 "com.android.contacts.action.LIST_STREQUENT"; 7786 7787 /** 7788 * A key for to be used as an intent extra to set the activity 7789 * title to a custom String value. 7790 */ 7791 public static final String TITLE_EXTRA_KEY = 7792 "com.android.contacts.extra.TITLE_EXTRA"; 7793 7794 /** 7795 * Activity Action: Display a filtered list of contacts 7796 * <p> 7797 * Input: Extra field {@link #FILTER_TEXT_EXTRA_KEY} is the text to use for 7798 * filtering 7799 * <p> 7800 * Output: Nothing. 7801 */ 7802 public static final String FILTER_CONTACTS_ACTION = 7803 "com.android.contacts.action.FILTER_CONTACTS"; 7804 7805 /** 7806 * Used as an int extra field in {@link #FILTER_CONTACTS_ACTION} 7807 * intents to supply the text on which to filter. 7808 */ 7809 public static final String FILTER_TEXT_EXTRA_KEY = 7810 "com.android.contacts.extra.FILTER_TEXT"; 7811 } 7812 7813 /** 7814 * Convenience class that contains string constants used 7815 * to create contact {@link android.content.Intent Intents}. 7816 */ 7817 public static final class Insert { 7818 /** The action code to use when adding a contact */ 7819 public static final String ACTION = Intent.ACTION_INSERT; 7820 7821 /** 7822 * If present, forces a bypass of quick insert mode. 7823 */ 7824 public static final String FULL_MODE = "full_mode"; 7825 7826 /** 7827 * The extra field for the contact name. 7828 * <P>Type: String</P> 7829 */ 7830 public static final String NAME = "name"; 7831 7832 // TODO add structured name values here. 7833 7834 /** 7835 * The extra field for the contact phonetic name. 7836 * <P>Type: String</P> 7837 */ 7838 public static final String PHONETIC_NAME = "phonetic_name"; 7839 7840 /** 7841 * The extra field for the contact company. 7842 * <P>Type: String</P> 7843 */ 7844 public static final String COMPANY = "company"; 7845 7846 /** 7847 * The extra field for the contact job title. 7848 * <P>Type: String</P> 7849 */ 7850 public static final String JOB_TITLE = "job_title"; 7851 7852 /** 7853 * The extra field for the contact notes. 7854 * <P>Type: String</P> 7855 */ 7856 public static final String NOTES = "notes"; 7857 7858 /** 7859 * The extra field for the contact phone number. 7860 * <P>Type: String</P> 7861 */ 7862 public static final String PHONE = "phone"; 7863 7864 /** 7865 * The extra field for the contact phone number type. 7866 * <P>Type: Either an integer value from 7867 * {@link CommonDataKinds.Phone}, 7868 * or a string specifying a custom label.</P> 7869 */ 7870 public static final String PHONE_TYPE = "phone_type"; 7871 7872 /** 7873 * The extra field for the phone isprimary flag. 7874 * <P>Type: boolean</P> 7875 */ 7876 public static final String PHONE_ISPRIMARY = "phone_isprimary"; 7877 7878 /** 7879 * The extra field for an optional second contact phone number. 7880 * <P>Type: String</P> 7881 */ 7882 public static final String SECONDARY_PHONE = "secondary_phone"; 7883 7884 /** 7885 * The extra field for an optional second contact phone number type. 7886 * <P>Type: Either an integer value from 7887 * {@link CommonDataKinds.Phone}, 7888 * or a string specifying a custom label.</P> 7889 */ 7890 public static final String SECONDARY_PHONE_TYPE = "secondary_phone_type"; 7891 7892 /** 7893 * The extra field for an optional third contact phone number. 7894 * <P>Type: String</P> 7895 */ 7896 public static final String TERTIARY_PHONE = "tertiary_phone"; 7897 7898 /** 7899 * The extra field for an optional third contact phone number type. 7900 * <P>Type: Either an integer value from 7901 * {@link CommonDataKinds.Phone}, 7902 * or a string specifying a custom label.</P> 7903 */ 7904 public static final String TERTIARY_PHONE_TYPE = "tertiary_phone_type"; 7905 7906 /** 7907 * The extra field for the contact email address. 7908 * <P>Type: String</P> 7909 */ 7910 public static final String EMAIL = "email"; 7911 7912 /** 7913 * The extra field for the contact email type. 7914 * <P>Type: Either an integer value from 7915 * {@link CommonDataKinds.Email} 7916 * or a string specifying a custom label.</P> 7917 */ 7918 public static final String EMAIL_TYPE = "email_type"; 7919 7920 /** 7921 * The extra field for the email isprimary flag. 7922 * <P>Type: boolean</P> 7923 */ 7924 public static final String EMAIL_ISPRIMARY = "email_isprimary"; 7925 7926 /** 7927 * The extra field for an optional second contact email address. 7928 * <P>Type: String</P> 7929 */ 7930 public static final String SECONDARY_EMAIL = "secondary_email"; 7931 7932 /** 7933 * The extra field for an optional second contact email type. 7934 * <P>Type: Either an integer value from 7935 * {@link CommonDataKinds.Email} 7936 * or a string specifying a custom label.</P> 7937 */ 7938 public static final String SECONDARY_EMAIL_TYPE = "secondary_email_type"; 7939 7940 /** 7941 * The extra field for an optional third contact email address. 7942 * <P>Type: String</P> 7943 */ 7944 public static final String TERTIARY_EMAIL = "tertiary_email"; 7945 7946 /** 7947 * The extra field for an optional third contact email type. 7948 * <P>Type: Either an integer value from 7949 * {@link CommonDataKinds.Email} 7950 * or a string specifying a custom label.</P> 7951 */ 7952 public static final String TERTIARY_EMAIL_TYPE = "tertiary_email_type"; 7953 7954 /** 7955 * The extra field for the contact postal address. 7956 * <P>Type: String</P> 7957 */ 7958 public static final String POSTAL = "postal"; 7959 7960 /** 7961 * The extra field for the contact postal address type. 7962 * <P>Type: Either an integer value from 7963 * {@link CommonDataKinds.StructuredPostal} 7964 * or a string specifying a custom label.</P> 7965 */ 7966 public static final String POSTAL_TYPE = "postal_type"; 7967 7968 /** 7969 * The extra field for the postal isprimary flag. 7970 * <P>Type: boolean</P> 7971 */ 7972 public static final String POSTAL_ISPRIMARY = "postal_isprimary"; 7973 7974 /** 7975 * The extra field for an IM handle. 7976 * <P>Type: String</P> 7977 */ 7978 public static final String IM_HANDLE = "im_handle"; 7979 7980 /** 7981 * The extra field for the IM protocol 7982 */ 7983 public static final String IM_PROTOCOL = "im_protocol"; 7984 7985 /** 7986 * The extra field for the IM isprimary flag. 7987 * <P>Type: boolean</P> 7988 */ 7989 public static final String IM_ISPRIMARY = "im_isprimary"; 7990 7991 /** 7992 * The extra field that allows the client to supply multiple rows of 7993 * arbitrary data for a single contact created using the {@link Intent#ACTION_INSERT} 7994 * or edited using {@link Intent#ACTION_EDIT}. It is an ArrayList of 7995 * {@link ContentValues}, one per data row. Supplying this extra is 7996 * similar to inserting multiple rows into the {@link Data} table, 7997 * except the user gets a chance to see and edit them before saving. 7998 * Each ContentValues object must have a value for {@link Data#MIMETYPE}. 7999 * If supplied values are not visible in the editor UI, they will be 8000 * dropped. Duplicate data will dropped. Some fields 8001 * like {@link CommonDataKinds.Email#TYPE Email.TYPE} may be automatically 8002 * adjusted to comply with the constraints of the specific account type. 8003 * For example, an Exchange contact can only have one phone numbers of type Home, 8004 * so the contact editor may choose a different type for this phone number to 8005 * avoid dropping the valueable part of the row, which is the phone number. 8006 * <p> 8007 * Example: 8008 * <pre> 8009 * ArrayList<ContentValues> data = new ArrayList<ContentValues>(); 8010 * 8011 * ContentValues row1 = new ContentValues(); 8012 * row1.put(Data.MIMETYPE, Organization.CONTENT_ITEM_TYPE); 8013 * row1.put(Organization.COMPANY, "Android"); 8014 * data.add(row1); 8015 * 8016 * ContentValues row2 = new ContentValues(); 8017 * row2.put(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE); 8018 * row2.put(Email.TYPE, Email.TYPE_CUSTOM); 8019 * row2.put(Email.LABEL, "Green Bot"); 8020 * row2.put(Email.ADDRESS, "android@android.com"); 8021 * data.add(row2); 8022 * 8023 * Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI); 8024 * intent.putParcelableArrayListExtra(Insert.DATA, data); 8025 * 8026 * startActivity(intent); 8027 * </pre> 8028 */ 8029 public static final String DATA = "data"; 8030 8031 /** 8032 * Used to specify the account in which to create the new contact. 8033 * <p> 8034 * If this value is not provided, the user is presented with a disambiguation 8035 * dialog to chose an account 8036 * <p> 8037 * Type: {@link Account} 8038 * 8039 * @hide 8040 */ 8041 public static final String ACCOUNT = "com.android.contacts.extra.ACCOUNT"; 8042 8043 /** 8044 * Used to specify the data set within the account in which to create the 8045 * new contact. 8046 * <p> 8047 * This value is optional - if it is not specified, the contact will be 8048 * created in the base account, with no data set. 8049 * <p> 8050 * Type: String 8051 * 8052 * @hide 8053 */ 8054 public static final String DATA_SET = "com.android.contacts.extra.DATA_SET"; 8055 } 8056 } 8057} 8058