简体   繁体   中英

Android Dropbox Core API implementation

I am trying to implement the CORE API at my Android application.

I am following the Dropbox tutorial for this.

https://www.dropbox.com/developers/core/start/android

final static private String APP_KEY = "INSERT_APP_KEY";
final static private String APP_SECRET = "INSERT_APP_SECRET";

// In the class declaration section:
private DropboxAPI<AndroidAuthSession> mDBApi;

// And later in some initialization function:
AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
AndroidAuthSession session = new AndroidAuthSession(appKeys);
mDBApi = new DropboxAPI<AndroidAuthSession>(session);

But, i don't know where to put this line of code?

mDBApi.getSession().startOAuth2Authentication(MyActivity.this);

When i put it within the Oncreate() function i get a endless loop of authenticating the account with the Dropbox App.

Can someone please show me a robust sample of code which is functional?

I also want to know how to read files from Dropbox via Dropbox CORE API?

Should i download first the file, save it to the mobile memory and then access it just like a local file?

Thanks in advance.

From the official documentation

We'll start by calling the startOAuth2Authentication() method which will ask the user to authorize your app. If the Dropbox app is installed, the SDK will switch to it so the user doesn't have to sign in, and it will fallback to the browser if not.

Meaning you must have this method called when you are ready to initiate a transaction with the Dropbox 's servers. It seems like this method is checking for Dropbox's existance on the phone first and authenticates the user and if not found sends him to the web page to log in. So it sounds like this method fires up a special intent for the Dropbox app or the device's browser to handle, thus making it not suitable for placing it in the onCreate() method. This method should be placed right before you initiate a transaction with the server. (eg. a readFile() method that will be called once by a button's click.

From scanning through the official documentation it seems that in order to read a file you have to first download the file, save it as a cache ( temporary ) file, read it and when you're done remove it.

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