This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scannerLauncher = | |
rememberLauncherForActivityResult(contract = ActivityResultContracts.StartIntentSenderForResult(), | |
onResult = { activityResult -> | |
val resultCode = activityResult.resultCode | |
val result = GmsDocumentScanningResult.fromActivityResultIntent( | |
activityResult.data | |
) | |
when (resultCode) { | |
RESULT_OK -> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return GmsDocumentScannerOptions.Builder() | |
.setScannerMode(GmsDocumentScannerOptions.SCANNER_MODE_FULL) | |
.setGalleryImportAllowed(true) | |
.setPageLimit(numberOfPages.toInt()) | |
.setResultFormats( | |
GmsDocumentScannerOptions.RESULT_FORMAT_JPEG, | |
GmsDocumentScannerOptions.RESULT_FORMAT_PDF | |
).build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var pages by remember { | |
mutableStateOf<List<Uri>>(emptyList()) | |
} | |
scannerLauncher = | |
rememberLauncherForActivityResult(contract = ActivityResultContracts.StartIntentSenderForResult(), | |
onResult = { activityResult -> | |
val resultCode = activityResult.resultCode | |
val result = GmsDocumentScanningResult.fromActivityResultIntent( | |
activityResult.data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
result?.pdf?.let { pdf -> | |
val fileOutputStream = FileOutputStream( | |
File( | |
filesDir, | |
"$documentName.pdf" | |
) | |
) | |
contentResolver.openInputStream(pdf.uri).use { | |
it?.copyTo(fileOutputStream) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val options = configureDucumentScannerOptions() | |
val scanner = GmsDocumentScanning.getClient(options) | |
scanner.getStartScanIntent(this@MainActivity).addOnSuccessListener { | |
scannerLauncher.launch( | |
IntentSenderRequest.Builder(it).build() | |
) | |
}.addOnFailureListener { | |
it.message?.let { errorMessage -> showToast(errorMessage) } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scanner.getStartScanIntent(this@MainActivity).addOnSuccessListener { | |
scannerLauncher.launch( | |
IntentSenderRequest.Builder(it).build() | |
) | |
}.addOnFailureListener { | |
it.message?.let { errorMessage -> showToast(errorMessage) } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setContent { | |
CountriesApp { | |
Navigation() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TopAppBar(backgroundColor = Color.Transparent, elevation = 0.dp) { | |
Row( | |
horizontalArrangement = Arrangement.Start, | |
modifier = Modifier.padding(start = 8.dp) | |
) { | |
Icon( | |
imageVector = Icons.Default.ArrowBack, | |
contentDescription = "Arrow Back", | |
modifier = Modifier.clickable { | |
navController.popBackStack() |
NewerOlder