I have a search and search for questions about storing and extracting files from ContentProvider, but my situation is slightly different.
I am creating an application that will host content for one of our other applications. Think of it as a way to sell content without actually buying in the app.
It currently works, but I need to make copies of the images in the cache so that the returned ParcelFileDescriptor from openFile is valid. I was hoping that someone could know how to reference and arbitrarily ParcelFileDescriptor from the file associated with the application. Assets do not seem to facilitate this. Raw materials probably have the same scenario.
Let me try to explain with an example ... THIS is how I expect everything to work if I keep all my files in assets (which I now find).
@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;
}
But of course this does not work. I get a valid ParcelFileDescriptor which returns to the application that calls the ContentResolver, but it apparently points to the entire resource directory. After some time scrolling through the time intervals, it seems that the assets do not allow the descriptor to reference it because of the application with which it is associated (although I have no links to this).
I “solved” the problem by copying the file in question into the cache application of the application hosting the ContentProvider and returning the cached file ParcelFileDescriptor. This works fine ... but I end up doubling the size of the application.
What's at the heart of my question ... Is there a way to link a static file (of any type) that needs to be served with the ContentProvider without having to copy it to the cache.
Even if I used sqlite and saved the files as blobs, I would have to make the original copy of the database so that it was writable ... so this is the same end.
It makes sense?: -)
source
share