Cookies on this site

We would like to use cookies to understand how the site is used and to measure our campaigns. Nothing is set until you choose, and you can change your mind at any time from “Cookie settings” at the foot of every page. Privacy policy

Contact UsContact Us

Resources / Blogs

Cloud & apps

Android – Optimally Using Zxing Barcode Scanner and Camera Orientation

Unable to figure out how to configure the camera to rotate orientation automatically in Android? There is a simple solution use zxing-android-embedded.

· · 1 min read

Zxing Barcode Scanner

Need a barcode scanner for your app? Yes, “Zxing” is the best solution. Zxing (https://github.com/zxing/zxing) is the most popular library of its kind which can scan and decode result in a fraction of a second.

Now what?? Unable to figure out how to configure the camera to rotate automatically? Yes, free version of this library support landscape mode only while scanning a code. There are some situations where automatic rotation of the camera is a must. If you had tried to fix this already, probably you would know how much time you have spent on this and what is the level of complexity! Yes, there is a simple solution to this. Use zxing-android-embedded (https://github.com/journeyapps/zxing-android-embedded) library instead. Internally, this library uses Zxing core for decoding and the camera supports both landscape and portrait modes. You can set your desired orientation in AndroidManifest.xml file by setting up the orientation for the corresponding activity.Step 1 – Modification in XML part:
Use CompoundBarcodeView component in xml layout (e.g. scanner_activity.xml) file-

<com.journeyapps.barcodescanner.CompoundBarcodeView android:id=“@+id/scanner” android:layout_width=“match_parent” android:layout_height=“match_parent” android:layout_alignParentTop=“true”> com.journeyapps.barcodescanner.CompoundBarcodeView>

Step 2 – Modification in Activity class:
Initialize the above component in your activity class (e.g. MyBarCodeScannerActivity.java)-

Create an instance variable

private CompoundBarcodeView mBarcodeView;

Initialize inside onCreate()

mBarcodeView = (CompoundBarcodeView) findViewById(R.id.scanner);

barcodeView.decodeSingle(callback);

Impliment a callback to handle the result –

private BarcodeCallback callback = new BarcodeCallback() {
   @Override
   public void barcodeResult(final BarcodeResult result) {
	//code to handle “result”
      Toast.makeText(YourActivityName.this, result.getText(), Toast.LENGTH_SHORT).show();
   }
   @Override
   public void possibleResultPoints(List resultPoints) {
   }
};

Step 3 – Modification in AndroidMenifest.xml file:
Setting up the screen orientations:
Add the following property to the activity declaration of MyBarCodeScannerActivity.java in AndroidMenifest.xml file

For landscape- android:screenOrientation="landscape",
For portrait-android:screenOrientation="portrait",

To support both the orientation just remove android:screenOrientationproperty from that activity.

← All articles

Case studies

Cloud Consulting in practice

Client names are withheld. We are happy to share details on a call.

All case studies
  • Delivered

    On-prem → Amazon RDS

    Nonprofit

    Cloud Consulting

    Oracle from on-premises to Amazon RDS for a national nonprofit

    The nonprofit's on-premises Oracle database had become hard to maintain and scale. We planned the move with automated workflows and validation tests, migrated to Amazon RDS for Oracle with minimal disruption and left a repeatable process for future changes.

    • Automated, tested migration
    • Less day-to-day database upkeep
  • Delivered

    600k files, < 3 days

    Document management

    Microsoft

    600,000 documents moved from ImageRight to SharePoint in under three days

    A one-file-at-a-time script would have needed about 22 days of continuous running. We rebuilt the migration around a SQL work queue with parallel uploads, automatic retries and crash recovery, and it finished unattended in under three days.

    • 1,125 → 8,314 files per hour
    • Under 3 days instead of about 22
  • Delivered

    Every change, flagged

    Food manufacturing

    AI Consulting

    Label comparison agent for a national food cooperative

    Compares two versions of a product label, highlights every change, annotates the PDF and returns an audit-ready list of differences. We moved it from Copilot Studio to Azure Functions when the document processing outgrew the low-code platform.

    • Audit-ready differences in one chat turn
    • Rebuilt from low-code to cloud functions

Keep reading

All Cloud & apps articles

Moving an application to the cloud?

Request a migration plan consult. We will scope the move with you and come back with a fixed-scope plan.