Skip to content

Instantly share code, notes, and snippets.

@MyricSeptember
Created March 19, 2024 16:03
Show Gist options
  • Save MyricSeptember/49a8f834c860864dc3bd6e44d15b9b29 to your computer and use it in GitHub Desktop.
Save MyricSeptember/49a8f834c860864dc3bd6e44d15b9b29 to your computer and use it in GitHub Desktop.
testing
scannerLauncher =
rememberLauncherForActivityResult(contract = ActivityResultContracts.StartIntentSenderForResult(),
onResult = { activityResult ->
val resultCode = activityResult.resultCode
val result = GmsDocumentScanningResult.fromActivityResultIntent(
activityResult.data
)
when (resultCode) {
RESULT_OK -> {
//get images
pages = result?.pages?.map { it.imageUri } ?: emptyList()
//getPDF
result?.pdf?.let { pdf ->
val fileOutputStream = FileOutputStream(
File(
filesDir,
"$documentName.pdf"
)
)
contentResolver.openInputStream(pdf.uri).use {
it?.copyTo(fileOutputStream)
}
}
}
RESULT_CANCELED -> {
showToast("Scanner Cancelled")
}
else -> {
showToast("Something went wrong")
}
}
})
DocumentScannerScreen(pages)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment