Created
March 19, 2024 13:33
-
-
Save MyricSeptember/a510c7105a5bc3aae495b92809090838 to your computer and use it in GitHub Desktop.
Launch Activity For Result
This file contains hidden or 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 | |
) | |
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") | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment