Button-blocking
The button-blocking feature allows you to block or unblock certain button gestures on a scanner connected to Insight Mobile. This makes it impossible to scan any barcodes, receive certain button events, or take photos with the scanner until the block is resolved.
Use it in situations where the worker needs to perform an action outside of the regular workflow, like an acknowledgement of an error.
Depending on the blocking command, the button can be enabled again either by a predefined action of the worker or by sending the unblocking command.
Turn on button-blocking
To block the button, call blockPgTrigger() on your PgManager reference with the following parameters:
PgCommandobject holding theBlockPgTriggersParamsand an optionalPgCommandParams, whereBlockPgTriggersParamsconsists of:blockByTriggers- List ofPredefinedPgTriggerbutton gestures to block. If empty and[block]is true, all known button gestures will be blockedunblockByTriggers- List ofPredefinedPgTriggerbutton gestures that unblock the blocked buttonsdurationMs- The duration that the button should be blocked, in milliseconds. A value of 0 will block the button indefinitelyNote
If you are using scanners with firmware version lower than v2.5.0
durationMsvalue will be ignored.block- True
The object implementing
IBlockPgTriggersCallback. After the button is successfully blocked (or in case of any errors), theIBlockPgTriggersCallbackis called with the relevant information.
You can also broadcast an Intent with the following data:
Action:
com.proglove.api.BLOCK_TRIGGERExtras:
com.proglove.api.extra.TRIGGERS_BLOCK- Array of button gestures (identified by a string) to block. If empty, all known button gestures will be blocked. The allowed values:BUTTON_1_SINGLE_CLICKBUTTON_1_DOUBLE_CLICKBUTTON_1_TRIPLE_CLICK
Note
If you do not send this extra, the single-press will be blocked.
com.proglove.api.extra.TRIGGERS_UNBLOCK_BY- Array of button gestures (identified by a string) that unblock the blocked buttons. The allowed values:BUTTON_1_SINGLE_CLICKBUTTON_1_DOUBLE_CLICKBUTTON_1_TRIPLE_CLICK
Note
If you do not send this extra, the double-press unblocks the button.
com.proglove.api.extra.DURATION- The duration in milliseconds (integer) that the button should be blocked. A value of 0 will block the button indefinitelyNote
If you do not send this extra, the button will be blocked indefinitely.
If you are using scanners with firmware version lower than v2.5.0 this extra will be ignored.
val blockParams = BlockPgTriggersParams(
blockTriggers = listOf(PredefinedPgTrigger.DefaultPgTrigger),
unblockByTriggers = emptyList(),
durationMs = 10000,
block = true
)
pgManager.blockPgTrigger(
PgCommand(blockParams),
object : IBlockPgTriggersCallback {
override fun onBlockTriggersCommandSuccess() {
runOnUiThread {
Toast.makeText(
applicationContext,
"Blocking trigger(s) success",
Toast.LENGTH_LONG
).show()
lastResponseValue.text = getString(R.string.block_trigger_success)
}
}
override fun onError(error: PgError) {
runOnUiThread {
Toast.makeText(
applicationContext,
"Failed to block the trigger(s): $error",
Toast.LENGTH_LONG
).show()
lastResponseValue.text = error.toString()
}
}
})val intent = Intent().apply {
action = "com.proglove.api.BLOCK_TRIGGER"
putExtra("com.proglove.api.extra.TRIGGERS_BLOCK", arrayOf("BUTTON_1_SINGLE_CLICK"))
putExtra("com.proglove.api.extra.TRIGGERS_UNBLOCK_BY", emptyArray<String>())
putExtra("com.proglove.api.extra.DURATION", 10000)
}
sendBroadcast(intent)val blockParams = BlockPgTriggersParams(
blockTriggers = emptyList(),
unblockByTriggers = emptyList(),
durationMs = 0,
block = true
)
pgManager.blockPgTrigger(
PgCommand(blockParams),
object : IBlockPgTriggersCallback {
override fun onBlockTriggersCommandSuccess() {
runOnUiThread {
Toast.makeText(
applicationContext,
"Blocking trigger(s) success",
Toast.LENGTH_LONG
).show()
lastResponseValue.text = getString(R.string.block_trigger_success)
}
}
override fun onError(error: PgError) {
runOnUiThread {
Toast.makeText(
applicationContext,
"Failed to block the trigger(s): $error",
Toast.LENGTH_LONG
).show()
lastResponseValue.text = error.toString()
}
}
})val intent = Intent().apply {
action = "com.proglove.api.BLOCK_TRIGGER"
putExtra("com.proglove.api.extra.TRIGGERS_BLOCK", emptyArray<String>())
putExtra("com.proglove.api.extra.TRIGGERS_UNBLOCK_BY", emptyArray<String>())
putExtra("com.proglove.api.extra.DURATION", 0)
}
sendBroadcast(intent)val blockParams = BlockPgTriggersParams(
blockTriggers = listOf(PredefinedPgTrigger.DefaultPgTrigger),
unblockByTriggers = listOf(PredefinedPgTrigger.DoubleClickMainPgTrigger),
durationMs = 0,
block = true
)
pgManager.blockPgTrigger(
PgCommand(blockParams),
object : IBlockPgTriggersCallback {
override fun onBlockTriggersCommandSuccess() {
runOnUiThread {
Toast.makeText(
applicationContext,
"Blocking trigger(s) success",
Toast.LENGTH_LONG
).show()
lastResponseValue.text = getString(R.string.block_trigger_success)
}
}
override fun onError(error: PgError) {
runOnUiThread {
Toast.makeText(
applicationContext,
"Failed to block the trigger(s): $error",
Toast.LENGTH_LONG
).show()
lastResponseValue.text = error.toString()
}
}
})val intent = Intent().apply {
action = "com.proglove.api.BLOCK_TRIGGER"
putExtra("com.proglove.api.extra.TRIGGERS_BLOCK", arrayOf("BUTTON_1_SINGLE_CLICK"))
putExtra("com.proglove.api.extra.TRIGGERS_UNBLOCK_BY", arrayOf("BUTTON_1_DOUBLE_CLICK"))
putExtra("com.proglove.api.extra.DURATION", 0)
}
sendBroadcast(intent)Turn off button-blocking
To unblock the button, call blockTrigger() on PgManager reference with the following parameters:
PgCommandobject holding theBlockPgTriggersParamsand an optionalPgCommandParams, whereBlockPgTriggersParamsconsists of:blockByTriggers- Empty listunblockByTriggers- Empty listdurationMs- 0block- False
The object implementing
IBlockPgTriggersCallback. After the button is successfully unblocked (or in case of any errors), theIBlockPgTriggersCallbackis called with the relevant information.
You can also broadcast an Intent with the following data:
Action:
com.proglove.api.UNBLOCK_TRIGGERNo Extras
val blockParams = BlockPgTriggersParams(
blockTriggers = emptyList(),
unblockByTriggers = emptyList(),
durationMs = 0,
block = false
)
pgManager.blockPgTrigger(
PgCommand(blockParams),
object : IBlockPgTriggersCallback {
override fun onBlockTriggersCommandSuccess() {
runOnUiThread {
Toast.makeText(
applicationContext,
"Unblocking triggers success",
Toast.LENGTH_LONG
).show()
lastResponseValue.text = getString(R.string.block_trigger_success)
}
}
override fun onError(error: PgError) {
runOnUiThread {
Toast.makeText(
applicationContext,
"Failed to unblock the triggers: $error",
Toast.LENGTH_LONG
).show()
lastResponseValue.text = error.toString()
}
}
})val intent = Intent().apply {
action = "com.proglove.api.UNBLOCK_TRIGGER"
}
sendBroadcast(intent)Another way to unblock the button is to use the button gestures specified in the unblockByTriggers or com.proglove.api.extra.TRIGGERS_UNBLOCK_BY under Turn on button-blocking.
You can also wait for the blocking timeout specified in the durationMs or com.proglove.api.extra.DURATION under Turn on button-blocking to expire.
Action:
com.proglove.api.TRIGGER_UNBLOCKEDNo Extras
To get this, call the pgManager.subscribeToPgTriggersUnblocked() function and implement the ITriggersUnblockedOutput interface.
For example, in the same onCreate of our sample app we subscribe to the button unblocked info, and we unsubscribe in the onDestroy() function.
override fun onCreate(savedInstanceState: Bundle?) {
//...
pgManager.subscribeToPgTriggersUnblocked(this)
//...
}
override fun onDestroy() {
super.onDestroy()
//...
pgManager.unsubscribeFromPgTriggersUnblocked(this)
}
// To do this, our Activity needs to implement the `ITriggersUnblockedOutput` interface:
//
// -- ITriggersUnblockedOutput --
//
override fun onPgTriggersUnblocked() {
// the trigger unblocked events will come on background threads, make sure to execute this on the UI Thread
runOnUiThread {
Toast.makeText(this, "Triggers unblocked", Toast.LENGTH_SHORT).show()
}
}// 1 Implement a broadcast receiver (in this case the class is called MessageHandler):
class MessageHandler : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
if (intent != null && intent.action == "com.proglove.api.TRIGGER_UNBLOCKED") {
// Triggers unblocked
}
}
}
// 2 define an IntentFilter filtering for the specified actions:
val messageHandler: MessageHandler = MessageHandler()
val filter = IntentFilter()
filter.addAction("com.proglove.api.TRIGGER_UNBLOCKED")
filter.addCategory(Intent.CATEGORY_DEFAULT)
// 3 Somewhere where a context is available (usually an Activity's or Service's onCreate):
context.registerReceiver(messageHandler, filter)
// Do not forget to unregister the receiver again, for example in onDestroy:
context.unregisterReceiver(messageHandler)When the button is unblocked, scanning, receiving button events and taking photos with scanner are enabled again.