Cursor cursor = resolver.query(
Data.CONTENT_URI,
DataQuery.PROJECTION,
DataQuery.SELECTION,
new String[] {String.valueOf(rawContactId)},
null);
There are a few issues that i could locate with the following query:
Cursor cursor = resolver.query(Data.CONTENT_URI,
UserIdQuery.PROJECTION,
UserIdQuery.SELECTION,
new String[] {username}, null);
RawContacts.CONTENT_URI
instead of Data.CONTENT_URI
.Here the value of RawContacts.SOURCE_ID is compared with username
public static final String SELECTION = RawContacts.ACCOUNT_TYPE + "='" +
"com.tagapp.android" + "' AND " + RawContacts.SOURCE_ID + "=?";
new String[] {username}
There was an error in the lookupRawContactId method, the rawcontactId long I was getting wasn't the right one. It should have looked like this:
private static long lookupRawContact(ContentResolver resolver, String username) {
Log.e("Looking up Raw Contact", username);
long authorId = 0;
Cursor cursor = resolver.query(
RawContacts.CONTENT_URI,
UserIdQuery.PROJECTION,
UserIdQuery.SELECTION,
new String[] {username},
null);
try {
if(cursor != null && cursor.moveToFirst()) {
authorId = cursor.getLong(UserIdQuery.COLUMN_ID);
}
} finally {
if(cursor != null) {
cursor.close();
}
}
return authorId;
}