From 21e9a304c520a2fb0b3e2a437eeffc72a3887e5b Mon Sep 17 00:00:00 2001 From: Quiet Date: Sun, 27 Oct 2024 00:56:30 +1100 Subject: [PATCH] **Fix 2:** I believe the issue described is actually caused by a failure to obtain storage read and write permissions. On my phone, this bug manifests as a crash when attempting to store the rotated image (I tested this on both my emulator and my real phone; Fix 1 addresses the emulator, and Fix 2 is for the real phone). The issue described in the report could not be reproduced, and I suspect this is due to the storage permission problem manifesting differently on different emulators/phones. In any case, the two situations mentioned in the issue no longer occur. I added code to request permissions in the `getRotatedImage` function of `EditActivity.kt` to resolve this problem. --- .../java/fr/free/nrw/commons/edit/EditActivity.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/src/main/java/fr/free/nrw/commons/edit/EditActivity.kt b/app/src/main/java/fr/free/nrw/commons/edit/EditActivity.kt index d585a99e9..445792028 100644 --- a/app/src/main/java/fr/free/nrw/commons/edit/EditActivity.kt +++ b/app/src/main/java/fr/free/nrw/commons/edit/EditActivity.kt @@ -1,5 +1,6 @@ package fr.free.nrw.commons.edit +import android.Manifest import android.animation.Animator import android.animation.Animator.AnimatorListener import android.animation.ValueAnimator @@ -20,6 +21,11 @@ import androidx.lifecycle.ViewModelProvider import fr.free.nrw.commons.databinding.ActivityEditBinding import timber.log.Timber import java.io.File +import androidx.core.content.ContextCompat +import android.content.pm.PackageManager +import androidx.core.app.ActivityCompat + + /** * An activity class for editing and rotating images using LLJTran with EXIF attribute preservation. @@ -239,6 +245,12 @@ class EditActivity : AppCompatActivity() { * as a result, and finishes the current activity. */ fun getRotatedImage() { + //Get Permission to saccess + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) + != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 7747) + } + val filePath = imageUri.toUri().path val file = filePath?.let { File(it) }