title: Serving images and other files from a ContentProvider
body: <p>I've search around and found questions about storing and retrieving files from a ContentProvider but my situation is a little different.</p>
  
  <p>I am building an app that will host content for one of our other apps.  Think of it as a way to sell content without actually having in-app-purchase.</p>
  
  <p>It is currently working, but I have to make copies of the images into the cache so that the ParcelFileDescriptor passed back from openFile is valid.  I was hoping that someone might know how to reference and arbitrary ParcelFileDescriptor from a file bundled with the app.  Assets doesn't seem to facilitate this.  Raw is likely the same scenario.</p>
  
  <p>Let me try to explain by example...
  THIS is how I would expect things to work if I were storing all my files in assets (which I currently am).</p>
  
  <pre><code>@Override
  public ParcelFileDescriptor openFile(Uri uri, String mode)
  throws FileNotFoundException {
      String fileName = uri.getEncodedPath();
      AssetFileDescriptor afd = getContext().getAssets().openFd(fileName);
      ParcelFileDescriptor pfd = afd.getParcelFileDescriptor();
      return pfd;
  }
  </code></pre>
  
  <p>But, of course, this doesn't work.  I get a valid ParcelFileDescriptor returned to the app calling the ContentResolver, but it appears to be pointing to the entire assets directory.
  After reading around the intertubes for a while, it seems that assets doesn't allow for a descriptor to reference it from outside of the app it's associated with (though, I have no references for this).</p>
  
  <p>I "solved" the problem by copying the file in question into the cache of the app hosting the ContentProvider then returning the ParcelFileDescriptor of the cached file.
  This works just fine... but I end up doubling the size of the app.</p>
  
  <p>That's the heart of my question... Is there a way to bundle a static file (of any type) to be served from a ContentProvider without having to copy it into a cache.</p>
  
  <p>Even if I were to use sqlite and store the files as blobs, I'd have to make an initial copy of the database so that it would be writable... so it's the same end.</p>
  
  <p>Does this make sense? :-)</p>