0

I need to save the photos that i have downloaded from firebase storage to the phone for not downloading them again and again every time the program runs.

url = "https://firebasestorage.googleapis.com/v0/b/****-*************.jpg"
Picasso.get().load(url).into(imageView);

I have no trouble viewing the picture but when I run the program again, I don't want the image to be reloaded. How can I achieve this?

Pehr Sibusiso
  • 862
  • 1
  • 14
  • 27
  • Picasso doesn't download your image again and again, it just download once(on the first call of the url). The loading in the 2nd, 3rd, ... try is just Picasso browsing your image in its cache. Check your profiler for the data consumption and try it on network close. – L2_Paver Nov 21 '19 at 00:51

3 Answers3

1

Better use Glide 4 instead of Picasso. Glide's image caching strategy is useful for these kind of purpose. More details : https://bumptech.github.io/glide/doc/caching.html

0

first you will want convert the ImageView where you have the image to bitmap

BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
Bitmap bitmap = drawable.getBitmap();

now you can save the bitmap

try (FileOutputStream out = new FileOutputStream(filename)) { //where filename is your path location file
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);     
} catch (IOException e) {
    e.printStackTrace();
}
0

I think you need to follow such steps to get good images and present to imageview.

1) Download from firebase and save to directory on android. 2) Display image from android directory.

Or you can download image using link from firebase. It is not a good idea to get image from imageview.

KpStar
  • 122
  • 7