Save gif to android gallery

11.9k views Asked by At

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?

2

There are 2 answers

4
Rahul Kumar On BEST ANSWER

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.

0
koush On

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.