From 0e38255961215aa26e7e28315000c50722d96294 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 31 May 2017 22:06:54 +0200 Subject: [PATCH] fix a different type of contact photo picking too --- .../gallery/activities/MainActivity.kt | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index e2c9649b9..aa86c6a72 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -28,6 +28,9 @@ import com.simplemobiletools.gallery.models.Directory import com.simplemobiletools.gallery.views.MyScalableRecyclerView import kotlinx.android.synthetic.main.activity_main.* import java.io.File +import java.io.FileInputStream +import java.io.InputStream +import java.io.OutputStream import java.util.* class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { @@ -291,9 +294,23 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { val path = resultData.data.path val uri = Uri.fromFile(File(path)) if (mIsGetImageContentIntent || mIsGetVideoContentIntent || mIsGetAnyContentIntent) { - val type = File(path).getMimeType("image/jpeg") - setDataAndTypeAndNormalize(uri, type) - flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + if (intent.extras?.containsKey(MediaStore.EXTRA_OUTPUT) == true) { + var inputStream: InputStream? = null + var outputStream: OutputStream? = null + try { + val output = intent.extras.get(MediaStore.EXTRA_OUTPUT) as Uri + inputStream = FileInputStream(File(path)) + outputStream = contentResolver.openOutputStream(output) + inputStream.copyTo(outputStream) + } finally { + inputStream?.close() + outputStream?.close() + } + } else { + val type = File(path).getMimeType("image/jpeg") + setDataAndTypeAndNormalize(uri, type) + flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + } } else if (mIsPickImageIntent || mIsPickVideoIntent) { data = uri flags = Intent.FLAG_GRANT_READ_URI_PERMISSION