Add App Icon On Contact Not Working In Marshmallow
Solution 1:
You're creating a newRawContact
, and hoping that the system aggregates it into an existing Contact
.
You're missing the "please attach this new raw-contact into this existing contact" part.
To do that you need to add an AggregationExceptions.
First, find the current RawContact IDs
in the Contact
you wish to add to, then add a line to AggregationExceptions
that links between your new RawContact._ID
(raw1
) and an existing RawContact._ID
(raw2
)
Builder builder = ContentProviderOperation.newUpdate(AggregationExceptions.CONTENT_URI);
builder.withValue(AggregationExceptions.TYPE, AggregationExceptions.TYPE_KEEP_TOGETHER);
builder.withValue(AggregationExceptions.RAW_CONTACT_ID1, raw1);
builder.withValue(AggregationExceptions.RAW_CONTACT_ID2, raw2);
ops.add(builder.build());
EDIT
If you want to add this code to your existing batch:
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
// insert account name and account type
ops.add(ContentProviderOperation.newInsert( ... ).build());
// insert contact number
ops.add(ContentProviderOperation.newInsert( ... ).build());
// insert mime-type data
ops.add(ContentProviderOperation.newInsert( ... ).build());
// add an AggregationExceptions line
ops.add(ContentProviderOperation.newUpdate(AggregationExceptions.CONTENT_URI)
.withValue(AggregationExceptions.TYPE, AggregationExceptions.TYPE_KEEP_TOGETHER)
.withValueBackReference(AggregationExceptions.RAW_CONTACT_ID1, 0)
.withValue(AggregationExceptions.RAW_CONTACT_ID2, theRawContactIdOfTheExistingContact)
.build());
try {
resolver.applyBatch(ContactsContract.AUTHORITY, ops);
} catch (Exception e) { ... }
The only thing you need to fill in here is theRawContactIdOfTheExistingContact
, note that it's not a contact-id, it's a raw-contact-id, you'll need to put the right value there, depending on the rest of your code, and how you find the contact to add your data to.
Post a Comment for "Add App Icon On Contact Not Working In Marshmallow"