I am working on a barcode scanner using DataWedge API's for TC26 device. I can see sometimes the value in EditTextBox the value is shown twice randomly. For example : value 123 is scanned but in EdittextBox it shows 123123. I've tried clearing EditTextBox and set the value again but still no luck.
Code for receiving the output from laser scan.
open fun initPackageScan(
context: Context?,
listener: PackageScanListener
){
this.packageScanListener = listener
}
inner class ScanBroadcastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val action = intent.action
if (action == BuildConfig.APPLICATION_ID) {
// Received a barcode scan
try {
var scanData = intent.getStringExtra(DWInterface.DATAWEDGE_SCAN_EXTRA_DATA_STRING)
var symbology = intent.getStringExtra(DWInterface.DATAWEDGE_SCAN_EXTRA_LABEL_TYPE)
Timber.i("Scanned item $scanData and it's type $symbology")
if(!scanData.isNullOrEmpty() || !symbology.isNullOrEmpty()) {
var labelType = symbology?.substringAfterLast("-")
packageScanListener.onPackageScanned(scanData, labelType)
}
}
catch (e: Exception) {
Timber.e(e)
e.printStackTrace()
}
}
}
In onReceive of my BroadcastReceiver() I always get the correct output like if the value scanned is 123 then 123 is returned in onReceive. Below is the code where in the callback method I am setting the scanned value in editText:
override fun onPackageScanned(packageId: String, barcodeType: String) {
Timber.i ("Scanned value :: %s", scanEditText.text.toString())
scanEditText.text.clear() // trying to clear before setting the value
scanEditText.setText(packageId) // the value to be set on editText
}
I've tried on following devices TC25( works great), TC57,TC56 and TC26 shows same value sometimes randomly.
Any help would be great.
Thank you
I would try to put a delay time to the function from one scan to other. Could be that the laserscan scan too much quickly.
You could make a function that read the text box input and if is already set the function will not make another scan.