Datastore API SDKs

The Datastore API lets you effortlessly sync all of your app's structured data such as contacts, to-do items, and game state. It enables your app to sync data quickly, manage conflicting changes, and even work offline.

Before building an app using the Datastore API, you'll need to create an app on the App Console.

Android SDK

These instructions assume you're using Eclipse with the ADT plug-in, but you can also use the Datastore API without Eclipse. The Datastore API requires Android API 4 or later.

Installing the Datastore API libraries

Download the Datastore API Android SDK linked above. The necessary libraries are located in the libs directory of the SDK package. The .jar file in the libs directory contains the Java classes which make up the Android SDK. The subdirectories contain the native components, built for each supported Android platform. You can safely omit some of them if you know which platforms your app needs to support ("armeabi" is the most common).

Adding them to an Eclipse project

The recommended way to create your first Datastore API app is to use Eclipse, and the tutorial assumes that you are. If you don't have Eclipse installed, download the Android Development Tools Bundle which includes Eclipse and the ADT plug-in.

To add the SDK to your Eclipse project:

  1. Copy the contents of the libs directory of the Android SDK package into the libs directory of your project.
  2. In Eclipse, open the context menu on your project and click Refresh.

Optional: Installing the Javadocs

To allow Eclipse to display Javadoc documentation for SDK classes, you can create a dropbox-sync-sdk-android.jar.properties file in your project's libs directory containing a path to the javadoc directory of the Android SDK package as follows.

dropbox-sync-sdk-android.jar.properties
# Replace the path below with the correct path on your system
doc=../../../dropbox-sync-sdk-android/javadoc

Required changes to AndroidManifest.xml

The Datastore API needs permission to access the Internet. Additionally, a few SDK components need to be published so that Android can find them. Here are the two snippets to add to your AndroidManifest.xml.

AndroidManifest.xml
Required permissions (inside the <manifest> element).
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Activities and Services (inside the <application> element).
Be sure to replace the APP_KEY below with your real Dropbox app key, which can be found in the App Console.
<activity android:name="com.dropbox.sync.android.DbxAuthActivity" />
<activity
  android:name="com.dropbox.client2.android.AuthActivity"
  android:launchMode="singleTask" >
  <intent-filter>
    <data android:scheme="db-APP_KEY" />
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.BROWSABLE" />
    <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
</activity>
<service
  android:name="com.dropbox.sync.android.DbxSyncService"
  android:enabled="true"
  android:exported="false"
  android:label="Dropbox Sync" />

Example apps

If you want to see the Datastore API in action, check out the examples directory in the SDK bundle. There you can find a simple task tracking app that uses the Datastore API to save tasks to Dropbox. This app will also sync tasks with the tasks example included in the SDKs for other platforms.

  1. In Eclipse, select File → New → Other → Android project from existing code.
  2. Browse to the example app you'd like to try.
  3. Check the box for copy projects into your workspace and click Finish.
  4. Add the required SDK libraries to the new project as described above.
  5. From the project's context menu, choose Run As → Android Application.

More info