Closed needhelp17 closed 2 years ago
I think this can help you: https://stackoverflow.com/questions/68520524/how-to-return-a-result-in-activityresultlauncher
after i saw the hint by @monteirohat , i create custom ActivityResultContract for handle intent result.
class QrCodeScannerContract: ActivityResultContract<IntentIntegrator, IntentResult>() {
override fun createIntent(context: Context, input: IntentIntegrator): Intent {
return input.apply {
setDesiredBarcodeFormats(IntentIntegrator.QR_CODE)
setPrompt("Point the Scanner at the QR Code")
setBeepEnabled(false)
setBarcodeImageEnabled(true)
setOrientationLocked(true)
}.createScanIntent()
}
override fun parseResult(resultCode: Int, intent: Intent?): IntentResult {
return IntentIntegrator.parseActivityResult(resultCode, intent)
}
}
and the launcher :
private val qrCodeScannerLauncher = registerForActivityResult(QrCodeScannerContract()){
if (!it.contents.isNullOrEmpty()){
Log.d("RESULT_INTENT", it.contents)
}else{
Log.d("RESULT_INTENT", "CANCELED")
}
}
and then you can call launcher like this:
qrCodeScannerLauncher.launch(IntentIntegrator.forSupportFragment(this))
I hope this can help you
Merging into #628.
since onActivityResult is deprecate we should use registerForActivityResult but I can find a way to start you scan and handle the result in the ActivityResultCallback
have you an idea to how I can implement this ?