How to marge between 2 or more contacts on android - android

In my application that i write i have 2 or more contacts that i need to marge.
So i want to use the android feature "join" between those contacts to make this marge between than.
For example, I have contact "AAA" with an email account and a phone number, and I've noticed that some apps like whatsapp, Facebook and Skype are creating new contact entries for AAA, instead of merging the existing one.
How can i do it ?
I don't find any example on the web or anything how to do it.

There is an aggregate mode(RawContacts.AGGREGATION_MODE). Have a look at this Android not adding all contacts with duplicate fields

Related

How to add a custom contacts repo to Android?

As an android user, I would like to develop an app that installs a local contacts repo that is in parallel with the Google and Samsung contact providers/repos.
The reason is adding temporary contacts with a TTL. When looking for an apartment, I don't want all these random contacts. When selling something, I have just multitudes of contacts with no names just so I don't save these temps. When calling up moving companies, or any temporary agency ... I do not want these contacts forever on my phone.
How do I create a custom contacts repo such as in manage accounts?
I looked all over for something like this, and I found ContactProvider which felt like the right one, but after reading the docs, it doesn't quite fit. Tried AccountProvider but that is mostly about authorization from what I understand.
How can I add a contact provider such as Google Contacts or Samsung Contacts?

How to control android contact aggregation

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?
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);

how to display device address book ordered by custom external data

In my android application I would like to display the mobile user's contacts (names, profile picture ) displaying first the contacts that have already installed and registrered that application (the matching is made by contact's email).
Trying to loop over each contact and match if their email is already registered (in an external SQLITE table) don't seems to be an efficient way.
I would like to directly add (somewhere in the address book ?) the extra data "isRegistered = true/false) and order my addreess book query by this value to scroll the address book.
Is it possible? How to implement this in detail ?
OPTION 1
I think the most efficient way would be what you thought about initially, with a slight improvement:
store the list of registered emails (for the user's contacts) in a local SQLite DB.
read the entire list of emails on application launch, and store them in a HashSet
When sorting the contacts, create a custom Comparator to first check if the contact is an app user or not, and only then fallback to name compare.
OPTION 2
If you still want to check the option of storing the custom value in the Contacts DB, and integrate it into your query, you need to create a SyncAdapter.
This is basically a service that is able to sync contacts to/from a server into your own RawContact, which is then aggregated into one-or-more existing RawContacts, like Google does for Google Contacts.
You can set it to be notified when a new contact is added, and have your SyncAdapter add the needed info to the contact so it'll show links to your app.
If you go to your phone settings > accounts, you can see Whatsapp and Google's SyncAdapters there, where you can turn them off/on.
To create a sync adapter, you can follow the official docs, or this great tutorial.

Which contacts have my application installed?

I'm building a small app for messaging (in some way a bit similar to 'WhatsApp' or 'Viber'). WhatsApp and Viber show you contacts that are from your contact list and have an account with them. so my question is how to sync?
For now, I have database which stores all users using the application and their phone number.
Do I need to run a query for each contact in my phone in order to find it in the database?
It looks a lot of queries for every sync request.
What is the efficient way in order to do this?
If you have both sets of data as database tables, then can't you just join on some attribute like 'Full Name' and the resulting table will be all people in your contacts list with the app installed?
You can display contacts in your app that are just pulled from the contact list on the phone. Using LoadManager you can get a contact list that is synced with the phone list.
Check out these links for more info
http://developer.android.com/training/contacts-provider/retrieve-names.html
https://developer.android.com/training/load-data-background/setup-loader.html

Is it possible to insert the two new contacts with same display name on Android 2.2?

I need to insert two new contacts with same display name. But all other fields are different.
How its possible?
I tried to insert like this, but both contacts are conflicted on Android 2.2 contacts.
Android's 2.x Contacts API will aggregate 2 raw contacts with the same name by default. See the section Automatic aggregation in Using the Contacts API.
What you need to do is disable automatic aggregration, which is also described in that very useful article. You merely have to set your RawContact record's AGGREGATION_MODE value to AGGREGATION_MODE_DISABLED.

Categories

Resources