Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
923 views
in Technique[技术] by (71.8m points)

camera - Change QR Scanner orientation with ZXING in Android Studio

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...