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