Button - SDK/Intent API
The Button SDK/Intent API enables you to receive events beyond simple barcode retrieval.
This feature allows you to receive an event in your application when the button is pressed twice in quick succession, like a double-click on a computer mouse, within the period of 250ms (milliseconds) followed by period of 300ms without a button press.
To learn more, see Receive Button events and Button-blocking.
To integrate the *Button** feature via Intent or SDK API, test the API with an existing app, or build out the feature’s functionalities yourself, check out the Sample app’s code in our GitHub repository.
Receive Button events
The Insight Mobile app sends a Button event when the button is pressed twice in quick succession (like a double-click on a computer mouse).
To receive this event, register a callback object via SDK or listen for broadcast Intents of the following structure:
Action:
com.proglove.api.DISPLAY_BUTTON
Extras:
String in
com.proglove.api.extra.DISPLAY_BUTTON
contains the ID of the pressed button
override fun onCreate(savedInstanceState: Bundle?) { //... pgManager.subscribeToButtonPresses(this) //... } override fun onDestroy() { super.onDestroy() pgManager.unsubscribeFromButtonPresses(this) } // To do this, our Activity needs to implement the `IButtonOutput` interface: // // -- IButtonOutput -- // override fun onButtonPressed(buttonPressed: ButtonPress) { // the button presses will come on background threads, make sure to execute this on the UI Thread runOnUiThread { Toast.makeText(this, "Got a button Press: ${buttonPressed.id}", 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.DISPLAY_BUTTON") { intent.getStringExtra("com.proglove.api.extra.DISPLAY_BUTTON") } } } // 2 define an IntentFilter filtering for the specified actions: val messageHandler: MessageHandler = MessageHandler() val filter = IntentFilter() filter.addAction("com.proglove.api.DISPLAY_BUTTON") 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)
How to receive Button events for Ivanti’s Velocity browser
You can configure the button trigger to send a barcode Intent to the integrated Ivanti’s Velocity browser on double-click in order to send notifications to the worker’s MARK Display scanner.
To enable this event:
On Insight Webportal , under Device Visibility, select Configurations.
The list of existing configurations displays.
At the bottom of the page, select Create New Configuration.
Note
You can also click the pencil icon next to an existing configuration to modify it.
Select Insight Mobile (Android) and click Next.
Under Workflow Rules, click Add Rule.
Under Trigger, select Double-click.
Under Action, select Send Intent.
Click Save Action.
Click Save Rule.
Scan the configuration barcode to apply the configuration or download it to your Android device.
Receiving this event can be done by listening for broadcast Intents of the following structure:
Action:
com.wavelink.intent.action.BARCODE
Extras:
com.proglove.api.extra.BARCODE_DATA
=“BUTTON_PRESSED”com.proglove.api.extra.BARCODE_SYMBOLOGY
=“SPECIAL_BUTTON”String in
com.proglove.api.extra.DISPLAY_BUTTON
contains the ID of the pressed button
Make sure you filter the incoming Intents by this data to distinguish it from normal scans.
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.
Turn on button-blocking
To block the button, call blockPgTrigger()
on your PgManager
reference with the following parameters:
PgCommand
object holding theBlockPgTriggersParams(PredefinedPgTrigger.DefaultPgTrigger)
and optionalPgCommandParams
The object implementing
IBlockPgTriggersCallback
. After the button is successfully blocked (or in case of any errors), theIBlockPgTriggersCallback
is called with the relevant information.
You can also broadcast an Intent with the following data:
Action:
com.proglove.api.BLOCK_TRIGGER
No Extras
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)
Turn off button-blocking
The button can be unblocked by calling blockTrigger()
on PgManager
reference with the following parameters:
PgCommand
object holding theBlockPgTriggersParams(null)
and optionalPgCommandParams
The object implementing
IBlockPgTriggersCallback
. After the button is successfully unblocked (or in case of any errors), theIBlockPgTriggersCallback
is called with the relevant information.
You can also broadcast an Intent with the following data:
Action:
com.proglove.api.UNBLOCK_TRIGGER
No Extras
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.