Android contacts sync in background - android

I want to show the contacts whoever using my app. I know this is an old one but nothing satisfies me. I'm already using the method that gets all the contacts from phone and send to server and checking the available contacts who all are
using my app then return to my app.
Finally, it will save into the local database. But the problem is when adding new contact we have to sync again. For that time it will take more time and other functionality may become slow.
What I need is when I open the app at first time it should sync all the contacts and then it should monitor the changes like add, delete and update of the contacts then only it should check the changed contact.
I refers this blog, but there is no proper code. So many files are missed. How can i sync contacts?

finally,I have done with this library.

Related

How to cancel contentresolver applyBatch?

I've built an application that requires to export 2000 contacts to native Android Contacts. I use contentresolver.applyBatch to make this happen, but if the user logs out I want to delete all of the apps exported contacts. It can occur that the contentresolver is not fully finished with saving the contacts.
My question:
How can I cancel the following opperation?:
resolver.applyBatch(ContactsContract.AUTHORITY, ops);
What I've tried so far:
I've tried to cancel the sync of the contentresolver like this:
ContentResolver.cancelSync(null, ContactsContract.AUTHORITY);
This doesn't work and I'm also not sure about the null value. It says it needs an account to stop syncing it for. But I'm not starting the sync on a specific account so why would it be needed?
What I need?
Something like resolver.stopBatch (a way to stop applying the batch).
Thank you for all your effort reading this.
If I understand the use case, you're syncing in new RawContacts into the device, when a user logs into your app.
If that's the case, you should create a SyncProvider, and have it sync in RawContacts on an account that is tied to your app and package name.
That way, when a user uninstalls your app, the account is automatically removed along with the data you've synced into the device, and when a user logs out of her account, you simply remove the contacts account programatically, which will also remove all data synced to the device.
Read these tutorials on how to create a contacts account, a SyncProvider and use it to sync contacts on your account:
http://blog.udinic.com/2013/04/24/write-your-own-android-authenticator/
http://blog.udinic.com/2013/07/24/write-your-own-android-sync-adapter/
https://developer.android.com/training/sync-adapters/creating-sync-adapter.html

Contact sync adapter in android

I want to use sync adapter in my application to sync the native and third party contacts (except FB) with server. ( Only client to server one way sync)
I have two doubts here -
1) If there are multiple sync adapters in the device and If dirty bit is already cleared by another sync adapter , would my sync adapter be able to detect the contacts change/update immediately.
2) I have used
ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true);
to sync the contacts with server .
It does start the sync in every 30 seconds .
But I want it to get notified immediately when ever contacts are added Or Deleted or Updated to start perfromSync operation.
Do I need to use observer too ?
In order to see changes to the contacts you will have to register an observer with the ContentResolver. The sync API is not intended to watch for every change, it is intended to be a background API that Android runs periodically automatically for you, so that it can batch operations and use the network more efficiently, not run when network is disabled, etc...
The dirty bit is used on a per account basis. In general the sync is designed to have an "owning" account per contact, and is not designed for exporting all the contacts from the device to a particular service. There is an aggregation process that handles joining contacts from multiple accounts into one "Contact" as seen by the user. See:
http://developer.android.com/reference/android/provider/ContactsContract.RawContacts.html
For more information on how this works.
If you intend to export all contacts on the device to your service you will need to walk the contacts and insert a raw contact for your service. You will then also want to watch the ContentResolver with an observer to see when the user adds a new contact on some service or periodically walk the table looking for contacts you have not yet exported.
use the version bit. If any contact edited
It automatically increased by 1.
so you create local database for compare previous version to current version. If any changes happen you trigger the update query.
for more information visit here.
This version helps for my sync updates. So I share this answer for all.

Two way sync adapter in Android

I have gone through a number of links and have spend a huge amount of time over this. Can someone please let me know the simplest approach to implement the Sync Adapter in Android which is 2 way. I mean the changes made on the remote database get reflected on the Android Device and the changes from the device should get updated on the server too.
Also, how to edit the contacts from the default contacts app editor??

Cant delete more than 200 contacts in HTC HERO

I'm working on security application which will copy all contacts to some other database and delete all contacts from phonebook.
I'm testing this on android HTC HERO.
I'm successful to delete contacts from phonebook and create new contact info database,
Till 200 it is working, but after 200 contacts its not working properly.
After tht application starts throwing error.
There is one Sync with Google Option in Menu>Setting>Data Sync, I think that is creating problem.
There is notification that "Too many contacts deleted"
n if i click tht there will b a dialog with title "Delete Limit exceeded".
Is there anything i can do to stop syncronization or any other ideas by which i can achieve
required output?
Please Help me on this
Google Sync is a bit picky - it hates it when there are too many things going on. The calendar has the same problem. I doubt that you want to turn syncing off (the user may not appreciate it either if you turn off a core functionality). What's your goal? Do you want the deletion of contacts to be synced with gmail.com or not?
At this point, your only options as far as I can tell would be to throttle your app so it doesn't delete more than 200 records within a certain timeframe. Alternatively, you could use gdata to modify the contacts, but that's a really roundabout way and probably not suitable for your needs.
Do you delete and then re-create the contacts? Is there any way for you to recycle existing contacts instead of deleting them and then starting from scratch?

Contact Detail syncing between people app and my app

I am involved in a project which has the functionality like whatsapp does for contacts.My app have to get the contact from phone(ie Peoples app) and sync it to server to find the users who are all already involved in my app.If a user not involved already i need to place a invite button.
For sync there is no problem i implemented a sync adapter,I have to get the updates like new phone no added or name changed in the contacts of people app.
I think VERSION and CONTACT_LAST_UPDATED_TIMESTAMP fields are not exactly what i need.Because they may be updated when other details in the
are changed.
I need to monitor the contacts change when my app starts,if there any changes in contacts i need to get that contact details and send it to server to know his status.Is running a service with content observer
will work for this case.
If it works how can i get the updated contact details.
Could someone help me?

Categories

Resources