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.