10

I am using the Glide to display images in my app. Now I want to know the location where the Glide is storing the cached images downloaded from the urls.

I am using below code to display image.

Glide.with(mContext)
            .load(mData.get(position).getImage())
            .centerCrop()
            .override(300, 300)
            .placeholder(R.drawable.default_small)
            .diskCacheStrategy(DiskCacheStrategy.SOURCE)
            .into(holder.ivCapturedImage);
Priyanka Singh
  • 40
  • 1
  • 14
android_griezmann
  • 3,757
  • 4
  • 16
  • 43

3 Answers3

19

This is one available method if you are using Glide 4.8.0 or higher

Kotlin:

val file: File = Glide.with(activity).asFile().load(url).submit().get()
val path: String = file.path

Java:

File file = Glide.with(activity).asFile().load(url).submit().get();
String path = file.getPath();

Then you can get a path looks like

/data/user/0/{package_name}/cache/image_manager_disk_cache/64c0af382f0a4b41c5dd210a3e945283d91c93b1938ee546f00b9ded701a7e40.0
Joonsoo
  • 788
  • 1
  • 13
  • 15
3
 private String getImgCachePath(String url) {
    FutureTarget<File> futureTarget = Glide.with(getBaseContext()).load(url).downloadOnly(100, 100);
    try {
        File file = futureTarget.get();
        String path = file.getAbsolutePath();
        return path;
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
    return null;
}

the parameter url is network address of the picture,the 100,100 is the width and height of the cached picture ,you can change them according to your needs. Then,The path is the cache path.

zhangxiaoping
  • 240
  • 2
  • 6
0
  Runnable runnable = new Runnable() {
            @Override
            public void run() {
                FutureTarget<File> futureTarget = Glide.with(context).load(vLink).downloadOnly(100,100);
                try {
                    File file = futureTarget.get();
                    String path = file.getAbsolutePath();
                    System.out.println("Path video  = "+path +"File  = "+file);
                    if (path != null) {
                        Uri imageUri = Uri.parse(path);
                        Intent shareIntent = new Intent(Intent.ACTION_SEND);
                        shareIntent.putExtra(Intent.EXTRA_TEXT, "shareMessage");
                        shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
                        shareIntent.setType("video/*");
                        context.startActivity(Intent.createChooser(shareIntent, "Share Image.."));
                    } else {
                        System.out.println("Image Uri = " + path + "\nResource = " + resource);
                    }
                } catch (ExecutionException | InterruptedException e) {
                e.printStackTrace();
            }
            }
        };
        new Thread(runnable).start();
Suresh B B
  • 1,387
  • 11
  • 13