From 54e9a701221030fcf0c574e9baac38c9ab6aa3dc Mon Sep 17 00:00:00 2001 From: dankito Date: Fri, 4 Oct 2024 16:50:41 +0200 Subject: [PATCH] Added check if Android device has a camera --- .../net/codinux/banking/ui/service/QrCodeService.android.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/composeApp/src/androidMain/kotlin/net/codinux/banking/ui/service/QrCodeService.android.kt b/composeApp/src/androidMain/kotlin/net/codinux/banking/ui/service/QrCodeService.android.kt index be0d0fe..b4555a2 100644 --- a/composeApp/src/androidMain/kotlin/net/codinux/banking/ui/service/QrCodeService.android.kt +++ b/composeApp/src/androidMain/kotlin/net/codinux/banking/ui/service/QrCodeService.android.kt @@ -1,6 +1,7 @@ package net.codinux.banking.ui.service import android.Manifest +import android.content.pm.PackageManager import android.view.ScaleGestureDetector import androidx.camera.core.* import androidx.camera.lifecycle.ProcessCameraProvider @@ -30,7 +31,10 @@ actual object QrCodeService { private val log by logger() - actual val supportsReadingQrCodesFromCamera = true + actual val supportsReadingQrCodesFromCamera = hasCamera() + + private fun hasCamera(): Boolean = AndroidContext.applicationContext.packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY) + @Composable actual fun readQrCodeFromCamera(resultCallback: (QrCodeReadResult) -> Unit) {