Skip to content

Latest commit

 

History

History
 
 

README.md

Android WebView - Scan Using Foundational API

This sample demonstrates how to integrate Dynamsoft Barcode Reader JavaScript SDK into an Android WebView application using the Foundational API for maximum flexibility and customization.

Key Features

1. Camera Permission Handling

Camera permission is declared in AndroidManifest.xml:

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

2. Foundational API Implementation

The HTML file (decodeBarcodeInVideo.html) demonstrates:

  • CameraEnhancer: Controls camera operations (open, close, resolution)
  • CameraView: Manages the UI layer for camera preview
  • CaptureVisionRouter: Routes captured frames to the barcode reader
  • Result Callbacks: Custom handling of decoded barcode results

Example code structure:

// Create camera view and enhancer
const cameraView = await Dynamsoft.DCE.CameraView.createInstance();
const cameraEnhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance(cameraView);

// Create capture vision router
const cvRouter = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
cvRouter.setInput(cameraEnhancer);

// Add result receiver
cvRouter.addResultReceiver({
  onDecodedBarcodesReceived: (result) => {
    // Handle decoded barcodes
  }
});

// Start scanning
await cameraEnhancer.open();
await cvRouter.startCapturing("ReadSingleBarcode");

How to Run

  1. Open the Project

    cd android
    # Open in Android Studio
  2. Build and Run

    • Connect an Android device or start an emulator
    • Click Run (Shift+F10) in Android Studio
    • Grant camera permission when prompted
  3. Test the Scanner

    • Point the camera at a barcode
    • Decoded results will appear below the camera view

API Reference

For complete API documentation:

License

This sample uses a Dynamsoft trial license. To use in production:

  1. Visit the Customer Portal to obtain a license
  2. Replace the license key in decodeBarcodeInVideo.html:
    Dynamsoft.License.LicenseManager.initLicense("YOUR-LICENSE-KEY");

Troubleshooting

Camera not opening:

  • Ensure camera permission is granted in device settings
  • Check Android version compatibility (API 21+)
  • Verify WebView version supports getUserMedia API

WebView blank screen:

  • Enable JavaScript in WebView settings
  • Check Developer Console for JavaScript errors

Support

Need help? Contact Dynamsoft support:

Related Samples