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