ContentResolver.requestSync in Sync Adapter is not working in Android

瘦欲@ 提交于 2019-12-01 16:57:16

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

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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!