繁体   English   中英

以编程方式启用自动同步

[英]Enable auto sync programmatically

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

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

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

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

未启用自动同步

问题出在ContentResolver.setSyncAutomatically(account, authority, true);中的authority字符串参数中ContentResolver.setSyncAutomatically(account, authority, true); ,联系人同步需要为"com.android.contacts"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM