I have an Activity
in which I download a zipfile of images and then unzip in the getFilesDir()
. Path is like this :
/data/user/0/packagename/files/files/example.png
When I try to load these images however, they're not showing. I'm using this code to get the path and load the image:
String loc = getFilesDir().getPath() + "/" + Config.IMAGES_LOCATION +"/";
String imageloc = loc + model.getThumbnail();
Glide.with(ActivityImageGallery.this).load(imageloc).into(image);
The imageloc path is the same as the save location and when creating a file from the path, it shows that it would exist.
I tried using file://
in front of the path, but that doesn't work either. WRITE_EXTERNAL
en READ_EXTERNAL
permissions are asked and granted.
You click sync in Glide If you are building your project in Glide and need to see the latest data from your data source, you can click the sync button.
To simply load an image to LinearLayout, we call the with() method of Glide class and pass the context, then we call the load() method, which contains the URL of the image to be downloaded and finally we call the into() method to display the downloaded image on our ImageView.
This works for me, make file instance and pass file's uri that you want to load into ImageView
Glide.with(context)
.load(new File(fileUri.getPath())) // Uri of the picture
.into(profileAvatar);
Make sure you have added
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
You can also use RequestListener
to trace the error in case of failure
new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
return false;
}
First capture your image path,either you are capturing image from camera or picking it from gallery(I assume you have already given read and write permissions). Then Try this
Glide.with(context).load(new File(imagePath)).dontAnimate().error(R.drawable.errorImage).placeholder(R.drawable.placeholderImage).into(imageView);
Using .dontAnimate()
because in some case it may be that image did not load or show when you load first time(or take extra time).
Hope it will help.
Did you try using loading listener of glide using this
1.Debug:-
https://stackoverflow.com/a/42067675/5492047
Glide.with(getActivity())
.load(args.getString(IMAGE_TO_SHOW))
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
return false;
}
})
.into(imageFrame);
and check the exception ?
2.Debug Again.
Can you use any file explorer app and go to the exact place where the file is loaded and open then file?.
3.Path
Is it really /files/files/ in the path?
4.Extension Can you remove .png from the file path and load and check?
5.Tutorial
An awesome tutorial can be found here in depth https://futurestud.io/tutorials/glide-getting-started.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With