Information required for SDK integration
Dependencies
class SDKHandler private constructor() {
Pre-Required
- See first section Implementation and SDKHandler
Access X-Scan concurency
In competitive applications, it's important to release the connection when the application isn't in the foreground or destroyed, so in the following I'll explain the Android functions and what you need to do. Create variable launchApp to avoid close connect twice at launch (at creation passed in OnCreated and OnResume functions)
Note : comments in the code explain configuration options in more detail
In your MainActivity :
-
onCreate()
This method is called when app startoverride fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate() launchApp = true
} -
sendIntentXTrack(message:String)
This method is created to send message to X-Track to disconnect or could connect to the scannerprivate fun sendIntentXTrack(message:String) {
- val i = Intent("com.crosscall.xtrack.action.MULTIAPPS") i.setPackage("com.crosscall.xtrack") i.putExtra("com.crosscall.xtrack.service", message) sendBroadcast(i)
} -
onResume()
This method is called when app it is at first planoverride fun onResume() {
- super.onResume() //Make delay between close and connect between 2 apps Thread.sleep(250) // Disconnection if X-Track is present (release connexion to take it) // with two apps without X-Track doesn't implement it sendIntentXTrack("disconnection") //Make delay between disconnection and connect Thread.sleep(250) sdkHandler = SDKHandler.getInstance(baseContext, this, true, true, true, false) sdkHandler.connect() if(launchApp){
}// /!\ Only if you use X-TRACK and multi-apps, adopt a unique configuration between your apps and X-TRACK because config between X-TRACK and apps will be in concurrency. It's no user friendly to push all configuration at any change between App and X-TRACK (all configuration made 3 seconds to push) //sdkHandler.setConfig() // Comment this line if you use X-TRACK and apps, by default X-TRACK has works configuration (All barcodes format activated, no prefix/suffix). If you want different configuration change configuration with X-TRACK launchApp = false} - super.onResume() //Make delay between close and connect between 2 apps Thread.sleep(250) // Disconnection if X-Track is present (release connexion to take it) // with two apps without X-Track doesn't implement it sendIntentXTrack("disconnection") //Make delay between disconnection and connect Thread.sleep(250) sdkHandler = SDKHandler.getInstance(baseContext, this, true, true, true, false) sdkHandler.connect() if(launchApp){
-
onPause()
This method is called when app passed to the backgroundoverride fun onPause() {
- super.onPause() //Send message to X-Track to say that it could take the connection, with two apps without X-Track doesn't implement it sendIntentXTrack("can_connect") //Disconnection of X-Scan before application goes to background to release connection sdkHandler.close()
} -
onDestroy()
Role: This method is called when app closedoverride fun onDestroy() {
- super.onDestroy() //Send message to X-Track to say that it could take the connection, with two apps without X-Track doesn't implement it sendIntentXTrack("can_connect") //Disconnection of X-Scan before application closed to release connection sdkHandler.close()
}
Step 1
The first step is initialize the xScanManager to appaired the device with the scanner
You could configure the different param alert with this method:
- Connect beep to play beep when the scanner is connected
- Scan beep to play beep when the scanner scanned
- Disconnect beep to play beep when the scanner is disconnected
- Vibration to vibrate when action is performed
- Show toast for use visual alert when action is performed
- Auto Connect If you activate autoconnect option the application automatically goes to connect the scanner with your app.
Auto-connect option (Multi-apps)
/!\ If you use only one App that handling X-Scan without X-Track you must put Auto Connect to true If you use one or more one App with X-Track you must put auto-connect to false to avoid concurency access to X-Scan /!\
All theses alerts are by default activated except autoConnect
You need to copy and paste the SDKHandler class into the SDKHandler section. I created this singleton class to ensure that you only have one instance to manage X-Scan. All you need to do is create a single sdkHandler variable in your MainActivity like this:
sdkHandler = SDKHandler.getInstance(baseContext, this, true, true, true, false)
Step 2
The second step is to configure your configuration in the singleton SDKHandler class in the setConfig() method to best adapt the product to the customer's needs.
There are 3 ways of doing this:
There are two types of configuration: barcode formats and scan modes to be activated .
To do this, simply add your barcode formats or scan options to separate lists and then call up the two different XScanManager methods to take them into account, respectively .setBarcodeFormatEnable(formats) and .setScannerOptionEnable(scannerOptions)
It's important to note that only activation is called for scan or barcode options. This is why there are specific commands that can be called with the latter method .setMultiCommands(commands).
// Clear parameter list formats.clear() commands.clear() scannerOptions.clear() // Add the barcode formats you wish to enable or disable formats.add(BarcodeFormatAIM128(IBarcodeFormat.Activation.Enable)) formats.add(BarcodeFormatAztec(IBarcodeFormat.Activation.Enable)) formats.add(BarcodeFormatCodabar(IBarcodeFormat.Activation.Enable)) formats.add(BarcodeFormatCode11(IBarcodeFormat.Activation.Enable)) // Enable barcode formats xScanManager.setBarcodeFormatEnable(formats) // Add the following scanner options that you wish to enable or disable scannerOptions.add(BarReadMessageOption(IScannerOption.Activation.Off)) scannerOptions.add(ExternalIluminationOption(IScannerOption.Illumination.AlwaysOn)) scannerOptions.add(InternalIluminationOption(IScannerOption.Illumination.Off)) scannerOptions.add(DecodeAreaOption(IScannerOption.DecodeArea.WholeArea)) scannerOptions.add(SurroundGS1AIParentheseOption(IScannerOption.Activation.Off)) // Enable scanner options xScanManager.setScannerOptionEnable(scannerOptions) // Add the specific command you wish to configure val suffix = SuffixModeOption(IScannerOption.Activation.On) scannerOptions.add(suffix) commands.add(suffix.getCommandSuffix("suffix")) // Configuring specific commands xScanManager.setMultiCommands(commands)
Step 3
Once the scan configured you could easily call the scan sdkHandler method with the following snippet code:
sdkHandler.startScan()
Import configuration with QR Code
It's possible to generate the QrCode and import it with ImageView with Bitmap with the following snippet code:
val configCSV = sdkHandler.generateCSV(formats,scannerOptions,commands) qrCode.setImageBitmap(sdkHandler.generateQrCodeAsBitmap(configCSV,350,350))
Once the QrCode generated you have just to scan the Qrcode with the scanner to import the configuration (The QrCode format must be activate)
Step 4
To manage the connection, if you only have one application, you can use autoconnect. Otherwise, refer to the MultiApps section to find out how to release and resume the connection when you need it.
Integration
- Create the libs folder if it doesn't exist in the app folder
- Copy/paste the aar file into the libs folder
- Synchronize your build.graddle (Module:app)
- Now you can integrate the sample code to use it see: