aggregation of contacts

satya - Monday, November 01, 2010 12:54:58 PM

contact aggregation

contact aggregation

Search Google for: contact aggregation

Search Android Developers Group for: contact aggregation

Search Android Beginers Group for: contact aggregation

Search Google Code for: contact aggregation

Search Android Issues Database for: contact aggregation

satya - Monday, November 01, 2010 12:56:25 PM

few notes on contact look up uri

few notes on contact look up uri

satya - Monday, November 01, 2010 1:02:59 PM

A must read thread on how lookupkeys are formed

A must read on how lookupkeys are formed

Find subsequently what is posted here.

satya - Monday, November 01, 2010 1:03:32 PM

A quote from tehre.

Lookup key is unique at any point in time. It's not unique over time.

The anatomy of a lookup key is basically this. If an aggregate contact has three raw contacts with server-side IDs "A", "B" and "C", the lookup key will effectively be accountA/A.accountB/B.accountC/C

satya - Monday, November 01, 2010 1:05:51 PM

containging the most of the original raw contacts

contact ID, which will be the one containing the most of the original raw contacts

satya - Monday, November 01, 2010 1:07:17 PM

Something to digest from that topic

Lookup key is unique at any point in time. It's not unique over time.

The anatomy of a lookup key is basically this. If an aggregate contact has three raw contacts with server-side IDs "A", "B" and "C", the lookup key will effectively be accountA/A.accountB/B.accountC/C

We don't attempt to find a contact with that exact lookup key. We actually parse it, find all those three raw contacts and infer the id of the new contact ID, which will be the one containing the most of the original raw contacts. In other words, even though the result is a bit unpredictable, the user shouldn't be surprised by what they see. The original contact had A, B and C - now I am looking at something that has either A or B or C or a couple of those or maybe A,B,C and D.

You are right that you should not use lookup keys to compare contact identities to each other. You can use the ContactsContract.Contacts.lookupContact(resolver, lookupUri) method, which will give you the current contact ID for your contact. Be careful though - between the moment you get it and the moment you use it the contact may change. Any kind of background sync could cause this change to happen. I would try to design the software in such a way that either doesn't need to do this type of resolution or uses something even more robust than lookup keys, e.g. raw contact IDs.

satya - Monday, November 01, 2010 1:12:47 PM

On Aggregation algorithms

can tell you what we did when we faced a similar requirement. We needed to store things like custom ringtone, "straight-to-voicemail" etc on a per-contact basis. What we ended up doing is simply replicating this information into each raw contact in the aggregate. When raw contacts are re-aggregated, we use a heuristic to figure out the values for the entire aggregate (e.g. if one of the raw contacts has straight-to-voicemail=false, then the entire contact has straight-to-voicemail=false).

I would do the same in your case. You can always get _ids of all raw contacts in an aggregate contact and then in your database have a row for each of those raw contacts. To retrieve the information for an aggregate contact, you would pull it for all constituent raw contacts and use an algorithm to "aggregate" the data.

satya - Monday, November 01, 2010 1:22:16 PM

Another meaty thread on contacts api

Another meaty thread on contacts api

satya - Monday, November 01, 2010 1:23:42 PM

How to have the contacts app create a contact for your need

You can always delegate contact creation to the Contacts app using the ContactsContract.Intents.UI.Insert intent with extras. This will show the edit UI.

satya - Monday, November 01, 2010 1:27:42 PM

get a list of accounts


AccountManager am = AccountManager.get(getContext()); 
Account[] accounts = am.getAccounts();

satya - Monday, November 01, 2010 1:31:15 PM

account types


SyncAdapterType[] syncs 
= ContentResolver.getContentService().getSyncAdapterTypes(); 

for (SyncAdapterType sync : syncs) 
{ 
     if (ContactsContract.AUTHORITY.equals(sync.authority) 
          && sync.supportsUploading()) 
     { 
          contactAccountTypes.add(sync.accountType); 
     } 
}

for (Account acct: accounts) 
{ 
   if (contactAccountTypes.contains(acct.type)) 
   { 
      contactAccounts.add(account); 
   } 
}

satya - Monday, November 01, 2010 1:34:43 PM

More on structure

"Contacts" represents an aggregated contact

"RawContacts" represents a contact as it was inserted by the sync adapter.

RawContact has a CONTACT_ID field that binds it to a Contact.

"Data" represents everything about a RawContact: emails, phone numbers, notes, birthday, high school graduation year, you name it.

Data has a RAW_CONTACT_ID field that binds it a RawContact.

The other important field is MIMETYPE. That's what determines the kind of data stored in a Data row. Everything else is just convenience API.

satya - Monday, November 01, 2010 1:36:58 PM

On Group Memberships

Raw contacts can have group memberships. A GroupMembership is a row in the Data table. If you want to add a membership find the group you need and add a row to the Data table with mimetype GroupMembership.CONTENT_ITEM_TYPE and the id of the group:

satya - Monday, November 01, 2010 1:37:43 PM

On Photos

Regarding photos: are you setting the IS_SUPER_PRIMARY flag on your Photo row? The notion of "super-primary" has to do with multiple accounts. You can have only one super-primary photo for an entire aggregated contact.

satya - Monday, November 01, 2010 1:41:01 PM

On Deletion

- Deleting an aggregated contact will delete all constituent raw contacts

- Deleting all constituent raw contacts will delete the aggregated contact

- Deleting a raw contact automatically deletes all constituent data rows.

- This is a technical detail, but resolver.delete(...), does not physically delete a raw contacts row. It sets the DELETED flag on the raw contact.

The sync adapter then deletes the raw contact from the server and finalizes phone-side deletion by calling resolver.delete(...) again and passing the CALLER_IS_SYNCADAPTER query parameter.

satya - Monday, November 01, 2010 1:43:10 PM

On Sync adapters

A sync adapter is a service whose job is to sync data between a back end and the phone. It is typically kicked-off automatically on a schedule. Sync adapters are managed by sync manager, which knows when to start them, avoids running multiple at the same time and does a bunch of other useful stuff. You will want to inherit from android.content.AbstractThreadedSyncAdapter.

Also, see if it makes sense for you to have a separate account. Then instead of dropping new contacts to the Gmail or Exchange servers you would just bring them to the phone. Your contacts will get nicely aggregated with other contacts on the phone.

satya - Monday, November 01, 2010 2:13:22 PM

See if this library is useful

http://code.google.com/p/libs-for-android/

satya - Monday, November 01, 2010 2:17:18 PM

writing sync adapter part 1

writing sync adapter part 1

satya - Monday, November 01, 2010 2:18:12 PM

and part 2

and part 2

satya - Monday, November 01, 2010 2:19:15 PM

sourceconstraints xml

sourceconstraints xml

Search Google for: sourceconstraints xml

Search Android Developers Group for: sourceconstraints xml

Search Android Beginers Group for: sourceconstraints xml

Search Google Code for: sourceconstraints xml

Search Android Issues Database for: sourceconstraints xml

satya - Monday, November 01, 2010 2:30:17 PM

locate source code for contacts application

locate source code for contacts application

satya - Monday, November 01, 2010 2:30:39 PM

source code for android contacts application

source code for android contacts application

Search for: source code for android contacts application

satya - Monday, November 01, 2010 2:33:45 PM

sample sync provider from google

sample sync provider from google

satya - Tuesday, November 02, 2010 10:26:15 AM

Displaying a contact from two accounts

Displaying a android contact from two accounts

Search Google for: Displaying a contact from two accounts

Search Android Developers Group for: Displaying a contact from two accounts

Search Android Beginers Group for: Displaying a contact from two accounts

Search Google Code for: Displaying a contact from two accounts

Search Android Issues Database for: Displaying a contact from two accounts

satya - Tuesday, November 02, 2010 11:16:47 AM

displaying contacts first page

you will see icon (photo id), display name (borrowed from one of the raw contacts).

A contact may have more than one raw contact. which contact is to choose as the primary?? In a manual case you have the option. Not sure how this play out in auto mode.

May be there is a primary account.

satya - Tuesday, November 02, 2010 11:19:56 AM

rules for android contact aggregation

rules for android contact aggregation

Search for: rules for android contact aggregation

satya - Tuesday, November 02, 2010 11:24:01 AM

contact details will likely come from contact_entities_view

contact details will likely come from contact_entities_view

satya - Tuesday, November 02, 2010 11:36:30 AM

Resolving based on lookup key

lookup key is roughly a concatenation of the raw contact ids. So given a/b/c where a, b, c are raw contacts.

if "c" flies away fromt his flock, then the contact id based on the look up key will be one pointing to "a" and "b".

satya - Tuesday, November 02, 2010 12:57:46 PM

contacts overlappling fields

contacts overlappling fields

Search Google for: contacts overlappling fields

Search Android Developers Group for: contacts overlappling fields

Search Android Beginers Group for: contacts overlappling fields

Search Google Code for: contacts overlappling fields

Search Android Issues Database for: contacts overlappling fields

satya - Tuesday, November 02, 2010 12:59:34 PM

android contacts tutorial external link

android contacts tutorial external link

satya - Tuesday, November 02, 2010 1:21:54 PM

display contact from multiple accounts

display contact from multiple accounts

Search Google for: display contact from multiple accounts

Search Android Developers Group for: display contact from multiple accounts

Search Android Beginers Group for: display contact from multiple accounts

Search Google Code for: display contact from multiple accounts

Search Android Issues Database for: display contact from multiple accounts

satya - Tuesday, November 02, 2010 2:59:55 PM

merge contacts

merge contacts

Search Google for: merge contacts

Search Android Developers Group for: merge contacts

Search Android Beginers Group for: merge contacts

Search Google Code for: merge contacts

Search Android Issues Database for: merge contacts

satya - Tuesday, November 02, 2010 3:07:12 PM

This is a good read

This is a good read

Contacts with same last names but single first name seem to be merged. May be this is a good way to test overlapping fields. Let me see.

satya - Tuesday, November 02, 2010 3:31:16 PM

another post on that same issue

another post on that same issue