Deprecation warning

Please note that this is outdated documentation for an older release of the Scandit Barcode Scanner SDK.

We are deprecating the 5.x API on all platforms (except Linux). Release 5.19 in April 2021 will be our final. Applications running 5.x will continue to work, and we will continue to release critical bug fixes and security patches only, for one year. We encourage you to migrate to 6.x and take advantage of our latest / advanced features and improved performance.

You'll find the updated documentation at: Data Capture SDK Documentation for Android

Integrate the Scandit Barcode Scanner SDK into your app

To integrate the Scandit SDK into your Android app, follow the simple steps below.

Get the Scandit Barcode Scanner SDK

Choose a plan (e.g., free “Enterprise” or "Community" plan) at http://www.scandit.com/pricing and download the Scandit Barcode Scanner SDK for Android from your account.

Download page


Add the SDK to your project

If your project uses Gradle as the build system, the simplest way to integrate the Scandit Barcode Scanner SDK into your app is to use the AAR file contained in the SDK. If you are using Android Studio, but do not use Gradle, we commend to import the Barcode Scanner as a library module (see below). If you are using another IDE, you will have copy the files manually.

Adding the Barcode Scanner SDK for Gradle-Based builds

To add the barcode scanner to your gradle-based Android project, you can use the AAR file contained in the Scandit Barcode Scanner ZIP archive. The AAR file is located in the ScanditSDK subfolder. If your project already has a local flatDir repository, add the AAR to that folder. If you do not have a flatDir repository yet, create a new one in your build.gradle file as illustrated in the code-snippet below:

repositories {
flatDir{
dirs '/path/to/folder/containing/the/aar/file'
}
}

Add the ScanditBarcodeScanner as a dependency to your build.gradle file:

dependencies {
compile(name:'ScanditBarcodeScanner', ext:'aar')
}

You can now use the functionality contained in the AAR file in your project.

Adding the Barcode Scanner SDK as a Library Module

If you are using IntelliJ, but do not use gradle for building, you can import the Scandit Barcode Scanner as a library module. Choose "New" → "Module from Existing Sources..". In the file-chooser dialog choose the ScanditSDK/ScanditBarcodeScanner.iml file and click "OK". Now the Barcode Scanner is included as a module inside your project. You need to add the module dependency to your application. Right click on your application module, and click on "Open Module Settings". In the dependencies tab, click on the "+" button and then select "Module Dependency" and add the ScanditBarcodeScanner module.

Manually adding the Barcode Scanner SDK

  1. Copy libs folder

    The ZIP file you downloaded contains a folder named libs (ScanditSDK/libs). Create in your Android Studio project the folder jniLibs (at this location /app/src/main/) and copy the content of the lib folder in it.

  2. Copy the raw folder

    Copy the raw folder located inside the res folder to the res folder of your Android Studio project.

  3. Add jar

    Add the scandit-barcodescanner_x.x.x.jar, which is contained in the jniLibs folder, to Dependencies (right click → "Open Module Settings" →"Dependencies", add "File dependency").


Project Setup


Project tree:


Project Setup


Change minimum SDK version

Starting with Scandit Barcode Scanner SDK 4.0.0 the required Android version is 2.3. If the android:minSdkVersion in your manifest is below 10, change it to 10. If you are still using a Scandit Barcode Scanner version lower than 4.0.0 the required Android version is 2.2 which means the android:minSdkVersion needs to be set to 8.

Grant camera access permissions to your app

If not already done, grant your application the right to access the camera. You will need to add the following in the AndroidManifest.xml of your app. The element needs to be added as a child of the root manifest element.

<uses-permission android:name="android.permission.CAMERA"/>

If your target SDK is 6.0 or higher, you need to request the permission to access the camera at runtime (see Android 6.0 and Camera Permissions).

Prepare class to receive scanning events

To receive events from the Scandit Barcode Scanner SDK you have to implement the OnScanListener interface. This requires the following steps:

Specify that your class implements the OnScanListener interface.

If your class is an activity called DemoActivity, it looks something like this:

public class DemoActivity extends Activity
implements OnScanListener {
}

Import the necessary interface by pressing ALT + ENTER.


Implement callback methods

Add the following callback methods to the class (as defined by the interface):

@Override
public void didScan(ScanSession session) {
// This callback is called whenever a barcode is decoded.
}

For details on how to use the barcode data returned by the scan session consult the OnScanListener documentation or take a look at one of the included samples.


Instantiate and configure the barcode picker

The scanning process in managed by the BarcodePicker. Before instantiating the picker, you will have to set your Scandit Barcode Scanner License key. The Licene key is available from your Scandit Barcode Scanner SDK account at http://account.scandit.com in the License Keys section. The barcode scanning is configured through an instance of scan settings that you pass to the BarcodePicker constructor.

// Set your license key
ScanditLicense.setAppKey("-- ENTER YOUR SCANDIT LICENSE KEY HERE --");
ScanSettings settings = ScanSettings.create();
settings.setSymbologyEnabled(Barcode.SYMBOLOGY_EAN13, true);
settings.setSymbologyEnabled(Barcode.SYMBOLOGY_UPCA, true);
// Instantiate the barcode picker by using the settings defined above.
BarcodePicker picker = new BarcodePicker(this, settings);
// Set the on scan listener to receive barcode scan events.
picker.setOnScanListener(this);


Show the scan UI

Show the scanner to the user. The easiest way to do so is by setting it as the content view of your activity:

setContentView(mPicker);

For more information on the different ways to add the barcode picker to your view hierarchy, consult Presenting the Scandit Barcode Scanner.

Start the scanner

Starting and stopping should normally happen in the onPause() and onResume() methods of the same activity that contains the picker.

private BarcodePicker mPicker;
@Override
protected void onResume() {
mPicker.startScanning();
super.onResume();
}
@Override
protected void onPause() {
mPicker.stopScanning();
super.onPause();
}

It does not matter whether the picker is the root view of the activity or just a subview in the hierarchy. The camera resource needs to be freed before the activity ends or goes into the background, so stopping the picker in onPause() is a necessity. If it is not stopped your app will keep a lock on the camera which prevents any other app from opening the camera itself.


Run the project

Run your app on your Android device.

For Production: Adding Proguard Rules

If you are using proguard for your project, add the following lines to proguard.txt

-keep class com.scandit.** { *; }


Next steps