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