The changes made were pretty sweeping. The biggest addition was to allow on-device contact creation/editing, and supporting 2-way sync to the sample server that runs in Google App Engine. The client-side sample code also includes examples of how to support the user of AuthTokens (instead of always sending username/password to the server), how to change a contact's picture, and how to set IM-style status messages for each contact. I also greatly simplified the server code so that instead of mimicking both an addressbook and an IM-style status update system for multiple users, it really just simulates an addressbook for a single user. The server code also includes a cron job that (once a week) blows away the contact database, so that it's relatively self-cleaning. Change-Id: I017f1d3f9320a02fe05a20f1613846963107145e
39 lines
2.3 KiB
HTML
39 lines
2.3 KiB
HTML
<p>This sample demonstrates how an application can communicate with a
|
|
cloud-based service and synchronize its data with data stored locally in a
|
|
content provider. The sample uses two related parts of the Android framework
|
|
— the account manager and the synchronization manager (through a sync
|
|
adapter). It also demonstrates how to provide users the ability to create
|
|
and edit synchronized contacts using a custom editor.</p>
|
|
|
|
<p> The <a
|
|
href="../../../reference/android/accounts/AccountManager.html">account
|
|
manager</a> allows sharing of credentials across multiple applications and
|
|
services. Users enter the credentials for each account only once —
|
|
applications with the <code>USE_CREDENTIALS</code> permission can then query the
|
|
account manager to obtain an auth token for the account. An authenticator (a
|
|
pluggable component of account manager) requests credentials from the user,
|
|
validates them with an authentication server running in the cloud, and then
|
|
stores them to the account manager. This sample demonstrates how to write an
|
|
authenticator for your service by extending the new <code><a
|
|
href="../../../reference/android/accounts/AbstractAccountAuthenticator.html">
|
|
AbstractAccountAuthenticator</a></code> abstract class. </p>
|
|
|
|
<p>The sync adapter (essential to the synchronization service) declares the
|
|
account type and ContentProvider authority to the sync manager. This sample
|
|
demosntrates how to write your own sync adapters by extending the <code><a
|
|
href="../../../reference/android/content/AbstractThreadedSyncAdapter.html">
|
|
AbstractThreadedSyncAdapter</a></code> abstract class and implementing the
|
|
<code>onPerformSync()</code> method, which gets called whenever the sync manager
|
|
issues a sync operation for that sync adapter. </p>
|
|
|
|
<p> The cloud-based service for this sample application is running at: </p>
|
|
<p style="margin-left:2em;">http://samplesyncadapter2.appspot.com/</p>
|
|
|
|
<p>When you install this sample application, a new syncable "SampleSyncAdapter"
|
|
account will be added to your phone's account manager. You can go to "Settings |
|
|
Accounts & Sync" to view the account and change its sync settings. </p>
|
|
|
|
<img alt="Screenshot 1" src="../images/SampleSyncAdapter1.png" />
|
|
<img alt="Screenshot 2" src="../images/SampleSyncAdapter2.png" />
|
|
<img alt="Screenshot 3" src="../images/SampleSyncAdapter3.png" />
|