General Sync Settings "Auto Sync" programmatically

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

In this regard, the stock power management widget also has this feature. If this widget can do, there must be a solution for me too, right? Please guys help me, I am desperately looking for a solution on the Internet without success.

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

I am not looking for synchronization settings for a specific account, as I found in this forum, for example

ContentResolver.setSyncAutomatically(Account account, String authority, boolean sync); 
+7
source share
2 answers

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

UPDATE

Try setMasterSyncAutomatically() on a ContentResolver .

+9
source
 ContentResolver.setMasterSyncAutomatically(true); // enables AutoSync 

You should also add this.

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

into your AndroidManifest.xml file.

+1
source

All Articles