我有这个方法返回具有给定组ID的所有联系人:
public ArrayList<ContactEntity> getContactListByGroup(String groupID) {
if (groupID != null) {
ArrayList<ContactEntity> contacts = new ArrayList<ContactEntity>();
Uri groupURI = ContactsContract.Data.CONTENT_URI;
String[] projection = new String[]{
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.GroupMembership.RAW_CONTACT_ID};
Cursor c = context.getContentResolver().query(
groupURI,
projection,
ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID
+ "=" + groupID, null, null);
while (c.moveToNext()) {
String id = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.GroupMembership.RAW_CONTACT_ID));
contacts.add(getContactByID(id));
}
return contacts;
} else {
return null;
}
}
问题在于,当我在手机上手动添加联系人时,它不会返回新联系人。但是,如果我通过applyBatch
(代码端)添加它,此方法将按预期返回新联系人。
有什么想法吗?
谢谢,