How to Upload Into Dropbox on Android

Allow's upload a text file to Dropbox


Hither we'll show yous how to employ our Android SDK to upload a file to Dropbox. For this tutorial you volition need Android one.6 (or later) and an Android lawmaking editor. We've used Android Studio 0.4.half-dozen for this tutorial, but information technology will work equally well in whatsoever IDE you are using.

Ready Your Code Project

aneCreate a new project in Android Studio.

  1. In the New Project dialog, name the application "Temboo Test" (or whatever you like), uncheck Create custom launcher icon, and click Next.
  2. Select Bare Action, click Next.
  3. Get out the Activity Name and other settings equally-is and click Finish.

2Download and extract the Temboo Android SDK.

iiiAdd the Temboo SDK to your project:

  1. Find the core SDK .jar file (e.thousand. temboo-android-sdk-core-two.nineteen.0.jar) in the Temboo SDK folder yous just downloaded and extracted.
  2. Right-click and copy the .jar file, return to Android Studio, and right-click/paste the .jar into the libs folder of your project.
  3. Right-click on the .jar and select Add as Library. Click OK on the dialog that'south displayed.

Yous've now added the core Temboo SDK to your projection. Repeat the above steps to add the application bundle (e.thou. Dropbox-2.19.0.jar) from the Temboo SDK folder you simply extracted, which will allow us to use Dropbox APIs.

Set your Android application

We'll now brand some adjustments to the default awarding that Android Studio has generated for united states of america.

4Open up the Android manifest located at app/src/main/res/AndroidManifest.xml. In order to access the internet, you volition need to add together <uses-permission android:name="android.permission.INTERNET"/> below the <application> tag.

5The default layout of the application included a TextView that we volition use, but first, we need to give it an identifier. Locate and double-click on the file app > src > primary > res > layout > activity_main.xml. This file describes the layout of our MainActivity grade.

sixClick on the "Hello Earth" text in the device emulator to select the TextView.

7In the Backdrop console on the bottom-right of the editor, find the id property. Click to the right of it and enter @+id/response

8Next, locate the text belongings and delete the default "Hello Globe" value (we'll fill this in programmatically afterwards).

Get Fix Up With Temboo and Dropbox

9 Log in to Temboo. If you don't already take an business relationship, you can register for complimentary.

xYous'll need a gratis Dropbox account. If you don't already take ane, you can sign up here.

11If yous haven't already, create a Dropbox app in the Dropbox App Console.

When asked to cull an API, select Dropbox API. Choose the type of access your application will need: App folder or Full Dropbox. The app name tin can be whatever you like. When yous're done, click Create app.

Dropbox App Console

12On the next page, specify the callback URL beneath as a Redirect URI. Make certain to replace ACCOUNT_NAME with your Temboo account name.

https://ACCOUNT_NAME.temboolive.com/callback/dropbox        

To Access to Your Own Dropbox

13If you will only be needing access to your own account, yous tin can generate an Admission Token in the Dropbox App Panel. Click the Generate push button in the OAuth 2 section of your app settings page.

Generating a Dropbox access token for your own account

To Access to Another User's Dropbox

14In order to access Dropbox accounts other than your own, you will demand to complete the OAuth process. If y'all simply need access to your own account, you can skip ahead to the next department.

To begin, go to Dropbox > OAuth > InitializeOAuth in the Temboo code generation library. In the INPUT section of the page, enter the AppKey found on your app settings folio within the Dropbox App Console.

Supplying inputs needed for Dropbox Initialize OAuth

15Click the Generate Code push to run InitializeOAuth from the Temboo site. Scroll down to the OUTPUT section of the folio. Salve the CallbackID to employ in the next steps.

Outputs returned by Initialize OAuth

16The owner of the Dropbox account that your application needs to admission volition need to visit the AuthorizationURL institute in the OUTPUT department. They should click the Allow button on the page to grant the awarding permission to admission their account. Once they see a blank page in the browser, it'south rubber to close the page.

Allowing your app to access a Dropbox account

17Once permission has been granted on the AuthorizationURL page, you lot're fix to complete the OAuth process. Visit Dropbox > OAuth > FinalizeOAuth in the Temboo code generation library. In the INPUT department of the page, enter the AppKey and AppSecret found on your app settings folio in the Dropbox App Console.

Supply the CallbackID that was returned in the OUTPUT department of the InitializeOAuth page.

Required inputs for Finalize OAuth

18Now, with all the required inputs in place, click the Generate Code push to run FinalizeOAuth from the Temboo site. Scroll down once over again to the OUTPUT section of the folio. Hither you'll detect the AccessToken you'll need for whatsoever Dropbox processes for this user's account. Salve these it later.

Output returned by Finalize OAuth

Generate the Code

19 Go to the Dropbox > Files > Upload page in our lawmaking generation library. From the drop downward menu at the top of the page, select Android.

selecting Android as your development platform

20In the INPUT department of the folio, enter your Dropbox AccessToken. Click on Salve Profile in the upper correct corner of the INPUT department to relieve your Dropbox credentials for like shooting fish in a barrel use in other Dropbox Choreos in the future. Using a Temboo Contour volition also make your code simpler and more than secure.

Saving credentials to a Temboo Profile

21Enter the file location and filename for your new file in the Path field. To create a text file in the root directory of your Dropbox account, try entering /exam.txt for your Path.

22Now supply the FileContent of your text file. Nosotros'll just use "Hello globe!".

At this point, your INPUT department should look something like this:

Required inputs to upload a file

23We need to tell Dropbox that our file content is manifestly text rather than Base64 encoded binary data. To do so, click on OPTIONAL INPUT at the lesser of the INPUT section to reveal more input fields. In the ContentType field, enter text/plain. You tin leave the other fields blank.

Specifying the Content Type

24Click the Generate Code button at the bottom of the INPUT department to test the file upload from the Temboo site. Y'all'll meet some details about your uploaded file in the OUTPUT section. If y'all get to your binder in Dropbox, you'll encounter your file appear.

File metadata returned by the upload file process

Prepare Your Lawmaking

25Because network operations block the chief thread execution, we'll need to make our calls to Temboo using AsyncTask. Create a new class that extends AsyncTask called "DropboxTask" (or whatever you like), adding the @Override implementations for doInBackground and onProcessComplete.

26Add a constructor that takes a TextView as an argument. This will reference the TextView nosotros set upwards earlier.

27At present that our AsyncTask is ready up, go back to the Temboo website, curlicue down to the CODE department and copy and paste the generated code into the doInBackground method of your AsyncTask class. We'll as well add together the required imports to create a SendMessage Choreo, UploadInputSet, and UploadResultSet:

import com.temboo.Library.Dropbox.Files.Upload; import com.temboo.Library.Dropbox.Files.UploadInputSet; import com.temboo.Library.Dropbox.Files.UploadResultSet; import com.temboo.core.TembooSession;        

28Uncomment the line of code containing your Temboo Account credentials, which looks something similar this

TembooSession session = new TembooSession(yourAccountName, yourAppName, yourAppKey);        

Print the Results

Each Choreo in the Android SDK returns a ResultSet bracket that contains get methods tailored specifically to the outputs of that Choreo. Using the ResultSet, you can think the raw data (typically XML or JSON) returned by a third-political party API or relevant fields that we've parsed out of the response for y'all.

To update the UI with the API response returned by the Choreo, do the following:

29Add the following code at the lesser of the try cake of the doInBackground method in your class:

return dropbox_files_upload.get_Response();

30The render value we've merely added is passed by Android as an argument to the onPostExecute method. We'll update the UI in that location:

          protected void onPostExecute(String result) {         try {             // Update the UI             textView.setText(consequence);         } catch(Exception eastward) {             // if an exception occurred, show an error message             Log.e(this.getClass().toString(), east.getMessage());         }     }        

Try it Out

31In order to see your new chore in action, you will need to invoke it from the MainActivity grade created with your project. The simplest mode to exercise this is to add a call to it in the onCreate method.

32Dropbox won't allow y'all to upload a file if there's already a file with the location and filename specified in the Path input. Delete your test file in Dropbox and so that you tin run the same code over again from your Android application.

33Deploy and run the application. After a few moments, the application will upload the file and you'll run into the response from Dropbox in the UI. If you check your Dropbox account, yous'll see a new file uploaded from your Android app.

What next?

Nosotros're all finished! This Android application can create a text file out of whatsoever string you might produce while coding. Bank check out the remainder of the 2000+ Choreos in our Library and find all sorts of valuable data that y'all could relieve to Dropbox.

Once you've got your code up and running, you're ready to move on and do more. From monitoring your running applications, to moving your generated Temboo code to your preferred development environment and sharing it with colleagues, collaborators and friends - we've got y'all covered.

Need help?

We're always happy to help. Only email us at support@temboo.com, and we'll answer your questions.


Dorsum

nashfrosigh53.blogspot.com

Source: https://temboo.com/android/upload-to-dropbox

0 Response to "How to Upload Into Dropbox on Android"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel