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 17 package android.provider; 18 19 import android.accounts.Account; 20 import android.app.Activity; 21 import android.content.ContentProviderClient; 22 import android.content.ContentProviderOperation; 23 import android.content.ContentResolver; 24 import android.content.ContentUris; 25 import android.content.ContentValues; 26 import android.content.Context; 27 import android.content.CursorEntityIterator; 28 import android.content.Entity; 29 import android.content.EntityIterator; 30 import android.content.Intent; 31 import android.content.res.AssetFileDescriptor; 32 import android.content.res.Resources; 33 import android.database.Cursor; 34 import android.database.DatabaseUtils; 35 import android.graphics.Rect; 36 import android.net.Uri; 37 import android.os.Bundle; 38 import android.os.RemoteException; 39 import android.text.TextUtils; 40 import android.util.DisplayMetrics; 41 import android.util.Pair; 42 import android.view.View; 43 44 import java.io.ByteArrayInputStream; 45 import java.io.IOException; 46 import java.io.InputStream; 47 import java.util.ArrayList; 48 import java.util.List; 49 import java.util.regex.Matcher; 50 import java.util.regex.Pattern; 51 52 /** 53 * <p> 54 * The contract between the contacts provider and applications. Contains 55 * definitions for the supported URIs and columns. These APIs supersede 56 * {@link Contacts}. 57 * </p> 58 * <h3>Overview</h3> 59 * <p> 60 * ContactsContract defines an extensible database of contact-related 61 * information. Contact information is stored in a three-tier data model: 62 * </p> 63 * <ul> 64 * <li> 65 * A row in the {@link Data} table can store any kind of personal data, such 66 * as a phone number or email addresses. The set of data kinds that can be 67 * stored in this table is open-ended. There is a predefined set of common 68 * kinds, but any application can add its own data kinds. 69 * </li> 70 * <li> 71 * A row in the {@link RawContacts} table represents a set of data describing a 72 * person and associated with a single account (for example, one of the user's 73 * Gmail accounts). 74 * </li> 75 * <li> 76 * A row in the {@link Contacts} table represents an aggregate of one or more 77 * RawContacts presumably describing the same person. When data in or associated with 78 * the RawContacts table is changed, the affected aggregate contacts are updated as 79 * necessary. 80 * </li> 81 * </ul> 82 * <p> 83 * Other tables include: 84 * </p> 85 * <ul> 86 * <li> 87 * {@link Groups}, which contains information about raw contact groups 88 * such as Gmail contact groups. The 89 * current API does not support the notion of groups spanning multiple accounts. 90 * </li> 91 * <li> 92 * {@link StatusUpdates}, which contains social status updates including IM 93 * availability. 94 * </li> 95 * <li> 96 * {@link AggregationExceptions}, which is used for manual aggregation and 97 * disaggregation of raw contacts 98 * </li> 99 * <li> 100 * {@link Settings}, which contains visibility and sync settings for accounts 101 * and groups. 102 * </li> 103 * <li> 104 * {@link SyncState}, which contains free-form data maintained on behalf of sync 105 * adapters 106 * </li> 107 * <li> 108 * {@link PhoneLookup}, which is used for quick caller-ID lookup</li> 109 * </ul> 110 */ 111 @SuppressWarnings("unused") 112 public final class ContactsContract { 113 /** The authority for the contacts provider */ 114 public static final String AUTHORITY = "com.android.contacts"; 115 /** A content:// style uri to the authority for the contacts provider */ 116 public static final Uri AUTHORITY_URI = Uri.parse("content://" + AUTHORITY); 117 118 /** 119 * An optional URI parameter for insert, update, or delete queries 120 * that allows the caller 121 * to specify that it is a sync adapter. The default value is false. If true 122 * {@link RawContacts#DIRTY} is not automatically set and the 123 * "syncToNetwork" parameter is set to false when calling 124 * {@link 125 * ContentResolver#notifyChange(android.net.Uri, android.database.ContentObserver, boolean)}. 126 * This prevents an unnecessary extra synchronization, see the discussion of 127 * the delete operation in {@link RawContacts}. 128 */ 129 public static final String CALLER_IS_SYNCADAPTER = "caller_is_syncadapter"; 130 131 /** 132 * Query parameter that should be used by the client to access a specific 133 * {@link Directory}. The parameter value should be the _ID of the corresponding 134 * directory, e.g. 135 * {@code content://com.android.contacts/data/emails/filter/acme?directory=3} 136 */ 137 public static final String DIRECTORY_PARAM_KEY = "directory"; 138 139 /** 140 * A query parameter that limits the number of results returned. The 141 * parameter value should be an integer. 142 */ 143 public static final String LIMIT_PARAM_KEY = "limit"; 144 145 /** 146 * A query parameter specifing a primary account. This parameter should be used with 147 * {@link #PRIMARY_ACCOUNT_TYPE}. The contacts provider handling a query may rely on 148 * this information to optimize its query results. 149 * 150 * For example, in an email composition screen, its implementation can specify an account when 151 * obtaining possible recipients, letting the provider know which account is selected during 152 * the composition. The provider may use the "primary account" information to optimize 153 * the search result. 154 */ 155 public static final String PRIMARY_ACCOUNT_NAME = "name_for_primary_account"; 156 157 /** 158 * A query parameter specifing a primary account. This parameter should be used with 159 * {@link #PRIMARY_ACCOUNT_NAME}. See the doc in {@link #PRIMARY_ACCOUNT_NAME}. 160 */ 161 public static final String PRIMARY_ACCOUNT_TYPE = "type_for_primary_account"; 162 163 /** 164 * A boolean parameter for {@link Contacts#CONTENT_STREQUENT_URI} and 165 * {@link Contacts#CONTENT_STREQUENT_FILTER_URI}, which requires the ContactsProvider to 166 * return only phone-related results. For example, frequently contacted person list should 167 * include persons contacted via phone (not email, sms, etc.) 168 * 169 * @hide 170 */ 171 public static final String STREQUENT_PHONE_ONLY = "strequent_phone_only"; 172 173 /** 174 * A key to a boolean in the "extras" bundle of the cursor. 175 * The boolean indicates that the provider did not create a snippet and that the client asking 176 * for the snippet should do it (true means the snippeting was deferred to the client). 177 * 178 * @hide 179 */ 180 public static final String DEFERRED_SNIPPETING = "deferred_snippeting"; 181 182 /** 183 * Key to retrieve the original query on the client side. 184 * 185 * @hide 186 */ 187 public static final String DEFERRED_SNIPPETING_QUERY = "deferred_snippeting_query"; 188 189 /** 190 * <p> 191 * API for obtaining a pre-authorized version of a URI that normally requires special 192 * permission (beyond READ_CONTACTS) to read. The caller obtaining the pre-authorized URI 193 * must already have the necessary permissions to access the URI; otherwise a 194 * {@link SecurityException} will be thrown. 195 * </p> 196 * <p> 197 * The authorized URI returned in the bundle contains an expiring token that allows the 198 * caller to execute the query without having the special permissions that would normally 199 * be required. 200 * </p> 201 * <p> 202 * This API does not access disk, and should be safe to invoke from the UI thread. 203 * </p> 204 * <p> 205 * Example usage: 206 * <pre> 207 * Uri profileUri = ContactsContract.Profile.CONTENT_VCARD_URI; 208 * Bundle uriBundle = new Bundle(); 209 * uriBundle.putParcelable(ContactsContract.Authorization.KEY_URI_TO_AUTHORIZE, uri); 210 * Bundle authResponse = getContext().getContentResolver().call( 211 * ContactsContract.AUTHORITY_URI, 212 * ContactsContract.Authorization.AUTHORIZATION_METHOD, 213 * null, // String arg, not used. 214 * uriBundle); 215 * if (authResponse != null) { 216 * Uri preauthorizedProfileUri = (Uri) authResponse.getParcelable( 217 * ContactsContract.Authorization.KEY_AUTHORIZED_URI); 218 * // This pre-authorized URI can be queried by a caller without READ_PROFILE 219 * // permission. 220 * } 221 * </pre> 222 * </p> 223 * @hide 224 */ 225 public static final class Authorization { 226 /** 227 * The method to invoke to create a pre-authorized URI out of the input argument. 228 */ 229 public static final String AUTHORIZATION_METHOD = "authorize"; 230 231 /** 232 * The key to set in the outbound Bundle with the URI that should be authorized. 233 */ 234 public static final String KEY_URI_TO_AUTHORIZE = "uri_to_authorize"; 235 236 /** 237 * The key to retrieve from the returned Bundle to obtain the pre-authorized URI. 238 */ 239 public static final String KEY_AUTHORIZED_URI = "authorized_uri"; 240 } 241 242 /** 243 * @hide 244 */ 245 public static final class Preferences { 246 247 /** 248 * A key in the {@link android.provider.Settings android.provider.Settings} provider 249 * that stores the preferred sorting order for contacts (by given name vs. by family name). 250 * 251 * @hide 252 */ 253 public static final String SORT_ORDER = "android.contacts.SORT_ORDER"; 254 255 /** 256 * The value for the SORT_ORDER key corresponding to sorting by given name first. 257 * 258 * @hide 259 */ 260 public static final int SORT_ORDER_PRIMARY = 1; 261 262 /** 263 * The value for the SORT_ORDER key corresponding to sorting by family name first. 264 * 265 * @hide 266 */ 267 public static final int SORT_ORDER_ALTERNATIVE = 2; 268 269 /** 270 * A key in the {@link android.provider.Settings android.provider.Settings} provider 271 * that stores the preferred display order for contacts (given name first vs. family 272 * name first). 273 * 274 * @hide 275 */ 276 public static final String DISPLAY_ORDER = "android.contacts.DISPLAY_ORDER"; 277 278 /** 279 * The value for the DISPLAY_ORDER key corresponding to showing the given name first. 280 * 281 * @hide 282 */ 283 public static final int DISPLAY_ORDER_PRIMARY = 1; 284 285 /** 286 * The value for the DISPLAY_ORDER key corresponding to showing the family name first. 287 * 288 * @hide 289 */ 290 public static final int DISPLAY_ORDER_ALTERNATIVE = 2; 291 } 292 293 /** 294 * A Directory represents a contacts corpus, e.g. Local contacts, 295 * Google Apps Global Address List or Corporate Global Address List. 296 * <p> 297 * A Directory is implemented as a content provider with its unique authority and 298 * the same API as the main Contacts Provider. However, there is no expectation that 299 * every directory provider will implement this Contract in its entirety. If a 300 * directory provider does not have an implementation for a specific request, it 301 * should throw an UnsupportedOperationException. 302 * </p> 303 * <p> 304 * The most important use case for Directories is search. A Directory provider is 305 * expected to support at least {@link ContactsContract.Contacts#CONTENT_FILTER_URI 306 * Contacts.CONTENT_FILTER_URI}. If a Directory provider wants to participate 307 * in email and phone lookup functionalities, it should also implement 308 * {@link CommonDataKinds.Email#CONTENT_FILTER_URI CommonDataKinds.Email.CONTENT_FILTER_URI} 309 * and 310 * {@link CommonDataKinds.Phone#CONTENT_FILTER_URI CommonDataKinds.Phone.CONTENT_FILTER_URI}. 311 * </p> 312 * <p> 313 * A directory provider should return NULL for every projection field it does not 314 * recognize, rather than throwing an exception. This way it will not be broken 315 * if ContactsContract is extended with new fields in the future. 316 * </p> 317 * <p> 318 * The client interacts with a directory via Contacts Provider by supplying an 319 * optional {@code directory=} query parameter. 320 * <p> 321 * <p> 322 * When the Contacts Provider receives the request, it transforms the URI and forwards 323 * the request to the corresponding directory content provider. 324 * The URI is transformed in the following fashion: 325 * <ul> 326 * <li>The URI authority is replaced with the corresponding {@link #DIRECTORY_AUTHORITY}.</li> 327 * <li>The {@code accountName=} and {@code accountType=} parameters are added or 328 * replaced using the corresponding {@link #ACCOUNT_TYPE} and {@link #ACCOUNT_NAME} values.</li> 329 * </ul> 330 * </p> 331 * <p> 332 * Clients should send directory requests to Contacts Provider and let it 333 * forward them to the respective providers rather than constructing 334 * directory provider URIs by themselves. This level of indirection allows 335 * Contacts Provider to implement additional system-level features and 336 * optimizations. Access to Contacts Provider is protected by the 337 * READ_CONTACTS permission, but access to the directory provider is not. 338 * Therefore directory providers must reject requests coming from clients 339 * other than the Contacts Provider itself. An easy way to prevent such 340 * unauthorized access is to check the name of the calling package: 341 * <pre> 342 * private boolean isCallerAllowed() { 343 * PackageManager pm = getContext().getPackageManager(); 344 * for (String packageName: pm.getPackagesForUid(Binder.getCallingUid())) { 345 * if (packageName.equals("com.android.providers.contacts")) { 346 * return true; 347 * } 348 * } 349 * return false; 350 * } 351 * </pre> 352 * </p> 353 * <p> 354 * The Directory table is read-only and is maintained by the Contacts Provider 355 * automatically. 356 * </p> 357 * <p>It always has at least these two rows: 358 * <ul> 359 * <li> 360 * The local directory. It has {@link Directory#_ID Directory._ID} = 361 * {@link Directory#DEFAULT Directory.DEFAULT}. This directory can be used to access locally 362 * stored contacts. The same can be achieved by omitting the {@code directory=} 363 * parameter altogether. 364 * </li> 365 * <li> 366 * The local invisible contacts. The corresponding directory ID is 367 * {@link Directory#LOCAL_INVISIBLE Directory.LOCAL_INVISIBLE}. 368 * </li> 369 * </ul> 370 * </p> 371 * <p>Custom Directories are discovered by the Contacts Provider following this procedure: 372 * <ul> 373 * <li>It finds all installed content providers with meta data identifying them 374 * as directory providers in AndroidManifest.xml: 375 * <code> 376 * <meta-data android:name="android.content.ContactDirectory" 377 * android:value="true" /> 378 * </code> 379 * <p> 380 * This tag should be placed inside the corresponding content provider declaration. 381 * </p> 382 * </li> 383 * <li> 384 * Then Contacts Provider sends a {@link Directory#CONTENT_URI Directory.CONTENT_URI} 385 * query to each of the directory authorities. A directory provider must implement 386 * this query and return a list of directories. Each directory returned by 387 * the provider must have a unique combination for the {@link #ACCOUNT_NAME} and 388 * {@link #ACCOUNT_TYPE} columns (nulls are allowed). Since directory IDs are assigned 389 * automatically, the _ID field will not be part of the query projection. 390 * </li> 391 * <li>Contacts Provider compiles directory lists received from all directory 392 * providers into one, assigns each individual directory a globally unique ID and 393 * stores all directory records in the Directory table. 394 * </li> 395 * </ul> 396 * </p> 397 * <p>Contacts Provider automatically interrogates newly installed or replaced packages. 398 * Thus simply installing a package containing a directory provider is sufficient 399 * to have that provider registered. A package supplying a directory provider does 400 * not have to contain launchable activities. 401 * </p> 402 * <p> 403 * Every row in the Directory table is automatically associated with the corresponding package 404 * (apk). If the package is later uninstalled, all corresponding directory rows 405 * are automatically removed from the Contacts Provider. 406 * </p> 407 * <p> 408 * When the list of directories handled by a directory provider changes 409 * (for instance when the user adds a new Directory account), the directory provider 410 * should call {@link #notifyDirectoryChange} to notify the Contacts Provider of the change. 411 * In response, the Contacts Provider will requery the directory provider to obtain the 412 * new list of directories. 413 * </p> 414 * <p> 415 * A directory row can be optionally associated with an existing account 416 * (see {@link android.accounts.AccountManager}). If the account is later removed, 417 * the corresponding directory rows are automatically removed from the Contacts Provider. 418 * </p> 419 */ 420 public static final class Directory implements BaseColumns { 421 422 /** 423 * Not instantiable. 424 */ 425 private Directory() { 426 } 427 428 /** 429 * The content:// style URI for this table. Requests to this URI can be 430 * performed on the UI thread because they are always unblocking. 431 */ 432 public static final Uri CONTENT_URI = 433 Uri.withAppendedPath(AUTHORITY_URI, "directories"); 434 435 /** 436 * The MIME-type of {@link #CONTENT_URI} providing a directory of 437 * contact directories. 438 */ 439 public static final String CONTENT_TYPE = 440 "vnd.android.cursor.dir/contact_directories"; 441 442 /** 443 * The MIME type of a {@link #CONTENT_URI} item. 444 */ 445 public static final String CONTENT_ITEM_TYPE = 446 "vnd.android.cursor.item/contact_directory"; 447 448 /** 449 * _ID of the default directory, which represents locally stored contacts. 450 */ 451 public static final long DEFAULT = 0; 452 453 /** 454 * _ID of the directory that represents locally stored invisible contacts. 455 */ 456 public static final long LOCAL_INVISIBLE = 1; 457 458 /** 459 * The name of the package that owns this directory. Contacts Provider 460 * fill it in with the name of the package containing the directory provider. 461 * If the package is later uninstalled, the directories it owns are 462 * automatically removed from this table. 463 * 464 * <p>TYPE: TEXT</p> 465 */ 466 public static final String PACKAGE_NAME = "packageName"; 467 468 /** 469 * The type of directory captured as a resource ID in the context of the 470 * package {@link #PACKAGE_NAME}, e.g. "Corporate Directory" 471 * 472 * <p>TYPE: INTEGER</p> 473 */ 474 public static final String TYPE_RESOURCE_ID = "typeResourceId"; 475 476 /** 477 * An optional name that can be used in the UI to represent this directory, 478 * e.g. "Acme Corp" 479 * <p>TYPE: text</p> 480 */ 481 public static final String DISPLAY_NAME = "displayName"; 482 483 /** 484 * <p> 485 * The authority of the Directory Provider. Contacts Provider will 486 * use this authority to forward requests to the directory provider. 487 * A directory provider can leave this column empty - Contacts Provider will fill it in. 488 * </p> 489 * <p> 490 * Clients of this API should not send requests directly to this authority. 491 * All directory requests must be routed through Contacts Provider. 492 * </p> 493 * 494 * <p>TYPE: text</p> 495 */ 496 public static final String DIRECTORY_AUTHORITY = "authority"; 497 498 /** 499 * The account type which this directory is associated. 500 * 501 * <p>TYPE: text</p> 502 */ 503 public static final String ACCOUNT_TYPE = "accountType"; 504 505 /** 506 * The account with which this directory is associated. If the account is later 507 * removed, the directories it owns are automatically removed from this table. 508 * 509 * <p>TYPE: text</p> 510 */ 511 public static final String ACCOUNT_NAME = "accountName"; 512 513 /** 514 * One of {@link #EXPORT_SUPPORT_NONE}, {@link #EXPORT_SUPPORT_ANY_ACCOUNT}, 515 * {@link #EXPORT_SUPPORT_SAME_ACCOUNT_ONLY}. This is the expectation the 516 * directory has for data exported from it. Clients must obey this setting. 517 */ 518 public static final String EXPORT_SUPPORT = "exportSupport"; 519 520 /** 521 * An {@link #EXPORT_SUPPORT} setting that indicates that the directory 522 * does not allow any data to be copied out of it. 523 */ 524 public static final int EXPORT_SUPPORT_NONE = 0; 525 526 /** 527 * An {@link #EXPORT_SUPPORT} setting that indicates that the directory 528 * allow its data copied only to the account specified by 529 * {@link #ACCOUNT_TYPE}/{@link #ACCOUNT_NAME}. 530 */ 531 public static final int EXPORT_SUPPORT_SAME_ACCOUNT_ONLY = 1; 532 533 /** 534 * An {@link #EXPORT_SUPPORT} setting that indicates that the directory 535 * allow its data copied to any contacts account. 536 */ 537 public static final int EXPORT_SUPPORT_ANY_ACCOUNT = 2; 538 539 /** 540 * One of {@link #SHORTCUT_SUPPORT_NONE}, {@link #SHORTCUT_SUPPORT_DATA_ITEMS_ONLY}, 541 * {@link #SHORTCUT_SUPPORT_FULL}. This is the expectation the directory 542 * has for shortcuts created for its elements. Clients must obey this setting. 543 */ 544 public static final String SHORTCUT_SUPPORT = "shortcutSupport"; 545 546 /** 547 * An {@link #SHORTCUT_SUPPORT} setting that indicates that the directory 548 * does not allow any shortcuts created for its contacts. 549 */ 550 public static final int SHORTCUT_SUPPORT_NONE = 0; 551 552 /** 553 * An {@link #SHORTCUT_SUPPORT} setting that indicates that the directory 554 * allow creation of shortcuts for data items like email, phone or postal address, 555 * but not the entire contact. 556 */ 557 public static final int SHORTCUT_SUPPORT_DATA_ITEMS_ONLY = 1; 558 559 /** 560 * An {@link #SHORTCUT_SUPPORT} setting that indicates that the directory 561 * allow creation of shortcuts for contact as well as their constituent elements. 562 */ 563 public static final int SHORTCUT_SUPPORT_FULL = 2; 564 565 /** 566 * One of {@link #PHOTO_SUPPORT_NONE}, {@link #PHOTO_SUPPORT_THUMBNAIL_ONLY}, 567 * {@link #PHOTO_SUPPORT_FULL}. This is a feature flag indicating the extent 568 * to which the directory supports contact photos. 569 */ 570 public static final String PHOTO_SUPPORT = "photoSupport"; 571 572 /** 573 * An {@link #PHOTO_SUPPORT} setting that indicates that the directory 574 * does not provide any photos. 575 */ 576 public static final int PHOTO_SUPPORT_NONE = 0; 577 578 /** 579 * An {@link #PHOTO_SUPPORT} setting that indicates that the directory 580 * can only produce small size thumbnails of contact photos. 581 */ 582 public static final int PHOTO_SUPPORT_THUMBNAIL_ONLY = 1; 583 584 /** 585 * An {@link #PHOTO_SUPPORT} setting that indicates that the directory 586 * has full-size contact photos, but cannot provide scaled thumbnails. 587 */ 588 public static final int PHOTO_SUPPORT_FULL_SIZE_ONLY = 2; 589 590 /** 591 * An {@link #PHOTO_SUPPORT} setting that indicates that the directory 592 * can produce thumbnails as well as full-size contact photos. 593 */ 594 public static final int PHOTO_SUPPORT_FULL = 3; 595 596 /** 597 * Notifies the system of a change in the list of directories handled by 598 * a particular directory provider. The Contacts provider will turn around 599 * and send a query to the directory provider for the full list of directories, 600 * which will replace the previous list. 601 */ 602 public static void notifyDirectoryChange(ContentResolver resolver) { 603 // This is done to trigger a query by Contacts Provider back to the directory provider. 604 // No data needs to be sent back, because the provider can infer the calling 605 // package from binder. 606 ContentValues contentValues = new ContentValues(); 607 resolver.update(Directory.CONTENT_URI, contentValues, null, null); 608 } 609 } 610 611 /** 612 * @hide should be removed when users are updated to refer to SyncState 613 * @deprecated use SyncState instead 614 */ 615 @Deprecated 616 public interface SyncStateColumns extends SyncStateContract.Columns { 617 } 618 619 /** 620 * A table provided for sync adapters to use for storing private sync state data for contacts. 621 * 622 * @see SyncStateContract 623 */ 624 public static final class SyncState implements SyncStateContract.Columns { 625 /** 626 * This utility class cannot be instantiated 627 */ 628 private SyncState() {} 629 630 public static final String CONTENT_DIRECTORY = 631 SyncStateContract.Constants.CONTENT_DIRECTORY; 632 633 /** 634 * The content:// style URI for this table 635 */ 636 public static final Uri CONTENT_URI = 637 Uri.withAppendedPath(AUTHORITY_URI, CONTENT_DIRECTORY); 638 639 /** 640 * @see android.provider.SyncStateContract.Helpers#get 641 */ 642 public static byte[] get(ContentProviderClient provider, Account account) 643 throws RemoteException { 644 return SyncStateContract.Helpers.get(provider, CONTENT_URI, account); 645 } 646 647 /** 648 * @see android.provider.SyncStateContract.Helpers#get 649 */ 650 public static Pair<Uri, byte[]> getWithUri(ContentProviderClient provider, Account account) 651 throws RemoteException { 652 return SyncStateContract.Helpers.getWithUri(provider, CONTENT_URI, account); 653 } 654 655 /** 656 * @see android.provider.SyncStateContract.Helpers#set 657 */ 658 public static void set(ContentProviderClient provider, Account account, byte[] data) 659 throws RemoteException { 660 SyncStateContract.Helpers.set(provider, CONTENT_URI, account, data); 661 } 662 663 /** 664 * @see android.provider.SyncStateContract.Helpers#newSetOperation 665 */ 666 public static ContentProviderOperation newSetOperation(Account account, byte[] data) { 667 return SyncStateContract.Helpers.newSetOperation(CONTENT_URI, account, data); 668 } 669 } 670 671 672 /** 673 * A table provided for sync adapters to use for storing private sync state data for the 674 * user's personal profile. 675 * 676 * @see SyncStateContract 677 */ 678 public static final class ProfileSyncState implements SyncStateContract.Columns { 679 /** 680 * This utility class cannot be instantiated 681 */ 682 private ProfileSyncState() {} 683 684 public static final String CONTENT_DIRECTORY = 685 SyncStateContract.Constants.CONTENT_DIRECTORY; 686 687 /** 688 * The content:// style URI for this table 689 */ 690 public static final Uri CONTENT_URI = 691 Uri.withAppendedPath(Profile.CONTENT_URI, CONTENT_DIRECTORY); 692 693 /** 694 * @see android.provider.SyncStateContract.Helpers#get 695 */ 696 public static byte[] get(ContentProviderClient provider, Account account) 697 throws RemoteException { 698 return SyncStateContract.Helpers.get(provider, CONTENT_URI, account); 699 } 700 701 /** 702 * @see android.provider.SyncStateContract.Helpers#get 703 */ 704 public static Pair<Uri, byte[]> getWithUri(ContentProviderClient provider, Account account) 705 throws RemoteException { 706 return SyncStateContract.Helpers.getWithUri(provider, CONTENT_URI, account); 707 } 708 709 /** 710 * @see android.provider.SyncStateContract.Helpers#set 711 */ 712 public static void set(ContentProviderClient provider, Account account, byte[] data) 713 throws RemoteException { 714 SyncStateContract.Helpers.set(provider, CONTENT_URI, account, data); 715 } 716 717 /** 718 * @see android.provider.SyncStateContract.Helpers#newSetOperation 719 */ 720 public static ContentProviderOperation newSetOperation(Account account, byte[] data) { 721 return SyncStateContract.Helpers.newSetOperation(CONTENT_URI, account, data); 722 } 723 } 724 725 /** 726 * Generic columns for use by sync adapters. The specific functions of 727 * these columns are private to the sync adapter. Other clients of the API 728 * should not attempt to either read or write this column. 729 * 730 * @see RawContacts 731 * @see Groups 732 */ 733 protected interface BaseSyncColumns { 734 735 /** Generic column for use by sync adapters. */ 736 public static final String SYNC1 = "sync1"; 737 /** Generic column for use by sync adapters. */ 738 public static final String SYNC2 = "sync2"; 739 /** Generic column for use by sync adapters. */ 740 public static final String SYNC3 = "sync3"; 741 /** Generic column for use by sync adapters. */ 742 public static final String SYNC4 = "sync4"; 743 } 744 745 /** 746 * Columns that appear when each row of a table belongs to a specific 747 * account, including sync information that an account may need. 748 * 749 * @see RawContacts 750 * @see Groups 751 */ 752 protected interface SyncColumns extends BaseSyncColumns { 753 /** 754 * The name of the account instance to which this row belongs, which when paired with 755 * {@link #ACCOUNT_TYPE} identifies a specific account. 756 * <P>Type: TEXT</P> 757 */ 758 public static final String ACCOUNT_NAME = "account_name"; 759 760 /** 761 * The type of account to which this row belongs, which when paired with 762 * {@link #ACCOUNT_NAME} identifies a specific account. 763 * <P>Type: TEXT</P> 764 */ 765 public static final String ACCOUNT_TYPE = "account_type"; 766 767 /** 768 * String that uniquely identifies this row to its source account. 769 * <P>Type: TEXT</P> 770 */ 771 public static final String SOURCE_ID = "sourceid"; 772 773 /** 774 * Version number that is updated whenever this row or its related data 775 * changes. 776 * <P>Type: INTEGER</P> 777 */ 778 public static final String VERSION = "version"; 779 780 /** 781 * Flag indicating that {@link #VERSION} has changed, and this row needs 782 * to be synchronized by its owning account. 783 * <P>Type: INTEGER (boolean)</P> 784 */ 785 public static final String DIRTY = "dirty"; 786 } 787 788 /** 789 * Columns of {@link ContactsContract.Contacts} that track the user's 790 * preferences for, or interactions with, the contact. 791 * 792 * @see Contacts 793 * @see RawContacts 794 * @see ContactsContract.Data 795 * @see PhoneLookup 796 * @see ContactsContract.Contacts.AggregationSuggestions 797 */ 798 protected interface ContactOptionsColumns { 799 /** 800 * The number of times a contact has been contacted 801 * <P>Type: INTEGER</P> 802 */ 803 public static final String TIMES_CONTACTED = "times_contacted"; 804 805 /** 806 * The last time a contact was contacted. 807 * <P>Type: INTEGER</P> 808 */ 809 public static final String LAST_TIME_CONTACTED = "last_time_contacted"; 810 811 /** 812 * Is the contact starred? 813 * <P>Type: INTEGER (boolean)</P> 814 */ 815 public static final String STARRED = "starred"; 816 817 /** 818 * URI for a custom ringtone associated with the contact. If null or missing, 819 * the default ringtone is used. 820 * <P>Type: TEXT (URI to the ringtone)</P> 821 */ 822 public static final String CUSTOM_RINGTONE = "custom_ringtone"; 823 824 /** 825 * Whether the contact should always be sent to voicemail. If missing, 826 * defaults to false. 827 * <P>Type: INTEGER (0 for false, 1 for true)</P> 828 */ 829 public static final String SEND_TO_VOICEMAIL = "send_to_voicemail"; 830 } 831 832 /** 833 * Columns of {@link ContactsContract.Contacts} that refer to intrinsic 834 * properties of the contact, as opposed to the user-specified options 835 * found in {@link ContactOptionsColumns}. 836 * 837 * @see Contacts 838 * @see ContactsContract.Data 839 * @see PhoneLookup 840 * @see ContactsContract.Contacts.AggregationSuggestions 841 */ 842 protected interface ContactsColumns { 843 /** 844 * The display name for the contact. 845 * <P>Type: TEXT</P> 846 */ 847 public static final String DISPLAY_NAME = ContactNameColumns.DISPLAY_NAME_PRIMARY; 848 849 /** 850 * Reference to the row in the RawContacts table holding the contact name. 851 * <P>Type: INTEGER REFERENCES raw_contacts(_id)</P> 852 * @hide 853 */ 854 public static final String NAME_RAW_CONTACT_ID = "name_raw_contact_id"; 855 856 /** 857 * Reference to the row in the data table holding the photo. A photo can 858 * be referred to either by ID (this field) or by URI (see {@link #PHOTO_THUMBNAIL_URI} 859 * and {@link #PHOTO_URI}). 860 * If PHOTO_ID is null, consult {@link #PHOTO_URI} or {@link #PHOTO_THUMBNAIL_URI}, 861 * which is a more generic mechanism for referencing the contact photo, especially for 862 * contacts returned by non-local directories (see {@link Directory}). 863 * 864 * <P>Type: INTEGER REFERENCES data(_id)</P> 865 */ 866 public static final String PHOTO_ID = "photo_id"; 867 868 /** 869 * Photo file ID of the full-size photo. If present, this will be used to populate 870 * {@link #PHOTO_URI}. The ID can also be used with 871 * {@link ContactsContract.DisplayPhoto#CONTENT_URI} to create a URI to the photo. 872 * If this is present, {@link #PHOTO_ID} is also guaranteed to be populated. 873 * 874 * <P>Type: INTEGER</P> 875 */ 876 public static final String PHOTO_FILE_ID = "photo_file_id"; 877 878 /** 879 * A URI that can be used to retrieve the contact's full-size photo. 880 * If PHOTO_FILE_ID is not null, this will be populated with a URI based off 881 * {@link ContactsContract.DisplayPhoto#CONTENT_URI}. Otherwise, this will 882 * be populated with the same value as {@link #PHOTO_THUMBNAIL_URI}. 883 * A photo can be referred to either by a URI (this field) or by ID 884 * (see {@link #PHOTO_ID}). If either PHOTO_FILE_ID or PHOTO_ID is not null, 885 * PHOTO_URI and PHOTO_THUMBNAIL_URI shall not be null (but not necessarily 886 * vice versa). Thus using PHOTO_URI is a more robust method of retrieving 887 * contact photos. 888 * 889 * <P>Type: TEXT</P> 890 */ 891 public static final String PHOTO_URI = "photo_uri"; 892 893 /** 894 * A URI that can be used to retrieve a thumbnail of the contact's photo. 895 * A photo can be referred to either by a URI (this field or {@link #PHOTO_URI}) 896 * or by ID (see {@link #PHOTO_ID}). If PHOTO_ID is not null, PHOTO_URI and 897 * PHOTO_THUMBNAIL_URI shall not be null (but not necessarily vice versa). 898 * If the content provider does not differentiate between full-size photos 899 * and thumbnail photos, PHOTO_THUMBNAIL_URI and {@link #PHOTO_URI} can contain 900 * the same value, but either both shall be null or both not null. 901 * 902 * <P>Type: TEXT</P> 903 */ 904 public static final String PHOTO_THUMBNAIL_URI = "photo_thumb_uri"; 905 906 /** 907 * Flag that reflects the {@link Groups#GROUP_VISIBLE} state of any 908 * {@link CommonDataKinds.GroupMembership} for this contact. 909 */ 910 public static final String IN_VISIBLE_GROUP = "in_visible_group"; 911 912 /** 913 * Flag that reflects whether this contact represents the user's 914 * personal profile entry. 915 */ 916 public static final String IS_USER_PROFILE = "is_user_profile"; 917 918 /** 919 * An indicator of whether this contact has at least one phone number. "1" if there is 920 * at least one phone number, "0" otherwise. 921 * <P>Type: INTEGER</P> 922 */ 923 public static final String HAS_PHONE_NUMBER = "has_phone_number"; 924 925 /** 926 * An opaque value that contains hints on how to find the contact if 927 * its row id changed as a result of a sync or aggregation. 928 */ 929 public static final String LOOKUP_KEY = "lookup"; 930 } 931 932 /** 933 * @see Contacts 934 */ 935 protected interface ContactStatusColumns { 936 /** 937 * Contact presence status. See {@link StatusUpdates} for individual status 938 * definitions. 939 * <p>Type: NUMBER</p> 940 */ 941 public static final String CONTACT_PRESENCE = "contact_presence"; 942 943 /** 944 * Contact Chat Capabilities. See {@link StatusUpdates} for individual 945 * definitions. 946 * <p>Type: NUMBER</p> 947 */ 948 public static final String CONTACT_CHAT_CAPABILITY = "contact_chat_capability"; 949 950 /** 951 * Contact's latest status update. 952 * <p>Type: TEXT</p> 953 */ 954 public static final String CONTACT_STATUS = "contact_status"; 955 956 /** 957 * The absolute time in milliseconds when the latest status was 958 * inserted/updated. 959 * <p>Type: NUMBER</p> 960 */ 961 public static final String CONTACT_STATUS_TIMESTAMP = "contact_status_ts"; 962 963 /** 964 * The package containing resources for this status: label and icon. 965 * <p>Type: TEXT</p> 966 */ 967 public static final String CONTACT_STATUS_RES_PACKAGE = "contact_status_res_package"; 968 969 /** 970 * The resource ID of the label describing the source of contact 971 * status, e.g. "Google Talk". This resource is scoped by the 972 * {@link #CONTACT_STATUS_RES_PACKAGE}. 973 * <p>Type: NUMBER</p> 974 */ 975 public static final String CONTACT_STATUS_LABEL = "contact_status_label"; 976 977 /** 978 * The resource ID of the icon for the source of contact status. This 979 * resource is scoped by the {@link #CONTACT_STATUS_RES_PACKAGE}. 980 * <p>Type: NUMBER</p> 981 */ 982 public static final String CONTACT_STATUS_ICON = "contact_status_icon"; 983 } 984 985 /** 986 * Constants for various styles of combining given name, family name etc into 987 * a full name. For example, the western tradition follows the pattern 988 * 'given name' 'middle name' 'family name' with the alternative pattern being 989 * 'family name', 'given name' 'middle name'. The CJK tradition is 990 * 'family name' 'middle name' 'given name', with Japanese favoring a space between 991 * the names and Chinese omitting the space. 992 */ 993 public interface FullNameStyle { 994 public static final int UNDEFINED = 0; 995 public static final int WESTERN = 1; 996 997 /** 998 * Used if the name is written in Hanzi/Kanji/Hanja and we could not determine 999 * which specific language it belongs to: Chinese, Japanese or Korean. 1000 */ 1001 public static final int CJK = 2; 1002 1003 public static final int CHINESE = 3; 1004 public static final int JAPANESE = 4; 1005 public static final int KOREAN = 5; 1006 } 1007 1008 /** 1009 * Constants for various styles of capturing the pronunciation of a person's name. 1010 */ 1011 public interface PhoneticNameStyle { 1012 public static final int UNDEFINED = 0; 1013 1014 /** 1015 * Pinyin is a phonetic method of entering Chinese characters. Typically not explicitly 1016 * shown in UIs, but used for searches and sorting. 1017 */ 1018 public static final int PINYIN = 3; 1019 1020 /** 1021 * Hiragana and Katakana are two common styles of writing out the pronunciation 1022 * of a Japanese names. 1023 */ 1024 public static final int JAPANESE = 4; 1025 1026 /** 1027 * Hangul is the Korean phonetic alphabet. 1028 */ 1029 public static final int KOREAN = 5; 1030 } 1031 1032 /** 1033 * Types of data used to produce the display name for a contact. In the order 1034 * of increasing priority: {@link #EMAIL}, {@link #PHONE}, 1035 * {@link #ORGANIZATION}, {@link #NICKNAME}, {@link #STRUCTURED_NAME}. 1036 */ 1037 public interface DisplayNameSources { 1038 public static final int UNDEFINED = 0; 1039 public static final int EMAIL = 10; 1040 public static final int PHONE = 20; 1041 public static final int ORGANIZATION = 30; 1042 public static final int NICKNAME = 35; 1043 public static final int STRUCTURED_NAME = 40; 1044 } 1045 1046 /** 1047 * Contact name and contact name metadata columns in the RawContacts table. 1048 * 1049 * @see Contacts 1050 * @see RawContacts 1051 */ 1052 protected interface ContactNameColumns { 1053 1054 /** 1055 * The kind of data that is used as the display name for the contact, such as 1056 * structured name or email address. See {@link DisplayNameSources}. 1057 */ 1058 public static final String DISPLAY_NAME_SOURCE = "display_name_source"; 1059 1060 /** 1061 * <p> 1062 * The standard text shown as the contact's display name, based on the best 1063 * available information for the contact (for example, it might be the email address 1064 * if the name is not available). 1065 * The information actually used to compute the name is stored in 1066 * {@link #DISPLAY_NAME_SOURCE}. 1067 * </p> 1068 * <p> 1069 * A contacts provider is free to choose whatever representation makes most 1070 * sense for its target market. 1071 * For example in the default Android Open Source Project implementation, 1072 * if the display name is 1073 * based on the structured name and the structured name follows 1074 * the Western full-name style, then this field contains the "given name first" 1075 * version of the full name. 1076 * <p> 1077 * 1078 * @see ContactsContract.ContactNameColumns#DISPLAY_NAME_ALTERNATIVE 1079 */ 1080 public static final String DISPLAY_NAME_PRIMARY = "display_name"; 1081 1082 /** 1083 * <p> 1084 * An alternative representation of the display name, such as "family name first" 1085 * instead of "given name first" for Western names. If an alternative is not 1086 * available, the values should be the same as {@link #DISPLAY_NAME_PRIMARY}. 1087 * </p> 1088 * <p> 1089 * A contacts provider is free to provide alternatives as necessary for 1090 * its target market. 1091 * For example the default Android Open Source Project contacts provider 1092 * currently provides an 1093 * alternative in a single case: if the display name is 1094 * based on the structured name and the structured name follows 1095 * the Western full name style, then the field contains the "family name first" 1096 * version of the full name. 1097 * Other cases may be added later. 1098 * </p> 1099 */ 1100 public static final String DISPLAY_NAME_ALTERNATIVE = "display_name_alt"; 1101 1102 /** 1103 * The phonetic alphabet used to represent the {@link #PHONETIC_NAME}. See 1104 * {@link PhoneticNameStyle}. 1105 */ 1106 public static final String PHONETIC_NAME_STYLE = "phonetic_name_style"; 1107 1108 /** 1109 * <p> 1110 * Pronunciation of the full name in the phonetic alphabet specified by 1111 * {@link #PHONETIC_NAME_STYLE}. 1112 * </p> 1113 * <p> 1114 * The value may be set manually by the user. This capability is of 1115 * interest only in countries with commonly used phonetic alphabets, 1116 * such as Japan and Korea. See {@link PhoneticNameStyle}. 1117 * </p> 1118 */ 1119 public static final String PHONETIC_NAME = "phonetic_name"; 1120 1121 /** 1122 * Sort key that takes into account locale-based traditions for sorting 1123 * names in address books. The default 1124 * sort key is {@link #DISPLAY_NAME_PRIMARY}. For Chinese names 1125 * the sort key is the name's Pinyin spelling, and for Japanese names 1126 * it is the Hiragana version of the phonetic name. 1127 */ 1128 public static final String SORT_KEY_PRIMARY = "sort_key"; 1129 1130 /** 1131 * Sort key based on the alternative representation of the full name, 1132 * {@link #DISPLAY_NAME_ALTERNATIVE}. Thus for Western names, 1133 * it is the one using the "family name first" format. 1134 */ 1135 public static final String SORT_KEY_ALTERNATIVE = "sort_key_alt"; 1136 } 1137 1138 /** 1139 * URI parameter and cursor extras that return counts of rows grouped by the 1140 * address book index, which is usually the first letter of the sort key. 1141 * When this parameter is supplied, the row counts are returned in the 1142 * cursor extras bundle. 1143 * 1144 * @hide 1145 */ 1146 public final static class ContactCounts { 1147 1148 /** 1149 * Add this query parameter to a URI to get back row counts grouped by 1150 * the address book index as cursor extras. For most languages it is the 1151 * first letter of the sort key. This parameter does not affect the main 1152 * content of the cursor. 1153 * 1154 * @hide 1155 */ 1156 public static final String ADDRESS_BOOK_INDEX_EXTRAS = "address_book_index_extras"; 1157 1158 /** 1159 * The array of address book index titles, which are returned in the 1160 * same order as the data in the cursor. 1161 * <p>TYPE: String[]</p> 1162 * 1163 * @hide 1164 */ 1165 public static final String EXTRA_ADDRESS_BOOK_INDEX_TITLES = "address_book_index_titles"; 1166 1167 /** 1168 * The array of group counts for the corresponding group. Contains the same number 1169 * of elements as the EXTRA_ADDRESS_BOOK_INDEX_TITLES array. 1170 * <p>TYPE: int[]</p> 1171 * 1172 * @hide 1173 */ 1174 public static final String EXTRA_ADDRESS_BOOK_INDEX_COUNTS = "address_book_index_counts"; 1175 } 1176 1177 /** 1178 * Constants for the contacts table, which contains a record per aggregate 1179 * of raw contacts representing the same person. 1180 * <h3>Operations</h3> 1181 * <dl> 1182 * <dt><b>Insert</b></dt> 1183 * <dd>A Contact cannot be created explicitly. When a raw contact is 1184 * inserted, the provider will first try to find a Contact representing the 1185 * same person. If one is found, the raw contact's 1186 * {@link RawContacts#CONTACT_ID} column gets the _ID of the aggregate 1187 * Contact. If no match is found, the provider automatically inserts a new 1188 * Contact and puts its _ID into the {@link RawContacts#CONTACT_ID} column 1189 * of the newly inserted raw contact.</dd> 1190 * <dt><b>Update</b></dt> 1191 * <dd>Only certain columns of Contact are modifiable: 1192 * {@link #TIMES_CONTACTED}, {@link #LAST_TIME_CONTACTED}, {@link #STARRED}, 1193 * {@link #CUSTOM_RINGTONE}, {@link #SEND_TO_VOICEMAIL}. Changing any of 1194 * these columns on the Contact also changes them on all constituent raw 1195 * contacts.</dd> 1196 * <dt><b>Delete</b></dt> 1197 * <dd>Be careful with deleting Contacts! Deleting an aggregate contact 1198 * deletes all constituent raw contacts. The corresponding sync adapters 1199 * will notice the deletions of their respective raw contacts and remove 1200 * them from their back end storage.</dd> 1201 * <dt><b>Query</b></dt> 1202 * <dd> 1203 * <ul> 1204 * <li>If you need to read an individual contact, consider using 1205 * {@link #CONTENT_LOOKUP_URI} instead of {@link #CONTENT_URI}.</li> 1206 * <li>If you need to look up a contact by the phone number, use 1207 * {@link PhoneLookup#CONTENT_FILTER_URI PhoneLookup.CONTENT_FILTER_URI}, 1208 * which is optimized for this purpose.</li> 1209 * <li>If you need to look up a contact by partial name, e.g. to produce 1210 * filter-as-you-type suggestions, use the {@link #CONTENT_FILTER_URI} URI. 1211 * <li>If you need to look up a contact by some data element like email 1212 * address, nickname, etc, use a query against the {@link ContactsContract.Data} table. 1213 * The result will contain contact ID, name etc. 1214 * </ul> 1215 * </dd> 1216 * </dl> 1217 * <h2>Columns</h2> 1218 * <table class="jd-sumtable"> 1219 * <tr> 1220 * <th colspan='4'>Contacts</th> 1221 * </tr> 1222 * <tr> 1223 * <td>long</td> 1224 * <td>{@link #_ID}</td> 1225 * <td>read-only</td> 1226 * <td>Row ID. Consider using {@link #LOOKUP_KEY} instead.</td> 1227 * </tr> 1228 * <tr> 1229 * <td>String</td> 1230 * <td>{@link #LOOKUP_KEY}</td> 1231 * <td>read-only</td> 1232 * <td>An opaque value that contains hints on how to find the contact if its 1233 * row id changed as a result of a sync or aggregation.</td> 1234 * </tr> 1235 * <tr> 1236 * <td>long</td> 1237 * <td>NAME_RAW_CONTACT_ID</td> 1238 * <td>read-only</td> 1239 * <td>The ID of the raw contact that contributes the display name 1240 * to the aggregate contact. During aggregation one of the constituent 1241 * raw contacts is chosen using a heuristic: a longer name or a name 1242 * with more diacritic marks or more upper case characters is chosen.</td> 1243 * </tr> 1244 * <tr> 1245 * <td>String</td> 1246 * <td>DISPLAY_NAME_PRIMARY</td> 1247 * <td>read-only</td> 1248 * <td>The display name for the contact. It is the display name 1249 * contributed by the raw contact referred to by the NAME_RAW_CONTACT_ID 1250 * column.</td> 1251 * </tr> 1252 * <tr> 1253 * <td>long</td> 1254 * <td>{@link #PHOTO_ID}</td> 1255 * <td>read-only</td> 1256 * <td>Reference to the row in the {@link ContactsContract.Data} table holding the photo. 1257 * That row has the mime type 1258 * {@link CommonDataKinds.Photo#CONTENT_ITEM_TYPE}. The value of this field 1259 * is computed automatically based on the 1260 * {@link CommonDataKinds.Photo#IS_SUPER_PRIMARY} field of the data rows of 1261 * that mime type.</td> 1262 * </tr> 1263 * <tr> 1264 * <td>long</td> 1265 * <td>{@link #PHOTO_URI}</td> 1266 * <td>read-only</td> 1267 * <td>A URI that can be used to retrieve the contact's full-size photo. This 1268 * column is the preferred method of retrieving the contact photo.</td> 1269 * </tr> 1270 * <tr> 1271 * <td>long</td> 1272 * <td>{@link #PHOTO_THUMBNAIL_URI}</td> 1273 * <td>read-only</td> 1274 * <td>A URI that can be used to retrieve the thumbnail of contact's photo. This 1275 * column is the preferred method of retrieving the contact photo.</td> 1276 * </tr> 1277 * <tr> 1278 * <td>int</td> 1279 * <td>{@link #IN_VISIBLE_GROUP}</td> 1280 * <td>read-only</td> 1281 * <td>An indicator of whether this contact is supposed to be visible in the 1282 * UI. "1" if the contact has at least one raw contact that belongs to a 1283 * visible group; "0" otherwise.</td> 1284 * </tr> 1285 * <tr> 1286 * <td>int</td> 1287 * <td>{@link #HAS_PHONE_NUMBER}</td> 1288 * <td>read-only</td> 1289 * <td>An indicator of whether this contact has at least one phone number. 1290 * "1" if there is at least one phone number, "0" otherwise.</td> 1291 * </tr> 1292 * <tr> 1293 * <td>int</td> 1294 * <td>{@link #TIMES_CONTACTED}</td> 1295 * <td>read/write</td> 1296 * <td>The number of times the contact has been contacted. See 1297 * {@link #markAsContacted}. When raw contacts are aggregated, this field is 1298 * computed automatically as the maximum number of times contacted among all 1299 * constituent raw contacts. Setting this field automatically changes the 1300 * corresponding field on all constituent raw contacts.</td> 1301 * </tr> 1302 * <tr> 1303 * <td>long</td> 1304 * <td>{@link #LAST_TIME_CONTACTED}</td> 1305 * <td>read/write</td> 1306 * <td>The timestamp of the last time the contact was contacted. See 1307 * {@link #markAsContacted}. Setting this field also automatically 1308 * increments {@link #TIMES_CONTACTED}. When raw contacts are aggregated, 1309 * this field is computed automatically as the latest time contacted of all 1310 * constituent raw contacts. Setting this field automatically changes the 1311 * corresponding field on all constituent raw contacts.</td> 1312 * </tr> 1313 * <tr> 1314 * <td>int</td> 1315 * <td>{@link #STARRED}</td> 1316 * <td>read/write</td> 1317 * <td>An indicator for favorite contacts: '1' if favorite, '0' otherwise. 1318 * When raw contacts are aggregated, this field is automatically computed: 1319 * if any constituent raw contacts are starred, then this field is set to 1320 * '1'. Setting this field automatically changes the corresponding field on 1321 * all constituent raw contacts.</td> 1322 * </tr> 1323 * <tr> 1324 * <td>String</td> 1325 * <td>{@link #CUSTOM_RINGTONE}</td> 1326 * <td>read/write</td> 1327 * <td>A custom ringtone associated with a contact. Typically this is the 1328 * URI returned by an activity launched with the 1329 * {@link android.media.RingtoneManager#ACTION_RINGTONE_PICKER} intent.</td> 1330 * </tr> 1331 * <tr> 1332 * <td>int</td> 1333 * <td>{@link #SEND_TO_VOICEMAIL}</td> 1334 * <td>read/write</td> 1335 * <td>An indicator of whether calls from this contact should be forwarded 1336 * directly to voice mail ('1') or not ('0'). When raw contacts are 1337 * aggregated, this field is automatically computed: if <i>all</i> 1338 * constituent raw contacts have SEND_TO_VOICEMAIL=1, then this field is set 1339 * to '1'. Setting this field automatically changes the corresponding field 1340 * on all constituent raw contacts.</td> 1341 * </tr> 1342 * <tr> 1343 * <td>int</td> 1344 * <td>{@link #CONTACT_PRESENCE}</td> 1345 * <td>read-only</td> 1346 * <td>Contact IM presence status. See {@link StatusUpdates} for individual 1347 * status definitions. Automatically computed as the highest presence of all 1348 * constituent raw contacts. The provider may choose not to store this value 1349 * in persistent storage. The expectation is that presence status will be 1350 * updated on a regular basic.</td> 1351 * </tr> 1352 * <tr> 1353 * <td>String</td> 1354 * <td>{@link #CONTACT_STATUS}</td> 1355 * <td>read-only</td> 1356 * <td>Contact's latest status update. Automatically computed as the latest 1357 * of all constituent raw contacts' status updates.</td> 1358 * </tr> 1359 * <tr> 1360 * <td>long</td> 1361 * <td>{@link #CONTACT_STATUS_TIMESTAMP}</td> 1362 * <td>read-only</td> 1363 * <td>The absolute time in milliseconds when the latest status was 1364 * inserted/updated.</td> 1365 * </tr> 1366 * <tr> 1367 * <td>String</td> 1368 * <td>{@link #CONTACT_STATUS_RES_PACKAGE}</td> 1369 * <td>read-only</td> 1370 * <td> The package containing resources for this status: label and icon.</td> 1371 * </tr> 1372 * <tr> 1373 * <td>long</td> 1374 * <td>{@link #CONTACT_STATUS_LABEL}</td> 1375 * <td>read-only</td> 1376 * <td>The resource ID of the label describing the source of contact status, 1377 * e.g. "Google Talk". This resource is scoped by the 1378 * {@link #CONTACT_STATUS_RES_PACKAGE}.</td> 1379 * </tr> 1380 * <tr> 1381 * <td>long</td> 1382 * <td>{@link #CONTACT_STATUS_ICON}</td> 1383 * <td>read-only</td> 1384 * <td>The resource ID of the icon for the source of contact status. This 1385 * resource is scoped by the {@link #CONTACT_STATUS_RES_PACKAGE}.</td> 1386 * </tr> 1387 * </table> 1388 */ 1389 public static class Contacts implements BaseColumns, ContactsColumns, 1390 ContactOptionsColumns, ContactNameColumns, ContactStatusColumns { 1391 /** 1392 * This utility class cannot be instantiated 1393 */ 1394 private Contacts() {} 1395 1396 /** 1397 * The content:// style URI for this table 1398 */ 1399 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "contacts"); 1400 1401 /** 1402 * A content:// style URI for this table that should be used to create 1403 * shortcuts or otherwise create long-term links to contacts. This URI 1404 * should always be followed by a "/" and the contact's {@link #LOOKUP_KEY}. 1405 * It can optionally also have a "/" and last known contact ID appended after 1406 * that. This "complete" format is an important optimization and is highly recommended. 1407 * <p> 1408 * As long as the contact's row ID remains the same, this URI is 1409 * equivalent to {@link #CONTENT_URI}. If the contact's row ID changes 1410 * as a result of a sync or aggregation, this URI will look up the 1411 * contact using indirect information (sync IDs or constituent raw 1412 * contacts). 1413 * <p> 1414 * Lookup key should be appended unencoded - it is stored in the encoded 1415 * form, ready for use in a URI. 1416 */ 1417 public static final Uri CONTENT_LOOKUP_URI = Uri.withAppendedPath(CONTENT_URI, 1418 "lookup"); 1419 1420 /** 1421 * Base {@link Uri} for referencing a single {@link Contacts} entry, 1422 * created by appending {@link #LOOKUP_KEY} using 1423 * {@link Uri#withAppendedPath(Uri, String)}. Provides 1424 * {@link OpenableColumns} columns when queried, or returns the 1425 * referenced contact formatted as a vCard when opened through 1426 * {@link ContentResolver#openAssetFileDescriptor(Uri, String)}. 1427 */ 1428 public static final Uri CONTENT_VCARD_URI = Uri.withAppendedPath(CONTENT_URI, 1429 "as_vcard"); 1430 1431 /** 1432 * Boolean parameter that may be used with {@link #CONTENT_VCARD_URI} 1433 * and {@link #CONTENT_MULTI_VCARD_URI} to indicate that the returned 1434 * vcard should not contain a photo. 1435 * 1436 * @hide 1437 */ 1438 public static final String QUERY_PARAMETER_VCARD_NO_PHOTO = "nophoto"; 1439 1440 /** 1441 * Base {@link Uri} for referencing multiple {@link Contacts} entry, 1442 * created by appending {@link #LOOKUP_KEY} using 1443 * {@link Uri#withAppendedPath(Uri, String)}. The lookup keys have to be 1444 * encoded and joined with the colon (":") separator. The resulting string 1445 * has to be encoded again. Provides 1446 * {@link OpenableColumns} columns when queried, or returns the 1447 * referenced contact formatted as a vCard when opened through 1448 * {@link ContentResolver#openAssetFileDescriptor(Uri, String)}. 1449 * 1450 * This is private API because we do not have a well-defined way to 1451 * specify several entities yet. The format of this Uri might change in the future 1452 * or the Uri might be completely removed. 1453 * 1454 * @hide 1455 */ 1456 public static final Uri CONTENT_MULTI_VCARD_URI = Uri.withAppendedPath(CONTENT_URI, 1457 "as_multi_vcard"); 1458 1459 /** 1460 * Builds a {@link #CONTENT_LOOKUP_URI} style {@link Uri} describing the 1461 * requested {@link Contacts} entry. 1462 * 1463 * @param contactUri A {@link #CONTENT_URI} row, or an existing 1464 * {@link #CONTENT_LOOKUP_URI} to attempt refreshing. 1465 */ 1466 public static Uri getLookupUri(ContentResolver resolver, Uri contactUri) { 1467 final Cursor c = resolver.query(contactUri, new String[] { 1468 Contacts.LOOKUP_KEY, Contacts._ID 1469 }, null, null, null); 1470 if (c == null) { 1471 return null; 1472 } 1473 1474 try { 1475 if (c.moveToFirst()) { 1476 final String lookupKey = c.getString(0); 1477 final long contactId = c.getLong(1); 1478 return getLookupUri(contactId, lookupKey); 1479 } 1480 } finally { 1481 c.close(); 1482 } 1483 return null; 1484 } 1485 1486 /** 1487 * Build a {@link #CONTENT_LOOKUP_URI} lookup {@link Uri} using the 1488 * given {@link ContactsContract.Contacts#_ID} and {@link #LOOKUP_KEY}. 1489 */ 1490 public static Uri getLookupUri(long contactId, String lookupKey) { 1491 return ContentUris.withAppendedId(Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, 1492 lookupKey), contactId); 1493 } 1494 1495 /** 1496 * Computes a content URI (see {@link #CONTENT_URI}) given a lookup URI. 1497 * <p> 1498 * Returns null if the contact cannot be found. 1499 */ 1500 public static Uri lookupContact(ContentResolver resolver, Uri lookupUri) { 1501 if (lookupUri == null) { 1502 return null; 1503 } 1504 1505 Cursor c = resolver.query(lookupUri, new String[]{Contacts._ID}, null, null, null); 1506 if (c == null) { 1507 return null; 1508 } 1509 1510 try { 1511 if (c.moveToFirst()) { 1512 long contactId = c.getLong(0); 1513 return ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId); 1514 } 1515 } finally { 1516 c.close(); 1517 } 1518 return null; 1519 } 1520 1521 /** 1522 * Mark a contact as having been contacted. Updates two fields: 1523 * {@link #TIMES_CONTACTED} and {@link #LAST_TIME_CONTACTED}. The 1524 * TIMES_CONTACTED field is incremented by 1 and the LAST_TIME_CONTACTED 1525 * field is populated with the current system time. 1526 * 1527 * @param resolver the ContentResolver to use 1528 * @param contactId the person who was contacted 1529 */ 1530 public static void markAsContacted(ContentResolver resolver, long contactId) { 1531 Uri uri = ContentUris.withAppendedId(CONTENT_URI, contactId); 1532 ContentValues values = new ContentValues(); 1533 // TIMES_CONTACTED will be incremented when LAST_TIME_CONTACTED is modified. 1534 values.put(LAST_TIME_CONTACTED, System.currentTimeMillis()); 1535 resolver.update(uri, values, null, null); 1536 } 1537 1538 /** 1539 * The content:// style URI used for "type-to-filter" functionality on the 1540 * {@link #CONTENT_URI} URI. The filter string will be used to match 1541 * various parts of the contact name. The filter argument should be passed 1542 * as an additional path segment after this URI. 1543 */ 1544 public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath( 1545 CONTENT_URI, "filter"); 1546 1547 /** 1548 * The content:// style URI for this table joined with useful data from 1549 * {@link ContactsContract.Data}, filtered to include only starred contacts 1550 * and the most frequently contacted contacts. 1551 */ 1552 public static final Uri CONTENT_STREQUENT_URI = Uri.withAppendedPath( 1553 CONTENT_URI, "strequent"); 1554 1555 /** 1556 * The content:// style URI for showing frequently contacted person listing. 1557 * @hide 1558 */ 1559 public static final Uri CONTENT_FREQUENT_URI = Uri.withAppendedPath( 1560 CONTENT_URI, "frequent"); 1561 1562 /** 1563 * The content:// style URI used for "type-to-filter" functionality on the 1564 * {@link #CONTENT_STREQUENT_URI} URI. The filter string will be used to match 1565 * various parts of the contact name. The filter argument should be passed 1566 * as an additional path segment after this URI. 1567 */ 1568 public static final Uri CONTENT_STREQUENT_FILTER_URI = Uri.withAppendedPath( 1569 CONTENT_STREQUENT_URI, "filter"); 1570 1571 public static final Uri CONTENT_GROUP_URI = Uri.withAppendedPath( 1572 CONTENT_URI, "group"); 1573 1574 /** 1575 * The MIME type of {@link #CONTENT_URI} providing a directory of 1576 * people. 1577 */ 1578 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/contact"; 1579 1580 /** 1581 * The MIME type of a {@link #CONTENT_URI} subdirectory of a single 1582 * person. 1583 */ 1584 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact"; 1585 1586 /** 1587 * The MIME type of a {@link #CONTENT_URI} subdirectory of a single 1588 * person. 1589 */ 1590 public static final String CONTENT_VCARD_TYPE = "text/x-vcard"; 1591 1592 /** 1593 * A sub-directory of a single contact that contains all of the constituent raw contact 1594 * {@link ContactsContract.Data} rows. This directory can be used either 1595 * with a {@link #CONTENT_URI} or {@link #CONTENT_LOOKUP_URI}. 1596 */ 1597 public static final class Data implements BaseColumns, DataColumns { 1598 /** 1599 * no public constructor since this is a utility class 1600 */ 1601 private Data() {} 1602 1603 /** 1604 * The directory twig for this sub-table 1605 */ 1606 public static final String CONTENT_DIRECTORY = "data"; 1607 } 1608 1609 /** 1610 * <p> 1611 * A sub-directory of a contact that contains all of its 1612 * {@link ContactsContract.RawContacts} as well as 1613 * {@link ContactsContract.Data} rows. To access this directory append 1614 * {@link #CONTENT_DIRECTORY} to the contact URI. 1615 * </p> 1616 * <p> 1617 * Entity has three ID fields: {@link #CONTACT_ID} for the contact, 1618 * {@link #RAW_CONTACT_ID} for the raw contact and {@link #DATA_ID} for 1619 * the data rows. Entity always contains at least one row per 1620 * constituent raw contact, even if there are no actual data rows. In 1621 * this case the {@link #DATA_ID} field will be null. 1622 * </p> 1623 * <p> 1624 * Entity reads all data for the entire contact in one transaction, to 1625 * guarantee consistency. There is significant data duplication 1626 * in the Entity (each row repeats all Contact columns and all RawContact 1627 * columns), so the benefits of transactional consistency should be weighed 1628 * against the cost of transferring large amounts of denormalized data 1629 * from the Provider. 1630 * </p> 1631 * <p> 1632 * To reduce the amount of data duplication the contacts provider and directory 1633 * providers implementing this protocol are allowed to provide common Contacts 1634 * and RawContacts fields in the first row returned for each raw contact only and 1635 * leave them as null in subsequent rows. 1636 * </p> 1637 */ 1638 public static final class Entity implements BaseColumns, ContactsColumns, 1639 ContactNameColumns, RawContactsColumns, BaseSyncColumns, SyncColumns, DataColumns, 1640 StatusColumns, ContactOptionsColumns, ContactStatusColumns { 1641 /** 1642 * no public constructor since this is a utility class 1643 */ 1644 private Entity() { 1645 } 1646 1647 /** 1648 * The directory twig for this sub-table 1649 */ 1650 public static final String CONTENT_DIRECTORY = "entities"; 1651 1652 /** 1653 * The ID of the raw contact row. 1654 * <P>Type: INTEGER</P> 1655 */ 1656 public static final String RAW_CONTACT_ID = "raw_contact_id"; 1657 1658 /** 1659 * The ID of the data row. The value will be null if this raw contact has no 1660 * data rows. 1661 * <P>Type: INTEGER</P> 1662 */ 1663 public static final String DATA_ID = "data_id"; 1664 } 1665 1666 /** 1667 * <p> 1668 * A sub-directory of a single contact that contains all of the constituent raw contact 1669 * {@link ContactsContract.StreamItems} rows. This directory can be used either 1670 * with a {@link #CONTENT_URI} or {@link #CONTENT_LOOKUP_URI}. 1671 * </p> 1672 * <p> 1673 * Querying for social stream data requires android.permission.READ_SOCIAL_STREAM 1674 * permission. 1675 * </p> 1676 * @hide 1677 */ 1678 public static final class StreamItems implements StreamItemsColumns { 1679 /** 1680 * no public constructor since this is a utility class 1681 */ 1682 private StreamItems() {} 1683 1684 /** 1685 * The directory twig for this sub-table 1686 */ 1687 public static final String CONTENT_DIRECTORY = "stream_items"; 1688 } 1689 1690 /** 1691 * <p> 1692 * A <i>read-only</i> sub-directory of a single contact aggregate that 1693 * contains all aggregation suggestions (other contacts). The 1694 * aggregation suggestions are computed based on approximate data 1695 * matches with this contact. 1696 * </p> 1697 * <p> 1698 * <i>Note: this query may be expensive! If you need to use it in bulk, 1699 * make sure the user experience is acceptable when the query runs for a 1700 * long time.</i> 1701 * <p> 1702 * Usage example: 1703 * 1704 * <pre> 1705 * Uri uri = Contacts.CONTENT_URI.buildUpon() 1706 * .appendEncodedPath(String.valueOf(contactId)) 1707 * .appendPath(Contacts.AggregationSuggestions.CONTENT_DIRECTORY) 1708 * .appendQueryParameter("limit", "3") 1709 * .build() 1710 * Cursor cursor = getContentResolver().query(suggestionsUri, 1711 * new String[] {Contacts.DISPLAY_NAME, Contacts._ID, Contacts.LOOKUP_KEY}, 1712 * null, null, null); 1713 * </pre> 1714 * 1715 * </p> 1716 * <p> 1717 * This directory can be used either with a {@link #CONTENT_URI} or 1718 * {@link #CONTENT_LOOKUP_URI}. 1719 * </p> 1720 */ 1721 public static final class AggregationSuggestions implements BaseColumns, ContactsColumns, 1722 ContactOptionsColumns, ContactStatusColumns { 1723 /** 1724 * No public constructor since this is a utility class 1725 */ 1726 private AggregationSuggestions() {} 1727 1728 /** 1729 * The directory twig for this sub-table. The URI can be followed by an optional 1730 * type-to-filter, similar to 1731 * {@link android.provider.ContactsContract.Contacts#CONTENT_FILTER_URI}. 1732 */ 1733 public static final String CONTENT_DIRECTORY = "suggestions"; 1734 1735 /** 1736 * Used with {@link Builder#addParameter} to specify what kind of data is 1737 * supplied for the suggestion query. 1738 * 1739 * @hide 1740 */ 1741 public static final String PARAMETER_MATCH_NAME = "name"; 1742 1743 /** 1744 * Used with {@link Builder#addParameter} to specify what kind of data is 1745 * supplied for the suggestion query. 1746 * 1747 * @hide 1748 */ 1749 public static final String PARAMETER_MATCH_EMAIL = "email"; 1750 1751 /** 1752 * Used with {@link Builder#addParameter} to specify what kind of data is 1753 * supplied for the suggestion query. 1754 * 1755 * @hide 1756 */ 1757 public static final String PARAMETER_MATCH_PHONE = "phone"; 1758 1759 /** 1760 * Used with {@link Builder#addParameter} to specify what kind of data is 1761 * supplied for the suggestion query. 1762 * 1763 * @hide 1764 */ 1765 public static final String PARAMETER_MATCH_NICKNAME = "nickname"; 1766 1767 /** 1768 * A convenience builder for aggregation suggestion content URIs. 1769 * 1770 * TODO: change documentation for this class to use the builder. 1771 * @hide 1772 */ 1773 public static final class Builder { 1774 private long mContactId; 1775 private ArrayList<String> mKinds = new ArrayList<String>(); 1776 private ArrayList<String> mValues = new ArrayList<String>(); 1777 private int mLimit; 1778 1779 /** 1780 * Optional existing contact ID. If it is not provided, the search 1781 * will be based exclusively on the values supplied with {@link #addParameter}. 1782 */ 1783 public Builder setContactId(long contactId) { 1784 this.mContactId = contactId; 1785 return this; 1786 } 1787 1788 /** 1789 * A value that can be used when searching for an aggregation 1790 * suggestion. 1791 * 1792 * @param kind can be one of 1793 * {@link AggregationSuggestions#PARAMETER_MATCH_NAME}, 1794 * {@link AggregationSuggestions#PARAMETER_MATCH_EMAIL}, 1795 * {@link AggregationSuggestions#PARAMETER_MATCH_NICKNAME}, 1796 * {@link AggregationSuggestions#PARAMETER_MATCH_PHONE} 1797 */ 1798 public Builder addParameter(String kind, String value) { 1799 if (!TextUtils.isEmpty(value)) { 1800 mKinds.add(kind); 1801 mValues.add(value); 1802 } 1803 return this; 1804 } 1805 1806 public Builder setLimit(int limit) { 1807 mLimit = limit; 1808 return this; 1809 } 1810 1811 public Uri build() { 1812 android.net.Uri.Builder builder = Contacts.CONTENT_URI.buildUpon(); 1813 builder.appendEncodedPath(String.valueOf(mContactId)); 1814 builder.appendPath(Contacts.AggregationSuggestions.CONTENT_DIRECTORY); 1815 if (mLimit != 0) { 1816 builder.appendQueryParameter("limit", String.valueOf(mLimit)); 1817 } 1818 1819 int count = mKinds.size(); 1820 for (int i = 0; i < count; i++) { 1821 builder.appendQueryParameter("query", mKinds.get(i) + ":" + mValues.get(i)); 1822 } 1823 1824 return builder.build(); 1825 } 1826 } 1827 1828 /** 1829 * @hide 1830 */ 1831 public static final Builder builder() { 1832 return new Builder(); 1833 } 1834 } 1835 1836 /** 1837 * A <i>read-only</i> sub-directory of a single contact that contains 1838 * the contact's primary photo. The photo may be stored in up to two ways - 1839 * the default "photo" is a thumbnail-sized image stored directly in the data 1840 * row, while the "display photo", if present, is a larger version stored as 1841 * a file. 1842 * <p> 1843 * Usage example: 1844 * <dl> 1845 * <dt>Retrieving the thumbnail-sized photo</dt> 1846 * <dd> 1847 * <pre> 1848 * public InputStream openPhoto(long contactId) { 1849 * Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId); 1850 * Uri photoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.CONTENT_DIRECTORY); 1851 * Cursor cursor = getContentResolver().query(photoUri, 1852 * new String[] {Contacts.Photo.PHOTO}, null, null, null); 1853 * if (cursor == null) { 1854 * return null; 1855 * } 1856 * try { 1857 * if (cursor.moveToFirst()) { 1858 * byte[] data = cursor.getBlob(0); 1859 * if (data != null) { 1860 * return new ByteArrayInputStream(data); 1861 * } 1862 * } 1863 * } finally { 1864 * cursor.close(); 1865 * } 1866 * return null; 1867 * } 1868 * </pre> 1869 * </dd> 1870 * <dt>Retrieving the larger photo version</dt> 1871 * <dd> 1872 * <pre> 1873 * public InputStream openDisplayPhoto(long contactId) { 1874 * Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId); 1875 * Uri displayPhotoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.DISPLAY_PHOTO); 1876 * try { 1877 * AssetFileDescriptor fd = 1878 * getContentResolver().openAssetFileDescriptor(displayPhotoUri, "r"); 1879 * return fd.createInputStream(); 1880 * } catch (IOException e) { 1881 * return null; 1882 * } 1883 * } 1884 * </pre> 1885 * </dd> 1886 * </dl> 1887 * 1888 * </p> 1889 * <p>You may also consider using the convenience method 1890 * {@link ContactsContract.Contacts#openContactPhotoInputStream(ContentResolver, Uri, boolean)} 1891 * to retrieve the raw photo contents of either the thumbnail-sized or the full-sized photo. 1892 * </p> 1893 * <p> 1894 * This directory can be used either with a {@link #CONTENT_URI} or 1895 * {@link #CONTENT_LOOKUP_URI}. 1896 * </p> 1897 */ 1898 public static final class Photo implements BaseColumns, DataColumnsWithJoins { 1899 /** 1900 * no public constructor since this is a utility class 1901 */ 1902 private Photo() {} 1903 1904 /** 1905 * The directory twig for this sub-table 1906 */ 1907 public static final String CONTENT_DIRECTORY = "photo"; 1908 1909 /** 1910 * The directory twig for retrieving the full-size display photo. 1911 */ 1912 public static final String DISPLAY_PHOTO = "display_photo"; 1913 1914 /** 1915 * Full-size photo file ID of the raw contact. 1916 * See {@link ContactsContract.DisplayPhoto}. 1917 * <p> 1918 * Type: NUMBER 1919 */ 1920 public static final String PHOTO_FILE_ID = DATA14; 1921 1922 /** 1923 * Thumbnail photo of the raw contact. This is the raw bytes of an image 1924 * that could be inflated using {@link android.graphics.BitmapFactory}. 1925 * <p> 1926 * Type: BLOB 1927 */ 1928 public static final String PHOTO = DATA15; 1929 } 1930 1931 /** 1932 * Opens an InputStream for the contacts's photo and returns the 1933 * photo as a byte stream. 1934 * @param cr The content resolver to use for querying 1935 * @param contactUri the contact whose photo should be used. This can be used with 1936 * either a {@link #CONTENT_URI} or a {@link #CONTENT_LOOKUP_URI} URI. 1937 * @param preferHighres If this is true and the contact has a higher resolution photo 1938 * available, it is returned. If false, this function always tries to get the thumbnail 1939 * @return an InputStream of the photo, or null if no photo is present 1940 */ 1941 public static InputStream openContactPhotoInputStream(ContentResolver cr, Uri contactUri, 1942 boolean preferHighres) { 1943 if (preferHighres) { 1944 final Uri displayPhotoUri = Uri.withAppendedPath(contactUri, 1945 Contacts.Photo.DISPLAY_PHOTO); 1946 InputStream inputStream; 1947 try { 1948 AssetFileDescriptor fd = cr.openAssetFileDescriptor(displayPhotoUri, "r"); 1949 return fd.createInputStream(); 1950 } catch (IOException e) { 1951 // fallback to the thumbnail code 1952 } 1953 } 1954 1955 Uri photoUri = Uri.withAppendedPath(contactUri, Photo.CONTENT_DIRECTORY); 1956 if (photoUri == null) { 1957 return null; 1958 } 1959 Cursor cursor = cr.query(photoUri, 1960 new String[] { 1961 ContactsContract.CommonDataKinds.Photo.PHOTO 1962 }, null, null, null); 1963 try { 1964 if (cursor == null || !cursor.moveToNext()) { 1965 return null; 1966 } 1967 byte[] data = cursor.getBlob(0); 1968 if (data == null) { 1969 return null; 1970 } 1971 return new ByteArrayInputStream(data); 1972 } finally { 1973 if (cursor != null) { 1974 cursor.close(); 1975 } 1976 } 1977 } 1978 1979 /** 1980 * Opens an InputStream for the contacts's thumbnail photo and returns the 1981 * photo as a byte stream. 1982 * @param cr The content resolver to use for querying 1983 * @param contactUri the contact whose photo should be used. This can be used with 1984 * either a {@link #CONTENT_URI} or a {@link #CONTENT_LOOKUP_URI} URI. 1985 * @return an InputStream of the photo, or null if no photo is present 1986 * @see #openContactPhotoInputStream(ContentResolver, Uri, boolean), if instead 1987 * of the thumbnail the high-res picture is preferred 1988 */ 1989 public static InputStream openContactPhotoInputStream(ContentResolver cr, Uri contactUri) { 1990 return openContactPhotoInputStream(cr, contactUri, false); 1991 } 1992 } 1993 1994 /** 1995 * <p> 1996 * Constants for the user's profile data, which is represented as a single contact on 1997 * the device that represents the user. The profile contact is not aggregated 1998 * together automatically in the same way that normal contacts are; instead, each 1999 * account (including data set, if applicable) on the device may contribute a single 2000 * raw contact representing the user's personal profile data from that source. 2001 * </p> 2002 * <p> 2003 * Access to the profile entry through these URIs (or incidental access to parts of 2004 * the profile if retrieved directly via ID) requires additional permissions beyond 2005 * the read/write contact permissions required by the provider. Querying for profile 2006 * data requires android.permission.READ_PROFILE permission, and inserting or 2007 * updating profile data requires android.permission.WRITE_PROFILE permission. 2008 * </p> 2009 * <h3>Operations</h3> 2010 * <dl> 2011 * <dt><b>Insert</b></dt> 2012 * <dd>The user's profile entry cannot be created explicitly (attempting to do so 2013 * will throw an exception). When a raw contact is inserted into the profile, the 2014 * provider will check for the existence of a profile on the device. If one is 2015 * found, the raw contact's {@link RawContacts#CONTACT_ID} column gets the _ID of 2016 * the profile Contact. If no match is found, the profile Contact is created and 2017 * its _ID is put into the {@link RawContacts#CONTACT_ID} column of the newly 2018 * inserted raw contact.</dd> 2019 * <dt><b>Update</b></dt> 2020 * <dd>The profile Contact has the same update restrictions as Contacts in general, 2021 * but requires the android.permission.WRITE_PROFILE permission.</dd> 2022 * <dt><b>Delete</b></dt> 2023 * <dd>The profile Contact cannot be explicitly deleted. It will be removed 2024 * automatically if all of its constituent raw contact entries are deleted.</dd> 2025 * <dt><b>Query</b></dt> 2026 * <dd> 2027 * <ul> 2028 * <li>The {@link #CONTENT_URI} for profiles behaves in much the same way as 2029 * retrieving a contact by ID, except that it will only ever return the user's 2030 * profile contact. 2031 * </li> 2032 * <li> 2033 * The profile contact supports all of the same sub-paths as an individual contact 2034 * does - the content of the profile contact can be retrieved as entities or 2035 * data rows. Similarly, specific raw contact entries can be retrieved by appending 2036 * the desired raw contact ID within the profile. 2037 * </li> 2038 * </ul> 2039 * </dd> 2040 * </dl> 2041 */ 2042 public static final class Profile implements BaseColumns, ContactsColumns, 2043 ContactOptionsColumns, ContactNameColumns, ContactStatusColumns { 2044 /** 2045 * This utility class cannot be instantiated 2046 */ 2047 private Profile() { 2048 } 2049 2050 /** 2051 * The content:// style URI for this table, which requests the contact entry 2052 * representing the user's personal profile data. 2053 */ 2054 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "profile"); 2055 2056 /** 2057 * {@link Uri} for referencing the user's profile {@link Contacts} entry, 2058 * Provides {@link OpenableColumns} columns when queried, or returns the 2059 * user's profile contact formatted as a vCard when opened through 2060 * {@link ContentResolver#openAssetFileDescriptor(Uri, String)}. 2061 */ 2062 public static final Uri CONTENT_VCARD_URI = Uri.withAppendedPath(CONTENT_URI, 2063 "as_vcard"); 2064 2065 /** 2066 * {@link Uri} for referencing the raw contacts that make up the user's profile 2067 * {@link Contacts} entry. An individual raw contact entry within the profile 2068 * can be addressed by appending the raw contact ID. The entities or data within 2069 * that specific raw contact can be requested by appending the entity or data 2070 * path as well. 2071 */ 2072 public static final Uri CONTENT_RAW_CONTACTS_URI = Uri.withAppendedPath(CONTENT_URI, 2073 "raw_contacts"); 2074 2075 /** 2076 * The minimum ID for any entity that belongs to the profile. This essentially 2077 * defines an ID-space in which profile data is stored, and is used by the provider 2078 * to determine whether a request via a non-profile-specific URI should be directed 2079 * to the profile data rather than general contacts data, along with all the special 2080 * permission checks that entails. 2081 * 2082 * Callers may use {@link #isProfileId} to check whether a specific ID falls into 2083 * the set of data intended for the profile. 2084 */ 2085 public static final long MIN_ID = Long.MAX_VALUE - (long) Integer.MAX_VALUE; 2086 } 2087 2088 /** 2089 * This method can be used to identify whether the given ID is associated with profile 2090 * data. It does not necessarily indicate that the ID is tied to valid data, merely 2091 * that accessing data using this ID will result in profile access checks and will only 2092 * return data from the profile. 2093 * 2094 * @param id The ID to check. 2095 * @return Whether the ID is associated with profile data. 2096 */ 2097 public static boolean isProfileId(long id) { 2098 return id >= Profile.MIN_ID; 2099 } 2100 2101 protected interface RawContactsColumns { 2102 /** 2103 * A reference to the {@link ContactsContract.Contacts#_ID} that this 2104 * data belongs to. 2105 * <P>Type: INTEGER</P> 2106 */ 2107 public static final String CONTACT_ID = "contact_id"; 2108 2109 /** 2110 * The data set within the account that this row belongs to. This allows 2111 * multiple sync adapters for the same account type to distinguish between 2112 * each others' data. 2113 * 2114 * This is empty by default, and is completely optional. It only needs to 2115 * be populated if multiple sync adapters are entering distinct data for 2116 * the same account type and account name. 2117 * <P>Type: TEXT</P> 2118 */ 2119 public static final String DATA_SET = "data_set"; 2120 2121 /** 2122 * A concatenation of the account type and data set (delimited by a forward 2123 * slash) - if the data set is empty, this will be the same as the account 2124 * type. For applications that need to be aware of the data set, this can 2125 * be used instead of account type to distinguish sets of data. This is 2126 * never intended to be used for specifying accounts. 2127 * @hide 2128 */ 2129 public static final String ACCOUNT_TYPE_AND_DATA_SET = "account_type_and_data_set"; 2130 2131 /** 2132 * The aggregation mode for this contact. 2133 * <P>Type: INTEGER</P> 2134 */ 2135 public static final String AGGREGATION_MODE = "aggregation_mode"; 2136 2137 /** 2138 * The "deleted" flag: "0" by default, "1" if the row has been marked 2139 * for deletion. When {@link android.content.ContentResolver#delete} is 2140 * called on a raw contact, it is marked for deletion and removed from its 2141 * aggregate contact. The sync adaptor deletes the raw contact on the server and 2142 * then calls ContactResolver.delete once more, this time passing the 2143 * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to finalize 2144 * the data removal. 2145 * <P>Type: INTEGER</P> 2146 */ 2147 public static final String DELETED = "deleted"; 2148 2149 /** 2150 * The "name_verified" flag: "1" means that the name fields on this raw 2151 * contact can be trusted and therefore should be used for the entire 2152 * aggregated contact. 2153 * <p> 2154 * If an aggregated contact contains more than one raw contact with a 2155 * verified name, one of those verified names is chosen at random. 2156 * If an aggregated contact contains no verified names, the 2157 * name is chosen randomly from the constituent raw contacts. 2158 * </p> 2159 * <p> 2160 * Updating this flag from "0" to "1" automatically resets it to "0" on 2161 * all other raw contacts in the same aggregated contact. 2162 * </p> 2163 * <p> 2164 * Sync adapters should only specify a value for this column when 2165 * inserting a raw contact and leave it out when doing an update. 2166 * </p> 2167 * <p> 2168 * The default value is "0" 2169 * </p> 2170 * <p>Type: INTEGER</p> 2171 * 2172 * @hide 2173 */ 2174 public static final String NAME_VERIFIED = "name_verified"; 2175 2176 /** 2177 * The "read-only" flag: "0" by default, "1" if the row cannot be modified or 2178 * deleted except by a sync adapter. See {@link ContactsContract#CALLER_IS_SYNCADAPTER}. 2179 * <P>Type: INTEGER</P> 2180 */ 2181 public static final String RAW_CONTACT_IS_READ_ONLY = "raw_contact_is_read_only"; 2182 2183 /** 2184 * Flag that reflects whether this raw contact belongs to the user's 2185 * personal profile entry. 2186 */ 2187 public static final String RAW_CONTACT_IS_USER_PROFILE = "raw_contact_is_user_profile"; 2188 } 2189 2190 /** 2191 * Constants for the raw contacts table, which contains one row of contact 2192 * information for each person in each synced account. Sync adapters and 2193 * contact management apps 2194 * are the primary consumers of this API. 2195 * 2196 * <h3>Aggregation</h3> 2197 * <p> 2198 * As soon as a raw contact is inserted or whenever its constituent data 2199 * changes, the provider will check if the raw contact matches other 2200 * existing raw contacts and if so will aggregate it with those. The 2201 * aggregation is reflected in the {@link RawContacts} table by the change of the 2202 * {@link #CONTACT_ID} field, which is the reference to the aggregate contact. 2203 * </p> 2204 * <p> 2205 * Changes to the structured name, organization, phone number, email address, 2206 * or nickname trigger a re-aggregation. 2207 * </p> 2208 * <p> 2209 * See also {@link AggregationExceptions} for a mechanism to control 2210 * aggregation programmatically. 2211 * </p> 2212 * 2213 * <h3>Operations</h3> 2214 * <dl> 2215 * <dt><b>Insert</b></dt> 2216 * <dd> 2217 * <p> 2218 * Raw contacts can be inserted incrementally or in a batch. 2219 * The incremental method is more traditional but less efficient. 2220 * It should be used 2221 * only if no {@link Data} values are available at the time the raw contact is created: 2222 * <pre> 2223 * ContentValues values = new ContentValues(); 2224 * values.put(RawContacts.ACCOUNT_TYPE, accountType); 2225 * values.put(RawContacts.ACCOUNT_NAME, accountName); 2226 * Uri rawContactUri = getContentResolver().insert(RawContacts.CONTENT_URI, values); 2227 * long rawContactId = ContentUris.parseId(rawContactUri); 2228 * </pre> 2229 * </p> 2230 * <p> 2231 * Once {@link Data} values become available, insert those. 2232 * For example, here's how you would insert a name: 2233 * 2234 * <pre> 2235 * values.clear(); 2236 * values.put(Data.RAW_CONTACT_ID, rawContactId); 2237 * values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE); 2238 * values.put(StructuredName.DISPLAY_NAME, "Mike Sullivan"); 2239 * getContentResolver().insert(Data.CONTENT_URI, values); 2240 * </pre> 2241 * </p> 2242 * <p> 2243 * The batch method is by far preferred. It inserts the raw contact and its 2244 * constituent data rows in a single database transaction 2245 * and causes at most one aggregation pass. 2246 * <pre> 2247 * ArrayList<ContentProviderOperation> ops = 2248 * new ArrayList<ContentProviderOperation>(); 2249 * ... 2250 * int rawContactInsertIndex = ops.size(); 2251 * ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI) 2252 * .withValue(RawContacts.ACCOUNT_TYPE, accountType) 2253 * .withValue(RawContacts.ACCOUNT_NAME, accountName) 2254 * .build()); 2255 * 2256 * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI) 2257 * .withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex) 2258 * .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE) 2259 * .withValue(StructuredName.DISPLAY_NAME, "Mike Sullivan") 2260 * .build()); 2261 * 2262 * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); 2263 * </pre> 2264 * </p> 2265 * <p> 2266 * Note the use of {@link ContentProviderOperation.Builder#withValueBackReference(String, int)} 2267 * to refer to the as-yet-unknown index value of the raw contact inserted in the 2268 * first operation. 2269 * </p> 2270 * 2271 * <dt><b>Update</b></dt> 2272 * <dd><p> 2273 * Raw contacts can be updated incrementally or in a batch. 2274 * Batch mode should be used whenever possible. 2275 * The procedures and considerations are analogous to those documented above for inserts. 2276 * </p></dd> 2277 * <dt><b>Delete</b></dt> 2278 * <dd><p>When a raw contact is deleted, all of its Data rows as well as StatusUpdates, 2279 * AggregationExceptions, PhoneLookup rows are deleted automatically. When all raw 2280 * contacts associated with a {@link Contacts} row are deleted, the {@link Contacts} row 2281 * itself is also deleted automatically. 2282 * </p> 2283 * <p> 2284 * The invocation of {@code resolver.delete(...)}, does not immediately delete 2285 * a raw contacts row. 2286 * Instead, it sets the {@link #DELETED} flag on the raw contact and 2287 * removes the raw contact from its aggregate contact. 2288 * The sync adapter then deletes the raw contact from the server and 2289 * finalizes phone-side deletion by calling {@code resolver.delete(...)} 2290 * again and passing the {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter.<p> 2291 * <p>Some sync adapters are read-only, meaning that they only sync server-side 2292 * changes to the phone, but not the reverse. If one of those raw contacts 2293 * is marked for deletion, it will remain on the phone. However it will be 2294 * effectively invisible, because it will not be part of any aggregate contact. 2295 * </dd> 2296 * 2297 * <dt><b>Query</b></dt> 2298 * <dd> 2299 * <p> 2300 * It is easy to find all raw contacts in a Contact: 2301 * <pre> 2302 * Cursor c = getContentResolver().query(RawContacts.CONTENT_URI, 2303 * new String[]{RawContacts._ID}, 2304 * RawContacts.CONTACT_ID + "=?", 2305 * new String[]{String.valueOf(contactId)}, null); 2306 * </pre> 2307 * </p> 2308 * <p> 2309 * To find raw contacts within a specific account, 2310 * you can either put the account name and type in the selection or pass them as query 2311 * parameters. The latter approach is preferable, especially when you can reuse the 2312 * URI: 2313 * <pre> 2314 * Uri rawContactUri = RawContacts.URI.buildUpon() 2315 * .appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName) 2316 * .appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType) 2317 * .build(); 2318 * Cursor c1 = getContentResolver().query(rawContactUri, 2319 * RawContacts.STARRED + "<>0", null, null, null); 2320 * ... 2321 * Cursor c2 = getContentResolver().query(rawContactUri, 2322 * RawContacts.DELETED + "<>0", null, null, null); 2323 * </pre> 2324 * </p> 2325 * <p>The best way to read a raw contact along with all the data associated with it is 2326 * by using the {@link Entity} directory. If the raw contact has data rows, 2327 * the Entity cursor will contain a row for each data row. If the raw contact has no 2328 * data rows, the cursor will still contain one row with the raw contact-level information. 2329 * <pre> 2330 * Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId); 2331 * Uri entityUri = Uri.withAppendedPath(rawContactUri, Entity.CONTENT_DIRECTORY); 2332 * Cursor c = getContentResolver().query(entityUri, 2333 * new String[]{RawContacts.SOURCE_ID, Entity.DATA_ID, Entity.MIMETYPE, Entity.DATA1}, 2334 * null, null, null); 2335 * try { 2336 * while (c.moveToNext()) { 2337 * String sourceId = c.getString(0); 2338 * if (!c.isNull(1)) { 2339 * String mimeType = c.getString(2); 2340 * String data = c.getString(3); 2341 * ... 2342 * } 2343 * } 2344 * } finally { 2345 * c.close(); 2346 * } 2347 * </pre> 2348 * </p> 2349 * </dd> 2350 * </dl> 2351 * <h2>Columns</h2> 2352 * 2353 * <table class="jd-sumtable"> 2354 * <tr> 2355 * <th colspan='4'>RawContacts</th> 2356 * </tr> 2357 * <tr> 2358 * <td>long</td> 2359 * <td>{@link #_ID}</td> 2360 * <td>read-only</td> 2361 * <td>Row ID. Sync adapters should try to preserve row IDs during updates. In other words, 2362 * it is much better for a sync adapter to update a raw contact rather than to delete and 2363 * re-insert it.</td> 2364 * </tr> 2365 * <tr> 2366 * <td>long</td> 2367 * <td>{@link #CONTACT_ID}</td> 2368 * <td>read-only</td> 2369 * <td>The ID of the row in the {@link ContactsContract.Contacts} table 2370 * that this raw contact belongs 2371 * to. Raw contacts are linked to contacts by the aggregation process, which can be controlled 2372 * by the {@link #AGGREGATION_MODE} field and {@link AggregationExceptions}.</td> 2373 * </tr> 2374 * <tr> 2375 * <td>int</td> 2376 * <td>{@link #AGGREGATION_MODE}</td> 2377 * <td>read/write</td> 2378 * <td>A mechanism that allows programmatic control of the aggregation process. The allowed 2379 * values are {@link #AGGREGATION_MODE_DEFAULT}, {@link #AGGREGATION_MODE_DISABLED} 2380 * and {@link #AGGREGATION_MODE_SUSPENDED}. See also {@link AggregationExceptions}.</td> 2381 * </tr> 2382 * <tr> 2383 * <td>int</td> 2384 * <td>{@link #DELETED}</td> 2385 * <td>read/write</td> 2386 * <td>The "deleted" flag: "0" by default, "1" if the row has been marked 2387 * for deletion. When {@link android.content.ContentResolver#delete} is 2388 * called on a raw contact, it is marked for deletion and removed from its 2389 * aggregate contact. The sync adaptor deletes the raw contact on the server and 2390 * then calls ContactResolver.delete once more, this time passing the 2391 * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to finalize 2392 * the data removal.</td> 2393 * </tr> 2394 * <tr> 2395 * <td>int</td> 2396 * <td>{@link #TIMES_CONTACTED}</td> 2397 * <td>read/write</td> 2398 * <td>The number of times the contact has been contacted. To have an effect 2399 * on the corresponding value of the aggregate contact, this field 2400 * should be set at the time the raw contact is inserted. 2401 * After that, this value is typically updated via 2402 * {@link ContactsContract.Contacts#markAsContacted}.</td> 2403 * </tr> 2404 * <tr> 2405 * <td>long</td> 2406 * <td>{@link #LAST_TIME_CONTACTED}</td> 2407 * <td>read/write</td> 2408 * <td>The timestamp of the last time the contact was contacted. To have an effect 2409 * on the corresponding value of the aggregate contact, this field 2410 * should be set at the time the raw contact is inserted. 2411 * After that, this value is typically updated via 2412 * {@link ContactsContract.Contacts#markAsContacted}. 2413 * </td> 2414 * </tr> 2415 * <tr> 2416 * <td>int</td> 2417 * <td>{@link #STARRED}</td> 2418 * <td>read/write</td> 2419 * <td>An indicator for favorite contacts: '1' if favorite, '0' otherwise. 2420 * Changing this field immediately affects the corresponding aggregate contact: 2421 * if any raw contacts in that aggregate contact are starred, then the contact 2422 * itself is marked as starred.</td> 2423 * </tr> 2424 * <tr> 2425 * <td>String</td> 2426 * <td>{@link #CUSTOM_RINGTONE}</td> 2427 * <td>read/write</td> 2428 * <td>A custom ringtone associated with a raw contact. Typically this is the 2429 * URI returned by an activity launched with the 2430 * {@link android.media.RingtoneManager#ACTION_RINGTONE_PICKER} intent. 2431 * To have an effect on the corresponding value of the aggregate contact, this field 2432 * should be set at the time the raw contact is inserted. To set a custom 2433 * ringtone on a contact, use the field {@link ContactsContract.Contacts#CUSTOM_RINGTONE 2434 * Contacts.CUSTOM_RINGTONE} 2435 * instead.</td> 2436 * </tr> 2437 * <tr> 2438 * <td>int</td> 2439 * <td>{@link #SEND_TO_VOICEMAIL}</td> 2440 * <td>read/write</td> 2441 * <td>An indicator of whether calls from this raw contact should be forwarded 2442 * directly to voice mail ('1') or not ('0'). To have an effect 2443 * on the corresponding value of the aggregate contact, this field 2444 * should be set at the time the raw contact is inserted.</td> 2445 * </tr> 2446 * <tr> 2447 * <td>String</td> 2448 * <td>{@link #ACCOUNT_NAME}</td> 2449 * <td>read/write-once</td> 2450 * <td>The name of the account instance to which this row belongs, which when paired with 2451 * {@link #ACCOUNT_TYPE} identifies a specific account. 2452 * For example, this will be the Gmail address if it is a Google account. 2453 * It should be set at the time the raw contact is inserted and never 2454 * changed afterwards.</td> 2455 * </tr> 2456 * <tr> 2457 * <td>String</td> 2458 * <td>{@link #ACCOUNT_TYPE}</td> 2459 * <td>read/write-once</td> 2460 * <td> 2461 * <p> 2462 * The type of account to which this row belongs, which when paired with 2463 * {@link #ACCOUNT_NAME} identifies a specific account. 2464 * It should be set at the time the raw contact is inserted and never 2465 * changed afterwards. 2466 * </p> 2467 * <p> 2468 * To ensure uniqueness, new account types should be chosen according to the 2469 * Java package naming convention. Thus a Google account is of type "com.google". 2470 * </p> 2471 * </td> 2472 * </tr> 2473 * <tr> 2474 * <td>String</td> 2475 * <td>{@link #DATA_SET}</td> 2476 * <td>read/write-once</td> 2477 * <td> 2478 * <p> 2479 * The data set within the account that this row belongs to. This allows 2480 * multiple sync adapters for the same account type to distinguish between 2481 * each others' data. The combination of {@link #ACCOUNT_TYPE}, 2482 * {@link #ACCOUNT_NAME}, and {@link #DATA_SET} identifies a set of data 2483 * that is associated with a single sync adapter. 2484 * </p> 2485 * <p> 2486 * This is empty by default, and is completely optional. It only needs to 2487 * be populated if multiple sync adapters are entering distinct data for 2488 * the same account type and account name. 2489 * </p> 2490 * <p> 2491 * It should be set at the time the raw contact is inserted and never 2492 * changed afterwards. 2493 * </p> 2494 * </td> 2495 * </tr> 2496 * <tr> 2497 * <td>String</td> 2498 * <td>{@link #SOURCE_ID}</td> 2499 * <td>read/write</td> 2500 * <td>String that uniquely identifies this row to its source account. 2501 * Typically it is set at the time the raw contact is inserted and never 2502 * changed afterwards. The one notable exception is a new raw contact: it 2503 * will have an account name and type (and possibly a data set), but no 2504 * source id. This indicates to the sync adapter that a new contact needs 2505 * to be created server-side and its ID stored in the corresponding 2506 * SOURCE_ID field on the phone. 2507 * </td> 2508 * </tr> 2509 * <tr> 2510 * <td>int</td> 2511 * <td>{@link #VERSION}</td> 2512 * <td>read-only</td> 2513 * <td>Version number that is updated whenever this row or its related data 2514 * changes. This field can be used for optimistic locking of a raw contact. 2515 * </td> 2516 * </tr> 2517 * <tr> 2518 * <td>int</td> 2519 * <td>{@link #DIRTY}</td> 2520 * <td>read/write</td> 2521 * <td>Flag indicating that {@link #VERSION} has changed, and this row needs 2522 * to be synchronized by its owning account. The value is set to "1" automatically 2523 * whenever the raw contact changes, unless the URI has the 2524 * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter specified. 2525 * The sync adapter should always supply this query parameter to prevent 2526 * unnecessary synchronization: user changes some data on the server, 2527 * the sync adapter updates the contact on the phone (without the 2528 * CALLER_IS_SYNCADAPTER flag) flag, which sets the DIRTY flag, 2529 * which triggers a sync to bring the changes to the server. 2530 * </td> 2531 * </tr> 2532 * <tr> 2533 * <td>String</td> 2534 * <td>{@link #SYNC1}</td> 2535 * <td>read/write</td> 2536 * <td>Generic column provided for arbitrary use by sync adapters. 2537 * The content provider 2538 * stores this information on behalf of the sync adapter but does not 2539 * interpret it in any way. 2540 * </td> 2541 * </tr> 2542 * <tr> 2543 * <td>String</td> 2544 * <td>{@link #SYNC2}</td> 2545 * <td>read/write</td> 2546 * <td>Generic column for use by sync adapters. 2547 * </td> 2548 * </tr> 2549 * <tr> 2550 * <td>String</td> 2551 * <td>{@link #SYNC3}</td> 2552 * <td>read/write</td> 2553 * <td>Generic column for use by sync adapters. 2554 * </td> 2555 * </tr> 2556 * <tr> 2557 * <td>String</td> 2558 * <td>{@link #SYNC4}</td> 2559 * <td>read/write</td> 2560 * <td>Generic column for use by sync adapters. 2561 * </td> 2562 * </tr> 2563 * </table> 2564 */ 2565 public static final class RawContacts implements BaseColumns, RawContactsColumns, 2566 ContactOptionsColumns, ContactNameColumns, SyncColumns { 2567 /** 2568 * This utility class cannot be instantiated 2569 */ 2570 private RawContacts() { 2571 } 2572 2573 /** 2574 * The content:// style URI for this table, which requests a directory of 2575 * raw contact rows matching the selection criteria. 2576 */ 2577 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "raw_contacts"); 2578 2579 /** 2580 * The MIME type of the results from {@link #CONTENT_URI} when a specific 2581 * ID value is not provided, and multiple raw contacts may be returned. 2582 */ 2583 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/raw_contact"; 2584 2585 /** 2586 * The MIME type of the results when a raw contact ID is appended to {@link #CONTENT_URI}, 2587 * yielding a subdirectory of a single person. 2588 */ 2589 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/raw_contact"; 2590 2591 /** 2592 * Aggregation mode: aggregate immediately after insert or update operation(s) are complete. 2593 */ 2594 public static final int AGGREGATION_MODE_DEFAULT = 0; 2595 2596 /** 2597 * Aggregation mode: aggregate at the time the raw contact is inserted/updated. 2598 * @deprecated Aggregation is synchronous, this historic value is a no-op 2599 */ 2600 @Deprecated 2601 public static final int AGGREGATION_MODE_IMMEDIATE = 1; 2602 2603 /** 2604 * <p> 2605 * Aggregation mode: aggregation suspended temporarily, and is likely to be resumed later. 2606 * Changes to the raw contact will update the associated aggregate contact but will not 2607 * result in any change in how the contact is aggregated. Similar to 2608 * {@link #AGGREGATION_MODE_DISABLED}, but maintains a link to the corresponding 2609 * {@link Contacts} aggregate. 2610 * </p> 2611 * <p> 2612 * This can be used to postpone aggregation until after a series of updates, for better 2613 * performance and/or user experience. 2614 * </p> 2615 * <p> 2616 * Note that changing 2617 * {@link #AGGREGATION_MODE} from {@link #AGGREGATION_MODE_SUSPENDED} to 2618 * {@link #AGGREGATION_MODE_DEFAULT} does not trigger an aggregation pass, but any 2619 * subsequent 2620 * change to the raw contact's data will. 2621 * </p> 2622 */ 2623 public static final int AGGREGATION_MODE_SUSPENDED = 2; 2624 2625 /** 2626 * <p> 2627 * Aggregation mode: never aggregate this raw contact. The raw contact will not 2628 * have a corresponding {@link Contacts} aggregate and therefore will not be included in 2629 * {@link Contacts} query results. 2630 * </p> 2631 * <p> 2632 * For example, this mode can be used for a raw contact that is marked for deletion while 2633 * waiting for the deletion to occur on the server side. 2634 * </p> 2635 * 2636 * @see #AGGREGATION_MODE_SUSPENDED 2637 */ 2638 public static final int AGGREGATION_MODE_DISABLED = 3; 2639 2640 /** 2641 * Build a {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI} 2642 * style {@link Uri} for the parent {@link android.provider.ContactsContract.Contacts} 2643 * entry of the given {@link RawContacts} entry. 2644 */ 2645 public static Uri getContactLookupUri(ContentResolver resolver, Uri rawContactUri) { 2646 // TODO: use a lighter query by joining rawcontacts with contacts in provider 2647 final Uri dataUri = Uri.withAppendedPath(rawContactUri, Data.CONTENT_DIRECTORY); 2648 final Cursor cursor = resolver.query(dataUri, new String[] { 2649 RawContacts.CONTACT_ID, Contacts.LOOKUP_KEY 2650 }, null, null, null); 2651 2652 Uri lookupUri = null; 2653 try { 2654 if (cursor != null && cursor.moveToFirst()) { 2655 final long contactId = cursor.getLong(0); 2656 final String lookupKey = cursor.getString(1); 2657 return Contacts.getLookupUri(contactId, lookupKey); 2658 } 2659 } finally { 2660 if (cursor != null) cursor.close(); 2661 } 2662 return lookupUri; 2663 } 2664 2665 /** 2666 * A sub-directory of a single raw contact that contains all of its 2667 * {@link ContactsContract.Data} rows. To access this directory 2668 * append {@link Data#CONTENT_DIRECTORY} to the raw contact URI. 2669 */ 2670 public static final class Data implements BaseColumns, DataColumns { 2671 /** 2672 * no public constructor since this is a utility class 2673 */ 2674 private Data() { 2675 } 2676 2677 /** 2678 * The directory twig for this sub-table 2679 */ 2680 public static final String CONTENT_DIRECTORY = "data"; 2681 } 2682 2683 /** 2684 * <p> 2685 * A sub-directory of a single raw contact that contains all of its 2686 * {@link ContactsContract.Data} rows. To access this directory append 2687 * {@link RawContacts.Entity#CONTENT_DIRECTORY} to the raw contact URI. See 2688 * {@link RawContactsEntity} for a stand-alone table containing the same 2689 * data. 2690 * </p> 2691 * <p> 2692 * Entity has two ID fields: {@link #_ID} for the raw contact 2693 * and {@link #DATA_ID} for the data rows. 2694 * Entity always contains at least one row, even if there are no 2695 * actual data rows. In this case the {@link #DATA_ID} field will be 2696 * null. 2697 * </p> 2698 * <p> 2699 * Using Entity should be preferred to using two separate queries: 2700 * RawContacts followed by Data. The reason is that Entity reads all 2701 * data for a raw contact in one transaction, so there is no possibility 2702 * of the data changing between the two queries. 2703 */ 2704 public static final class Entity implements BaseColumns, DataColumns { 2705 /** 2706 * no public constructor since this is a utility class 2707 */ 2708 private Entity() { 2709 } 2710 2711 /** 2712 * The directory twig for this sub-table 2713 */ 2714 public static final String CONTENT_DIRECTORY = "entity"; 2715 2716 /** 2717 * The ID of the data row. The value will be null if this raw contact has no 2718 * data rows. 2719 * <P>Type: INTEGER</P> 2720 */ 2721 public static final String DATA_ID = "data_id"; 2722 } 2723 2724 /** 2725 * <p> 2726 * A sub-directory of a single raw contact that contains all of its 2727 * {@link ContactsContract.StreamItems} rows. To access this directory append 2728 * {@link RawContacts.StreamItems#CONTENT_DIRECTORY} to the raw contact URI. See 2729 * {@link ContactsContract.StreamItems} for a stand-alone table containing the 2730 * same data. 2731 * </p> 2732 * <p> 2733 * Access to the social stream through this sub-directory requires additional permissions 2734 * beyond the read/write contact permissions required by the provider. Querying for 2735 * social stream data requires android.permission.READ_SOCIAL_STREAM permission, and 2736 * inserting or updating social stream items requires android.permission.WRITE_SOCIAL_STREAM 2737 * permission. 2738 * </p> 2739 * @hide 2740 */ 2741 public static final class StreamItems implements BaseColumns, StreamItemsColumns { 2742 /** 2743 * No public constructor since this is a utility class 2744 */ 2745 private StreamItems() { 2746 } 2747 2748 /** 2749 * The directory twig for this sub-table 2750 */ 2751 public static final String CONTENT_DIRECTORY = "stream_items"; 2752 } 2753 2754 /** 2755 * <p> 2756 * A sub-directory of a single raw contact that represents its primary 2757 * display photo. To access this directory append 2758 * {@link RawContacts.DisplayPhoto#CONTENT_DIRECTORY} to the raw contact URI. 2759 * The resulting URI represents an image file, and should be interacted with 2760 * using ContentResolver.openAssetFileDescriptor. 2761 * <p> 2762 * <p> 2763 * Note that this sub-directory also supports opening the photo as an asset file 2764 * in write mode. Callers can create or replace the primary photo associated 2765 * with this raw contact by opening the asset file and writing the full-size 2766 * photo contents into it. When the file is closed, the image will be parsed, 2767 * sized down if necessary for the full-size display photo and thumbnail 2768 * dimensions, and stored. 2769 * </p> 2770 * <p> 2771 * Usage example: 2772 * <pre> 2773 * public void writeDisplayPhoto(long rawContactId, byte[] photo) { 2774 * Uri rawContactPhotoUri = Uri.withAppendedPath( 2775 * ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId), 2776 * RawContacts.DisplayPhoto.CONTENT_DIRECTORY); 2777 * try { 2778 * AssetFileDescriptor fd = 2779 * getContentResolver().openAssetFileDescriptor(rawContactPhotoUri, "rw"); 2780 * OutputStream os = fd.createOutputStream(); 2781 * os.write(photo); 2782 * os.close(); 2783 * fd.close(); 2784 * } catch (IOException e) { 2785 * // Handle error cases. 2786 * } 2787 * } 2788 * </pre> 2789 * </p> 2790 */ 2791 public static final class DisplayPhoto { 2792 /** 2793 * No public constructor since this is a utility class 2794 */ 2795 private DisplayPhoto() { 2796 } 2797 2798 /** 2799 * The directory twig for this sub-table 2800 */ 2801 public static final String CONTENT_DIRECTORY = "display_photo"; 2802 } 2803 2804 /** 2805 * TODO: javadoc 2806 * @param cursor 2807 * @return 2808 */ 2809 public static EntityIterator newEntityIterator(Cursor cursor) { 2810 return new EntityIteratorImpl(cursor); 2811 } 2812 2813 private static class EntityIteratorImpl extends CursorEntityIterator { 2814 private static final String[] DATA_KEYS = new String[]{ 2815 Data.DATA1, 2816 Data.DATA2, 2817 Data.DATA3, 2818 Data.DATA4, 2819 Data.DATA5, 2820 Data.DATA6, 2821 Data.DATA7, 2822 Data.DATA8, 2823 Data.DATA9, 2824 Data.DATA10, 2825 Data.DATA11, 2826 Data.DATA12, 2827 Data.DATA13, 2828 Data.DATA14, 2829 Data.DATA15, 2830 Data.SYNC1, 2831 Data.SYNC2, 2832 Data.SYNC3, 2833 Data.SYNC4}; 2834 2835 public EntityIteratorImpl(Cursor cursor) { 2836 super(cursor); 2837 } 2838 2839 @Override 2840 public android.content.Entity getEntityAndIncrementCursor(Cursor cursor) 2841 throws RemoteException { 2842 final int columnRawContactId = cursor.getColumnIndexOrThrow(RawContacts._ID); 2843 final long rawContactId = cursor.getLong(columnRawContactId); 2844 2845 // we expect the cursor is already at the row we need to read from 2846 ContentValues cv = new ContentValues(); 2847 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ACCOUNT_NAME); 2848 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ACCOUNT_TYPE); 2849 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, DATA_SET); 2850 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, _ID); 2851 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DIRTY); 2852 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, VERSION); 2853 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SOURCE_ID); 2854 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC1); 2855 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC2); 2856 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC3); 2857 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC4); 2858 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DELETED); 2859 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, CONTACT_ID); 2860 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, STARRED); 2861 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, NAME_VERIFIED); 2862 android.content.Entity contact = new android.content.Entity(cv); 2863 2864 // read data rows until the contact id changes 2865 do { 2866 if (rawContactId != cursor.getLong(columnRawContactId)) { 2867 break; 2868 } 2869 // add the data to to the contact 2870 cv = new ContentValues(); 2871 cv.put(Data._ID, cursor.getLong(cursor.getColumnIndexOrThrow(Entity.DATA_ID))); 2872 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, 2873 Data.RES_PACKAGE); 2874 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, Data.MIMETYPE); 2875 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, Data.IS_PRIMARY); 2876 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, 2877 Data.IS_SUPER_PRIMARY); 2878 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, Data.DATA_VERSION); 2879 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, 2880 CommonDataKinds.GroupMembership.GROUP_SOURCE_ID); 2881 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, 2882 Data.DATA_VERSION); 2883 for (String key : DATA_KEYS) { 2884 final int columnIndex = cursor.getColumnIndexOrThrow(key); 2885 switch (cursor.getType(columnIndex)) { 2886 case Cursor.FIELD_TYPE_NULL: 2887 // don't put anything 2888 break; 2889 case Cursor.FIELD_TYPE_INTEGER: 2890 case Cursor.FIELD_TYPE_FLOAT: 2891 case Cursor.FIELD_TYPE_STRING: 2892 cv.put(key, cursor.getString(columnIndex)); 2893 break; 2894 case Cursor.FIELD_TYPE_BLOB: 2895 cv.put(key, cursor.getBlob(columnIndex)); 2896 break; 2897 default: 2898 throw new IllegalStateException("Invalid or unhandled data type"); 2899 } 2900 } 2901 contact.addSubValue(ContactsContract.Data.CONTENT_URI, cv); 2902 } while (cursor.moveToNext()); 2903 2904 return contact; 2905 } 2906 2907 } 2908 } 2909 2910 /** 2911 * Social status update columns. 2912 * 2913 * @see StatusUpdates 2914 * @see ContactsContract.Data 2915 */ 2916 protected interface StatusColumns { 2917 /** 2918 * Contact's latest presence level. 2919 * <P>Type: INTEGER (one of the values below)</P> 2920 */ 2921 public static final String PRESENCE = "mode"; 2922 2923 /** 2924 * @deprecated use {@link #PRESENCE} 2925 */ 2926 @Deprecated 2927 public static final String PRESENCE_STATUS = PRESENCE; 2928 2929 /** 2930 * An allowed value of {@link #PRESENCE}. 2931 */ 2932 int OFFLINE = 0; 2933 2934 /** 2935 * An allowed value of {@link #PRESENCE}. 2936 */ 2937 int INVISIBLE = 1; 2938 2939 /** 2940 * An allowed value of {@link #PRESENCE}. 2941 */ 2942 int AWAY = 2; 2943 2944 /** 2945 * An allowed value of {@link #PRESENCE}. 2946 */ 2947 int IDLE = 3; 2948 2949 /** 2950 * An allowed value of {@link #PRESENCE}. 2951 */ 2952 int DO_NOT_DISTURB = 4; 2953 2954 /** 2955 * An allowed value of {@link #PRESENCE}. 2956 */ 2957 int AVAILABLE = 5; 2958 2959 /** 2960 * Contact latest status update. 2961 * <p>Type: TEXT</p> 2962 */ 2963 public static final String STATUS = "status"; 2964 2965 /** 2966 * @deprecated use {@link #STATUS} 2967 */ 2968 @Deprecated 2969 public static final String PRESENCE_CUSTOM_STATUS = STATUS; 2970 2971 /** 2972 * The absolute time in milliseconds when the latest status was inserted/updated. 2973 * <p>Type: NUMBER</p> 2974 */ 2975 public static final String STATUS_TIMESTAMP = "status_ts"; 2976 2977 /** 2978 * The package containing resources for this status: label and icon. 2979 * <p>Type: TEXT</p> 2980 */ 2981 public static final String STATUS_RES_PACKAGE = "status_res_package"; 2982 2983 /** 2984 * The resource ID of the label describing the source of the status update, e.g. "Google 2985 * Talk". This resource should be scoped by the {@link #STATUS_RES_PACKAGE}. 2986 * <p>Type: NUMBER</p> 2987 */ 2988 public static final String STATUS_LABEL = "status_label"; 2989 2990 /** 2991 * The resource ID of the icon for the source of the status update. 2992 * This resource should be scoped by the {@link #STATUS_RES_PACKAGE}. 2993 * <p>Type: NUMBER</p> 2994 */ 2995 public static final String STATUS_ICON = "status_icon"; 2996 2997 /** 2998 * Contact's audio/video chat capability level. 2999 * <P>Type: INTEGER (one of the values below)</P> 3000 */ 3001 public static final String CHAT_CAPABILITY = "chat_capability"; 3002 3003 /** 3004 * An allowed flag of {@link #CHAT_CAPABILITY}. Indicates audio-chat capability (microphone 3005 * and speaker) 3006 */ 3007 public static final int CAPABILITY_HAS_VOICE = 1; 3008 3009 /** 3010 * An allowed flag of {@link #CHAT_CAPABILITY}. Indicates that the contact's device can 3011 * display a video feed. 3012 */ 3013 public static final int CAPABILITY_HAS_VIDEO = 2; 3014 3015 /** 3016 * An allowed flag of {@link #CHAT_CAPABILITY}. Indicates that the contact's device has a 3017 * camera that can be used for video chat (e.g. a front-facing camera on a phone). 3018 */ 3019 public static final int CAPABILITY_HAS_CAMERA = 4; 3020 } 3021 3022 /** 3023 * <p> 3024 * Constants for the stream_items table, which contains social stream updates from 3025 * the user's contact list. 3026 * </p> 3027 * <p> 3028 * Only a certain number of stream items will ever be stored under a given raw contact. 3029 * Users of this API can query {@link ContactsContract.StreamItems#CONTENT_LIMIT_URI} to 3030 * determine this limit, and should restrict the number of items inserted in any given 3031 * transaction correspondingly. Insertion of more items beyond the limit will 3032 * automatically lead to deletion of the oldest items, by {@link StreamItems#TIMESTAMP}. 3033 * </p> 3034 * <p> 3035 * Access to the social stream through these URIs requires additional permissions beyond the 3036 * read/write contact permissions required by the provider. Querying for social stream data 3037 * requires android.permission.READ_SOCIAL_STREAM permission, and inserting or updating social 3038 * stream items requires android.permission.WRITE_SOCIAL_STREAM permission. 3039 * </p> 3040 * <h3>Operations</h3> 3041 * <dl> 3042 * <dt><b>Insert</b></dt> 3043 * <dd> 3044 * <p>Social stream updates are always associated with a raw contact. There are a couple 3045 * of ways to insert these entries. 3046 * <dl> 3047 * <dt>Via the {@link RawContacts.StreamItems#CONTENT_DIRECTORY} sub-path of a raw contact:</dt> 3048 * <dd> 3049 * <pre> 3050 * ContentValues values = new ContentValues(); 3051 * values.put(StreamItems.TEXT, "Breakfasted at Tiffanys"); 3052 * values.put(StreamItems.TIMESTAMP, timestamp); 3053 * values.put(StreamItems.COMMENTS, "3 people reshared this"); 3054 * Uri streamItemUri = getContentResolver().insert( 3055 * Uri.withAppendedPath(ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId), 3056 * RawContacts.StreamItems.CONTENT_DIRECTORY), values); 3057 * long streamItemId = ContentUris.parseId(streamItemUri); 3058 * </pre> 3059 * </dd> 3060 * <dt>Via {@link StreamItems#CONTENT_URI}:</dt> 3061 * <dd> 3062 *<pre> 3063 * ContentValues values = new ContentValues(); 3064 * values.put(StreamItems.RAW_CONTACT_ID, rawContactId); 3065 * values.put(StreamItems.TEXT, "Breakfasted at Tiffanys"); 3066 * values.put(StreamItems.TIMESTAMP, timestamp); 3067 * values.put(StreamItems.COMMENTS, "3 people reshared this"); 3068 * Uri streamItemUri = getContentResolver().insert(StreamItems.CONTENT_URI, values); 3069 * long streamItemId = ContentUris.parseId(streamItemUri); 3070 *</pre> 3071 * </dd> 3072 * </dl> 3073 * </dd> 3074 * </p> 3075 * <p> 3076 * Once a {@link StreamItems} entry has been inserted, photos associated with that 3077 * social update can be inserted. For example, after one of the insertions above, 3078 * photos could be added to the stream item in one of the following ways: 3079 * <dl> 3080 * <dt>Via a URI including the stream item ID:</dt> 3081 * <dd> 3082 * <pre> 3083 * values.clear(); 3084 * values.put(StreamItemPhotos.SORT_INDEX, 1); 3085 * values.put(StreamItemPhotos.PHOTO, photoData); 3086 * getContentResolver().insert(Uri.withAppendedPath( 3087 * ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId), 3088 * StreamItems.StreamItemPhotos.CONTENT_DIRECTORY), values); 3089 * </pre> 3090 * </dd> 3091 * <dt>Via {@link ContactsContract.StreamItems#CONTENT_PHOTO_URI}:</dt> 3092 * <dd> 3093 * <pre> 3094 * values.clear(); 3095 * values.put(StreamItemPhotos.STREAM_ITEM_ID, streamItemId); 3096 * values.put(StreamItemPhotos.SORT_INDEX, 1); 3097 * values.put(StreamItemPhotos.PHOTO, photoData); 3098 * getContentResolver().insert(StreamItems.CONTENT_PHOTO_URI, values); 3099 * </pre> 3100 * <p>Note that this latter form allows the insertion of a stream item and its 3101 * photos in a single transaction, by using {@link ContentProviderOperation} with 3102 * back references to populate the stream item ID in the {@link ContentValues}. 3103 * </dd> 3104 * </dl> 3105 * </p> 3106 * </dd> 3107 * <dt><b>Update</b></dt> 3108 * <dd>Updates can be performed by appending the stream item ID to the 3109 * {@link StreamItems#CONTENT_URI} URI. Only social stream entries that were 3110 * created by the calling package can be updated.</dd> 3111 * <dt><b>Delete</b></dt> 3112 * <dd>Deletes can be performed by appending the stream item ID to the 3113 * {@link StreamItems#CONTENT_URI} URI. Only social stream entries that were 3114 * created by the calling package can be deleted.</dd> 3115 * <dt><b>Query</b></dt> 3116 * <dl> 3117 * <dt>Finding all social stream updates for a given contact</dt> 3118 * <dd>By Contact ID: 3119 * <pre> 3120 * Cursor c = getContentResolver().query(Uri.withAppendedPath( 3121 * ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId), 3122 * Contacts.StreamItems.CONTENT_DIRECTORY), 3123 * null, null, null, null); 3124 * </pre> 3125 * </dd> 3126 * <dd>By lookup key: 3127 * <pre> 3128 * Cursor c = getContentResolver().query(Contacts.CONTENT_URI.buildUpon() 3129 * .appendPath(lookupKey) 3130 * .appendPath(Contacts.StreamItems.CONTENT_DIRECTORY).build(), 3131 * null, null, null, null); 3132 * </pre> 3133 * </dd> 3134 * <dt>Finding all social stream updates for a given raw contact</dt> 3135 * <dd> 3136 * <pre> 3137 * Cursor c = getContentResolver().query(Uri.withAppendedPath( 3138 * ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId), 3139 * RawContacts.StreamItems.CONTENT_DIRECTORY)), 3140 * null, null, null, null); 3141 * </pre> 3142 * </dd> 3143 * <dt>Querying for a specific stream item by ID</dt> 3144 * <dd> 3145 * <pre> 3146 * Cursor c = getContentResolver().query(ContentUris.withAppendedId( 3147 * StreamItems.CONTENT_URI, streamItemId), 3148 * null, null, null, null); 3149 * </pre> 3150 * </dd> 3151 * </dl> 3152 * @hide 3153 */ 3154 public static final class StreamItems implements BaseColumns, StreamItemsColumns { 3155 /** 3156 * This utility class cannot be instantiated 3157 */ 3158 private StreamItems() { 3159 } 3160 3161 /** 3162 * The content:// style URI for this table, which handles social network stream 3163 * updates for the user's contacts. 3164 */ 3165 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "stream_items"); 3166 3167 /** 3168 * <p> 3169 * A content:// style URI for the photos stored in a sub-table underneath 3170 * stream items. This is only used for inserts, and updates - queries and deletes 3171 * for photos should be performed by appending 3172 * {@link StreamItems.StreamItemPhotos#CONTENT_DIRECTORY} path to URIs for a 3173 * specific stream item. 3174 * </p> 3175 * <p> 3176 * When using this URI, the stream item ID for the photo(s) must be identified 3177 * in the {@link ContentValues} passed in. 3178 * </p> 3179 */ 3180 public static final Uri CONTENT_PHOTO_URI = Uri.withAppendedPath(CONTENT_URI, "photo"); 3181 3182 /** 3183 * This URI allows the caller to query for the maximum number of stream items 3184 * that will be stored under any single raw contact. 3185 */ 3186 public static final Uri CONTENT_LIMIT_URI = 3187 Uri.withAppendedPath(AUTHORITY_URI, "stream_items_limit"); 3188 3189 /** 3190 * The MIME type of a directory of stream items. 3191 */ 3192 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/stream_item"; 3193 3194 /** 3195 * The MIME type of a single stream item. 3196 */ 3197 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/stream_item"; 3198 3199 /** 3200 * Queries to {@link ContactsContract.StreamItems#CONTENT_LIMIT_URI} will 3201 * contain this column, with the value indicating the maximum number of 3202 * stream items that will be stored under any single raw contact. 3203 */ 3204 public static final String MAX_ITEMS = "max_items"; 3205 3206 /** 3207 * <p> 3208 * A sub-directory of a single stream item entry that contains all of its 3209 * photo rows. To access this 3210 * directory append {@link StreamItems.StreamItemPhotos#CONTENT_DIRECTORY} to 3211 * an individual stream item URI. 3212 * </p> 3213 * <p> 3214 * Access to social stream photos requires additional permissions beyond the read/write 3215 * contact permissions required by the provider. Querying for social stream photos 3216 * requires android.permission.READ_SOCIAL_STREAM permission, and inserting or updating 3217 * social stream photos requires android.permission.WRITE_SOCIAL_STREAM permission. 3218 * </p> 3219 */ 3220 public static final class StreamItemPhotos 3221 implements BaseColumns, StreamItemPhotosColumns { 3222 /** 3223 * No public constructor since this is a utility class 3224 */ 3225 private StreamItemPhotos() { 3226 } 3227 3228 /** 3229 * The directory twig for this sub-table 3230 */ 3231 public static final String CONTENT_DIRECTORY = "photo"; 3232 3233 /** 3234 * The MIME type of a directory of stream item photos. 3235 */ 3236 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/stream_item_photo"; 3237 3238 /** 3239 * The MIME type of a single stream item photo. 3240 */ 3241 public static final String CONTENT_ITEM_TYPE 3242 = "vnd.android.cursor.item/stream_item_photo"; 3243 } 3244 } 3245 3246 /** 3247 * Columns in the StreamItems table. 3248 * 3249 * @see ContactsContract.StreamItems 3250 * @hide 3251 */ 3252 protected interface StreamItemsColumns { 3253 /** 3254 * A reference to the {@link android.provider.ContactsContract.Contacts#_ID} 3255 * that this stream item belongs to. 3256 * 3257 * <p>Type: INTEGER</p> 3258 * <p>read-only</p> 3259 */ 3260 public static final String CONTACT_ID = "contact_id"; 3261 3262 /** 3263 * A reference to the {@link android.provider.ContactsContract.Contacts#LOOKUP_KEY} 3264 * that this stream item belongs to. 3265 * 3266 * <p>Type: TEXT</p> 3267 * <p>read-only</p> 3268 */ 3269 public static final String CONTACT_LOOKUP_KEY = "contact_lookup"; 3270 3271 /** 3272 * A reference to the {@link RawContacts#_ID} 3273 * that this stream item belongs to. 3274 * <p>Type: INTEGER</p> 3275 */ 3276 public static final String RAW_CONTACT_ID = "raw_contact_id"; 3277 3278 /** 3279 * The package name to use when creating {@link Resources} objects for 3280 * this stream item. This value is only designed for use when building 3281 * user interfaces, and should not be used to infer the owner. 3282 * <P>Type: TEXT</P> 3283 */ 3284 public static final String RES_PACKAGE = "res_package"; 3285 3286 /** 3287 * The account type to which the raw_contact of this item is associated. See 3288 * {@link RawContacts#ACCOUNT_TYPE} 3289 * 3290 * <p>Type: TEXT</p> 3291 * <p>read-only</p> 3292 */ 3293 public static final String ACCOUNT_TYPE = "account_type"; 3294 3295 /** 3296 * The account name to which the raw_contact of this item is associated. See 3297 * {@link RawContacts#ACCOUNT_NAME} 3298 * 3299 * <p>Type: TEXT</p> 3300 * <p>read-only</p> 3301 */ 3302 public static final String ACCOUNT_NAME = "account_name"; 3303 3304 /** 3305 * The data set within the account that the raw_contact of this row belongs to. This allows 3306 * multiple sync adapters for the same account type to distinguish between 3307 * each others' data. 3308 * {@link RawContacts#DATA_SET} 3309 * 3310 * <P>Type: TEXT</P> 3311 * <p>read-only</p> 3312 */ 3313 public static final String DATA_SET = "data_set"; 3314 3315 /** 3316 * The source_id of the raw_contact that this row belongs to. 3317 * {@link RawContacts#SOURCE_ID} 3318 * 3319 * <P>Type: TEXT</P> 3320 * <p>read-only</p> 3321 */ 3322 public static final String RAW_CONTACT_SOURCE_ID = "raw_contact_source_id"; 3323 3324 /** 3325 * The resource name of the icon for the source of the stream item. 3326 * This resource should be scoped by the {@link #RES_PACKAGE}. As this can only reference 3327 * drawables, the "@drawable/" prefix must be omitted. 3328 * <P>Type: TEXT</P> 3329 */ 3330 public static final String RES_ICON = "icon"; 3331 3332 /** 3333 * The resource name of the label describing the source of the status update, e.g. "Google 3334 * Talk". This resource should be scoped by the {@link #RES_PACKAGE}. As this can only 3335 * reference strings, the "@string/" prefix must be omitted. 3336 * <p>Type: TEXT</p> 3337 */ 3338 public static final String RES_LABEL = "label"; 3339 3340 /** 3341 * <P> 3342 * The main textual contents of the item. Typically this is content 3343 * that was posted by the source of this stream item, but it can also 3344 * be a textual representation of an action (e.g. Checked in at Joe's). 3345 * This text is displayed to the user and allows formatting and embedded 3346 * resource images via HTML (as parseable via 3347 * {@link android.text.Html#fromHtml}). 3348 * </P> 3349 * <P> 3350 * Long content may be truncated and/or ellipsized - the exact behavior 3351 * is unspecified, but it should not break tags. 3352 * </P> 3353 * <P>Type: TEXT</P> 3354 */ 3355 public static final String TEXT = "text"; 3356 3357 /** 3358 * The absolute time (milliseconds since epoch) when this stream item was 3359 * inserted/updated. 3360 * <P>Type: NUMBER</P> 3361 */ 3362 public static final String TIMESTAMP = "timestamp"; 3363 3364 /** 3365 * <P> 3366 * Summary information about the stream item, for example to indicate how 3367 * many people have reshared it, how many have liked it, how many thumbs 3368 * up and/or thumbs down it has, what the original source was, etc. 3369 * </P> 3370 * <P> 3371 * This text is displayed to the user and allows simple formatting via 3372 * HTML, in the same manner as {@link #TEXT} allows. 3373 * </P> 3374 * <P> 3375 * Long content may be truncated and/or ellipsized - the exact behavior 3376 * is unspecified, but it should not break tags. 3377 * </P> 3378 * <P>Type: TEXT</P> 3379 */ 3380 public static final String COMMENTS = "comments"; 3381 3382 /** Generic column for use by sync adapters. */ 3383 public static final String SYNC1 = "stream_item_sync1"; 3384 /** Generic column for use by sync adapters. */ 3385 public static final String SYNC2 = "stream_item_sync2"; 3386 /** Generic column for use by sync adapters. */ 3387 public static final String SYNC3 = "stream_item_sync3"; 3388 /** Generic column for use by sync adapters. */ 3389 public static final String SYNC4 = "stream_item_sync4"; 3390 } 3391 3392 /** 3393 * <p> 3394 * Constants for the stream_item_photos table, which contains photos associated with 3395 * social stream updates. 3396 * </p> 3397 * <p> 3398 * Access to social stream photos requires additional permissions beyond the read/write 3399 * contact permissions required by the provider. Querying for social stream photos 3400 * requires android.permission.READ_SOCIAL_STREAM permission, and inserting or updating 3401 * social stream photos requires android.permission.WRITE_SOCIAL_STREAM permission. 3402 * </p> 3403 * <h3>Operations</h3> 3404 * <dl> 3405 * <dt><b>Insert</b></dt> 3406 * <dd> 3407 * <p>Social stream photo entries are associated with a social stream item. Photos 3408 * can be inserted into a social stream item in a couple of ways: 3409 * <dl> 3410 * <dt> 3411 * Via the {@link StreamItems.StreamItemPhotos#CONTENT_DIRECTORY} sub-path of a 3412 * stream item: 3413 * </dt> 3414 * <dd> 3415 * <pre> 3416 * ContentValues values = new ContentValues(); 3417 * values.put(StreamItemPhotos.SORT_INDEX, 1); 3418 * values.put(StreamItemPhotos.PHOTO, photoData); 3419 * Uri photoUri = getContentResolver().insert(Uri.withAppendedPath( 3420 * ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId) 3421 * StreamItems.StreamItemPhotos#CONTENT_DIRECTORY), values); 3422 * long photoId = ContentUris.parseId(photoUri); 3423 * </pre> 3424 * </dd> 3425 * <dt>Via the {@link ContactsContract.StreamItems#CONTENT_PHOTO_URI} URI:</dt> 3426 * <dd> 3427 * <pre> 3428 * ContentValues values = new ContentValues(); 3429 * values.put(StreamItemPhotos.STREAM_ITEM_ID, streamItemId); 3430 * values.put(StreamItemPhotos.SORT_INDEX, 1); 3431 * values.put(StreamItemPhotos.PHOTO, photoData); 3432 * Uri photoUri = getContentResolver().insert(StreamItems.CONTENT_PHOTO_URI, values); 3433 * long photoId = ContentUris.parseId(photoUri); 3434 * </pre> 3435 * </dd> 3436 * </dl> 3437 * </p> 3438 * </dd> 3439 * <dt><b>Update</b></dt> 3440 * <dd> 3441 * <p>Updates can only be made against a specific {@link StreamItemPhotos} entry, 3442 * identified by both the stream item ID it belongs to and the stream item photo ID. 3443 * This can be specified in two ways. 3444 * <dl> 3445 * <dt>Via the {@link StreamItems.StreamItemPhotos#CONTENT_DIRECTORY} sub-path of a 3446 * stream item: 3447 * </dt> 3448 * <dd> 3449 * <pre> 3450 * ContentValues values = new ContentValues(); 3451 * values.put(StreamItemPhotos.PHOTO, newPhotoData); 3452 * getContentResolver().update( 3453 * ContentUris.withAppendedId( 3454 * Uri.withAppendedPath( 3455 * ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId) 3456 * StreamItems.StreamItemPhotos#CONTENT_DIRECTORY), 3457 * streamItemPhotoId), values, null, null); 3458 * </pre> 3459 * </dd> 3460 * <dt>Via the {@link ContactsContract.StreamItems#CONTENT_PHOTO_URI} URI:</dt> 3461 * <dd> 3462 * <pre> 3463 * ContentValues values = new ContentValues(); 3464 * values.put(StreamItemPhotos.STREAM_ITEM_ID, streamItemId); 3465 * values.put(StreamItemPhotos.PHOTO, newPhotoData); 3466 * getContentResolver().update(StreamItems.CONTENT_PHOTO_URI, values); 3467 * </pre> 3468 * </dd> 3469 * </dl> 3470 * </p> 3471 * </dd> 3472 * <dt><b>Delete</b></dt> 3473 * <dd>Deletes can be made against either a specific photo item in a stream item, or 3474 * against all or a selected subset of photo items under a stream item. 3475 * For example: 3476 * <dl> 3477 * <dt>Deleting a single photo via the 3478 * {@link StreamItems.StreamItemPhotos#CONTENT_DIRECTORY} sub-path of a stream item: 3479 * </dt> 3480 * <dd> 3481 * <pre> 3482 * getContentResolver().delete( 3483 * ContentUris.withAppendedId( 3484 * Uri.withAppendedPath( 3485 * ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId) 3486 * StreamItems.StreamItemPhotos#CONTENT_DIRECTORY), 3487 * streamItemPhotoId), null, null); 3488 * </pre> 3489 * </dd> 3490 * <dt>Deleting all photos under a stream item</dt> 3491 * <dd> 3492 * <pre> 3493 * getContentResolver().delete( 3494 * Uri.withAppendedPath( 3495 * ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId) 3496 * StreamItems.StreamItemPhotos#CONTENT_DIRECTORY), null, null); 3497 * </pre> 3498 * </dd> 3499 * </dl> 3500 * </dd> 3501 * <dt><b>Query</b></dt> 3502 * <dl> 3503 * <dt>Querying for a specific photo in a stream item</dt> 3504 * <dd> 3505 * <pre> 3506 * Cursor c = getContentResolver().query( 3507 * ContentUris.withAppendedId( 3508 * Uri.withAppendedPath( 3509 * ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId) 3510 * StreamItems.StreamItemPhotos#CONTENT_DIRECTORY), 3511 * streamItemPhotoId), null, null, null, null); 3512 * </pre> 3513 * </dd> 3514 * <dt>Querying for all photos in a stream item</dt> 3515 * <dd> 3516 * <pre> 3517 * Cursor c = getContentResolver().query( 3518 * Uri.withAppendedPath( 3519 * ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId) 3520 * StreamItems.StreamItemPhotos#CONTENT_DIRECTORY), 3521 * null, null, null, StreamItemPhotos.SORT_INDEX); 3522 * </pre> 3523 * </dl> 3524 * The record will contain both a {@link StreamItemPhotos#PHOTO_FILE_ID} and a 3525 * {@link StreamItemPhotos#PHOTO_URI}. The {@link StreamItemPhotos#PHOTO_FILE_ID} 3526 * can be used in conjunction with the {@link ContactsContract.DisplayPhoto} API to 3527 * retrieve photo content, or you can open the {@link StreamItemPhotos#PHOTO_URI} as 3528 * an asset file, as follows: 3529 * <pre> 3530 * public InputStream openDisplayPhoto(String photoUri) { 3531 * try { 3532 * AssetFileDescriptor fd = getContentResolver().openAssetFileDescriptor(photoUri, "r"); 3533 * return fd.createInputStream(); 3534 * } catch (IOException e) { 3535 * return null; 3536 * } 3537 * } 3538 * <pre> 3539 * </dd> 3540 * </dl> 3541 * @hide 3542 */ 3543 public static final class StreamItemPhotos implements BaseColumns, StreamItemPhotosColumns { 3544 /** 3545 * No public constructor since this is a utility class 3546 */ 3547 private StreamItemPhotos() { 3548 } 3549 3550 /** 3551 * <p> 3552 * The binary representation of the photo. Any size photo can be inserted; 3553 * the provider will resize it appropriately for storage and display. 3554 * </p> 3555 * <p> 3556 * This is only intended for use when inserting or updating a stream item photo. 3557 * To retrieve the photo that was stored, open {@link StreamItemPhotos#PHOTO_URI} 3558 * as an asset file. 3559 * </p> 3560 * <P>Type: BLOB</P> 3561 */ 3562 public static final String PHOTO = "photo"; 3563 } 3564 3565 /** 3566 * Columns in the StreamItemPhotos table. 3567 * 3568 * @see ContactsContract.StreamItemPhotos 3569 * @hide 3570 */ 3571 protected interface StreamItemPhotosColumns { 3572 /** 3573 * A reference to the {@link StreamItems#_ID} this photo is associated with. 3574 * <P>Type: NUMBER</P> 3575 */ 3576 public static final String STREAM_ITEM_ID = "stream_item_id"; 3577 3578 /** 3579 * An integer to use for sort order for photos in the stream item. If not 3580 * specified, the {@link StreamItemPhotos#_ID} will be used for sorting. 3581 * <P>Type: NUMBER</P> 3582 */ 3583 public static final String SORT_INDEX = "sort_index"; 3584 3585 /** 3586 * Photo file ID for the photo. 3587 * See {@link ContactsContract.DisplayPhoto}. 3588 * <P>Type: NUMBER</P> 3589 */ 3590 public static final String PHOTO_FILE_ID = "photo_file_id"; 3591 3592 /** 3593 * URI for retrieving the photo content, automatically populated. Callers 3594 * may retrieve the photo content by opening this URI as an asset file. 3595 * <P>Type: TEXT</P> 3596 */ 3597 public static final String PHOTO_URI = "photo_uri"; 3598 3599 /** Generic column for use by sync adapters. */ 3600 public static final String SYNC1 = "stream_item_photo_sync1"; 3601 /** Generic column for use by sync adapters. */ 3602 public static final String SYNC2 = "stream_item_photo_sync2"; 3603 /** Generic column for use by sync adapters. */ 3604 public static final String SYNC3 = "stream_item_photo_sync3"; 3605 /** Generic column for use by sync adapters. */ 3606 public static final String SYNC4 = "stream_item_photo_sync4"; 3607 } 3608 3609 /** 3610 * <p> 3611 * Constants for the photo files table, which tracks metadata for hi-res photos 3612 * stored in the file system. 3613 * </p> 3614 * 3615 * @hide 3616 */ 3617 public static final class PhotoFiles implements BaseColumns, PhotoFilesColumns { 3618 /** 3619 * No public constructor since this is a utility class 3620 */ 3621 private PhotoFiles() { 3622 } 3623 } 3624 3625 /** 3626 * Columns in the PhotoFiles table. 3627 * 3628 * @see ContactsContract.PhotoFiles 3629 * 3630 * @hide 3631 */ 3632 protected interface PhotoFilesColumns { 3633 3634 /** 3635 * The height, in pixels, of the photo this entry is associated with. 3636 * <P>Type: NUMBER</P> 3637 */ 3638 public static final String HEIGHT = "height"; 3639 3640 /** 3641 * The width, in pixels, of the photo this entry is associated with. 3642 * <P>Type: NUMBER</P> 3643 */ 3644 public static final String WIDTH = "width"; 3645 3646 /** 3647 * The size, in bytes, of the photo stored on disk. 3648 * <P>Type: NUMBER</P> 3649 */ 3650 public static final String FILESIZE = "filesize"; 3651 } 3652 3653 /** 3654 * Columns in the Data table. 3655 * 3656 * @see ContactsContract.Data 3657 */ 3658 protected interface DataColumns { 3659 /** 3660 * The package name to use when creating {@link Resources} objects for 3661 * this data row. This value is only designed for use when building user 3662 * interfaces, and should not be used to infer the owner. 3663 * 3664 * @hide 3665 */ 3666 public static final String RES_PACKAGE = "res_package"; 3667 3668 /** 3669 * The MIME type of the item represented by this row. 3670 */ 3671 public static final String MIMETYPE = "mimetype"; 3672 3673 /** 3674 * A reference to the {@link RawContacts#_ID} 3675 * that this data belongs to. 3676 */ 3677 public static final String RAW_CONTACT_ID = "raw_contact_id"; 3678 3679 /** 3680 * Whether this is the primary entry of its kind for the raw contact it belongs to. 3681 * <P>Type: INTEGER (if set, non-0 means true)</P> 3682 */ 3683 public static final String IS_PRIMARY = "is_primary"; 3684 3685 /** 3686 * Whether this is the primary entry of its kind for the aggregate 3687 * contact it belongs to. Any data record that is "super primary" must 3688 * also be "primary". 3689 * <P>Type: INTEGER (if set, non-0 means true)</P> 3690 */ 3691 public static final String IS_SUPER_PRIMARY = "is_super_primary"; 3692 3693 /** 3694 * The "read-only" flag: "0" by default, "1" if the row cannot be modified or 3695 * deleted except by a sync adapter. See {@link ContactsContract#CALLER_IS_SYNCADAPTER}. 3696 * <P>Type: INTEGER</P> 3697 */ 3698 public static final String IS_READ_ONLY = "is_read_only"; 3699 3700 /** 3701 * The version of this data record. This is a read-only value. The data column is 3702 * guaranteed to not change without the version going up. This value is monotonically 3703 * increasing. 3704 * <P>Type: INTEGER</P> 3705 */ 3706 public static final String DATA_VERSION = "data_version"; 3707 3708 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3709 public static final String DATA1 = "data1"; 3710 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3711 public static final String DATA2 = "data2"; 3712 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3713 public static final String DATA3 = "data3"; 3714 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3715 public static final String DATA4 = "data4"; 3716 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3717 public static final String DATA5 = "data5"; 3718 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3719 public static final String DATA6 = "data6"; 3720 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3721 public static final String DATA7 = "data7"; 3722 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3723 public static final String DATA8 = "data8"; 3724 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3725 public static final String DATA9 = "data9"; 3726 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3727 public static final String DATA10 = "data10"; 3728 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3729 public static final String DATA11 = "data11"; 3730 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3731 public static final String DATA12 = "data12"; 3732 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3733 public static final String DATA13 = "data13"; 3734 /** Generic data column, the meaning is {@link #MIMETYPE} specific */ 3735 public static final String DATA14 = "data14"; 3736 /** 3737 * Generic data column, the meaning is {@link #MIMETYPE} specific. By convention, 3738 * this field is used to store BLOBs (binary data). 3739 */ 3740 public static final String DATA15 = "data15"; 3741 3742 /** Generic column for use by sync adapters. */ 3743 public static final String SYNC1 = "data_sync1"; 3744 /** Generic column for use by sync adapters. */ 3745 public static final String SYNC2 = "data_sync2"; 3746 /** Generic column for use by sync adapters. */ 3747 public static final String SYNC3 = "data_sync3"; 3748 /** Generic column for use by sync adapters. */ 3749 public static final String SYNC4 = "data_sync4"; 3750 } 3751 3752 /** 3753 * Combines all columns returned by {@link ContactsContract.Data} table queries. 3754 * 3755 * @see ContactsContract.Data 3756 */ 3757 protected interface DataColumnsWithJoins extends BaseColumns, DataColumns, StatusColumns, 3758 RawContactsColumns, ContactsColumns, ContactNameColumns, ContactOptionsColumns, 3759 ContactStatusColumns { 3760 } 3761 3762 /** 3763 * <p> 3764 * Constants for the data table, which contains data points tied to a raw 3765 * contact. Each row of the data table is typically used to store a single 3766 * piece of contact 3767 * information (such as a phone number) and its 3768 * associated metadata (such as whether it is a work or home number). 3769 * </p> 3770 * <h3>Data kinds</h3> 3771 * <p> 3772 * Data is a generic table that can hold any kind of contact data. 3773 * The kind of data stored in a given row is specified by the row's 3774 * {@link #MIMETYPE} value, which determines the meaning of the 3775 * generic columns {@link #DATA1} through 3776 * {@link #DATA15}. 3777 * For example, if the data kind is 3778 * {@link CommonDataKinds.Phone Phone.CONTENT_ITEM_TYPE}, then the column 3779 * {@link #DATA1} stores the 3780 * phone number, but if the data kind is 3781 * {@link CommonDataKinds.Email Email.CONTENT_ITEM_TYPE}, then {@link #DATA1} 3782 * stores the email address. 3783 * Sync adapters and applications can introduce their own data kinds. 3784 * </p> 3785 * <p> 3786 * ContactsContract defines a small number of pre-defined data kinds, e.g. 3787 * {@link CommonDataKinds.Phone}, {@link CommonDataKinds.Email} etc. As a 3788 * convenience, these classes define data kind specific aliases for DATA1 etc. 3789 * For example, {@link CommonDataKinds.Phone Phone.NUMBER} is the same as 3790 * {@link ContactsContract.Data Data.DATA1}. 3791 * </p> 3792 * <p> 3793 * {@link #DATA1} is an indexed column and should be used for the data element that is 3794 * expected to be most frequently used in query selections. For example, in the 3795 * case of a row representing email addresses {@link #DATA1} should probably 3796 * be used for the email address itself, while {@link #DATA2} etc can be 3797 * used for auxiliary information like type of email address. 3798 * <p> 3799 * <p> 3800 * By convention, {@link #DATA15} is used for storing BLOBs (binary data). 3801 * </p> 3802 * <p> 3803 * The sync adapter for a given account type must correctly handle every data type 3804 * used in the corresponding raw contacts. Otherwise it could result in lost or 3805 * corrupted data. 3806 * </p> 3807 * <p> 3808 * Similarly, you should refrain from introducing new kinds of data for an other 3809 * party's account types. For example, if you add a data row for 3810 * "favorite song" to a raw contact owned by a Google account, it will not 3811 * get synced to the server, because the Google sync adapter does not know 3812 * how to handle this data kind. Thus new data kinds are typically 3813 * introduced along with new account types, i.e. new sync adapters. 3814 * </p> 3815 * <h3>Batch operations</h3> 3816 * <p> 3817 * Data rows can be inserted/updated/deleted using the traditional 3818 * {@link ContentResolver#insert}, {@link ContentResolver#update} and 3819 * {@link ContentResolver#delete} methods, however the newer mechanism based 3820 * on a batch of {@link ContentProviderOperation} will prove to be a better 3821 * choice in almost all cases. All operations in a batch are executed in a 3822 * single transaction, which ensures that the phone-side and server-side 3823 * state of a raw contact are always consistent. Also, the batch-based 3824 * approach is far more efficient: not only are the database operations 3825 * faster when executed in a single transaction, but also sending a batch of 3826 * commands to the content provider saves a lot of time on context switching 3827 * between your process and the process in which the content provider runs. 3828 * </p> 3829 * <p> 3830 * The flip side of using batched operations is that a large batch may lock 3831 * up the database for a long time preventing other applications from 3832 * accessing data and potentially causing ANRs ("Application Not Responding" 3833 * dialogs.) 3834 * </p> 3835 * <p> 3836 * To avoid such lockups of the database, make sure to insert "yield points" 3837 * in the batch. A yield point indicates to the content provider that before 3838 * executing the next operation it can commit the changes that have already 3839 * been made, yield to other requests, open another transaction and continue 3840 * processing operations. A yield point will not automatically commit the 3841 * transaction, but only if there is another request waiting on the 3842 * database. Normally a sync adapter should insert a yield point at the 3843 * beginning of each raw contact operation sequence in the batch. See 3844 * {@link ContentProviderOperation.Builder#withYieldAllowed(boolean)}. 3845 * </p> 3846 * <h3>Operations</h3> 3847 * <dl> 3848 * <dt><b>Insert</b></dt> 3849 * <dd> 3850 * <p> 3851 * An individual data row can be inserted using the traditional 3852 * {@link ContentResolver#insert(Uri, ContentValues)} method. Multiple rows 3853 * should always be inserted as a batch. 3854 * </p> 3855 * <p> 3856 * An example of a traditional insert: 3857 * <pre> 3858 * ContentValues values = new ContentValues(); 3859 * values.put(Data.RAW_CONTACT_ID, rawContactId); 3860 * values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE); 3861 * values.put(Phone.NUMBER, "1-800-GOOG-411"); 3862 * values.put(Phone.TYPE, Phone.TYPE_CUSTOM); 3863 * values.put(Phone.LABEL, "free directory assistance"); 3864 * Uri dataUri = getContentResolver().insert(Data.CONTENT_URI, values); 3865 * </pre> 3866 * <p> 3867 * The same done using ContentProviderOperations: 3868 * <pre> 3869 * ArrayList<ContentProviderOperation> ops = 3870 * new ArrayList<ContentProviderOperation>(); 3871 * 3872 * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI) 3873 * .withValue(Data.RAW_CONTACT_ID, rawContactId) 3874 * .withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE) 3875 * .withValue(Phone.NUMBER, "1-800-GOOG-411") 3876 * .withValue(Phone.TYPE, Phone.TYPE_CUSTOM) 3877 * .withValue(Phone.LABEL, "free directory assistance") 3878 * .build()); 3879 * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); 3880 * </pre> 3881 * </p> 3882 * <dt><b>Update</b></dt> 3883 * <dd> 3884 * <p> 3885 * Just as with insert, update can be done incrementally or as a batch, 3886 * the batch mode being the preferred method: 3887 * <pre> 3888 * ArrayList<ContentProviderOperation> ops = 3889 * new ArrayList<ContentProviderOperation>(); 3890 * 3891 * ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI) 3892 * .withSelection(Data._ID + "=?", new String[]{String.valueOf(dataId)}) 3893 * .withValue(Email.DATA, "somebody (at) android.com") 3894 * .build()); 3895 * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); 3896 * </pre> 3897 * </p> 3898 * </dd> 3899 * <dt><b>Delete</b></dt> 3900 * <dd> 3901 * <p> 3902 * Just as with insert and update, deletion can be done either using the 3903 * {@link ContentResolver#delete} method or using a ContentProviderOperation: 3904 * <pre> 3905 * ArrayList<ContentProviderOperation> ops = 3906 * new ArrayList<ContentProviderOperation>(); 3907 * 3908 * ops.add(ContentProviderOperation.newDelete(Data.CONTENT_URI) 3909 * .withSelection(Data._ID + "=?", new String[]{String.valueOf(dataId)}) 3910 * .build()); 3911 * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); 3912 * </pre> 3913 * </p> 3914 * </dd> 3915 * <dt><b>Query</b></dt> 3916 * <dd> 3917 * <p> 3918 * <dl> 3919 * <dt>Finding all Data of a given type for a given contact</dt> 3920 * <dd> 3921 * <pre> 3922 * Cursor c = getContentResolver().query(Data.CONTENT_URI, 3923 * new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL}, 3924 * Data.CONTACT_ID + "=?" + " AND " 3925 * + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'", 3926 * new String[] {String.valueOf(contactId)}, null); 3927 * </pre> 3928 * </p> 3929 * <p> 3930 * </dd> 3931 * <dt>Finding all Data of a given type for a given raw contact</dt> 3932 * <dd> 3933 * <pre> 3934 * Cursor c = getContentResolver().query(Data.CONTENT_URI, 3935 * new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL}, 3936 * Data.RAW_CONTACT_ID + "=?" + " AND " 3937 * + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'", 3938 * new String[] {String.valueOf(rawContactId)}, null); 3939 * </pre> 3940 * </dd> 3941 * <dt>Finding all Data for a given raw contact</dt> 3942 * <dd> 3943 * Most sync adapters will want to read all data rows for a raw contact 3944 * along with the raw contact itself. For that you should use the 3945 * {@link RawContactsEntity}. See also {@link RawContacts}. 3946 * </dd> 3947 * </dl> 3948 * </p> 3949 * </dd> 3950 * </dl> 3951 * <h2>Columns</h2> 3952 * <p> 3953 * Many columns are available via a {@link Data#CONTENT_URI} query. For best performance you 3954 * should explicitly specify a projection to only those columns that you need. 3955 * </p> 3956 * <table class="jd-sumtable"> 3957 * <tr> 3958 * <th colspan='4'>Data</th> 3959 * </tr> 3960 * <tr> 3961 * <td style="width: 7em;">long</td> 3962 * <td style="width: 20em;">{@link #_ID}</td> 3963 * <td style="width: 5em;">read-only</td> 3964 * <td>Row ID. Sync adapter should try to preserve row IDs during updates. In other words, 3965 * it would be a bad idea to delete and reinsert a data row. A sync adapter should 3966 * always do an update instead.</td> 3967 * </tr> 3968 * <tr> 3969 * <td>String</td> 3970 * <td>{@link #MIMETYPE}</td> 3971 * <td>read/write-once</td> 3972 * <td> 3973 * <p>The MIME type of the item represented by this row. Examples of common 3974 * MIME types are: 3975 * <ul> 3976 * <li>{@link CommonDataKinds.StructuredName StructuredName.CONTENT_ITEM_TYPE}</li> 3977 * <li>{@link CommonDataKinds.Phone Phone.CONTENT_ITEM_TYPE}</li> 3978 * <li>{@link CommonDataKinds.Email Email.CONTENT_ITEM_TYPE}</li> 3979 * <li>{@link CommonDataKinds.Photo Photo.CONTENT_ITEM_TYPE}</li> 3980 * <li>{@link CommonDataKinds.Organization Organization.CONTENT_ITEM_TYPE}</li> 3981 * <li>{@link CommonDataKinds.Im Im.CONTENT_ITEM_TYPE}</li> 3982 * <li>{@link CommonDataKinds.Nickname Nickname.CONTENT_ITEM_TYPE}</li> 3983 * <li>{@link CommonDataKinds.Note Note.CONTENT_ITEM_TYPE}</li> 3984 * <li>{@link CommonDataKinds.StructuredPostal StructuredPostal.CONTENT_ITEM_TYPE}</li> 3985 * <li>{@link CommonDataKinds.GroupMembership GroupMembership.CONTENT_ITEM_TYPE}</li> 3986 * <li>{@link CommonDataKinds.Website Website.CONTENT_ITEM_TYPE}</li> 3987 * <li>{@link CommonDataKinds.Event Event.CONTENT_ITEM_TYPE}</li> 3988 * <li>{@link CommonDataKinds.Relation Relation.CONTENT_ITEM_TYPE}</li> 3989 * <li>{@link CommonDataKinds.SipAddress SipAddress.CONTENT_ITEM_TYPE}</li> 3990 * </ul> 3991 * </p> 3992 * </td> 3993 * </tr> 3994 * <tr> 3995 * <td>long</td> 3996 * <td>{@link #RAW_CONTACT_ID}</td> 3997 * <td>read/write-once</td> 3998 * <td>The id of the row in the {@link RawContacts} table that this data belongs to.</td> 3999 * </tr> 4000 * <tr> 4001 * <td>int</td> 4002 * <td>{@link #IS_PRIMARY}</td> 4003 * <td>read/write</td> 4004 * <td>Whether this is the primary entry of its kind for the raw contact it belongs to. 4005 * "1" if true, "0" if false. 4006 * </td> 4007 * </tr> 4008 * <tr> 4009 * <td>int</td> 4010 * <td>{@link #IS_SUPER_PRIMARY}</td> 4011 * <td>read/write</td> 4012 * <td>Whether this is the primary entry of its kind for the aggregate 4013 * contact it belongs to. Any data record that is "super primary" must 4014 * also be "primary". For example, the super-primary entry may be 4015 * interpreted as the default contact value of its kind (for example, 4016 * the default phone number to use for the contact).</td> 4017 * </tr> 4018 * <tr> 4019 * <td>int</td> 4020 * <td>{@link #DATA_VERSION}</td> 4021 * <td>read-only</td> 4022 * <td>The version of this data record. Whenever the data row changes 4023 * the version goes up. This value is monotonically increasing.</td> 4024 * </tr> 4025 * <tr> 4026 * <td>Any type</td> 4027 * <td> 4028 * {@link #DATA1}<br> 4029 * {@link #DATA2}<br> 4030 * {@link #DATA3}<br> 4031 * {@link #DATA4}<br> 4032 * {@link #DATA5}<br> 4033 * {@link #DATA6}<br> 4034 * {@link #DATA7}<br> 4035 * {@link #DATA8}<br> 4036 * {@link #DATA9}<br> 4037 * {@link #DATA10}<br> 4038 * {@link #DATA11}<br> 4039 * {@link #DATA12}<br> 4040 * {@link #DATA13}<br> 4041 * {@link #DATA14}<br> 4042 * {@link #DATA15} 4043 * </td> 4044 * <td>read/write</td> 4045 * <td> 4046 * <p> 4047 * Generic data columns. The meaning of each column is determined by the 4048 * {@link #MIMETYPE}. By convention, {@link #DATA15} is used for storing 4049 * BLOBs (binary data). 4050 * </p> 4051 * <p> 4052 * Data columns whose meaning is not explicitly defined for a given MIMETYPE 4053 * should not be used. There is no guarantee that any sync adapter will 4054 * preserve them. Sync adapters themselves should not use such columns either, 4055 * but should instead use {@link #SYNC1}-{@link #SYNC4}. 4056 * </p> 4057 * </td> 4058 * </tr> 4059 * <tr> 4060 * <td>Any type</td> 4061 * <td> 4062 * {@link #SYNC1}<br> 4063 * {@link #SYNC2}<br> 4064 * {@link #SYNC3}<br> 4065 * {@link #SYNC4} 4066 * </td> 4067 * <td>read/write</td> 4068 * <td>Generic columns for use by sync adapters. For example, a Photo row 4069 * may store the image URL in SYNC1, a status (not loaded, loading, loaded, error) 4070 * in SYNC2, server-side version number in SYNC3 and error code in SYNC4.</td> 4071 * </tr> 4072 * </table> 4073 * 4074 * <p> 4075 * Some columns from the most recent associated status update are also available 4076 * through an implicit join. 4077 * </p> 4078 * <table class="jd-sumtable"> 4079 * <tr> 4080 * <th colspan='4'>Join with {@link StatusUpdates}</th> 4081 * </tr> 4082 * <tr> 4083 * <td style="width: 7em;">int</td> 4084 * <td style="width: 20em;">{@link #PRESENCE}</td> 4085 * <td style="width: 5em;">read-only</td> 4086 * <td>IM presence status linked to this data row. Compare with 4087 * {@link #CONTACT_PRESENCE}, which contains the contact's presence across 4088 * all IM rows. See {@link StatusUpdates} for individual status definitions. 4089 * The provider may choose not to store this value 4090 * in persistent storage. The expectation is that presence status will be 4091 * updated on a regular basic. 4092 * </td> 4093 * </tr> 4094 * <tr> 4095 * <td>String</td> 4096 * <td>{@link #STATUS}</td> 4097 * <td>read-only</td> 4098 * <td>Latest status update linked with this data row.</td> 4099 * </tr> 4100 * <tr> 4101 * <td>long</td> 4102 * <td>{@link #STATUS_TIMESTAMP}</td> 4103 * <td>read-only</td> 4104 * <td>The absolute time in milliseconds when the latest status was 4105 * inserted/updated for this data row.</td> 4106 * </tr> 4107 * <tr> 4108 * <td>String</td> 4109 * <td>{@link #STATUS_RES_PACKAGE}</td> 4110 * <td>read-only</td> 4111 * <td>The package containing resources for this status: label and icon.</td> 4112 * </tr> 4113 * <tr> 4114 * <td>long</td> 4115 * <td>{@link #STATUS_LABEL}</td> 4116