0

I'm very new to android development. I'm receiving images and data from Flicker API using retrofit and showing it into my recyclerview. When I'm online images are loaded in imageview using URLs provided by API but now I want to store images and data into room database to work recyclerview offline (like Instagram). When the internet comes back online, it should refresh the recyclerview with more images.

Please help.

Parag Rane
  • 179
  • 4
  • 15

1 Answers1

0

If you want to work offline you have to store images directly in the database (not URLs). I can think of two options: Store the images on the device and have the file paths in the database, then fetch the filepath from the database and open it in android according to that fetched path.

You can also store the images in the database as binary data, decoding and encoding it accordingly.

qki
  • 1,769
  • 11
  • 25
  • For storing binary data in MS-SQL I suggest reading about FILESTREAM. Get back if you reached any success, happy coding! – qki Feb 04 '20 at 08:19
  • Hey, can you please help me to convert image from URLs to byte[ ] and from byte to Bitmap. – Parag Rane Feb 04 '20 at 14:25
  • there are already answers to this type of question, for example [here](https://stackoverflow.com/questions/10513976/how-to-convert-image-into-byte-array-and-byte-array-to-base64-string-in-android) – qki Feb 04 '20 at 14:29
  • I want to convert URLs to byte[ ] and got this(https://stackoverflow.com/questions/2295221/java-net-url-read-stream-to-byte) answer but it is giving error at url.openstream(). – Parag Rane Feb 04 '20 at 17:24