繁体   English   中英

Android多个同步适配器项目,如Google帐户?

[英]Android multiple sync adapter items like Google Account?

我目前将Android应用设置为使用Android的AccountManager功能,使用SyncAdapter和经过身份验证的帐户自动执行同步。

我只有一个同步适配器运行,它同步所有内容,但我想将其分开,以不同的间隔执行不同内容的同步。

我如何拥有像Google这样的多个同步项?

Google帐户截图

您只需使用相同的帐户类型定义多个同步适配器。

清单包含:

<service android:exported="true" android:name="com.example.FooSyncAdapterService">
  <intent-filter>
    <action android:name="android.content.SyncAdapter" />
  </intent-filter>
  <meta-data android:name="android.content.SyncAdapter" android:resource="@xml/syncadapter_foo" />
</service>
<service android:exported="true" android:name="com.example.BarSyncAdapterService">
  <intent-filter>
    <action android:name="android.content.SyncAdapter" />
  </intent-filter>
  <meta-data android:name="android.content.SyncAdapter" android:resource="@xml/syncadapter_bar" />
</service>

syncdataper_foo

<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
    android:contentAuthority="foo"
    android:accountType="com.example"
    android:allowParallelSyncs="true" />

syncdataper_bar

<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
    android:contentAuthority="bar"
    android:accountType="com.example"
    android:allowParallelSyncs="true" />

请注意,对于帐户类型“com.google”,同步适配器甚至由不同的应用程序(云端硬盘,文档,表格,Gmail,日历等)提供。

我想将主要属性添加到上面的答案中,该属性使同步类型在帐户菜单下可见。

“机器人:userVisible =”真”

<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
    android:contentAuthority="foo"
    android:accountType="com.example"
    android:allowParallelSyncs="true" 
    android:userVisible="true"/> // this line does the job of showing up.

暂无
暂无

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

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