Display device state
You can keep track of the connection state changes of your Display device by monitoring display and scanner connection events at the same time for MARK Display.
To get the Display and scanner connection events via SDK, call the pgManager.subscribeToDisplayEvents()
function and implement the IDisplayOutput
interface.
For example, in the same onCreate
of our sample app, we subscribe to the display info. And we unsubscribe in the onDestroy
function.
For Intent, broadcast the connection state similar to the scanner connection state:
Action:
com.proglove.api.DISPLAY_STATE
Extra: String in
com.proglove.api.extra.DISPLAY_STATE
Example code to get scanner state events (in Kotlin):
override fun onCreate(savedInstanceState: Bundle?) { //... pgManager.subscribeToDisplayEvents(this) //... } override fun onDestroy() { super.onDestroy() pgManager.unsubscribeFromDisplayEvents(this) //... } // To do this, our Activity needs to implement the `IDisplayOutput` interface: // // -- IDisplayOutput -- // override fun onDisplayConnected() { // let the user know that the display device is connected } override fun onDisplayDisconnected() { // Inform the user that the display has been disconnected }
// 1. Implement a broadcast receiver: val broadcastReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { if (intent != null && intent.action == "com.proglove.api.DISPLAY_STATE") { val displayState = intent.getStringExtra("com.proglove.api.extra.DISPLAY_STATE") if (displayState != null) { // use displayState when (displayState) { "CONNECTED" -> { Toast.makeText(context, "Display connected!", Toast.LENGTH_LONG).show() } "DISCONNECTED" -> { Toast.makeText(context, "Display disconnected!", Toast.LENGTH_LONG).show() } else -> { // remaining display states } } } } } } // 2. Define an `IntentFilter` for the desired actions: val filter = IntentFilter() filter.addAction("com.proglove.api.DISPLAY_STATE") filter.addCategory(Intent.CATEGORY_DEFAULT) // 3. Finally, register the broadcast receiver instance. The usual place for this call would be in the `onCreate` method of a `Service` or an `Activity` class: registerReceiver(broadcastReceiver, filter) // 4. Do not forget to unregister the receiver, for example in `onDestroy`: unregisterReceiver(broadcastReceiver)
For Intent: The passed status string (displayState
variable in our case) can be one of the following:
CONNECTED: The display is connected and you can start to set the screens and receive button press events.
DISCONNECTED: No display is connected.
CONNECTING: In the process of establishing a display BLE Connection.
ERROR: Something went wrong trying to establish the display connection or the BLE search in general. Consult the Insight Mobile app.
RECONNECTING: Lost connection to a previously connected display trying to re-establish the connection.
SEARCHING: Searching for a display.