android.provider.ContactsContract ㄧ些資料庫欄位

///
// ContactsContract.Contacts.CONTENT_URI
///
取得所有的欄位:

Contacts.TIMES_CONTACTED - times_contacted
Contacts.CONTACT_STATUS - contact_status
Contacts.CUSTOM_RINGTONE - custom_ringtone
Contacts.HAS_PHONE_NUMBER - has_phone_number
Contacts.PHONETIC_NAME - phonetic_name
Contacts.PHONETIC_NAME_STYLE - phonetic_name_style
Contacts.CONTACT_STATUS_LABEL - contact_status_label
Contacts.LOOKUP_KEY - lookup
Contacts.CONTACT_STATUS_ICON - contact_status_icon
Contacts.LAST_TIME_CONTACTED - last_time_contacted
Contacts.DISPLAY_NAME_PRIMARY - display_name
Contacts.SORT_KEY_ALTERNATIVE - sort_key_alt
Contacts.IN_VISIBLE_GROUP - in_visible_group
Contacts.Contacts._ID - _id 
Contacts.STARRED - starred
Contacts.SORT_KEY_PRIMARY - sort_key
Contacts.DISPLAY_NAME_ALTERNATIVE - display_name_alt
Contacts.CONTACT_PRESENCE - contact_presence
Contacts.DISPLAY_NAME_SOURCE - display_name_source
Contacts.CONTACT_STATUS_RES_PACKAGE - contact_status_res_package
Contacts.CONTACT_CHAT_CAPABILITY - contact_chat_capability
Contacts.CONTACT_STATUS_TIMESTAMP - contact_status_ts
Contacts.PHOTO_ID - photo_id
Contacts.SEND_TO_VOICEMAIL - send_to_voicemail

對應介面:(#表示對應欄位)

protected interface ContactOptionsColumns {
        #public static final String TIMES_CONTACTED = "times_contacted";
        #public static final String LAST_TIME_CONTACTED = "last_time_contacted";
        #public static final String STARRED = "starred";
        #public static final String CUSTOM_RINGTONE = "custom_ringtone";
        #public static final String SEND_TO_VOICEMAIL = "send_to_voicemail";
    }
    
protected interface ContactsColumns {
        #public static final String DISPLAY_NAME = ContactNameColumns.DISPLAY_NAME_PRIMARY;
        public static final String NAME_RAW_CONTACT_ID = "name_raw_contact_id";
        #public static final String PHOTO_ID = "photo_id";
        #public static final String IN_VISIBLE_GROUP = "in_visible_group";
        #public static final String HAS_PHONE_NUMBER = "has_phone_number";
        #public static final String LOOKUP_KEY = "lookup";
    }

protected interface ContactStatusColumns {
        #public static final String CONTACT_PRESENCE = "contact_presence";
        #public static final String CONTACT_CHAT_CAPABILITY = "contact_chat_capability";
        #public static final String CONTACT_STATUS = "contact_status";
        #public static final String CONTACT_STATUS_TIMESTAMP = "contact_status_ts";
        #public static final String CONTACT_STATUS_RES_PACKAGE = "contact_status_res_package";
        #public static final String CONTACT_STATUS_LABEL = "contact_status_label";
        #public static final String CONTACT_STATUS_ICON = "contact_status_icon";
    }
    
protected interface ContactNameColumns {
        #public static final String DISPLAY_NAME_SOURCE = "display_name_source";
        #public static final String DISPLAY_NAME_PRIMARY = "display_name";
        #public static final String DISPLAY_NAME_ALTERNATIVE = "display_name_alt";
        #public static final String PHONETIC_NAME_STYLE = "phonetic_name_style";
        #public static final String PHONETIC_NAME = "phonetic_name";
        #public static final String SORT_KEY_PRIMARY = "sort_key";
        #public static final String SORT_KEY_ALTERNATIVE = "sort_key_alt";
    }


///
// ContactsContract.RawContacts.CONTENT_URI
///
取得所有的欄位:

RawContacts.TIMES_CONTACTED times_contacted
RawContacts.PHONETIC_NAME phonetic_name
RawContacts.PHONETIC_NAME_STYLE phonetic_name_style
RawContacts.CONTACT_ID contact_id
RawContacts.VERSION version
RawContacts.LAST_TIME_CONTACTED last_time_contacted
RawContacts.AGGREGATION_MODE aggregation_mode
RawContacts._ID _id
RawContacts.NAME_VERIFIED name_verified
RawContacts.DISPLAY_NAME_SOURCE display_name_source
RawContacts.DIRTY dirty
RawContacts.SEND_TO_VOICEMAIL send_to_voicemail
RawContacts.ACCOUNT_TYPE account_type
RawContacts.CUSTOM_RINGTONE custom_ringtone
RawContacts.SYNC4 sync4
RawContacts.SYNC3 sync3
RawContacts.SYNC2 sync2
RawContacts.SYNC1 sync1
RawContacts.DELETED deleted
RawContacts.ACCOUNT_NAME account_name
RawContacts.DISPLAY_NAME_PRIMARY display_name
RawContacts.SORT_KEY_ALTERNATIVE sort_key_alt
RawContacts.STARRED starred
RawContacts.SORT_KEY_PRIMARY sort_key
RawContacts.DISPLAY_NAME_ALTERNATIVE display_name_alt
RawContacts.SOURCE_ID sourceid

對應介面:(#表示對應欄位)

protected interface ContactOptionsColumns {
        #public static final String TIMES_CONTACTED = "times_contacted";
        #public static final String LAST_TIME_CONTACTED = "last_time_contacted";
        #public static final String STARRED = "starred";
        public static final String CUSTOM_RINGTONE = "custom_ringtone";
        #public static final String SEND_TO_VOICEMAIL = "send_to_voicemail";
    }
    
protected interface ContactNameColumns {
        #public static final String DISPLAY_NAME_SOURCE = "display_name_source";
        #public static final String DISPLAY_NAME_PRIMARY = "display_name";
        #public static final String DISPLAY_NAME_ALTERNATIVE = "display_name_alt";
        public static final String PHONETIC_NAME_STYLE = "phonetic_name_style";
        public static final String PHONETIC_NAME = "phonetic_name";
        #public static final String SORT_KEY_PRIMARY = "sort_key";
        #public static final String SORT_KEY_ALTERNATIVE = "sort_key_alt";
    }
    
protected interface RawContactsColumns {
        #public static final String CONTACT_ID = "contact_id";
        public static final String IS_RESTRICTED = "is_restricted";
        #public static final String AGGREGATION_MODE = "aggregation_mode";
        #public static final String DELETED = "deleted";
        #public static final String NAME_VERIFIED = "name_verified";
    }
    
protected interface SyncColumns extends BaseSyncColumns {
        #public static final String ACCOUNT_NAME = "account_name";
        #public static final String ACCOUNT_TYPE = "account_type";
        #public static final String SOURCE_ID = "sourceid";
        #public static final String VERSION = "version";
        #public static final String DIRTY = "dirty";
    }
    
protected interface BaseSyncColumns {
        #public static final String SYNC1 = "sync1";
        #public static final String SYNC2 = "sync2";
        #public static final String SYNC3 = "sync3";
        #public static final String SYNC4 = "sync4";
    }


///
// ContactsContract.CommonDataKinds.Email.CONTENT_LOOKUP_URI
///

方法:

ContentResolver contentResolver = getContentResolver();
Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode("xxx@xxx.com"));
Cursor cur = contentResolver.query(uri,null, null, null, null);

取得所有的欄位:

data_version
phonetic_name
phonetic_name_style
contact_id
lookup
data12
data11
data10
mimetype
data15
data14
data13
display_name_source
data_sync1
data_sync3
data_sync2
contact_chat_capability
data_sync4
account_type
custom_ringtone
status
data1
data4
data5
data2
data3
data8
data9
group_sourceid
data6
account_name
data7
display_name
in_visible_group
display_name_alt
contact_status_res_package
is_primary
contact_status_ts
raw_contact_id
times_contacted
contact_status
status_res_package
status_icon
contact_status_icon
mode
version
last_time_contacted
res_package
_id
name_verified
status_ts
dirty
is_super_primary
photo_id
send_to_voicemail
name_raw_contact_id
contact_status_label
status_label
sort_key_alt
starred
sort_key
contact_presence
sourceid


///
// ContactsContract.CommonDataKinds 資料分類
///

android.provider.ContactsContract.CommonDataKinds
android.provider.ContactsContract.CommonDataKinds.Email
android.provider.ContactsContract.CommonDataKinds.Event
android.provider.ContactsContract.CommonDataKinds.GroupMembership
android.provider.ContactsContract.CommonDataKinds.Im
android.provider.ContactsContract.CommonDataKinds.Nickname
android.provider.ContactsContract.CommonDataKinds.Note
android.provider.ContactsContract.CommonDataKinds.Email
android.provider.ContactsContract.CommonDataKinds.Organization
android.provider.ContactsContract.CommonDataKinds.Phone
android.provider.ContactsContract.CommonDataKinds.Photo
android.provider.ContactsContract.CommonDataKinds.Relation
android.provider.ContactsContract.CommonDataKinds.SipAddress
android.provider.ContactsContract.CommonDataKinds.StructuredName
android.provider.ContactsContract.CommonDataKinds.StructuredPostal
android.provider.ContactsContract.CommonDataKinds.Website

應用:

(1)取得第一筆聯絡人名稱與電話

String sMemberName = "", sPhoneNumber = "";
Cursor cur = getContentResolver().query(Data.CONTENT_URI, null, null, null, null);
if(cur!=null){
	cur.moveToFirst();
	sMemberName = cur.getString(cur.getColumnIndex(Contacts.DISPLAY_NAME));
	sPhoneNumber = cur.getString(cur.getColumnIndex(Phone.NUMBER));
	cur.close();
}

(2)利用RawContact ID 來取得資料

String sMemberContactId = "";
String sMemberName = "", sPhoneNumber = "";
ContentResolver contentResolver = getContentResolver();
Cursor cur = contentResolver.query(RawContacts.CONTENT_URI,
	    new String[] {RawContacts.CONTACT_ID},  null, null, null);
if(cur!=null){
	cur.moveToFirst();
	sMemberContactId = cur.getString(cur.getColumnIndex(RawContacts.CONTACT_ID));
	cur.close();
}
if(!TextUtils.isEmpty(sMemberContactId)){
	 cur = getContentResolver().query(Data.CONTENT_URI,
	          new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL, Contacts.DISPLAY_NAME},
	          Data.RAW_CONTACT_ID + "=?" + " AND "
	                  + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'",
	          new String[] {String.valueOf(sMemberContactId)}, null);
	if(cur!=null){
		cur.moveToFirst();
		sMemberName = cur.getString(cur.getColumnIndex(Contacts.DISPLAY_NAME));
		sPhoneNumber = cur.getString(cur.getColumnIndex(Phone.NUMBER));
		cur.close();
	}
}

(3)利用E-Mail 尋找聯絡人

ContentResolver contentResolver = getContentResolver();
Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode("xxx@xxx.com"));
Cursor cur = contentResolver.query(uri,null, null, null, null);
if(cur!=null && cur.moveToFirst()){
	for(int i=0; i<cur.getColumnCount(); i++){
		Log.d(TAG, cur.getColumnName(i));
	}
}

转载于:https://www.cnblogs.com/lisztkao/archive/2011/06/23/2088070.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值