【发布时间】:2020-01-17 11:50:51
【问题描述】:
我想以编程方式在我的应用中的帐户设置中启用自动同步。我已经设置了 SyncAdapter,在清单中声明了它,我添加了帐户,并且在此操作之后我尝试了:
ContentResolver.setSyncAutomatically(account, authority, true);
ContentResolver.setMasterSyncAutomatically(true);
但它不起作用。 SE上也有同样的问题:
- Android how to enable/disable auto sync programmatically
- general sync settings "auto-sync" checkbox programmatically
- Toggle on auto-sync progarammatically in Android
- general sync settings "auto-sync" checkbox programmatically
但它们太旧了,我发现在它们中我需要使用ContentResolver.setMasterSyncAutomatically(true),但它不适用于我的 Android 7、Android 9。
【问题讨论】:
-
@Crazo7924 谢谢,我做到了,所有这些提示已经写在我的代码库中,但是应用帐户设置中的自动同步切换器没有启用。
标签: android synchronization android-syncadapter android-account