File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/ui Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 11package com.google.firebase.quickstart.ai.ui
22
3+ import android.Manifest
4+ import android.content.pm.PackageManager
35import androidx.activity.compose.rememberLauncherForActivityResult
46import androidx.activity.result.contract.ActivityResultContracts
7+ import androidx.core.content.ContextCompat
58import androidx.compose.foundation.layout.Arrangement
69import androidx.compose.foundation.layout.Box
710import androidx.compose.foundation.layout.Column
@@ -54,11 +57,25 @@ fun HybridInferenceScreen(
5457 }
5558 )
5659
60+ val permissionLauncher = rememberLauncherForActivityResult(
61+ ActivityResultContracts .RequestPermission ()
62+ ) { isGranted ->
63+ if (isGranted) {
64+ cameraLauncher.launch(null )
65+ }
66+ }
67+
5768 Scaffold (
5869 floatingActionButton = {
5970 FloatingActionButton (
6071 onClick = {
61- cameraLauncher.launch(null )
72+ val permissionCheckResult =
73+ ContextCompat .checkSelfPermission(context, Manifest .permission.CAMERA )
74+ if (permissionCheckResult == PackageManager .PERMISSION_GRANTED ) {
75+ cameraLauncher.launch(null )
76+ } else {
77+ permissionLauncher.launch(Manifest .permission.CAMERA )
78+ }
6279 },
6380 containerColor = MaterialTheme .colorScheme.primary,
6481 contentColor = MaterialTheme .colorScheme.onPrimary
You can’t perform that action at this time.
0 commit comments