0

May be this question is asked about 2-4 year ago.Still m not satisfied.My problem is: "how to turn on/off auto Sync Programmatically".I dont want any specific data to synchronous.Just want to know Is that possible to enable or disable Auto-sync programmatically ? If possible, then How? Can anyone give me Example?

which is shown like this on Android Screen: enter image description here

What is the use of ContentResolver.setSyncAutomatically(account, authority, true); in auto-sync?

Thanks in Advance.

Community
  • 1
  • 1
Bhoomika Brahmbhatt
  • 7,404
  • 3
  • 29
  • 44

1 Answers1

0

I guess you are talking about gmail auto sync the email right ? One way is setMasterSyncAutomatically() (ContentResolver), applies to all the accounts (and providers). If you set this off/false you can disable all the syncs.

This is what we have from android documentation.

public static void setMasterSyncAutomatically (boolean sync)

Added in API level 5
Sets the master auto-sync setting that applies to all the providers and accounts. If this is false then the per-provider auto-sync setting is ignored.

This method requires the caller to hold the permission WRITE_SYNC_SETTINGS.

Parameters
sync    the master auto-sync setting that applies to all the providers and accounts
Siddharth
  • 9,349
  • 16
  • 86
  • 148