From 5b22d06ff9267dfe82b893b504088bb24e286fcd Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 17 Dec 2018 20:00:44 +0100 Subject: [PATCH] keep exif data at editing images from Android 7+ --- .../gallery/pro/activities/EditActivity.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt index 285c110fb..ee4d4afd1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt @@ -1,12 +1,15 @@ package com.simplemobiletools.gallery.pro.activities +import android.annotation.TargetApi import android.app.Activity import android.content.Intent import android.graphics.Bitmap import android.graphics.Bitmap.CompressFormat import android.graphics.Color import android.graphics.Point +import android.media.ExifInterface import android.net.Uri +import android.os.Build import android.os.Bundle import android.provider.MediaStore import android.view.Menu @@ -24,6 +27,7 @@ import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE import com.simplemobiletools.commons.helpers.REAL_FILE_PATH +import com.simplemobiletools.commons.helpers.isNougatPlus import com.simplemobiletools.commons.models.FileDirItem import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.adapters.FiltersAdapter @@ -576,6 +580,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener } } + @TargetApi(Build.VERSION_CODES.N) private fun saveBitmap(file: File, bitmap: Bitmap, out: OutputStream, showSavingToast: Boolean) { if (showSavingToast) { toast(R.string.saving) @@ -587,6 +592,17 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener } else { bitmap.compress(file.absolutePath.getCompressionFormat(), 90, out) } + + try { + if (isNougatPlus()) { + val inputStream = contentResolver.openInputStream(uri) + val oldExif = ExifInterface(inputStream) + val newExif = ExifInterface(file.absolutePath) + oldExif.copyTo(newExif, false) + } + } catch (e: Exception) { + } + setResult(Activity.RESULT_OK, intent) scanFinalPath(file.absolutePath) out.close()