Memor K: unable to enter text in AlertDialog, when it has been open from barcode read event

I start an Android Studio Flamingo | 2022.2.1.
I create a new Empty Views Activity project with the default settings.
In settings.gradle, in /dependencyResolutionManagement/repositories section, I add:

maven { url "https://jitpack.io" }

In build.gradle (Module:app), in /dependencies section, I add:

implementation 'com.github.datalogic:datalogic-android-sdk:v1.31'

I click Sync Now in the Gradle notification.
In MainActivity, I add the following code to the import block:

import android.text.InputType
import android.view.KeyEvent
import android.widget.EditText
import androidx.appcompat.app.AlertDialog
import com.datalogic.decode.BarcodeManager
import com.datalogic.decode.ReadListener

And the following code to the MainActivity class:

private fun askQuantity(product: String) {
	stopScanner()

	val input = EditText(this)
	input.inputType = InputType.TYPE_CLASS_TEXT

	val builder = AlertDialog.Builder(this)
	builder.setTitle("Product: $product, please enter quantity:")
	builder.setCancelable(false)
	builder.setView(input)
	builder.setPositiveButton("OK") { _, _ -> startScanner() }
	builder.show()
}

override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
	if (keyCode == KeyEvent.KEYCODE_1) {
		askQuantity("1234567890")
		return true
	}

	return super.onKeyUp(keyCode, event)
}

private val barcodeManager = BarcodeManager()

private var readListener = ReadListener { result ->
	askQuantity(result.text)
}

private fun startScanner() {
	barcodeManager.addReadListener(readListener)
}

private fun stopScanner() {
	barcodeManager.removeReadListener(readListener)
}

override fun onResume() {
	super.onResume()
	startScanner()
}

override fun onPause() {
	stopScanner()
	super.onPause()
}

I perform a factory reset on the Datalogic Memor K scanner.
I build an APK, deploy the resulting app-debug.apk file to the device, install and run it.

I press the [1] hardware key on the scanner, a dialog window opens, where I can enter the quantity. I close the dialog by tapping the [OK] button in it.

Problem, which appers almost any time I do this:

I scan any barcode and the same dialog opens, but I cannot enter anything. Also tapping in the input field does not bring up the on-screen keyboard.

What helps:

With the dialog open, I press the square sensor key under the screen (Recent applications) and choose my application from the application list. Now I can enter the quantity.

Hello @Andrew_Usachov,

By default, the keyboard wedge is enabled on all our devices.
Also by default, they keyboard wedge sends and enter press after pasting the barcode data.
I believe this behavior you are experiencing is caused by the enter press being pressed in your AlertDialog.
This can be adjusted in DL settings, with Scan2Deploy, OEMConfig, and via our SDK.
Disable the keyboard wedge and see if this resolves your issue.

Drew Hugentobler
L3 Mobile Computer Support Specialist Engineer

Turning off Keyboard wedge does not help.
Have you tried your solution yourself?

P. S. Also I believe, that Keyboard wedge is not in effect at all, when the scanner is controlled directly via API.

Hello Andrew,

You described switching away and back to your app, and this put focus back in the AlertDialog.
This leads me to believe that focus is being lost for whatever reason.
Earlier I described it as the keyboard wedge pressing the enter button, but that is not exactly how it works.
Even though the keyboard wedge is disabled, barcode formatting still applies.
By default, standard formatting adds a Line Feed to the end of the barcode data.
This can be adjusted under DL Settings → Scanner & decoder → Formatting → Standard formatting → Label suffix.
I have not tested this, but I am hopeful removing the Line Feed will resolve your issue.
If removing the Line Feed from the Barcode Suffix does not resolve your issue I can build your example on my side and see if I can pinpoint the problem.

Drew Hugentobler
L3 Mobile Computer Specialist Support Engineer

Hello there,

Actually, in Memor K, it’s in Datalogic SettingsScanner SettingsFormattingLabel Suffix. I cleared it, now it displays as None.

But it did not fix the issue.

Most often the issue occurs, when I point the scanner away from the barcode, press the [Scan] button, and while holding it, point the beam at the barcode.

Hello Andrew,

I ran your code on my end and was able to reproduce the behavior you described.
But, when I disabled the keyboard wedge and removed the barcode suffix, it corrected the issue.
Here is a video showing the Memor K behaving as expected, after changing the settings.

Drew Hugentobler
L3 Mobile Computer Specialist Support Engineer

@Drew_Hugentobler,

Please try the following:

It is not always possible to scan a barcode the first time. Then the error appears:

Hello @Andrew_Usachov,

I am looking into this.

Drew Hugentobler
L3 Mobile Computer Specialist Support Engineer

Hello @Andrew_Usachov,

I would recommend creating a support ticket and a member of our support team will assist you in troubleshooting (report this conversation).
You can create a support ticket here:

Drew Hugentobler
L3 Mobile Computer Specialist Support Engineer

After reviewing the code, the problem is probably due to the old implementation of AlertDialog in Android 9, which conflicts with the handling of some system events, causing the application to temporarily lose focus when opening the AlertDialog.

You can work around this by assigning the focus to the alert dialog via code, for example by changing your code like this:

private fun askQuantity(product: String) {
	stopScanner()

	val input = EditText(this)
	input.inputType = InputType.TYPE_CLASS_TEXT

	val builder = AlertDialog.Builder(this)
	builder.setTitle("Product: $product, please enter quantity:")
	builder.setCancelable(false)
	builder.setView(input)
	builder.setPositiveButton("OK") { _, _ -> startScanner() }

	val dialog = builder.create()
	dialog.setOnShowListener {
				dialog.window?.setLocalFocus(true, true)
	}

	dialog.show()
}

Simone Callegari
Datalogic Mobile Products - L3 Specialist SW Engineer