Question

I want to synchronise a local Android database with a remote database on a server somewhere. For now, I want to do this via a REST API with basic HTTP authentication.

I have done some reading and watched the Google I/O 2010 "Developing Android REST Client Applications" video, however I am still a little confused as to which approach will be most suitable for me:

1.) Content Provider + Service

2.) Content Provider + SyncAdapter

3.) Something else?

I have already written a Content Provider. I am a bit confused about the SyncAdapter and how authentication works - can I used basic HTTP authentication with a SyncAdapter?.

Was it helpful?

Solution

Authentication is done with accounts in Android. Have a look at this class: https://developer.android.com/reference/android/accounts/AbstractAccountAuthenticator.html

Also have a look at this blog post: http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-1/

Regarding which approach to choose: If you want to sync between a remote DB and a local DB (that is you really want to sync and not only download content) a sync adapter is always the best choice!

If you have downloaded Android's samples you should also dig into the SampleSyncAdapter project. This should get you started.

BTW: Never ever do Basic HTTP authentication. This is not encrypted and all communication between your server and the app is readable to all. Always use TLS (SSL) instead!

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