Android content provider openFd FileNotFoundException (file compressed)
May 17, 2011 08:46:50 Last update: May 17, 2011 08:47:35
When I used AssetManager to open an XML file in a ContentProvider:
it failed with this exception:
It turned out that
An Android ticket was opened on this issue. Till that is fixed, the workaround is to add an exclusion in
getContext().getAssets().openFd("demo.xml");
it failed with this exception:
java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
It turned out that
openFd only works for asset files that are not compressed. It works on media files such as .mp3, .jpg, .wmv etc., which are not compressed during packaging. XML files are compressed by dedault, causing openFd to fail.
An Android ticket was opened on this issue. Till that is fixed, the workaround is to add an exclusion in
build.xml:
<?xml version="1.0" encoding="UTF-8"?> <project name="" defaule="help"> . . . <setup /> <target name="-package-resources"> <echo>Packaging resources!!!</echo> <aapt executable="${aapt}" command="package" versioncode="${version.code}" debug="${build.packaging.debug}" manifest="AndroidManifest.xml" assets="${asset.absolute.dir}" androidjar="${android.jar}" apkfolder="${out.absolute.dir}" resourcefilename="${resource.package.file.name}" resourcefilter="${aapt.resource.filter}"> <res path="${resource.absolute.dir}" /> <nocompress extension="xml" /> </aapt> </target> </project>