I don't want them to be stored in the phone while reading them
Technically, you do not have control over that. The third-party app is welcome to do whatever it wants with the data, which includes saving it to a file, sharing it over the Internet, etc.
You are welcome to write a ContentProvider
that streams your documents in response to openFile()
. In your case, since the content is not a file, you would need to use a ParcelFileDescriptor
pipe, so you can write your data to an OutputStream
. This sample project demonstrates the basic technique, though I am serving a PDF from assets.
I would not be surprised if you run into problems with larger documents, though. The client app may want to seek forwards and backwards in the stream, and pipes do not result in seekable streams.