Question

i previously used ContentObserver to get notified about changes in device's contacts list. the problem is i need that to work in background (when application is closed as well), so i used a service for that, but still it dosn't work (unless i declare the service to work on foreground - and we don't want that to happen).

so i saw another solution of using SyncAdapter. i have my own storage solution and i'm not using ContentProvider in my application. also i have my own implementation for detecting which contact has been added/removed/changed.

the only thing i need, is detecting WHEN that happen and get notified about it.

Do i need a stub content provider to achieve that? Is it enough to declare com.android.contacts as the authority for the sync adapter?

i need some help with configuring those...

Thanks in advance! Rotem.

Was it helpful?

Solution

O.k. so i finally figured things out.

to achieve that, (getting notified about device contacts changes only), you don't need a stub content provider. simply declare a sync adapter with a sync adapter service. in the syncadapter's xml declaration, use the ContactsContract.AUTHORITY which means: android:contentAuthority="com.android.contacts"

and set an automatic sync: ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true);

remember that your onPerformSync method in your SyncAdapter implementation won't be called right away, the system "waits" for the best time to make those syncs, any way from my experience it took ~40 seconds.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top