Wednesday, April 3, 2013

Dropbox client for Android

In one of my projects, I need to create a client in Android for Dropbox. So I like to share my experience in creating the Dropbox client. Dropbox has an Android SDK. So developers can just call the API and can use. When connecting the app with any cloud say, the authentication part is the tricky and some what complicated one. Once app establishes a connection to the cloud, then getting resources (say, files) is just a cakewalk. First I will just list down the steps for creating the dropbox client in Android.

1. First create an account in "Dropbox"

2. Then in developers page, go to the tab "My Apps". Click on the "Create an App". A dialog appears, there we specify our App name as well as the access level, either "full access" or "app folder" (means only to a specific folder in your account). We can select any one according to our choice.



3. After creating the app in dropbox, we will get the "App Key" & "App Secret". We need to use this "App Key" & "App Secret" in our application for authenticating our app with Dropbox cloud.

4. Open eclipse, create an Android app with application name same as what we provided in Dropbox page.

5. In the manifest file of the app, we need to put
 <activity   
 android:name="com.dropbox.client2.android.AuthActivity" android:launchMode="singleTask"   
 android:configChanges="orientation|keyboard">  
   <intent-filter>  
      <!-- Change this to be db- followed by our app key -->  
       <data android:scheme="db-our 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>  
This is for authenticating our app. For authenticating app will open browser with Dropbox login page, there we need to enter our Dropbox username & password. Dropbox will also ask for accessing Dropbox resources with this app. If we allow then only the android app can access Dropbox resources.

5. After allowing our app to access Dropbox resources, control will return to the application. App will return to the activtiy where it is called for authhentication. In that Activtiy in onRresume(), developer need to check whether the authentication with Dropbox is successful. If successful, app can take the desired action. Here I am just displaying all the resources in the account.

6. So app moves to the next activity named "ListDropboxActivity", where app will fetch all resources from the Dropbox and display the names of the resources as a listView. On Clicking on the resources names, app will open the resources, whether, it is a text file(.txt), or some images like .jpg, .png etc. This is all about the Dropbox client app.

You can get the full source code from here

Androidians