I created a raw contact which is updated if there is any changes from the contact. Peradventure, the user deletes the raw contact before the next sync, the contact has a dirty flag.
From my implementation, in such scenerio, i first clear the flag and update the contact.
private static void clearDirtyFlag(Context context, long rawContactId,
BatchOperation batchOperation) {
final ContactOperations contactOp =
ContactOperations.updateExistingContact(context, rawContactId,
batchOperation);
final Uri uri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
contactOp.updateDirtyFlag(false, uri);
}
private static void updateContact(Context context,
ContentResolver resolver, String accountName, User user,
long rawContactId, BatchOperation batchOperation) {
Uri uri;
String cellPhone = null;
String otherPhone = null;
String email = null;
final Cursor c =
resolver.query(Data.CONTENT_URI, DataQuery.PROJECTION,
DataQuery.SELECTION,
new String[]{String.valueOf(rawContactId)}, null);
final ContactOperations contactOp =
ContactOperations.updateExistingContact(context, rawContactId,
batchOperation);
try {
while (c.moveToNext()) {
final long id = c.getLong(DataQuery.COLUMN_ID);
final String mimeType = c.getString(DataQuery.COLUMN_MIMETYPE);
uri = ContentUris.withAppendedId(Data.CONTENT_URI, id);
if (mimeType.equals(StructuredName.CONTENT_ITEM_TYPE)) {
final String lastName =
c.getString(DataQuery.COLUMN_FAMILY_NAME);
final String firstName =
c.getString(DataQuery.COLUMN_GIVEN_NAME);
contactOp.updateName(uri, firstName, lastName, user
.getName());
} else if (mimeType.equals(Phone.CONTENT_ITEM_TYPE)) {
final int type = c.getInt(DataQuery.COLUMN_PHONE_TYPE);
if (type == Phone.TYPE_MOBILE) {
cellPhone = c.getString(DataQuery.COLUMN_PHONE_NUMBER);
contactOp.updatePhone(cellPhone, user.getCellPhone(),
uri);
} else if (type == Phone.TYPE_OTHER) {
otherPhone = c.getString(DataQuery.COLUMN_PHONE_NUMBER);
contactOp.updatePhone(otherPhone, user.getCellPhone(),
uri);
}
} else if (Data.MIMETYPE.equals(Email.CONTENT_ITEM_TYPE)) {
email = c.getString(DataQuery.COLUMN_EMAIL_ADDRESS);
// contactOp.updateEmail(user.getEmail(), email, uri);
}
} // while
} finally {
c.close();
}
}
issue is the contact is never updated as the raw_contact_id no longer exist. Am I implementing this the right way or what way can I update a dirty raw contact. Thanks