Contacts backup and sync application
I am working on a contacts backup and sync.
The target is to send all details of all contacts to a server (custom protocol defined) as a backup.
During initial launch of application, all the contacts will be queued and sent to the server. And after that, a backg开发者_JAVA技巧round service will be running all time which will listen to new contact addition/ contact update, and this new/updated contact will be sent to server by the background service.
I am using RawContactsEntity for fetching the records.
I tried using ContentObserver
on RawContacts/Data tables to get notification of contact addition or contact-change. But, AFAIK, the ContentObserver
gives notification (onChange()
) of changed data in table as a whole and not ID of individual record.
Now my problem is, how to get the exact id's of changed/new records?
I thought of creating a backup-table to compare with native contacts table and get the changed records. But as the number of contacts increase, the performance will decease drastically and this will hamper the battery life too.
Can you suggest me, The best way for achieving this contacts backup operation from performance and memory usage point of view? Is there any other way for contacts sync operation?
It would be very helpful if anyone can share examples which can help me in this.
If the contacts are stored within your account(AccountManger), Android will mark the dirty flag in raw contacts. If it is not your account then you can not trust the dirty flag as the accounts sync adapter might have updated the contact to the server and reset the dirty flag. Your only option is to either re-upload the full contacts(simple and easy to code) or keep track of the version column in RawContacts and check which one has changed. It is actually not recommended to copy and upload contacts from other accounts as the corresponding sync adapter will anyways maintain a backup of those. Like Google will have a copy of Google contacts on their server.
精彩评论