ContentResolver.requestSync in Sync Adapter is not working in Android

后端 未结 3 1936
旧时难觅i
旧时难觅i 2021-01-18 01:56

I am trying to write a sync adapter with \'StubProvider\' and \'StubAuthenticator\', i followed the offical guidelines, my code is running without any errors but \'onPerform

相关标签:
3条回答
  • 2021-01-18 02:12

    Did you specify your account_type on the metadata xml of the sync adapter?

    Your xml discriptor should be like this

    <sync-adapter
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:contentAuthority="com.android.contacts"
        android:accountType="com.syncadaptertest"
        android:userVisible="true"
        android:supportsUploading="false"
        android:allowParallelSyncs="false"
        android:isAlwaysSyncable="true"/>
    

    And most importantly it should be declared on your AndroidManifest file

    <service
            android:name=".sync.ContactSyncService"
            android:exported="true">
            <intent-filter>
                <action android:name="android.content.SyncAdapter" />
            </intent-filter>
            <meta-data
                android:name="android.content.SyncAdapter"
                android:resource="@xml/sync_contact" />
        </service>
    
    0 讨论(0)
  • 2021-01-18 02:32

    Are you sure it's not working?

    Remember that Sync Adapter is run on a Bound Service which is not in the same process, so your Log.d() in onPerformSync() will not show in the LogCat under your app main process but in the process that the Sync Adapter is using.

    Try removing the filter in the LogCat : instead of "Show only selected application" select "No filters".

    0 讨论(0)
  • 2021-01-18 02:38

    Remove android:process=":sync" from android manifest

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