SDK API - Basic Integration

In the Integration Path menu item or wizard, please select the option SDK as an Integration Path and press DONE.

SCREENSHOT OF WIZARD

PLEASE NOTE: The ProGlove Connect SDK requires a minimum Android API Level of 18. Please make sure your app uses at least this level.

Add library

To download the AAR, add this to your gradle repository (top level) (code in groovy)

allprojects {
  repositories {
      maven {
          url "https://dl.cloudsmith.io/basic/proglove/ProGlove Connect-prod/maven/"
          credentials {
              username "$proglove_user"
              password "$proglove_password"
          }
      }
   }
}

and then add this to your apps build.gradle in the dependencies block :

implementation 'de.proglove:connect-sdk:1.1.0'

Finally, use the username and password provided by ProGlove in your gradle.properties:

proglove_user=USERNAME
proglove_password=PASSWORD

Your project should now build/assemble without problems.

Note: Please be aware that in some cases, Android Studio requires a restart to register changes in the gradle.properties correctly.

Integration

To integrate the MARK scanner, you need somewhere to hold a reference to it. If you need access to the scanner in multiple places in your application, the SDK can be instantiated in the Application Android Object. However, any other Context object will work as well (Activity or Service). In the onCreate, instantiate the Scanner Manager and connect it to the ProGlove Connect App.

Please note: The example below is taken from the example app, where everything is implemented in a single activity (code in Kotlin). You can (and should) obviously adapt this to your needs.

val pgManager: PgManager = PgManager()

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate()
    val result = pgManager.ensureConnectionToService(this.applicationContext)
}

Check the return value (a boolean) to see if the service binding worked. If the correct version of ProGlove Connect App is installed on your device, you will get a positive response.

From this point on, access the pgManager variable to use the SDK.

(Optional) Callback For Service Connection

The connection to the SDK Service is very fast and you will most likely not encounter problems by proceeding with the pairing process right away. But it is still asynchronous. So you might want to register for callbacks of the Service connection. Before calling pgManager.connect(...) register your implementation of the IServiceOutput interface (In this case this). Also make sure to unsubscribe from these events. onCreate and onDestroy are great for that.

override fun onCreate(savedInstanceState: Bundle?) {

    //...
    pgManager.subscribeToServiceEvents(this)
}
   /*
    */
override fun onDestroy() {
    super.onDestroy()

    pgManager.unsubscribeFromServiceEvents(this)
}

Callback For Scanned Barcodes

Mainly, you will want to be informed about new barcode scans. To get this, call the pgManager.subscribeToScans() function and implement the IScannerOutput interface. For example, in the same onCreate of our sample app we subscribe to the scanner info. And we unsubscribe in the onDestroy function.

override fun onCreate(savedInstanceState: Bundle?) {

     //...

     pgManager.subscribeToScans(this)

     //...
}

override fun onDestroy() {
     super.onDestroy()
     pgManager.unsubscribeFromScans(this)
}

To do this, our Activity needs to implement the IScannerOutput interface:

//
// -- IScannerInput --
//

override fun onBarcodeScanned(barcodeScanResults: BarcodeScanResults) {
      // the scanner input will come on background threads, make sure to execute this on the UI Thread
    runOnUiThread {
        if(barcodeScanResults.symbology.isNotEmpty()) {
            Toast.makeText(this, "Got barcode: ${barcodeScanResults.barcodeContent} with symbology: ${barcodeScanResults.symbology}", Toast.LENGTH_LONG).show()
            // do some custom logic here to react on received barcodes and symbology
        } else {
            Toast.makeText(this, "Got barcode: ${barcodeScanResults.barcodeContent}", Toast.LENGTH_LONG).show()
            // not every Mark currently has the ability to send the barcode symbology
        }
    }
}

override fun onScannerConnected() {
        // let the user know that the scanner is connected
}

override fun onScannerDisconnected() {
     // Inform the user that the scanner has been disconnected
}

MARK Scanner State

The IScannerOutput callback and PgManager provide you with several methods for tracking the MARK state.

As you can see above, the IScannerInput Interface will be called whenever a MARK Scanner connects or disconnects.

You can also query the PgManager methods.

To disconnect, call the PgManager.disconnect() method.

Pair with MARK

To start the pairing process call startPairing() on your PgManager reference. The ProGlove Connect App will take over and show the paring QR-Code. After your device was paired with a MARK or the process was canceled by the user, your activity will be brought back to the foreground. Your registered IScannerOutput implementations will be called according to the updated scanner state.

Important Note for Android's pinned application mode: If your app runs inside Android's pinned Application mode you have to use startPairingFromPinnedActivity(activity) instead. activity must be an Activity running in the currently pinned Task. Pairing will work the same as with startPairing() but will be working in pinning Mode. pgManager.connect(this.applicationContext) should still be called with the ApplicationContext. That way a MARK will stay connected regardless of Lifecycle of a single Activity.

Starting the pairing from Background Task: Only startPairing() is able to work from a Service's Context.

Logging

To facilitate with debugging, the PgManager can be injected with a java.util.Logger object that will receive all log information.

    private val pgManager = PgManager(logger)

Example Apps

The Example App is a (very simple) implementation using the SDK to display the last scanned value in a text field. You can use this application to see how to implement the MARK Scanner API.

Symbologies

See Symbologies for the list of supported Symbologies.