views:

282

answers:

2

The content provider / resolver APIs provide a complicated, but robust way of transferring data between processes using an URI and the openInputStream() and openOutputStream() methods. Custom content providers have the ability to override the openFile() method with custom code to effectively resolve an URI into a Stream; however, the method signature of openFile() has an ParcelFileDescriptor return type and it is not clear how one might generate a proper representation for dynamically generated content to return from this method.

http://stackoverflow.com/questions/1542008/returning-a-memory-mapped-inputstream-from-a-content-provider

Are there examples of implementing ContentProvider.openFile() method for dynamic content in the existing code base? If not can you suggest source code or process for doing so?

+1  A: 

MemoryFile supports this, but the public API hasn't been finalized.

Jeff Sharkey
Are there plans to include a conversion between a memoryfile and parcelfiledescriptor in the future? Something along those lines would be nicer than cluttering/polluting the filesystem with temporary files having unkown lifetimes. Maybe there is some way to detect the closing of the stream within the content provider which could offer a little safer way to cleanup after yourself?I am concerned with sending attachments to an (gmail/standaed) email client though I'm sure there are other places where these issues could arise.
SmokingRope
Yes, MemoryFile.java currently has a `public ParcelFileDescriptor getParcelFileDescriptor()` method. This was committed as part of Donut, but as Jeff said, is still not finalized yet.I've confirmed that the "concept" at least works, and can be done currently, using reflection. It's very dirty though, and not recommended :)Unfortunately, even `ParcelFileDescriptor.fromSocket()` can't be used because `Memory.isMemoryFile()` throws an exception because the socket is neither a PFD nor a memory file.
Joe
A: 

But so, how can i store raw files in custom ContentProvider?

Andrea Scarafoni