2014-06-18 132 views
0

当前在我的应用程序中,我使用跟踪光标查询获取所有联系人。获取“正常”联系人

String[] columnsToReturn = new String[] { 
    ContactsContract.Contacts._ID, 
    ContactsContract.Contacts.DISPLAY_NAME_PRIMARY 
}; 

Cursor contactsCursor = getActivity().getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, columnsToReturn, null, null, null); 

这将返回所有联系人,包括Skype,WhatsApp等我不想要这些。我只想要“正常”的。那些不适用于任何应用程序的,只是存储在您的Google帐户中的应用程序。我该怎么做呢?

另外,我可以排除用户自己的条目吗?例如,我的名字在我的所有不同的电子邮件地址列表上多次出现。

回答

0

ContactsContract.Contacts表包含“合并”联系人。

...代表相同的 个人的原始联系人总数的记录。

如果要查询特定帐户或帐户类型的联系人,则需要使用RawContacts。例如,对于Google联系人,这将是:

Cursor c = getContentResolver().query(
     RawContacts.CONTENT_URI, 
     new String[] { RawContacts.CONTACT_ID, RawContacts.DISPLAY_NAME_PRIMARY }, 
     RawContacts.ACCOUNT_TYPE + "= ?", 
     new String[] { "com.google" }, 
     null); 

ArrayList<String> myContacts = new ArrayList<String>(); 
int contactNameColumn = c.getColumnIndex(RawContacts.DISPLAY_NAME_PRIMARY); 
while (c.moveToNext()) 
{ 
    // You can also read RawContacts.CONTACT_ID to read the 
    // ContactsContract.Contacts table or any of the other related ones. 
    myContacts.add(c.getString(contactNameColumn)); 
}