Syncing Contacts with an Android Application

How to Sync Google Contacts With Android: 4 Steps (with Pictures)

Syncing the phone book contacts in an android device with your application is being used by various android applications today. These applications include Whatsapp, Google+, Skype and various email applications. In this way, contacts syncing allows the user to access contacts from various social applications from the phone book itself.Now I will explain with an example Android application how the syncing process happens. This Android application runs in the background as soon as its launched and synchronizes itself with the device’s phone book contacts. Following is a screenshot of a contact synced with the app.

Clicking on MyData will take us to the desired screen on the application.


Contacts syncing requires three components to work in order which is:-

  1. Contacts provider
  2. Authenticator service
  3. Sync service

Contacts provider

Contacts provider is the standard access provider to the device’s data about people. All the contacts in the phone are managed by the contacts provider through tables that can be queried to get data. There are basically three tables that store data for a person.

These tables are-

Figure 1- Contacts provider table structure (Source)

  1. ContactsContract.Contacts is the table that contains the aggregated data from raw contacts rows that represents different people in the contacts list.
  2. ContactsContract.RawContacts table contains the person’s accounts and type data summary.
  3. ContactsContract.Data table contains other details corresponding to each raw contact like email address, phone number, etc.

I made use of the ContentProviderOperation to handle the table insertion operations on the table to add a raw contact and the data corresponding to my app and finally to apply the changes to the database as a batch operation.

Here is the sample code for the class that handles this functionality:

Authenticator Service

Tutorial: Build an Android Application with Secure User Authentication

The authenticator service is used to create an account for our app on the device. It plugs into the Android accounts and authentication framework through which an account type is created on the device corresponding to our app. Accounts for standard social applications like Whatsapp, Skype, Facebook, etc. can be found if you visit the accounts screen in settings on your device.

Sync Service

The sync service is made up of two parts the sync adapter and the sync service itself. The sync adapter is used to synchronize data between the server and the local database. My app doesn’t fetch any data from the server but still, it is required to implement the sync adapter. The sync service is what binds the sync adapter to the android sync framework.

The authenticator service runs in the background when the app is launched to create an account for the app on the device. The sync service is called in a periodic cycle to constantly sync the data.

When you tap on the Whatsapp icon on the contacts screen, it will take you to the chat screen of that contact. Similarly, in the phonebook contacts, your app icon can be seen which is clickable to access the app screens that correspond to that contact’s information on the app. The contact data can be sent through the intent extras to the activity that launches.


Share on facebook
Share on twitter
Share on pinterest
Share on linkedin
<b><strong>Karan Makan</strong></b>

Karan Makan

Technology Engineer and Entrepreneur. Currently working with International Clients and helping them scale their products through different ventures. With over 8 years of experience and strong background in Internet Product Management, Growth & Business Strategy.

On Key

Related Posts

Hook Up on Tinder

Since dating can be stressful, there is the possibility of humor to try to reduce tensions. In a new study published in the Proceedings of

error: Content is protected !!