file:///android_asset does not work

artem picture artem · May 30, 2014 · Viewed 12.9k times · Source

I store the images in assets/img/categories folder and trying to load them with this code:

ImageLoader.getInstance().displayImage(String.format("file:///android_asset/img/categories/%d.JPG", category.getId()), mImageIv);

It seems to be OK, but does not work:

E/ImageLoader(28790): /android_asset/img/categories/9.JPG: open failed: ENOENT (No such file or directory)
E/ImageLoader(28790): java.io.FileNotFoundException: /android_asset/img/categories/9.JPG: open failed: ENOENT (No such file or directory)

Why it does not work?

Answer

CommonsWare picture CommonsWare · May 30, 2014

file:///android_asset is only for use with WebView.

I do not know what ImageLoader is, but see if it accepts an InputStream. If so, use AssetManager and open() to get an InputStream on your desired asset.