读取所有联系数据 [英] Reading all contact data
本文介绍了读取所有联系数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是Android 2.3.3,API级别10.我想读取所有联系人和与其关联的数据,因此例如所有电子邮件地址,电话号码,自定义字段... 我这样尝试过:
I am on Android 2.3.3, API Level 10. I want to read all contacts and data associated to them, therefore e.g. all email addresses, phone numbers, custom fields... I tried it like this:
Uri contactUri = ContactsContract.Contacts.CONTENT_URI;
Cursor contacts = managedQuery(contactUri, null, null, null, null );
contacts.moveToFirst();
do {
for(int i=0;i<contacts.getColumnCount();i++)
{
System.out.println(contacts.getColumnName(i) + ": " + contacts.getString(i));
}
System.out.println("============\n\n");
} while (contacts.moveToNext());
contacts.close();
但是,这仅给我以下字段:
However this gives me only the following fields:
times_contacted: 0
contact_status: null
custom_ringtone: null
has_phone_number: 1
phonetic_name: null
phonetic_name_style: 0
contact_status_label: null
lookup: [removed]
contact_status_icon: null
last_time_contacted: 0
display_name: [removed]
sort_key_alt: [removed]
in_visible_group: 1
_id: 101
starred: 0
sort_key: [removed]
display_name_alt: [removed]
contact_presence: null
display_name_source: 40
contact_status_res_package: null
contact_chat_capability: null
contact_status_ts: null
photo_id: null
send_to_voicemail: 0
电话号码,电子邮件地址...在哪里?谢谢您的提示!
Where are the phone numbers, email addresses...? Thanks for any hint!
推荐答案
请参阅联系合同API示例
See Contact Contract API examples
http://www.higherpass.com/Android/Tutorials/Working-With-Android-Contacts/
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String id = cur.getString(
cur.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur.getString(
cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
//Query phone here. Covered next
}
}
}
}
看看这个例子
http://code.google.com/p/android-contacts -contract-example/
这篇关于读取所有联系数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文