1

I have an app that exports contacts. Similar contacts get aggregated by an internal scoring mechanism, see Android contacts aggregation process

My issue is that the same contacts exported with Outlook for Android get a different aggregation.

To test this i have created one contact (Identicus) with name, given name, work phone and email 5 times. It gets aggregated for both apps.

I have created another two contacts (Hans Test and Hans Othertest) with the same given name and work phone, but different names. When i export it the two contacts get aggregated, when Outlook exports it they are not aggregated.

With ContactsContract.RawContacts.AGGREGATION_MODE_DISABLED i can disable aggregation for all my contacts - but i want the identical contacts to be aggregated.

I checked https://developer.android.com/reference/android/provider/ContactsContract.Contacts.AggregationSuggestions to see if i could identify the contacts that were about to be aggregated and un-aggregate them by using an AggregationException, but the data seems to be not useful.

Does anybody have an idea why the aggregation works differently for Outlook and my app? Or a hint how i could control this behavior?

slowcar
  • 314
  • 2
  • 13

1 Answers1

1

AggregationExceptions is indeed the key here.

If you know the RawContact IDs of the contacts in question you can tell Android to aggregate them, or un-aggregate them by adding an AggregationException.

So if the RawContacts have ids 111 & 222 -

ContentProviderOperation.newUpdate(AggregationExceptions.CONTENT_URI)
            .withValue(AggregationExceptions.TYPE, AggregationExceptions.TYPE_KEEP_SEPARATE)
            .withValue(AggregationExceptions.RAW_CONTACT_ID1, 111)
            .withValue(AggregationExceptions.RAW_CONTACT_ID2, 222)
            .build()

will keep those raws separated, and -

ContentProviderOperation.newUpdate(AggregationExceptions.CONTENT_URI)
            .withValue(AggregationExceptions.TYPE, AggregationExceptions.TYPE_KEEP_TOGETHER)
            .withValue(AggregationExceptions.RAW_CONTACT_ID1, 111)
            .withValue(AggregationExceptions.RAW_CONTACT_ID2, 222)
            .build()

will keep those raws aggregated.

you'll of course need to apply the operations, via something like:

context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, operations);
marmor
  • 27,641
  • 11
  • 107
  • 150
  • I am pretty sure Outlook does not use any AggregationExceptions, at least there is no trace in their apk (taking a peek with jadx). As there are potentially thousands of contacts i would have to re-implement the whole Android aggregation framework - so i am looking for an easier solution. – slowcar Jun 23 '20 at 15:06
  • `Outlook does not use any AggregationExceptions` that's probably true, contacts sync-adapters usually don't handle aggregation on their own, but rely on the system built-in aggregation logic to merge their contacts with other sync-providers' contacts. – marmor Jul 06 '20 at 11:59
  • apps that DO have AggregationException in their code are contact apps, like google's "Contacts" app, or Contacts+, these apps offer the user to manually split / join contacts, and when that happens the app will use AggEx for that, also it is usually accompanied by surfacing duplicate suggestions to the user – marmor Jul 06 '20 at 12:01
  • @marmor can you help me with this https://stackoverflow.com/q/63970269/5457916 ? – humble_wolf Sep 19 '20 at 15:23