Web Demos

BARCODE READER SDK DEMO

Explore the flexibe barcode reading settings to optimize for your specific usage scenario.

WEB TWAIN SDK DEMO

Try the most popular web scanner features: scan images, import local images and PDF files, edit, save to local, upload to database, and etc.

BARCODE READER JAVASCRIPT DEMO

Transform any camera-equipped devices into real-time, browser-based barcode and QR code scanners.

MRZ SCANNER WEB DEMO

Detects the machine-readable zone of a passport, scans the text, and parses into human-readable data.

APP STORE DEMOS

BARCODE READER SDK FOR IOS

BARCODE READER SDK FOR ANDROID

VIEW MORE DEMOS >
Dev Center
Table of contents

Thanks for downloading Dynamsoft Barcode Reader Package!

Your download will start shortly. If your download does not begin, click here to retry.

Getting Started with Android

Requirements

  • Supported OS: Android 5.0 (API Level 21) or higher.
  • Supported ABI: armeabi-v7a, arm64-v8a, x86 and x86_64.
  • Development Environment: Android Studio 3.4+ (Android Studio 4.2+ recommended).

Add the SDK

The Dynamsoft Barcode Reader (DBR) Android SDK comes with two modules:

  • DynamsoftBarcodeReader.aar: Main module. Provides APIs to easily scan 1D and 2D barcodes from image files and camera video.

  • DynamsoftCameraEnhancer.aar (Optional): Dynamsoft Camera Enhancer (DCE) module for getting video frames from mobile cameras. Provides APIs for camera control, camera preview, and other advanced features.

    Note:

    DCE is optional. If you want to use Android CameraX SDK to control camera, preview video, and read barcodes in the callback function that outputs a video frame, please refer to DecodeWithCameraX example.

There are two ways to add the SDK into your project - Manually and Maven.

Add the Library Manually

  1. Download the SDK package from the Dynamsoft Website. After unzipping, two aar files can be found in the DynamsoftBarcodeReader\Libs directory:

    • DynamsoftBarcodeReader.aar
    • DynamsoftCameraEnhancer.aar (Optional)

      Note:

      If you want to use Android Camera SDK or your own sdk to control camera, please ignore DynamsoftCameraEnhancer.aar in the following steps.

  2. Copy the above two aar files to the target directory such as [App Project Root Path]\app\libs

  3. Open the file [App Project Root Path]\app\build.gradle and add reference in the dependencies:

     dependencies {
         implementation fileTree(dir: 'libs', include: ['*.aar'])
     }
    
  4. Click Sync Now. After the synchronization completes, the SDK is added to the project.

Add the Library via Maven

  1. Open the file [App Project Root Path]\app\build.gradle and add the maven repository:

     repositories {
          maven {
             url "https://download2.dynamsoft.com/maven/aar"
          }
     }
    
  2. Add reference in the dependencies:

    dependencies {
       implementation 'com.dynamsoft:dynamsoftbarcodereader:9.2.10@aar'
          
       // Remove the following line if you want to use Android Camera sdk or your own sdk to control camera.
       implementation 'com.dynamsoft:dynamsoftcameraenhancer:2.3.4@aar'
    }
    
  3. Click Sync Now. After the synchronization completes, the SDK is added to the project.

Build Your First Application

In this section, let’s see how to create a HelloWorld app for reading barcodes from camera video input.

Note:

  • Android Studio 4.2 is used here in this guide.
  • You can get the complete source code from Android HelloWorld Sample.
  • DCE is used for camera capture in this guide below. If you use the Android CameraX SDK for camera capture, check DecodeWithCameraX on how to add barcode scanning to your app.

Create a New Project

  1. Open Android Studio, select File > New > New Project.

  2. Choose the correct template for your project. In this sample, we use Empty Activity.

  3. When prompted, choose your app name ‘HelloWorld’ and set the Save location, Language, and Minimum SDK (we use 21 here).

    Note:

    • With minSdkVersion set to 21, your app is compatible with more than 94.1% of devices on the Google Play Store (last update: March 2021).

Include the Library

Add the SDK to your new project. Please read Add the SDK section for more details.

Initialize License

  1. Initialize the license in the file MainActivity.java.

    import com.dynamsoft.dbr.BarcodeReader;
    import com.dynamsoft.dbr.DBRLicenseVerificationListener;
       
    public class MainActivity extends AppCompatActivity {
    
       @Override
       protected void onCreate(Bundle savedInstanceState) { 
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          // Initialize license for Dynamsoft Barcode Reader.
          // The string "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" here is a time-limited public trial license. Note that network connection is required for this license to work.
          // You can also request an extension for your trial license in the customer portal: https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=guide&package=android
          BarcodeReader.initLicense("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9", new DBRLicenseVerificationListener() {
             @Override
             public void DBRLicenseVerificationCallback(boolean isSuccess, Exception error) {
                if(!isSuccess){
                   error.printStackTrace();
                }
             }
          });
       }
    }
    

    Note:

    • Network connection is required for the license to work.
    • The license string here will grant you a time-limited trial license.
    • If the license has expired, you can go to the Customer Portal to request for an extension.
    • If you download the Installation Package, it comes with a 30-day trial license.

Initialize Camera Module

  1. In the Project window, open app > res > layout > activity_main.xml and create a DCE camera view section under the root node.

    <com.dynamsoft.dce.DCECameraView
       android:id="@+id/cameraView"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       tools:layout_editor_absoluteX="25dp"
       tools:layout_editor_absoluteY="0dp" />
    
  2. Import the dynamsoft camera module, initialize the camera view and bind to the created Camera Enhancer instance in the file MainActivity.java.

    ...
       
    import com.dynamsoft.dce.DCECameraView;
    import com.dynamsoft.dce.CameraEnhancer;
    import com.dynamsoft.dce.CameraEnhancerException;
    
    public class MainActivity extends AppCompatActivity {
       CameraEnhancer mCameraEnhancer;
    
       @Override
       protected void onCreate(Bundle savedInstanceState) { 
    
          ...
          // Add camera view for previewing video.
          DCECameraView cameraView = findViewById(R.id.cameraView);
    
          mCameraEnhancer = new CameraEnhancer(MainActivity.this);
          mCameraEnhancer.setCameraView(cameraView);
       }
    }
    

Initialize Barcode Reader

  1. Import and initialize the barcode reader, bind to the created Camera Enhancer instance.

    ...
    
    import com.dynamsoft.dbr.BarcodeReaderException;
    
    public class MainActivity extends AppCompatActivity {
          
       ...
    
       BarcodeReader mReader;
    
       @Override
       protected void onCreate(Bundle savedInstanceState) { 
             
          ...
    
          try {
             mReader = new BarcodeReader();
          } catch (BarcodeReaderException e) {
             e.printStackTrace();
          }
    
          mReader.setCameraEnhancer(mCameraEnhancer);
       }
    }
    
  2. Create a barcode result listener and register with the barcode reader instance to get recognized barcode results.

    ...
    
    import com.dynamsoft.dbr.ImageData;
    import com.dynamsoft.dbr.TextResult;
    import com.dynamsoft.dbr.TextResultListener;
    
    public class MainActivity extends AppCompatActivity {
          
       @Override
       protected void onCreate(Bundle savedInstanceState) { 
             
          ...
          mReader.setTextResultListener(new TextResultListener() {
             // Obtain the recognized barcode results and display.
             @Override
                public void textResultCallback(int id, ImageData imageData, TextResult[] textResults) {
                      (MainActivity.this).runOnUiThread(new Runnable() {
                         @Override
                         public void run() {
                            showResult(textResults);
                         }
                      });
                }
          });
       }
    }
    
  3. Override the MainActivity.onResume and MainActivity.onPause functions to start/stop video barcode scanning. After scanning starts, the Barcode Reader will automatically invoke the decodeBuffer API to process the video frames from the Camera Enhancer, then send the recognized barcode results to the text result callback.

    public class MainActivity extends AppCompatActivity {
          
       ...
    
       @Override
       public void onResume() {
          // Start video barcode reading
          mReader.startScanning();
          try {
             mCameraEnhancer.open();
          } catch (CameraEnhancerException e) {
             e.printStackTrace();
          }
          super.onResume();
       }
    
       @Override
       public void onPause() {
          // Stop video barcode reading
          mReader.stopScanning();
          try {
             mCameraEnhancer.close();
          } catch (CameraEnhancerException e) {
             e.printStackTrace();
          }
          super.onPause();
       }
    }
    

Display Barcode Results

  1. In the Project window, open app > res > layout > activity_main.xml, create a text view section under the root node to display the recognized barcode results. The following sample code is a TextView under RelativeLayout

    ...
    <TextView
       android:id="@+id/tv_res"
       android:layout_width="match_parent"
       android:layout_height="200dp"
       android:layout_marginTop="430dp"
       android:textSize="16sp"
       android:gravity="center"
       android:scrollbars="vertical"
       android:textColor="@color/white"
       android:visibility="visible"/>
    
  2. Display barcode result in TextView.

    public class MainActivity extends AppCompatActivity {
          
       ...
       TextView tvRes;
    
       @Override
       protected void onCreate(Bundle savedInstanceState) {
          ...
             
          // Add TextView to display recognized barcode results.
          tvRes = findViewById(R.id.tv_res);
       }
    
       private void showResult(TextResult[] results) {
          if (results != null && results.length > 0) {
             String strRes = "";
             for (int i = 0; i < results.length; i++)
                   strRes += results[i].barcodeText + "\n\n";
             tvRes.setText(strRes);
          } else {
             tvRes.setText("");
          }
       }
    }
    

Build and Run the Project

  1. Select the device that you want to run your app on from the target device drop-down menu in the toolbar.

  2. Click the Run app button, then Android Studio installs your app on your connected device and starts it.

You can download the complete source code here:

Next Steps

From this page, you have learned how to create a simple video barcode decoding app. In the next steps, the following pages will help you on adding configurations to enhance your barcode reader.

Explore Features

If you want to explore the many features of the SDK and learn how to use them to best process the images you read in your application, read the articles in Explore Features.

Check Use Cases

If you want to check how the SDK works in popular use cases, read the articles in Use Cases.

Optimize Performance

If you have successfully integrated the SDK in your application but would like to get the best performance possible, read how to do this in Optimize Performance.

Using CameraX with DBR

If you use the Android CameraX SDK, DecodeWithCameraX will guide you on how to add barcode scanning to your app.

Other platforms

This page is compatible for:

Version 7.5.0

Is this page helpful?

YesYes NoNo

In this article:

latest version

  • Latest version
  • Version 9.x
    • Version 9.2.11
    • Version 9.2.10
    • Version 9.0.1
    • Version 9.0.0
  • Version 8.x
    • Version 8.9.3
    • Version 8.9.0
    • Version 8.8.7
    • Version 8.8.5
    • Version 8.8.3
    • Version 8.8.0
    • Version 8.6.3
    • Version 8.6.0
    • Version 8.4.0
    • Version 8.2.5
    • Version 8.2.3
    • Version 8.2.1
    • Version 8.2.0
    • Version 8.1.3
    • Version 8.1.2
    • Version 8.1.0
    • Version 8.0.0
  • Version 7.x
    • Version 7.6.0
    • Version 7.5.0
Change +
© 2003–2022 Dynamsoft. All rights reserved.
Privacy Statement / Site Map / Home / Purchase / Support