Skip to content

Commit

Permalink
Merge pull request morenoh149#132 from npomfret/master
Browse files Browse the repository at this point in the history
 * reverting use of SOURCE_ID field (in favour of CONTACT_ID ) as it doesn't seem to work on all devices
  • Loading branch information
morenoh149 authored Dec 22, 2016
2 parents 85c3e75 + 8eed6aa commit 57845fc
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ContactsProvider {
public static final int ID_FOR_PROFILE_CONTACT = -1;

private static final List<String> JUST_ME_PROJECTION = new ArrayList<String>() {{
add(ContactsContract.RawContacts.SOURCE_ID);
add(ContactsContract.Data.CONTACT_ID);
add(ContactsContract.Data.LOOKUP_KEY);
add(ContactsContract.Contacts.Data.MIMETYPE);
add(ContactsContract.Profile.DISPLAY_NAME);
Expand Down Expand Up @@ -128,14 +128,13 @@ private Map<String, Contact> loadContactsFrom(Cursor cursor) {

while (cursor != null && cursor.moveToNext()) {

String contactId = null;
int columnIndex = cursor.getColumnIndex(ContactsContract.RawContacts.SOURCE_ID);
int columnIndex = cursor.getColumnIndex(ContactsContract.Data.CONTACT_ID);
String contactId;
if (columnIndex != -1) {
contactId = cursor.getString(columnIndex);
}

if(contactId == null) {
contactId = String.valueOf(ID_FOR_PROFILE_CONTACT);// there is no sourceid for 'ME' user, as a result it can't (currently) be updated
} else {
//todo - double check this, it may not be necessary any more
contactId = String.valueOf(ID_FOR_PROFILE_CONTACT);//no contact id for 'ME' user
}

if (!map.containsKey(contactId)) {
Expand Down Expand Up @@ -227,7 +226,7 @@ public String getPhotoUriFromContactId(String contactId) {
Cursor cursor = contentResolver.query(
ContactsContract.Data.CONTENT_URI,
PHOTO_PROJECTION.toArray(new String[PHOTO_PROJECTION.size()]),
ContactsContract.RawContacts.SOURCE_ID + " = ?",
ContactsContract.RawContacts.CONTACT_ID + " = ?",
new String[]{contactId},
null
);
Expand Down

0 comments on commit 57845fc

Please sign in to comment.