简体   繁体   中英

DropBox in Android Application

I am pretty new to Android and am trying to have my android app to have access to the Dropbox on the same phone. I would want to have the authorization happen on the first activity that shows up on my app.

I've tried looking at the DropBox API information on their developers site but they don't have any details on how to implement authorization (just on how to loop through files etc..not that helpful)

I have tried looking here at: https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/java/com/dropbox/core/examples/android/DropboxActivity.java#L22

But I can't even have FileThumbnailRequestHandler.java class compile since Picasso.LoadedFrom.NETWORK returns a LoadedFrom and not an integer.

I'm pretty stuck and theres not a lot of documentation online on how to implement so help would be VERYYYYY appreciated!

To use Dropbox API v2 in Android, we recommend you use the official Dropbox API v2 Java SDK:

https://github.com/dropbox/dropbox-sdk-java

There isn't a step by step tutorial for that in particular, but there's an example Android app that uses it included with the SDK, with instructions for running it:

https://github.com/dropbox/dropbox-sdk-java/tree/master/examples/android

Though, it's probably easier to just install a released version of the Dropbox SDK rather than compile it locally, as long as you don't need to make changes to the Dropbox SDK. That is, in build.gradle, replace:

implementation group: 'com.dropbox.core', name: 'dropbox-core-sdk', version: '0-SNAPSHOT', changing: true

with:

implementation 'com.dropbox.core:dropbox-core-sdk:3.1.3'

You should refer to that example app as an example of how to implement the app authorization flow, which is accomplished via OAuth 2.

Your AndroidManifest.xml should be set up as shown here:

https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/AndroidManifest.xml#L33

You start the flow by calling startOAuth2Authentication as shown here:

https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/java/com/dropbox/core/examples/android/UserActivity.java#L34

You complete the flow by calling getOAuth2Token as shown here:

https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/java/com/dropbox/core/examples/android/DropboxActivity.java#L22

Your app can store and re-use the resulting access token for that user, as the example does here:

https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/java/com/dropbox/core/examples/android/DropboxActivity.java#L25

Make sure you follow the instructions for installing the SDK. Gradle or Maven should automatically install the right versions of the dependencies for you. I just tried it and it worked for me. That is, I didn't get the Picasso compilation error you mentioned, so I suspect you have a different version of the dependency installed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM