Integrate dropbox API with Android App & Perform CRUD action
The main objective of this blog is to give you more detailed information about how to Integrate Dropbox with your Android APP and Perform CRUD Action.
Introduction of The Tools
For Developing an Android application, we use an Android Studio, which allows the applications to be developed in a Java Language Environment.
Setting Up The Environment.
In Android Studio, create a new project by navigating to File ⇒ New Project and fill all the required details. When it prompts to select a default activity, select Blank Activity and proceed.
Integrate Dropbox With Your Android App.
What is DROPBOX? Dropbox is cloud storage wherein we can store photos, videos, documents, and files. We can access these files from any computer and from anywhere. To Integrate the DROPBOX API in your android application, follow the following steps: In this tutorial, The first screen will be – PickImageActivity To select an image and show on the screen. After selecting an image, We will code for uploading the Image on Your Dropbox Account. Make sure you have Dropbox app installed on your Android device. So after selecting an image, the Dropbox login screen will be opened. Once you are logged in, you will be redirected to The Second Screen. To support the uploading, the Dropbox documentation provides the following java files: The Second Screen will be MainActivity This has the code to upload the image to Dropbox.
1. Create a New Project in Android Studio
2. Select Your Platform and Proceed.
3. Select an Activity and Name it
4. To Use the Dropbox API
First of all, in your project, add the following permissions in your AndroidManifest file. p>
5. Now in a build.gradle file add the Following:
6. Add the Line to Avoid Conflict
In the same build.gradle file adds the lines to avoid a conflict during build time of multiple License.txt or Notice.txt files because sometimes android studio considers duplicate entry lib's and gives error while packaging.
7. Now Open App Console
Go to the https://www.dropbox.com/developers/apps And create the new app
8. Click on “CREATE APP”
9. Now Click on “DROPBOX API”
10. Open Your Project in Android Studio and in Your Manifest file, Add
Add an activity in manifest file which will be used to authenticate your application. Change the android:scheme to db - followed by your app key.
11. Now The First Screen of App is PickImageActivity.
Open your activity_pick_image and add the components: Two Buttons to select and upload and an ImageView to view the selected image.
12. Add the OnClickListner for Selecting Image.
Here we check the version of Android on the device so accordingly the code works.
13. Now we add onActivityResult.
By using this method we get the path of the image. Store the path of the image in the variable strImagePath.
14. Now We set the Image on ImageView.
15. Now Extract The Name of The Image From The Path and Store It in a String.
I have kept the button upload hidden till the path is obtained. So once you get the result1, use this to show the button upload
16. We Need to Use Runtime Permissions.
Add check self-permission. So we are done with image loading in our First Screen
Now We Check Step by Step How to Upload it to The Dropbox
Step 1: Use Dropbox Initialization. (Refer MainActivity.Java) Step 2: Code For Asynchornous Task for Image Upload (Refer UploadFileTask.Java) Step 3: On Click Of The Button, we upload the image on the DROPBOX (Refer activity_main.xml and uploadFile(uri_get); method in MainActivity.Java) Step 4: Initialize the Session of the Key pair to authenticate with Dropbox. Step 5: For Asynchronous Task For Image Upload And in this class, we code for file upload. Now our code for uploading is ready. Step 6: activity_mail.xml In our activity_main.xml, we have a button to upload the image to Dropbox. We have stored the path and URI of the image in shared preference. So use this button and inside the onClickListner of the button, call the async task that is the file UploadFileTask. After this code, Open your DROPBOX APPLICATION installed on your device, and reload it. You can see the uploaded file there. This is how we use DROPBOX API V2. If you are using API V1, The Shift to V2 as V1 is deprecated and doesn't work. Full Source Code Download APK
Top-5 Best Mobile Application Development Platform in 2022
It is not an exaggeration to say that Android is the most popular mobile OS with 85% market share and north of 5 million apps in the Google...
What are Android Emulators and How to Setup an Android Emulator?
There are a variety of reasons why you would want to run an Android emulator on your PC. Mobile app developers always look to test their app...