Android multiple sync adapter items like Google Account?

后端 未结 2 1089
慢半拍i
慢半拍i 2020-12-29 11:35

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.

<
相关标签:
2条回答
  • 2020-12-29 12:07

    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.
    
    0 讨论(0)
  • 2020-12-29 12:14

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

    0 讨论(0)
提交回复
热议问题