我想以编程方式在我的应用程序的帐户设置中启用自动同步。我已经设置了SyncAdapter,并在清单中对其进行了声明,然后添加了帐户,然后尝试执行此操作:
ContentResolver.setSyncAutomatically(account, authority, true);
ContentResolver.setMasterSyncAutomatically(true);
但是它不起作用。 SE上存在相同的问题:
但是它们太旧了,我发现其中我需要使用ContentResolver.setMasterSyncAutomatically(true)
,但在我的Android 7,Android 9上无法使用。
问题出在authority
中的ContentResolver.setSyncAutomatically(account, authority, true);
字符串参数中,联系人同步需要为com.android.contacts