diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionQRCodeScanFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionQRCodeScanFragment.kt index 85b652cd915..0d4e8262138 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionQRCodeScanFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionQRCodeScanFragment.kt @@ -1,6 +1,7 @@ package de.rki.coronawarnapp.ui.submission import android.Manifest +import android.content.pm.PackageManager import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -38,6 +39,7 @@ class SubmissionQRCodeScanFragment : Fragment() { private val viewModel: SubmissionViewModel by activityViewModels() private var _binding: FragmentSubmissionQrCodeScanBinding? = null private val binding: FragmentSubmissionQrCodeScanBinding get() = _binding!! + private var showsPermissionDialog = false override fun onCreateView( inflater: LayoutInflater, @@ -112,14 +114,6 @@ class SubmissionQRCodeScanFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - if (!CameraPermissionHelper.hasCameraPermission(requireActivity())) { - if (shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) { - showCameraPermissionRationaleDialog() - } else { - requestCameraPermission() - } - } - binding.submissionQrCodeScanTorch.setOnCheckedChangeListener { _, isChecked -> binding.submissionQrCodeScanPreview.setTorch( isChecked @@ -184,6 +178,25 @@ class SubmissionQRCodeScanFragment : Fragment() { DialogHelper.showDialog(invalidScanDialogInstance) } + override fun onRequestPermissionsResult( + requestCode: Int, + permissions: Array, + grantResults: IntArray + ) { + if (requestCode == REQUEST_CAMERA_PERMISSION_CODE) { + + // permission was denied + if ((grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_DENIED)) { + if (shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) { + showCameraPermissionRationaleDialog() + } else { + // user permanently denied access to the camera + showCameraPermissionDeniedDialog() + } + } + } + } + override fun onResume() { super.onResume() binding.submissionQrCodeScanContainer.sendAccessibilityEvent(AccessibilityEvent.TYPE_ANNOUNCEMENT) @@ -191,7 +204,32 @@ class SubmissionQRCodeScanFragment : Fragment() { if (CameraPermissionHelper.hasCameraPermission(requireActivity())) { binding.submissionQrCodeScanPreview.resume() startDecode() + return } + + // we might already show a rational dialog (e.g. when onRequestPermissionsResult was denied + // then do nothing + if (showsPermissionDialog) { + return + } + + requestCameraPermission() + } + + private fun showCameraPermissionDeniedDialog() { + val permissionDeniedDialog = DialogHelper.DialogInstance( + requireActivity(), + R.string.submission_qr_code_scan_permission_denied_dialog_headline, + R.string.submission_qr_code_scan_permission_denied_dialog_body, + R.string.submission_qr_code_scan_permission_denied_dialog_button, + cancelable = false, + positiveButtonFunction = { + showsPermissionDialog = false + goBack() + } + ) + showsPermissionDialog = true + DialogHelper.showDialog(permissionDeniedDialog) } private fun showCameraPermissionRationaleDialog() { @@ -203,13 +241,16 @@ class SubmissionQRCodeScanFragment : Fragment() { R.string.submission_qr_code_scan_permission_rationale_dialog_button_negative, false, { + showsPermissionDialog = false requestCameraPermission() }, { + showsPermissionDialog = false goBack() } ) + showsPermissionDialog = true DialogHelper.showDialog(cameraPermissionRationaleDialogInstance) } diff --git a/Corona-Warn-App/src/main/res/values/strings.xml b/Corona-Warn-App/src/main/res/values/strings.xml index 6ad547687b6..8c950aa7694 100644 --- a/Corona-Warn-App/src/main/res/values/strings.xml +++ b/Corona-Warn-App/src/main/res/values/strings.xml @@ -701,6 +701,14 @@ Nicht erlauben + + + Kamera Zugriff benötigt + + Bitte gehen Sie in die Systemeinstellungen und erlauben Sie der App die Benutzung der Kamera, um den QR-Code zu scannen. + + OK + QR-Code nicht korrekt