7

I am looking for a way to enable/disable the "auto-sync" checkbox in the "general sync settings".

Afair the stock power control widget has this feature too. If this widget can do, there should be a solution for me too, right? Please guys help me out, I am desperately looking for a solution on the web with no success.

Is it possible that a user interaction is mandatory for this operation? I know I can send an Intent to open the Sync View but this is not my intention!

I am not looking for the sync settings for a specific account as I found in this forum like

ContentResolver.setSyncAutomatically(Account account, String authority, boolean sync);
Cœur
  • 37,241
  • 25
  • 195
  • 267
GZA
  • 478
  • 6
  • 11

2 Answers2

8

I am looking for a way to enable/disable the "auto-sync" checkbox in the "general sync settings".

UPDATE

Try setMasterSyncAutomatically() on ContentResolver.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I am afraid to tell but what you wrote cannot be correct. There is a widget in the Android market by curvefish that does exactly the thing I wanted to do. It enables the auto sync feature without user interaction and it is not part of the firmware! So there must be a way to implement this. I've already written an email to the developer to find out. – GZA Nov 09 '11 at 12:38
  • @GZA: Ah, but you pointed out what might be the right area to look -- see replaced answer above. – CommonsWare Nov 09 '11 at 13:51
  • How to listen in a BroadcastReceiver (onReceive) ether Auto-sync data is turning on/off ? – hasnain_ahmad Jun 01 '16 at 05:53
  • It does not work on Android 9 (MIUI 11), Xiaomi Mi6 – Alexey Nikitin Jan 17 '20 at 09:32
0
ContentResolver.setMasterSyncAutomatically(true); // enables AutoSync

You should also add this

<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />

to your AndroidManifest.xml file.