I am writing an example app which implements a DocumentsProvider to share files with other apps using the SAF framework. The code can be found here: DocumentsProvider example project
I have a problem sharing the selected file with for example Gmail. Depending on the method I use in openDocument (see openDocument function in example project) I get various results (see the code in the above link).
In summary:
1) When I read in the contents of a file and return
ParcelFileDescriptor.open(file, ParcelFileDescriptor.parseMode(mode))
it works from Gmail. This is using the readFilesUsingOpenDocumment() function.
2) When I read in the contents and use createReliablePipe, I can get the contents in the sample app but not in Gmail., which gives the following exception:
2020-06-10 09:15:31.643 14097-14235/nl.jcraane.myapplication E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2 Process: nl.jcraane.myapplication, PID: 14097 Caused by: java.io.IOException: write failed: EPIPE (Broken pipe)
This is using the readFileUsingReliablePipe() function.
3) When I use createReliablePipe and I do not use a ASyncTask, the app hangs when large amounts (more than a couple of Kb) of data are transferred.
Does anyone have more insights in how openDocument should be implemented? Ideally I also want to download files via a URL and stream the bytes back when the download is finished. Is there a possibility of letting the calling app know a download is in progress (to show a progress bar)? How should createReliablePipe be used correctly?
I did look at Samba documents provider from which I have taken the ASyncTask solution but unfortunately without success.
Thanks!