First, let me just say that this library is flippin' awesome & the "question" I'm asking is prolly BIAD (b/c I'm a dummy).
Problem
Coil fails to load local image into an ImageView.
In the following code, I have a picture in the /sdcard/Android/data. I load it in via imageView.load().
val filePath = "/storage/emulated/0/Android/data/PACKAGE_ID/files/Pictures/PIC_2020-01-16_15:39:35:648.jpg"
imageView.load(filePath)
The problem is the bitmap never loads into my ImageView & no errors are displayed, but everything works when doing...
val bmp = BitmapFactory.decodeFile(filePath)
imageView.setImageBitmap(bmp)
Expected behavior
The imageView should load the bitmap.
Version
coil v0.9.1
Pixel XL running Android Q.
Questions
Any idea why coil fails to load the image?
Is there a way I can tell if coil fails to load the bitmap in the code (like a success/error listener)?
Thanks! To fix your issue you need to append file:// to the beginning:
// Note the 3 forward slashes.
imageView.load("file:///storage/emulated/0/Android/data/PACKAGE_ID/files/Pictures/PIC_2020-01-16_15:39:35:648.jpg")
// Optionally you could pass it as a File instead.
imageView.load(File("/storage/emulated/0/Android/data/PACKAGE_ID/files/Pictures/PIC_2020-01-16_15:39:35:648.jpg"))
Unlike Glide, Coil doesn't autodetect file paths. This is mostly a design choice as load(String) is meant for uris, which should always have a prefix.
Also you can listen to the result of a request by looking at the logs (and enabling them for debug builds: CoilLogger.setEnabled(BuildConfig.DEBUG) or by setting a listener:
imageView.load(path) {
listener(
onError = {}
)
}
That worked. Thanks for your help & for the awesome, kotlin-friendly library!
Hit this as well; file prefix works. or file.toUri()
Most helpful comment
Thanks! To fix your issue you need to append
file://to the beginning:Unlike Glide, Coil doesn't autodetect file paths. This is mostly a design choice as
load(String)is meant for uris, which should always have a prefix.Also you can listen to the result of a request by looking at the logs (and enabling them for debug builds:
CoilLogger.setEnabled(BuildConfig.DEBUG)or by setting a listener: