问题描述
我目前已设置Android应用程序以使用Android的AccountManager功能,并使用SyncAdapter和经过身份验证的帐户来自动执行同步.
I currently have my Android app set up to use the AccountManager feature of Android, using a SyncAdapter and an authenticated account to performs syncs automatically.
我只有一个运行中的同步适配器,它可以同步所有内容,但是我想将其分开,以便以不同的间隔对不同的内容执行同步.
I only have 1 sync adapter running which syncs all content, but I would like to separate this out to performs syncs for different content at different intervals.
我如何像Google一样拥有多个同步项目?
How can I have multiple sync items like Google does?
推荐答案
您只需要使用相同的帐户类型定义多个同步适配器即可.
You just have to define several sync adapters, using the same account type.
清单包含:
<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,日历等).
Note that in the case of the account type "com.google", the sync adapters are even provided by different applications (Drive, Docs, Sheets, Gmail, Calendar, etc.).
这篇关于Android是否有多个同步适配器项,例如Google帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!