general sync settings “auto-sync” checkbox programmatically

爷,独闯天下 提交于 2019-12-19 06:40:32

问题


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);

回答1:


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

UPDATE

Try setMasterSyncAutomatically() on ContentResolver.




回答2:


ContentResolver.setMasterSyncAutomatically(true); // enables AutoSync

You should also add this

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

to your AndroidManifest.xml file.



来源:https://stackoverflow.com/questions/8009273/general-sync-settings-auto-sync-checkbox-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!