14

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.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Stefan
  • 2,098
  • 2
  • 18
  • 29

5 Answers5

18

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;
            }
Zoe
  • 27,060
  • 21
  • 118
  • 148
Zeeshan Shabbir
  • 6,704
  • 4
  • 38
  • 74
3

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.

Ajeet Choudhary
  • 1,969
  • 1
  • 17
  • 41
2

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.

Reyansh Mishra
  • 1,879
  • 1
  • 14
  • 26
0

try this

File c = new File(Environment.getExternalStorageDirectory() + "/data/user/0/packagename/files/files/example.png");
Glide.with(MainActivity.this).load(c).error(R.drawable.empty_pic).placeholder(R.drawable.empty_pic).into(image2);

or try this

 Glide.with(getActivity()).load(new File(" your path").toString())
        .listener(new RequestListener<String, GlideDrawable>() {
            @Override
            public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                Log.e("xmx1","Error "+e.toString());
                return false;
            }

            @Override
            public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                Log.e("xmx1","no Error ");
                return false;
            }
        })
        .into(ivx);
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
  • i am getting images camera and gallery both can you please tell me which where i can get perfect path and set it in to glide for now i only see my place holder path= /storage/emulated/0/1586779115967.jpg like this. – Arbaz.in Apr 13 '20 at 12:00
0

You would need run time permissions to use internal storage.Second use latest glide library compile 'com.github.bumptech.glide:glide:3.7.0' and format as

Glide.with(context).load(image path).into(Imageview);
Nikhil
  • 107
  • 10