Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
Andhie W.
11 years agoNew member | Level 1
Android ACTION_GET_CONTENT from Dropbox sources
Device OS: Lollipop 5.0
When using the Intent ACTION_GET_CONTENT and selecting Dropbox from the Storage Provider, Dropbox prompts a file picker dialog to choose from. The result obtained in onActivityResult is something like
file:///storage/emulated/0/Android/data/com.dropbox.android/files/u6763728/scratch/Camera%20Uploads/2012-04-02%2012.34.44.jpg
The requesting app will not have read permission as its dropbox own private directory even with WRITE_EXTERNAL_STORAGE permission. In KitKat, it is recommended to use FileProvider to share a file via a content:// uri
26 Replies
Replies have been turned off for this discussion
- Greg-DB11 years ago
Dropbox Community Moderator
Thanks for the report! I'm sending this along to the right people.
- Michael G.8911 years agoNew member | Level 1
Any update on this? I've run into the same issue.
- Greg-DB11 years ago
Dropbox Community Moderator
Apologies, no update right now. I'll check in with the right people again.
- Craig M.2111 years agoNew member | Level 2
Has this been fixed recently? I did not run in to permission issues using the following code to initiate download...
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("*/*"); startActivityForResult(intent, PICKFILE_RESULT_CODE );The uri returned in
onActivityResultwas this:file:///storage/emulated/0/Android/data/com.dropbox.android/files/scratch/Kanji%20Sketch%20Pad/KanjiKnowledge.ks
Processing the data in
onActivityResultrequired a bit of a workaround for Dropbox, which I'll mention in a separate thread, but my app read the file okay. Does the issue only appear under certain circumstances? - Craig M.2111 years agoNew member | Level 2
I should add, I am using Android 5.0.2, device is HTCOne,
- Greg-DB11 years ago
Dropbox Community Moderator
Still no news on potentially using content:// instead yet, but I'll ask engineering if something changed about the existing behavior/any guidance.
- Greg-DB11 years ago
Dropbox Community Moderator
Thanks for your patience Craig. I heard back from engineering here with the following information:
-
FLAG_GRANT_READ_URI_PERMISSIONseems to have no effect. - On Android API level 18 (and presumably probably below), specifying
READ_EXTERNAL_STORAGEorWRITE_EXTERNAL_STORAGEdoes not matter. The calling app is able to read the file irrespective of these settings. - On Android API level 19 and above, the calling app needs the
READ_EXTERNAL_STORAGEorWRITE_EXTERNAL_STORAGEpermission to be able to read the data provided by us.
Also, on Android API level 19 and above caller will need to read the data using the
ContentResolver#openInputStream(fileUri)method to be able to read the files. While on API level 18 and below directly creating the file object to read the file works. -
- Craig M.2111 years agoNew member | Level 2
Thanks for that. I have not had any problems with reading the file. I am therefore unsure what the problem was that the other posters met.
I have read and write permissions set.
I initially used code like this (based on suggestions found online):
ParcelFileDescriptor mInputPFD = null ;
try {
mInputPFD = getContentResolver().openFileDescriptor(returnUri, "r");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("File not found...");
return;
}
if(mInputPFD!=null){
fd = mInputPFD.getFileDescriptor();
FileInputStream fis = new FileInputStream(fd);
//process the input stream
}I tried the more direct method suggested above and it also worked:
FileInputStream fis = null ;
try {
fis = (FileInputStream) getContentResolver().openInputStream(returnUri);
}
catch (FileNotFoundException e1) {
e1.printStackTrace();
System.out.println("File not found...");
return ;
}//process the input stream
I am using targeted Android API 19.
Can I assume that the
ContentResolver#openInputStream(fileUri)method will also work on API 18 and lower? - Greg-DB11 years ago
Dropbox Community Moderator
openInputStreamwas added in API level 1 and is documented to support both content and file schemes, so it looks like it should work. - ti11 years agoNew member | Level 1
Hi, thanks for useful Dropbox.
I have same problem.
So, does the future version of Dropbox support `content://` URI?
I hope that Dropbox returns `content://` URI that works fine without `READ_EXTERNAL_STORAGE` permission such as sharing files by `FileProvider`. I really hope so.
I don't want that the my apps require more permission that make users feel uneasy.
And then, I think that more users use Dropbox as the place to save files of more apps. Because since Kitkat many apps use `FileProvider` and they don't read/write the file by oneself.
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!