【问题标题】:Enable auto sync programmatically以编程方式启用自动同步
【发布时间】:2020-01-17 11:50:51
【问题描述】:

我想以编程方式在我的应用中的帐户设置中启用自动同步。我已经设置了 SyncAdapter,在清单中声明了它,我添加了帐户,并且在此操作之后我尝试了:

ContentResolver.setSyncAutomatically(account, authority, true);
ContentResolver.setMasterSyncAutomatically(true);

但它不起作用。 SE上也有同样的问题:

但它们太旧了,我发现在它们中我需要使用ContentResolver.setMasterSyncAutomatically(true),但它不适用于我的 Android 7、Android 9。

【问题讨论】:

  • @Crazo7924 谢谢,我做到了,所有这些提示已经写在我的代码库中,但是应用帐户设置中的自动同步切换器没有启用。

标签: android synchronization android-syncadapter android-account


【解决方案1】:

问题出在ContentResolver.setSyncAutomatically(account, authority, true); 中的authority 字符串参数中,它必须是"com.android.contacts" 才能进行联系人同步

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-13
    • 1970-01-01
    • 1970-01-01
    • 2018-07-29
    • 2012-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多