user1435114 user1435114 - 3 months ago 34
Android Question

Check if Sync is Enabled within Android App

Is there a way to check, programmatically within my Android app, whether a particular setting under Settings > Accounts and Sync > Data & Synchronization is enabled or not?

Is there a way to check if the general sync settings are enabled?


If it helps to know "why," I'm currently rolling my own sync functionality (not using SyncAdapter). However, if possible I'd like to have my sync service listed under Data & Synchronization. Right now I'm planning to hack a dummy sync service that does nothing and have my app's sync service query whether or not the dummy sync service is enabled. That will tell me whether to sync or not.


You can check whether sync is enable or not with the help of below code and this Document

AccountManager am = AccountManager.get(YourActivity.this);
Account account = am.getAccountsByType(Const.ACCOUNT_TYPE)[0];
  if(ContentResolver.isSyncActive(account, DataProvider.AUTHORITY){
     // sync is enable

You can also set enable/disable programmatically with the help of this ContentResolver.setSyncAutomatically and ContentResolver.setMasterSyncAutomatically

Update :

isSyncActive returns true if there is currently a sync operation for the given account or authority in the pending list, or actively being processed.