Implements Glide offline mode
Asked Answered
S

0

8

I'm writing an Android app and I need to have an offline mode there, that means that I need to download all images from the back-end and in case I have no Internet connection I will be able to show them to the user. I read the official documentation for the caching Glide 4.3.1 and tried to use this code to download:

GlideApp.with(context)
      .downloadOnly()
      .load(url)
      .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
      .submit();

To load image I use:

GlideApp
        .with(context)
        .load(url)
        .error(R.drawable.image_placeholder)
        .into(imageView);`

It looks like it works because the space that my app takes increase. But when I try to run my app in offline mode most of the images are skipped and in logs I see the next:

Load failed for myhostname/myfilename.jpg with size [395x485]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, REMOTE 
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed
Cause (1 of 1): class java.net.UnknownHostException: Unable to resolve host "cava.cool": No address associated with hostname

Has someone faced with a similar problem?

P.S. When I have network connection it works perfect.

Streptococcus answered 7/12, 2017 at 16:38 Comment(6)
it will not get downloaded but next time when u open your app with internet connection it will take less tie then before.I guess u have to use sqlite to store and then retriveLu
Well, the images are downloaded - disk space that is allocated for my app fills up, the question is how to tell the Glide to read the images from the disk storage and show. P.S. I've tried all of the DiskCacheStrategies - no luck :-(Streptococcus
@Streptococcus did you find the answer ?Determinate
@Lu lol, are you suggesting to store the images in a relational database or meta data related to the image?Suttles
@Streptococcus did you find the answer?Lulalulea
i know it's a bit late, but the issue was in the server. When i've tried to load many icons - thought that i DoD him and dropped connection.Streptococcus

© 2022 - 2024 — McMap. All rights reserved.