I am using the syncadaptor extensively in my application for its core functionality. I also use the periodic refresh provided by the syncadaptor. Hence it the “Accounts and sync” is disabled on a phone my application will be pretty much useless. Is it considered a bad practice or rude to do a ContentResolver.setMasterSyncAutomatically(true) to turn the sync on. By just doing a ContentResolver.setIsSyncable doesnt help since if the main account and sync is disabled then periodic syncs dont work.
What is the common way of handling this scenario?
Thanks in advance,
-v-
I would call this bad practice.
There are two different enable flags for sync which serve different functions.
Master Sync is a single enable flag for ALL syncrhonization regardless of account type or content type. This setting is “Auto-Sync” on the Accounts & Sync page and a user typically turns it off to save battery. Some users might (ab)use it to go into a sort of “do not disturb” mode. Programatically, this is checked and unchecked through
ContentResolver.setMasterSyncAutomatically()Secondly, your Account/Authority pair has an enable flag. So, say a google account. You click on the google account and then you get a subpage… Sync drive, sync google play music, sync contacts, sync gmail… etc. Each of those is an Account(com.google) and an Authority(com.android.contacts), paired together. They are individually controllable, so I can have a google account that syncs contacts but not my calendar. Further, even the available items in the list can vary — I might have one account that has google music installed but another that does not — so the list of things in that subpage can vary, and what’s checked or unchecked can vary. Note that the account shows a green sync circle if there is an authority attached that is syncable, but the account itself is not sycable in isolation. Programatically, this is checked and unchecked through
ContentResolver.setSyncAutomatically(), and is enabled/disabled (greyed out) throughContentResolver.setIsSyncable(). You would grey it out when it’s not configured.Your app is well within its rights to turn sync on and off for its own account/authority pair (Though you should respect the user’s wishes.) Think like a “sync enabled” checkbox on your app’s sync settings page that reflects state to/from the A&S subpage through
(get/set)SyncAutomatically()Yes, your app can change the master sync flag — But in doing so, you really need to consider whether you’re going over the user’s head to make decisions about how their phone works. This can help users who don’t know how to work their phones, and will seriously piss off users who do. I would instantly uninstall an app that changed my phone-wide sync settings without my permission. The furthest I personally would go is to perhaps popup a dialog to the user when they configure sync — “Sync is configured, but will not be performed until Auto-Sync is turned on in the Accounts & Sync page. Would you like to turn Auto-Sync on?” and then fire an intent to take them them to the A&S page to turn it on if they say yes. That helps a user understand how their phone works, rather than just changing things behind their back and making it even more a mystery.
Overall, you should never reconfigure the phone without getting consent from the user.