{"id":19260725,"url":"https://github.com/evant/timesync","last_synced_at":"2025-06-21T22:06:26.315Z","repository":{"id":144875577,"uuid":"19964405","full_name":"evant/timesync","owner":"evant","description":"Android library for periodicly syncing data from server.","archived":false,"fork":false,"pushed_at":"2020-06-14T22:52:26.000Z","size":145,"stargazers_count":25,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-21T16:43:07.341Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/evant.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-05-20T02:07:31.000Z","updated_at":"2023-08-18T12:39:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"d45beb25-757b-4db8-aab3-d9236428dae6","html_url":"https://github.com/evant/timesync","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/evant/timesync","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evant%2Ftimesync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evant%2Ftimesync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evant%2Ftimesync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evant%2Ftimesync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evant","download_url":"https://codeload.github.com/evant/timesync/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evant%2Ftimesync/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261200403,"owners_count":23123951,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T19:22:41.665Z","updated_at":"2025-06-21T22:06:21.301Z","avatar_url":"https://github.com/evant.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"TimeSync\n========\n\nAndroid library for periodically syncing data to and from a server.\n\nThis library is an alternative to a SyncAdapter. It is easier to set up, and doesn't require you to worry about accounts or content providers.\n\nNote: this library uses permissions `ACCESS_NETWORK_STATE`, `WAKE_LOCK`, and `RECEIVE_BOOT_COMPLETED`.\n\n#### Features\n- Periodically sync on a given interval in a battery-conscious way.\n- Turn off syncing when there is no network connection.\n- Randomly offset syncs so that they don't all hit the server at once.\n- Sync across apps using this library at the same time to reduce wakeups.\n- Retry on sync failure.\n\n## Usage\nFirst create `MySync.java`. This will hold the logic of how your are syncing.\n\n```java\npublic class MySync extends TimeSync {\n  @Override\n  protected void onCreate(Context context) {\n    super.onCreate(context);\n    // This is called whenever MySync is created.\n  }\n  \n  @Override\n  public void onSync(Context context) throws Exception {\n    // Implement you sync logic here. This will run on a\n    // seperate thread and network is guaranteed to be available.\n    // An exception represents a sync failure.\n  }\n}\n```\n\nThen create `timesync.xml` in `res/xml`. This is where you put configuration for how and when syncs happen. You can define as many TimeSync classes as you want in here.\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\n\u003ctimesync\u003e\n    \u003clistener name=\".MySync\" every=\"1 day\"/\u003e\n\u003c/timesync\u003e\n```\n\nThen add a `meta-data` attribute to your `AndroidManifest`.\n\n```xml\n\u003capplication\u003e\n  ...\n  \u003cmeta-data android:name=\"me.tatarka.timesync.TimeSync\" android:resource=\"@xml/timesync\"/\u003e\n\u003c/application\u003e\n```\n\nFinally, make sure you start TimeSync in your Application subclass.\n\n```java\npublic class MyApplication extends Application {\n  @Override\n  public void onCreate(Context context) {\n    super.onCreate(context);\n    TimeSync.start(context);\n  }\n}\n```\n\n## Running\n\nYour sync class will automatically run based on it's configuration. If you want to start it manually, you can do so as well. Note that this will be ignored if your sync class is disabled.\n\n```java\n  TimeSyncProxy mySync = TimeSync.get(context, MySync.class);\n  mySync.sync();\n```\n\nWhen running as a response to some event, a GCM message for example, you may want to ensure all devices don't hit your server at exactly the same time. In this case use\n\n```java\n  mySync.syncInexact();\n```\n\n## Configuration\n\nConfiguration can either take place in xml, or at runtime, the second useful if you want to provide some user control.\n\nFor xml use\n\n```xml\n  \u003clistener name=\".MySync\" config_option=\"value\"/\u003e\n```\n\n- **enabled=\"true|false\"** If the TimeSync is even enabled. If not, both periodic and explicit syncs will not be run.\n- **every=\"10 [second(s)|minute(s)|hour(s)|day(s)|year(s)]\"** How often to sync periodically. If no unit is provided, it will be assumed milliseconds. The default is 0, which disables periodic syncing.\n- **range=\"5 [second(s)|minute(s)|hour(s)|day(s)|year(s)]\"** The range of the random offset added to syncs so that they don't hit the server at exactly the same time. A sync will occur up to the given value after regularly scheduled. The default is 5 minutes. This is also used for `TimeSync.syncInexact()`.\n\nIn code, use `TimeSyncProxy.edit(...)`. Setting values this way will override the xml config and be persisted across updates.\n\n### Proguard\n\n```\n  -keep class * extends me.tatarka.timesync.lib.TimeSync { *; }\n```\n\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevant%2Ftimesync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevant%2Ftimesync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevant%2Ftimesync/lists"}