Хотя этот код успешно создает изображение, которое также присутствует в галерее телефона, расширение имеет значение «.jpg» вместо «.gif».
File gifFile; // gif file stored in Context.getFilesDir()
final ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, "Image" + System.currentTimeMillis());
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "image/gif");
// Create a new gif image using MediaStore
final Uri gifContentUri = context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);
// Open a writable stream pointing to the new file created by MediaStore
OutputStream outputStream = context.getContentResolver().openOutputStream(gifContentUri, "w");
// Copy the original file from the app private data folder to the file created by MediaStore
IOUtils.copyFile(new FileInputStream(gifFile), outputStream);
Выходной файл создается в папке «Изображения» с помощьюMediaStore. Если я вручную изменю расширение выходного файла на gif, анимация gif будет воспроизводиться в галерее Android.
Мне кажется, мне не хватает небольшой детали, чтобы это работало