I am currently working on a android project in which I want to Sync mobile contacts to server, After researching a lot about SyncAdapter
and Creating account in accountmanager
, I have learned it myself. however there are two things I don't understand, I searched about these in google but could not get perfect answer. Please don't duplicate the question, I want to know more clearly how it works.
- As the Google documentation says whenever a sync is done, the dirty flag of the contact gets changed. My doubt is how will the android OS detect the status of the Sync of that particular contact as I am programatically specifying what contacts go to server?
Ex:- In below example, I want to send a bundle to server.
Bundle extras = new Bundle();
extras.putInt("contact name after filtering", "number after filtering");
ContentResolver.requestSync(account,ContactsContract.AUTHORITY, extras);
then the Bundle extras received on the onPerformSync
Method and send to server.
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
for (String key : extras.keySet())
{
Log.d("Bundle Debug", key + " = \"" + extras.get(key) + "\"");
}
//Code to send to server
}
Let's say in the above example, variable extras is a bundle which obtained after filtering changes in the contacts list,want to update them to server.Now how will the SyncAdapter framework or OS detect the changes and update dirty flag of that contact? Of course I have provided AUTHORITY
, don't know how does that help in finding what changed. IS the above method is correct way to implement?
- How to find if the sync is failed? or Finished ?