Change QR Scanner orientation with ZXING in Android Studio

Matías Gaete picture Matías Gaete · Jan 25, 2016 · Viewed 22.9k times · Source

I hope you can help me with this. Im using the Zxing Embedded Library in order to use the QR scanner, the problem is that is on Landscape mode and I would like to change it to Portrait.

I have this on the dependencies of my Graddle

compile 'com.journeyapps:zxing-android-embedded:2.0.1@aar'
compile 'com.journeyapps:zxing-android-integration:2.0.1@aar'
compile 'com.google.zxing:core:3.0.1'

and I have this in my java class to activate the scanner with a button...

public void scanQR(View view){
    IntentIntegrator integrator = new IntentIntegrator(this);
    integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
    integrator.setResultDisplayDuration(0);//Text..
    integrator.setPrompt(" Scan a QR Code");
    integrator.setScanningRectangle(450, 450);//size
    integrator.setCameraId(0);  // Use a specific camera of the device
    integrator.initiateScan();

}

Thanks for the help!

Answer

Ravi Tripathi picture Ravi Tripathi · Nov 29, 2017

Instead of extending a class, just add this to the manifest:

  <activity
            android:name="com.journeyapps.barcodescanner.CaptureActivity"
            android:screenOrientation="portrait"
            tools:replace="android:screenOrientation"
            android:stateNotNeeded="true"/>

Works like a charm