How to store large blobs in an android content provider?

后端 未结 3 1499
自闭症患者
自闭症患者 2020-11-30 04:19

I have some large files (images and video) which I need to store in a content provider. The android documentation indicates...

If you are exposing byt

3条回答
  •  暖寄归人
    2020-11-30 04:44

    There is a problem writing files though. How does the content provider know then the write is complete?

    When closing an OutputStream obtained via a ContentResolver.openOutputStream() I wish for the corresponding (custom) ContentProvider to perform some custom action. Presently I am using creating a FileObserver on a temporary file but it seems like the wrong way to get it done. My first thought was to subtype the ParcelFileDescriptor produced by the ContentProvider.openFile() method but that didn't seem to work for me.

    That being said there were some errors which resulted in the MyParcelFileDescriptor usage.

    • I didn't ensure that the file descriptor would not be garbage collected prematurely.
    • I didn't try to overriding finally() (the documentation seems to suggest that being the place to do this but close() seemed to be the right choice to me.

    Bottom line, is there any interaction between the file objects as seen by the ContentResolver and those of the ContentProvider?

提交回复
热议问题