I have an Android App that is basically a webView to our asp.net web application. Now I have to implement a barcode scanner in the Android app to read and transfer the number from the barcode to the asp.net backend. I have this line in js in the web to call the Android function for the barcode scanner:
window.AndroidWebInterface.getIcc();
In Android I tried many different approaches to start the ScanActivity which uses ML Kit to read the barcode which is working fine, but I have problem returning the code I read with the camera to the js caller function from the backend. I can display it in the Android app but don't know how to return it to the backend. Some code from the android app
barcodeScanner.process(inputImage)
.addOnSuccessListener { barcodeList ->
val barcode = barcodeList.getOrNull(0)
// `rawValue` is the decoded value of the barcode
barcode?.rawValue?.let { value ->
// update our textView to show the decoded value
binding.bottomText.text = barcode.displayValue
val data = Intent()
data.putExtra("icc", barcode.displayValue)
setResult(Activity.RESULT_OK, data)
finish()
}
}
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) {
icc = result.data?.getStringExtra("icc")
}
}
startForResult.launch(Intent(this, ScanActivity::class.java))