ContentResolver.addPeriodicSync doesn’t work – never syncs

By  | March 7, 2014 | Filed under: Software development

Probably you’ve followed Google’s Android sync adaptor training guide up to http://developer.android.com/training/sync-adapters/running-sync-adapter.html#RunPeriodic and are wondering why syncing never happens.

There are two mistakes in the training guide as far as explaining how to make addPeriodicSync work:

  1. You must call ContentResolver.setSyncAutomatically with true as the third (sync) parameter to enable syncing for your adaptor.
  2. The fourth (pollFrequency) parameter of ContentResolver.addPeriodicSync is a number of seconds, as stated here, and not milliseconds, as implied in the training guide. The demo code for addPeriodicSync in the training guide will cause a sync once every thousand hours instead of once an hour.

10 Responses to ContentResolver.addPeriodicSync doesn’t work – never syncs

  1. Edu Rodríguez May 23, 2014 at 12:30 pm

    Thanks,

    This solve my problem with addPeriodicSync and sample code :-/

  2. Ezequiel September 9, 2014 at 12:26 am

    Thanks!! This is the only place I found where somebody mentions the ContentResolver.setSyncAutomatically thing.

  3. Pingback: [android] Sync Adapter | PipisCrew Official Homepage

  4. Pingback: Android Programming | archartfact

  5. droiddude July 10, 2016 at 1:05 pm

    your first point of setting ContentResolver.setSyncAutomatically fixed the problem. i wonder why google missed this point!

  6. Boobaal September 1, 2018 at 1:44 pm

    in vivo 6.0.1 periodic sync working but in vivo 7.1.1 thats not happening help me guys iam using below code
    ContentResolver.setIsSyncable(account, “com.android.contacts”, 1);
    ContentResolver.setSyncAutomatically(account, AUTHORITY, true);
    ContentResolver.addPeriodicSync(account,AUTHORITY,result,SYNC_INTERVAL);

    • kotlinisland May 23, 2019 at 4:46 pm

      I know that the minimum sync interval was one hour on android before API 24 then is it 15 min on android after or equals to API 24

  7. Periklis Karachristos Boletis February 28, 2019 at 5:50 pm

    You rock my man

  8. kotlinisland May 23, 2019 at 4:18 pm

    It seems to work!

  9. kotlinisland May 23, 2019 at 4:45 pm

    Source code at that github address if you need :
    https://github.com/reuniware/Android-Sync-Adapter

    I have just updated it with the info I have just had here !

Leave a Reply

Your email address will not be published. Required fields are marked *