Jamie Craane

06/10/2020, 10:23 AM
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: I have a problem sharing the selected file with for example Gmail. Depending on the method I use in openDocument I get various results (see the code in the above link). In summary: - When I read in the contents of a file and return, ParcelFileDescriptor.parseMode(mode))
it works from Gmail. This is using the readFilesUsingOpenDocumment() function. - 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: write failed: EPIPE (Broken pipe)
This is using the readFileUsingReliablePipe() function. - 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? Thanks!
FYI: I also posted this in Stackoverflow
I have used another solution than a DocumentsProvider to share files from other apps. See for a full description of the solution. In short: I created an activity which handles GET_CONTENT and OPEN_DOCUMENT instead of a DocumentsProvider.