0

My content provider stores data in SQLite database. One column is a string. I would like to attach this string as a file attachment to an email message.

I got this working by implementing ParcelFileDescriptor openFile(Uri uri, String mode). The implementation

  1. Queries the column value from the database
  2. Stores the returned value in a file
  3. Returns the result of ParcelFileDescriptor.open(file,ParcelFileDescriptor.MODE_READ_ONLY)

Is it possible to avoid these steps and duplication by implementing ParcelFileDescriptor that would represent the column value of a record directly?

(I could store the string value in the file to avoid duplication, but I would like to keep using FTS3 facility provided by SQLite)

Thank you for your help!

Y2i
  • 3,748
  • 2
  • 28
  • 32

1 Answers1

0

Yay, I got it working by using public ParcelFileDescriptor simpleQueryForBlobFileDescriptor()

I can't believe it that I missed this precious piece of information :)

EDIT: there is another method ParcelFileDescriptor[] createPipe() that is more useful if the database column value needs to be transformed before returning to the client.

The example of how to use the method can be found here.

Community
  • 1
  • 1
Y2i
  • 3,748
  • 2
  • 28
  • 32
  • 1
    wow, i stand corrected. as of api level 11, there is a built-in function to create a memory-mapped file corresponding to a database blob. good job. – j__m Jul 23 '13 at 05:57
  • Thanks j__m! MMF is still some sort of duplication, but it is better than creating temporary files by hand. – Y2i Jul 23 '13 at 06:00