Back to top

Knox Capture sample app tutorial overview

This tutorial teaches you how to use the Knox Capture SDK.

Prerequisites

Before you start with this tutorial:

  • Make sure you have a valid Knox Capture SDK license. Please review SDK licensing for instructions on how to get and activate your license.

  • You need to add the knoxcapture-sdk-1.0.0.aar file into your project’s libs folder.

  • Download sample app source code from Knox Partner Program’s Developers console.

    • Refer to the Get Knox Capture SDK license guide if you do not already have access to the Knox Developers console.
    • Once you’re in the console, you can find the Knox Capture Sample App source code by going to SDK tools > Sample apps.

Review sample app code

Begin by downloading the sample app source code from the Knox Partner Program’s Developers console. Refer to the Get Knox Capture SDK license guide if you do not already have access to the Knox Developers console.

Once you’re in the console, you can find the Knox Capture Sample App source code by going to SDK tools > Sample apps.

Define BarcodeScanPreviewView

First of all, you need to define BarcodeScanPreviewView in an XML layout file. You can add your own UI components to trigger scanning or to show barcode scanning results:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.samsung.android.knox.smartscan.preview.BarcodeScanPreviewView
        android:id="@+id/preview_view"
        android:visibility="visible"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    // ..  Add views to trigger scanning and show result

</FrameLayout>

Define barcode result callback

You then need to define a barcode result callback in order to get barcode scanning results:

val resultHandlingCallback = object : PreviewResultHandlingCallback {
    override fun handleBarcodes(barcodeResult: BarcodeResult, environmentData: EnvironmentData) {
        if (barcodeResult.barcodes.isNotEmpty()) {
            //implement something with the scanned barcode results.
        }
    }
}

Initialize preview

Once you’ve determined your layout and barcode result callback, you need to initialize the camera preview:

var previewView: BarcodeScanPreviewView? = null
previewView = findViewById(R.id.preview_view)
    
//You can build preview config with detailed configuration. 
val config: PreviewConfig = PreviewConfig.Builder()
   .setCameraResolution(SDKConstants.CameraResolutions.RESOLUTION_UHD)
   .setSymbology(BarcodeInfo.allSupportedBarcodeSymbology)
   .build()

previewView?.init(config, resultHandlingCallback)  

Start camera preview and barcode detection

You can start the camera preview and barcode detection with the following:

previewView?.startPreview()
previewView?.startEngineAnalyzing()

For more information about implementation, please consult the sample app source code.

Is this page helpful?