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

Android multiple sync adapter items like Google Account?(Android 多个同步适配器项目,如 Google 帐户?)

本文介绍了Android 多个同步适配器项目,如 Google 帐户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

How can I have multiple sync items like Google does?

解决方案

You just have to define several sync adapters, using the same account type.

The manifest contains:

<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>

And syncdataper_foo is

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

And syncdataper_bar is

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

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 帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Android 多个同步适配器项目,如 Google 帐户?

基础教程推荐