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