I am developing an android chat app and would like to automatically add/synchronize contacts like whatsapp does when the user installs the app, and whenever a new contact is added or deleted. I intend using xmpp or a java library for the app. Thanks
I am developing an android chat app and would like to automatically add/synchronize contacts
Share
If your contact sync is to run separately from your chat app, you should use a
SyncAdapter. This runs as an Androidservice, so it can keep the contacts in-sync with a server even when your chat app isn’t running. See the following URL for theSampleSyncAdapterprovided by Google, that gives source code and information for building your ownSyncAdapter… http://developer.android.com/resources/samples/SampleSyncAdapter/index.htmlIf you’re only wanting to sync contacts when your app is running, then you don’t actually need any kind of sync mechanism, you just need to add contacts to your device.
For both these methods, you add contacts by creating
ContactsContractobjects, writing them to the Android contacts database. There are a number of variants ofContactsContractdepending on the type of data you want to store – for example,ContactsContract.CommonDataKinds.Emailis used to store email addresses for a contact. See this URL for information onContactsContract… http://developer.android.com/reference/android/provider/ContactsContract.htmlI would recommend that you definately read through the source code of the
SampleSyncAdapterhttp://developer.android.com/resources/samples/SampleSyncAdapter/index.html as it provides all the code you need to read and write contacts from the Android contacts database, it shows how to build theContactsContractfor storing contact information, and provides an example of theSyncAdapterif you choose to use it.