From a41747a3cfde9d3db61597d2b07b10ec7c885261 Mon Sep 17 00:00:00 2001 From: Faimi the Legend Zufarov Date: Mon, 7 Oct 2024 22:36:22 +0500 Subject: [PATCH] MWR-923 Replaced StartActivityForResult to PickVisualMedia & removed the READ_MEDIA_IMAGES permission --- app/src/main/AndroidManifest.xml | 1 - .../screens/scan/QRCodeScannerActivity.kt | 26 +++++++------------ 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e9f09cfbd..b7901ef43 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,7 +13,6 @@ - diff --git a/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/presentation/screens/scan/QRCodeScannerActivity.kt b/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/presentation/screens/scan/QRCodeScannerActivity.kt index 5b92242dc..d15dbc443 100644 --- a/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/presentation/screens/scan/QRCodeScannerActivity.kt +++ b/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/presentation/screens/scan/QRCodeScannerActivity.kt @@ -32,14 +32,14 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.feature_assets_impl.presentation.screens.scan -import android.app.Activity import android.content.Intent import android.graphics.Color +import android.net.Uri import android.os.Bundle import android.view.KeyEvent import android.widget.Toast -import androidx.activity.result.ActivityResult import androidx.activity.result.ActivityResultLauncher +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity @@ -68,12 +68,10 @@ class QRCodeScannerActivity : AppCompatActivity() { private var capture: CaptureManager? = null - private val startForResultFromGallery: ActivityResultLauncher = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult -> - if (result.resultCode == Activity.RESULT_OK) { - result.data?.data?.let { selectedImageUri -> - viewModel.decodeScannedQrCodeUri(selectedImageUri) - } + private val startForResultFromGallery: ActivityResultLauncher = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { resultUri: Uri? -> + resultUri?.let { selectedImageUri -> + viewModel.decodeScannedQrCodeUri(selectedImageUri) } } @@ -176,14 +174,8 @@ class QRCodeScannerActivity : AppCompatActivity() { } private fun selectQrFromGallery() { - val intent = Intent().apply { - type = QR_CODE_IMAGE_TYPE - action = Intent.ACTION_GET_CONTENT - } - startForResultFromGallery.launch(intent) - } - - private companion object { - const val QR_CODE_IMAGE_TYPE = "image/*" + val pickVisualMediaRequest = + PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly) + startForResultFromGallery.launch(pickVisualMediaRequest) } }