Skip to content

Button-blocking

The button-blocking feature allows you to block the scan-triggering on scanners. This makes it impossible to scan any barcodes 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.

When the button is blocked, the device is unable to scan. Also, receiving button events and taking photos with scanner are temporarily disabled.

How to turn on button-blocking

To block the button, call blockPgTrigger() on your PgManager reference with the following parameters:

  • PgCommand object holding the BlockPgTriggersParams(PredefinedPgTrigger.DefaultPgTrigger) and optional PgCommandParams
  • The object implementing IBlockPgTriggersCallback. After the button is successfully blocked (or in case of any errors), the IBlockPgTriggersCallback is called with the relevant information.

You can also broadcast an Intent with the following data:

  • Action: com.proglove.api.BLOCK_TRIGGER
  • No Extras

Example code:

pgManager.blockPgTrigger(
    PgCommand(BlockPgTriggersParams(PredefinedPgTrigger.DefaultPgTrigger)),
    object : IBlockPgTriggersCallback {
        override fun onBlockTriggersCommandSuccess() {
            runOnUiThread {
                Toast.makeText(
                    applicationContext,
                    "Blocking trigger success",
                    Toast.LENGTH_LONG
                ).show()
            }
        }

        override fun onError(error: PgError) {
            runOnUiThread {
                Toast.makeText(
                    applicationContext,
                    "Failed to block the trigger: $error",
                    Toast.LENGTH_LONG
                ).show()
            }
        }
    }
)
val intent = Intent()
intent.setAction("com.proglove.api.BLOCK_TRIGGER")
sendBroadcast(intent)

How to turn off button-blocking

The button can be unblocked by calling blockTrigger() on PgManager reference with the following parameters:

  • PgCommand object holding the BlockPgTriggersParams(null) and optional PgCommandParams
  • The object implementing IBlockPgTriggersCallback. After the button is successfully unblocked (or in case of any errors), the IBlockPgTriggersCallback is called with the relevant information.

You can also broadcast an Intent with the following data:

  • Action: com.proglove.api.UNBLOCK_TRIGGER
  • No Extras

Example code:

pgManager.blockPgTrigger(
    PgCommand(BlockPgTriggersParams(null)),
    object : IBlockPgTriggersCallback {
        override fun onBlockTriggersCommandSuccess() {
            runOnUiThread {
                Toast.makeText(
                    applicationContext,
                    "Unblocking trigger success",
                    Toast.LENGTH_LONG
                ).show()
            }
        }

        override fun onError(error: PgError) {
            runOnUiThread {
                Toast.makeText(
                    applicationContext,
                    "Failed to unblock the trigger: $error",
                    Toast.LENGTH_LONG
                ).show()
            }
        }
    }
)
val intent = Intent()
intent.setAction("com.proglove.api.UNBLOCK_TRIGGER")
sendBroadcast(intent)

Another way to unblock the button is by pressing the button twice in quick succession. In that case, Insight Mobile sends out a button unblocked event to all subscribed SDK callbacks and broadcasts an Intent of the following structure:

  • Action: com.proglove.api.TRIGGER_UNBLOCKED
  • No 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, "Trigger 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") {
            // Trigger 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.