联系人 数据库 contacts , data , raw_contacts表相关
联系人data表
类
android.provider.ContactsContract.Data
Constants for the data table, which contains data points tied to a raw contact. For example, a phone number or email address.
Data kinds
Data is a generic table that can hold all kinds of data. Sync adapters and applications can introduce their own data kinds. The kind of data stored in a particular row is determined by the mime type in the row. Fields from DATA1 through DATA15 are generic columns whose specific use is determined by the kind of data stored in the row. For example, if the data kind is Phone.CONTENT_ITEM_TYPE, then DATA1 stores the phone number, but if the data kind is Email.CONTENT_ITEM_TYPE, then DATA1 stores the email address.
ContactsContract defines a small number of common data kinds, e.g. ContactsContract.CommonDataKinds.Phone, ContactsContract.CommonDataKinds.Email etc. As a convenience, these classes define data kind specific aliases for DATA1 etc. For example, Phone.NUMBER is the same as Data.DATA1.
DATA1 is an indexed column and should be used for the data element that is expected to be most frequently used in query selections. For example, in the case of a row representing email addresses DATA1 should probably be used for the email address itself, while DATA2 etc can be used for auxiliary information like type of email address.
By convention, DATA15 is used for storing BLOBs (binary data).
Typically you should refrain from introducing new kinds of data for 3rd party account types. For example, if you add a data row for "favorite song" to a raw contact owned by a Google account, it will not get synced to the server, because the Google sync adapter does not know how to handle this data kind. Thus new data kinds are typically introduced along with new account types, i.e. new sync adapters.
查询操作
// 1 Finding all Data of a given type for a given contact Cursor c = getContentResolver().query(Data.CONTENT_URI, new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL}, Data.CONTACT_ID + "=?" + " AND " + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'", new String[] {String.valueOf(contactId)}, null);// 2 Finding all Data of a given type for a given raw contactCursor c = getContentResolver().query(Data.CONTENT_URI, new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL}, Data.RAW_CONTACT_ID + "=?" + " AND " + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'", new String[] {String.valueOf(rawContactId)}, null);
* StructuredName.CONTENT_ITEM_TYPE // "vnd.android.cursor.item/name" * Phone.CONTENT_ITEM_TYPE // "vnd.android.cursor.item/phone_v2" * Email.CONTENT_ITEM_TYPE // "vnd.android.cursor.item/email_v2" * Photo.CONTENT_ITEM_TYPE // "vnd.android.cursor.item/photo" * Organization.CONTENT_ITEM_TYPE // ..... * Im.CONTENT_ITEM_TYPE * Nickname.CONTENT_ITEM_TYPE // "vnd.android.cursor.item/nickname" * Note.CONTENT_ITEM_TYPE * StructuredPostal.CONTENT_ITEM_TYPE * GroupMembership.CONTENT_ITEM_TYPE * Website.CONTENT_ITEM_TYPE * Event.CONTENT_ITEM_TYPE * Relation.CONTENT_ITEM_TYPE
Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode("bob")); Cursor c = getContentResolver().query(uri, new String[]{Email.DISPLAY_NAME, Email.DATA}, null, null, null);
// 1, Finding all raw contacts in a Contact is easy: Cursor c = getContentResolver().query(RawContacts.CONTENT_URI, new String[]{RawContacts._ID}, RawContacts.CONTACT_ID + "=?", new String[]{String.valueOf(contactId)}, null);//There are two ways to find raw contacts within a specific account, // you can either put the account name and type in the selection or pass them as query parameters. // The latter approach is preferable, especially when you can reuse the URI: Uri rawContactUri = RawContacts.URI.buildUpon() .appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName) .appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType) .build(); Cursor c1 = getContentResolver().query(rawContactUri, RawContacts.STARRED + "<>0", null, null, null); ... Cursor c2 = getContentResolver().query(rawContactUri, RawContacts.DELETED + "<>0", null, null, null);// The best way to read a raw contact along with all the data associated with it is by using the ContactsContract.RawContacts.Entity directory. // If the raw contact has data rows, the Entity cursor will contain a row for each data row. // If the raw contact has no data rows, the cursor will still contain one row with the raw contact-level information. Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId); Uri entityUri = Uri.withAppendedPath(rawContactUri, Entity.CONTENT_DIRECTORY); Cursor c = getContentResolver().query(entityUri, new String[]{RawContacts.SOURCE_ID, Entity.DATA_ID, Entity.MIMETYPE, Entity.DATA1}, null, null, null); try { while (c.moveToNext()) { String sourceId = c.getString(0); if (!c.isNull(1)) { String mimeType = c.getString(2); String data = c.getString(3); ... } } } finally { c.close(); }
D/GN> columname of query uri( 4993): : Contacts.CONTENT_URI,D/GN> ( 4993): : <0>: times_contactedD/GN> ( 4993): : <1>: contact_statusD/GN> ( 4993): : <2>: custom_ringtoneD/GN> ( 4993): : <3>: has_phone_numberD/GN> ( 4993): : <4>: contact_status_labelD/GN> ( 4993): : <5>: lookupD/GN> ( 4993): : <6>: contact_status_iconD/GN> ( 4993): : <7>: last_time_contactedD/GN> ( 4993): : <8>: display_nameD/GN> ( 4993): : <9>: in_visible_groupD/GN> ( 4993): : <10>: _idD/GN> ( 4993): : <11>: starredD/GN> ( 4993): : <12>: contact_presenceD/GN> ( 4993): : <13>: contact_status_res_packageD/GN> ( 4993): : <14>: contact_status_tsD/GN> ( 4993): : <15>: photo_idD/GN> ( 4993): : <16>: send_to_voicemail
D/GN> column name of query uri( 4993): : ContactsContract.CommonDataKinds.Phone.CONTENT_URI,D/GN> ( 4993): : <0>: data_versionD/GN> ( 4993): : <1>: contact_idD/GN> ( 4993): : <2>: lookupD/GN> ( 4993): : <3>: data12D/GN> ( 4993): : <4>: data11D/GN> ( 4993): : <5>: data10D/GN> ( 4993): : <6>: mimetypeD/GN> ( 4993): : <7>: data15D/GN> ( 4993): : <8>: data14D/GN> ( 4993): : <9>: data13D/GN> ( 4993): : <10>: data_sync1D/GN> ( 4993): : <11>: data_sync3D/GN> ( 4993): : <12>: data_sync2D/GN> ( 4993): : <13>: data_sync4D/GN> ( 4993): : <14>: account_typeD/GN> ( 4993): : <15>: custom_ringtoneD/GN> ( 4993): : <16>: statusD/GN> ( 4993): : <17>: data1D/GN> ( 4993): : <18>: data4D/GN> ( 4993): : <19>: data5D/GN> ( 4993): : <20>: data2D/GN> ( 4993): : <21>: data3D/GN> ( 4993): : <22>: data8D/GN> ( 4993): : <23>: data9D/GN> ( 4993): : <24>: group_sourceidD/GN> ( 4993): : <25>: data6D/GN> ( 4993): : <26>: account_nameD/GN> ( 4993): : <27>: data7D/GN> ( 4993): : <28>: display_nameD/GN> ( 4993): : <29>: in_visible_groupD/GN> ( 4993): : <30>: contact_status_res_packageD/GN> ( 4993): : <31>: is_primaryD/GN> ( 4993): : <32>: contact_status_tsD/GN> ( 4993): : <33>: raw_contact_idD/GN> ( 4993): : <34>: times_contactedD/GN> ( 4993): : <35>: contact_statusD/GN> ( 4993): : <36>: status_res_packageD/GN> ( 4993): : <37>: status_iconD/GN> ( 4993): : <38>: contact_status_iconD/GN> ( 4993): : <39>: modeD/GN> ( 4993): : <40>: versionD/GN> ( 4993): : <41>: last_time_contactedD/GN> ( 4993): : <42>: res_packageD/GN> ( 4993): : <43>: _idD/GN> ( 4993): : <44>: status_tsD/GN> ( 4993): : <45>: dirtyD/GN> ( 4993): : <46>: is_super_primaryD/GN> ( 4993): : <47>: photo_idD/GN> ( 4993): : <48>: send_to_voicemailD/GN> ( 4993): : <49>: contact_status_labelD/GN> ( 4993): : <50>: status_labelD/GN> ( 4993): : <51>: starredD/GN> ( 4993): : <52>: contact_presenceD/GN> ( 4993): : <53>: sourceid
D/GN> columname of query uri( 4993): : ContactsContract.Data.CONTENT_URI,D/GN> ( 4993): : <0>: data_versionD/GN> ( 4993): : <1>: contact_idD/GN> ( 4993): : <2>: lookupD/GN> ( 4993): : <3>: data12D/GN> ( 4993): : <4>: data11D/GN> ( 4993): : <5>: data10D/GN> ( 4993): : <6>: mimetypeD/GN> ( 4993): : <7>: data15D/GN> ( 4993): : <8>: data14D/GN> ( 4993): : <9>: data13D/GN> ( 4993): : <10>: data_sync1D/GN> ( 4993): : <11>: data_sync3D/GN> ( 4993): : <12>: data_sync2D/GN> ( 4993): : <13>: data_sync4D/GN> ( 4993): : <14>: account_typeD/GN> ( 4993): : <15>: custom_ringtoneD/GN> ( 4993): : <16>: statusD/GN> ( 4993): : <17>: data1D/GN> ( 4993): : <18>: data4D/GN> ( 4993): : <19>: data5D/GN> ( 4993): : <20>: data2D/GN> ( 4993): : <21>: data3D/GN> ( 4993): : <22>: data8D/GN> ( 4993): : <23>: data9D/GN> ( 4993): : <24>: group_sourceidD/GN> ( 4993): : <25>: data6D/GN> ( 4993): : <26>: account_nameD/GN> ( 4993): : <27>: data7D/GN> ( 4993): : <28>: display_nameD/GN> ( 4993): : <29>: in_visible_groupD/GN> ( 4993): : <30>: contact_status_res_packageD/GN> ( 4993): : <31>: is_primaryD/GN> ( 4993): : <32>: contact_status_tsD/GN> ( 4993): : <33>: raw_contact_idD/GN> ( 4993): : <34>: times_contactedD/GN> ( 4993): : <35>: contact_statusD/GN> ( 4993): : <36>: status_res_packageD/GN> ( 4993): : <37>: status_iconD/GN> ( 4993): : <38>: contact_status_iconD/GN> ( 4993): : <39>: modeD/GN> ( 4993): : <40>: versionD/GN> ( 4993): : <41>: last_time_contactedD/GN> ( 4993): : <42>: res_packageD/GN> ( 4993): : <43>: _idD/GN> ( 4993): : <44>: status_tsD/GN> ( 4993): : <45>: dirtyD/GN> ( 4993): : <46>: is_super_primaryD/GN> ( 4993): : <47>: photo_idD/GN> ( 4993): : <48>: send_to_voicemailD/GN> ( 4993): : <49>: contact_status_labelD/GN> ( 4993): : <50>: status_labelD/GN> ( 4993): : <51>: starredD/GN> ( 4993): : <52>: contact_presenceD/GN> ( 4993): : <53>: sourceid
D/GN> columname of query uri( 4993): : ContactsContract.RawContacts.CONTENT_URI,D/GN> ( 4993): : <0>: times_contactedD/GN> ( 4993): : <1>: custom_ringtoneD/GN> ( 4993): : <2>: contact_idD/GN> ( 4993): : <3>: sync4D/GN> ( 4993): : <4>: sync3D/GN> ( 4993): : <5>: sync2D/GN> ( 4993): : <6>: sync1D/GN> ( 4993): : <7>: deletedD/GN> ( 4993): : <8>: versionD/GN> ( 4993): : <9>: account_nameD/GN> ( 4993): : <10>: last_time_contactedD/GN> ( 4993): : <11>: aggregation_modeD/GN> ( 4993): : <12>: _idD/GN> ( 4993): : <13>: starredD/GN> ( 4993): : <14>: dirtyD/GN> ( 4993): : <15>: sourceidD/GN> ( 4993): : <16>: send_to_voicemailD/GN> ( 4993): : <17>: account_type