Search code examples
androidsynchronizationandroid-syncadapterandroid-account

Enable auto sync programmatically


I want to enable auto sync in account settings in my app programmatically. I've set up the SyncAdapter, declared it in manifest, I added account and after this action I tried:

ContentResolver.setSyncAutomatically(account, authority, true);
ContentResolver.setMasterSyncAutomatically(true);

but it's not working. There is the same questions on SE:

but they are too old, and in them I found, that I need to use ContentResolver.setMasterSyncAutomatically(true), but it's not working on my Android 7, Android 9.

Auto sync is not enabled


Solution

  • The problem was in the authority string argument in ContentResolver.setSyncAutomatically(account, authority, true);, it needs to be "com.android.contacts" for contacts synchronization