diff --git a/android/build.gradle b/android/build.gradle index d93cdd02..8a033d6f 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -34,6 +34,7 @@ android { } dependencies { + implementation 'org.apache.commons:commons-imaging:1.0-alpha3' testImplementation 'junit:junit:4.13.2' testImplementation 'org.mockito:mockito-core:5.0.0' } diff --git a/android/src/main/java/studio/midoridesign/gal/GalPlugin.java b/android/src/main/java/studio/midoridesign/gal/GalPlugin.java index 16f6b628..222c386c 100644 --- a/android/src/main/java/studio/midoridesign/gal/GalPlugin.java +++ b/android/src/main/java/studio/midoridesign/gal/GalPlugin.java @@ -36,6 +36,9 @@ import java.io.ByteArrayInputStream; import java.util.UUID; +import org.apache.commons.imaging.ImageFormat; +import org.apache.commons.imaging.Imaging; + public class GalPlugin implements FlutterPlugin, MethodCallHandler, ActivityAware, PluginRegistry.RequestPermissionsResultListener { private static final String PERMISSION = Manifest.permission.WRITE_EXTERNAL_STORAGE; @@ -130,8 +133,10 @@ private void putMedia(Context context, String path, String album, boolean isImag private void putMediaBytes(Context context, byte[] bytes, String album) throws IOException, SecurityException { + ImageFormat imageFormat = Imaging.guessFormat(bytes); + String extension = "." + imageFormat.getDefaultExtension().toLowerCase(); try (InputStream in = new ByteArrayInputStream(bytes)) { - writeData(context, in, true, ".jpg", album); + writeData(context, in, true, extension, album); } }