I need to navigate to device camera app from my app and get result back from it. I have already added code for it and it is working as well, but there are few things I want to achieve to complete the module.
I have gone through so many blogs/sites to see how can I customise this but couldn't find any solution. Pasted below is my code. Any help would be much appreciated.
@Composable
fun OpenDeviceCamera(
viewModel: PhotoViewModel,
navController: DestinationsNavigator,
analytics: AnalyticsManager?
) {
val context = LocalContext.current
label.let { label ->
if (viewModel.showDeviceCam.value) {
val file = getPhotoFile(context)
val uri = FileProvider.getUriForFile(
context,
BuildConfig.APPLICATION_ID + ".provider", file
);
var capturedImageUri by remember {
mutableStateOf<Uri>(Uri.EMPTY)
}
val cameraLauncher =
rememberLauncherForActivityResult(ActivityResultContracts.TakePicture()) { isSuccess ->
if (isSuccess) {
capturedImageUri = uri
showPreviewOfImage(navController, analytics, uri.toString(), viewModel)
}
}
SideEffect {
cameraLauncher.launch(uri)
}
}
}
}
Neither of the things that you are seeking are part of the TakePicture
(ACTION_IMAGE_CAPTURE
) protocol. There are hundreds upon hundreds of camera apps that could be launched, and none have to even offer undocumented support for what you want.
TakePicture
/ ACTION_IMAGE_CAPTURE
are only suitable for cases where you need zero control over the picture-taking process, including whether or not it actually works (camera apps are buggy).
If you need your desired level of control, use CameraX or another camera library and implement the functionality in your own app.