We Want to Hear From You! What Do You Want to See on the Community? Tell us here!

Forum Discussion

AppDev's avatar
AppDev
Explorer | Level 3
7 years ago

Get a list of files from dropbox to android application

Hi everybody, I'm new to dropbox developing and I need help with it please. I wrote an android application that needs to get a list of files listing in dropbox. I used the tutorial and part of the code I wrote is:

 

private DropboxAPI<AndroidAuthSession> mDBApi;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); InitializeSession(); } void InitializeSession() { AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET); AndroidAuthSession session = new AndroidAuthSession(appKeys);
mDBApi = new DropboxAPI<AndroidAuthSession>(session);
mDBApi.getSession().startOAuth2Authentication(MainActivity.this); } @Override protected void onResume() { super.onResume(); if (mDBApi.getSession().authenticationSuccessful()) { try {
mDBApi.getSession().finishAuthentication(); String accessToken = mDBApi.getSession().getOAuth2AccessToken(); PopulateList(); } catch (IllegalStateException e) { System.out.println("Error : " + e.getMessage()); } } } private void PopulateList() { List<String> filename = new ArrayList<>(); String mPath = "/"; DropboxAPI.Entry dirent = null; try {
dirent = mDBApi.metadata(mPath, 1000, null, true, null); } catch (DropboxException e) { System.out.println("Error : " + e.getMessage()); } for (DropboxAPI.Entry ent : dirent.contents) { if (ent.isDir) {
filename.add(ent.fileName()); } ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1, filename); } }

 I am not getting the list of files from dropbox...

 In the PopulateList() method, after executing the line 

dirent = mDBApi.metadata(mPath, 1000, null, true, null);

The code stop executing and I get nothing to the dirent.

What am I doing wrong here? and what am I missing?

Do I somehow need to resume the authentication again?

One more thing I'm not sure about, with this code do I get files from sub folders too? if not, how can I get them? because the start path I use is "/".

 

I'm stuck on that for 2 weeks and can't find the solution or what did I do wrong...

Thanks for the helpers! :)

16 Replies

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,036 PostsLatest Activity: 9 months ago
411 Following

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!