【问题标题】:Syncing multiple providers with one SyncAdapter使用一个 SyncAdapter 同步多个提供程序
【发布时间】:2015-06-07 21:20:14
【问题描述】:

我想用一个 SyncAdapter 同步 com.android.contacts 和 com.android.calendar。这可能吗?

如果是,我必须如何编辑以下几行?

<sync-adapter
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:contentAuthority="com.android.contacts"
    android:accountType="com.package.account"
    android:supportsUploading="false"
    android:userVisible="true" />

【问题讨论】:

    标签: android android-syncadapter


    【解决方案1】:

    显然不是:

    “每个 SyncAdapter 都会启动一个 SyncThread,该 SyncThread 绑定到 sync-adapter.xml 中定义的权限,并且不能在此 xml 文件中定义多个权限...”

    (基亚纳特尼森)

    How to use one SyncAdapter-class for multiple authorities?

    【讨论】:

    • 这个答案是错误的——虽然您不能将SyncAdapter 绑定到多个权限,但您仍然可以从onPerformSync() 方法访问所有导出的ContentProviders...
    【解决方案2】:

    您可以从您的SyncAdapter 同步任何ContentProvider,只要它已导出并允许修改基础数据。

    为了实现这一点,您无需在 XML 中指定额外的提供者或权限 - 只需在 onPerformSync() 中获取对 ContentResolver 的引用并使用它来访问感兴趣的 ContentProviders。

    有关更多信息,请阅读此答案:https://stackoverflow.com/a/30693866/2463035

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-27
      • 1970-01-01
      • 2021-04-22
      • 1970-01-01
      • 2018-06-16
      • 2019-01-13
      相关资源
      最近更新 更多