I am writing an example app which implements a Doc...
# android
j
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: https://github.com/jcraane/DocumentsProviderExample I have a problem sharing the selected file with for example Gmail. Depending on the method I use in openDocument https://github.com/jcraane/DocumentsProviderExample/blob/4fe4f9fd8f48ab397b0f9d7bdfa9018dd60ddf77/app/src/main/java/nl/jcraane/myapplication/provider/SimulateNetworkDocumentsProvider.kt#L42 I get various results (see the code in the above link). In summary: - When I read in the contents of a file and return
Copy code
ParcelFileDescriptor.open(file, 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:
Copy code
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. - 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 https://stackoverflow.com/questions/62302642/correctly-implementing-opendocument-for-a-documentsprovider/62312914#62312914 for a full description of the solution. In short: I created an activity which handles GET_CONTENT and OPEN_DOCUMENT instead of a DocumentsProvider.