Closed MujahidHi5 closed 2 years ago
Hello there I think I got something, you need to swith to registerForActivityResult (https://developer.android.com/training/basics/intents/result)
Declare launcher with the result callback :
private val zxingActivityResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
val intentResult = IntentIntegrator.parseActivityResult(it.resultCode, it.data)
if(intentResult.contents != null) {
Toast.makeText(this, intentResult.contents, Toast.LENGTH_LONG).show()
}
}
And when you need to start the scanner :
zxingActivityResultLauncher.launch(intentIntegrator.createScanIntent())
Don't use the initiateScan
method which call the old startActivityForResult
This seems to work from my activity, I've not test from a fragment yet. Hope this help you.
Thanks! It is working fine!
This should be a part of the documentation :)
OnActivityResult method is deprecated, what is the alternative for getting result here?