javaandroidzxing

Zxing in android always in landscape mode


I'm trying to implement a barcode reader. https://www.youtube.com/watch?v=wfucGSKngq4&list=PLYBH5YZZegIf1DzLtuFmeDFqHYsfw1h1I&index=7&t=232s I've followed this tutorial, and almost everything works fine. The only issue I have is that it always opens in landscape screen, and I have absolutely no clue what I do wrong.

butonScanare.setOnClickListener(v -> {
        IntentIntegrator integrator = new IntentIntegrator(activity);
        integrator.setCaptureActivity(CaptureActivity.class);
        integrator.setOrientationLocked(false);
        integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);
        integrator.setPrompt("Scanare");
        integrator.initiateScan();
    });

Any clue what I'm doing wrong?


Solution

  • Just add this in your AndroidManifest.xml file

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