5

Using https://github.com/koush/ion image Loader to display gif files into ImageView

I save the jpg images into gallery by this code

    MediaStore.Images.Media.insertImage(
                                    getActivity().getContentResolver(), bitmap,
                                    "XXX", "Image1"); 

but this way is not working with gif files.

Do you have any idea how can i accomplish this?

Jehad
  • 472
  • 2
  • 10
  • 24

2 Answers2

2

Bitmaps are single images, so GIFs will not work with this API. To save a GIF, you'll need to download the gif to a file on external storage, and then notify MediaScanner to scan it. It will then show up in the gallery.

koush
  • 2,972
  • 28
  • 31
2

You could save gif using this code

  File file = new File(getBaseContext().getExternalCacheDir(),
                    "gif_name"+ ".gif");
            try {
                FileOutputStream fos = new FileOutputStream(file);
                fos.write(gif.getData());//gif is gif image object
                fos.flush();
                fos.close();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }

This code will save the gif in cache directory on your external sd card but will not be visible in Gallery.

Rahul Kumar
  • 5,120
  • 5
  • 33
  • 44
  • gif.getData() where to get this method – Zia Ur Rahman Jul 17 '18 at 18:46
  • Gif represents the actual gif that you fetch from a api – Rahul Kumar Jul 18 '18 at 03:00
  • my gif file is located in external storage and I have the path i.e. /storage/emulated/0/Android/data//files//xyz.gif. Now I want to Save/copy this file to Image Gallery and show there. How to do this. Because I didn't get the .getData() method not from String imagePath and not from file. – Zia Ur Rahman Jul 18 '18 at 07:54
  • First tell me where to get this methd getData() and then How to make this visible in Gallery ? – Zia Ur Rahman Jul 18 '18 at 10:24