Android multiple sync adapter items like Google Account?
Asked Answered
R

2

11

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?

Google account screenshot

Runt answered 23/6, 2015 at 8:49 Comment(0)
B
26

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

Boonie answered 1/7, 2015 at 12:18 Comment(2)
Thanks, I had tried that before but your answer led me to notice you had a different contentAuthority for each SyncAdapter, this showed me the problem- there must be multiple ContentProviders, each registered to the contentAuthority specified in the SyncAdapter xml file. Thanks a lot!Runt
How can i set label as at picture in question?Aerophobia
H
2

I would like to just add up the main attribute which makes the sync type visible under accounts menu to the above answer.

"android:userVisible="true"

<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.
Heritable answered 20/1, 2017 at 9:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.