Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
AppDev
8 years agoExplorer | Level 3
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 co...
AppDev
8 years agoExplorer | Level 3
I'm getting access denied, can you share the link again please?
Greg-DB
Dropbox Community Moderator
8 years agoApologies, here's the corrected link: https://www.dropboxforum.com/t5/API-Support-Feedback/NetworkOnMainThreadException-connecting-to-Dropbox-account/m-p/195874/highlight/true#M17988
- AppDev8 years agoExplorer | Level 3
Hi Greg, :)
Thank you so much for all your help! From what I read about the NetworkOnMainThreadException, I decided to implement what I need with IntentService and ResultReceive, and it is working perfectly fine now! :)
One more thing I still not sure about is the installation of the SDK. Now it is working for me because I added the jar manually. From the link you gave me, I don't understand how to use android studio package manager to download and install it automatically... Do you have a tutorial link that explane how to do that? All I tried didn't work. Sorry if it basic stuff, I realy am a begginer to this world... :(
- Greg-DB8 years ago
Dropbox Community Moderator
That's more about using Gradle/Maven/Android Studio themselves, so I can't offer much help, as that's outside the scope of Dropbox API support.
That said, it looks like their respective official documentation sites have some useful information:
- AppDev8 years agoExplorer | Level 3
Thanks Greg! :)
One last thing that is not working for me yet, is the download of selected files. In my app, I got a list of all files and the user chose from that list which files he wants to download. Now I want to download all those files in a loop from the IntentService I wrote. A part of my code is:
@Override
protected void onHandleIntent(Intent intent)
{
if (intent != null)
{
ResultReceiver receiver = intent.getParcelableExtra("receiverTag");
String accessToken = intent.getStringExtra("AccessTokenVal");
DbxRequestConfig config = DbxRequestConfig.newBuilder("dropbox/MyAppName").build();
DbxClientV2 client = new DbxClientV2(config, accessToken);
if (intent.getAction().equals("GET_FILES"))
{
// The code to get the list of files
}
else if (intent.getAction().equals("Download_FILES"))
{
List<String> filesToDownload = new ArrayList<>();
Gson gson = new Gson();
Type type = new TypeToken<ArrayList<String>>(){}.getType();
filesToDownload = gson.fromJson(intent.getStringExtra("DropboxFilesSelected"), type);
boolean isAllFilesDownloaded = true;
for (int i=0; i<filesToDownload.size(); i++)
{
try
{
DbxDownloader<FileMetadata> downloader = client.files().download(filesToDownload.get(i));
String[] arr = filesToDownload.get(i).split("/");
FileOutputStream outputStream = new FileOutputStream(Environment.getExternalStorageDirectory() + "/MyAppName/MyAppFolder/" + arr[arr.length - 1]);
downloader.download(outputStream);
}
catch (DbxException e)
{
e.printStackTrace();
isAllFilesDownloaded = false;
}
catch (FileNotFoundException e)
{
e.printStackTrace();
isAllFilesDownloaded = false;
}
catch (IOException e)
{
e.printStackTrace();
isAllFilesDownloaded = false;
}
}
}
}The code failes in the line:
DbxDownloader<FileMetadata> downloader = client.files().download(filesToDownload.get(i));
I even tried to download a file from the root and wrote the path as:
DbxDownloader<FileMetadata> downloader = client.files().download("/file.txt");In the Logcat, this is the error I get:
E/AndroidRuntime: FATAL EXCEPTION: IntentService[DropboxActions]
Process: my project name, PID: 4118
java.lang.IllegalArgumentException: String 'path' does not match pattern
at com.dropbox.core.v2.files.DownloadArg.<init>(DownloadArg.java:42)
at com.dropbox.core.v2.files.DownloadArg.<init>(DownloadArg.java:69)
at com.dropbox.core.v2.files.DbxUserFilesRequests.download(DbxUserFilesRequests.java:1120)
at my project name.DropboxActions.onHandleIntent(DropboxActions.java:111)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:67)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.os.HandlerThread.run(HandlerThread.java:61)Why is my path getting IllegalArgumentException? from what I read, I understood that a path to file in the root should be "/file.txt" and from a folder "/folder/file.txt".
What is wrong with my code?
Thanks again. :)
- Greg-DB8 years ago
Dropbox Community Moderator
AppDev That exception does indicate that the 'path' value you're supplying to the `download` method doesn't have the right format for a Dropbox path.
Can you double check that you're getting that same exact error for both versions of the line you pointed out? The second one, with the value "/file.txt" looks correct. That is a valid path format, and it is working for me.
For the first one, please print out the value of `filesToDownload.get(i)` just before that call to `download` to verify exactly what is being passed in.
- AppDev8 years agoExplorer | Level 3
I printed the value of `filesToDownload.get(i)` before calling the download, and the value is "/file.txt".
For both versions I'm getting that error... :(
The values I'm getting to the list `filesToDownload', is from the dropbox method for listing the list of files in dropbox, but I double checked it again and I'm grtting the correct value "/file.txt". I verified that the file is there in the root.
There might be a problem using 'DbxDownloader<FileMetadata>'? is there anything else I can use to download a file?
- Greg-DB8 years ago
Dropbox Community Moderator
That's the correct way to download a file. I just tried that line of code myself and it is working as expected for me.
It sounds like there's something else affecting this in your project, but I can't say off hand what that might be. We'll be happy to look into it further, but we'd need to be able to reproduce it here. Can you share a small sample project that reproduces the issue?
- AppDev8 years agoExplorer | Level 3
Hi Greg,
Sorry, it was my mistake... I didn't use Gson correctly, so when using it, I got inside the list the valuses ""/file1.txt"", ""/file2.txt"" etc. when I printed the values, I got "/file1.txt", "/file2.txt" instead of /file1.txt, /file2.txt. I thought that the extra "" are from the java println and that I'm getting the correct value...
Now everything is working for me and the files are downloading to my app.
I have no idea why the line with the hard coded file name didn't work before,
DbxDownloader<FileMetadata> downloader = client.files().download("/file.txt");But it is working now, so all is good.
Thank you so much for helping me with everything! :)
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
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, Facebook or Instagram.
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!