在Android Studio中使用ZXING更改QR扫描仪方向 [英] Change QR Scanner orientation with ZXING in Android Studio
问题描述
希望您能对此有所帮助.我使用Zxing嵌入式库以使用QR扫描仪,问题是在横向模式下,我想将其更改为纵向.
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.
我有这个关于我的Graddle的依赖项
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'
并且我在Java类中有一个按钮来激活扫描器...
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();
}
感谢您的帮助!
推荐答案
我正在使用
编译'com.journeyapps:zxing-android-embedded:3.1.0@aar'
compile 'com.journeyapps:zxing-android-embedded:3.1.0@aar'
它是不同的版本,所以我不知道这是否对您有用, 但这对我有用.
It is different version, so I don't know if this will work for you, but this is working for me.
有关我的设置的更多信息,我只能编译
More about my setup, I only compile
'com.journeyapps:zxing-android-embedded:3.1.0@aar'
'com.journeyapps:zxing-android-embedded:3.1.0@aar'
'com.google.zxing:core:3.0.1'
'com.google.zxing:core:3.0.1'
我没有编译
'com.journeyapps:zxing-android-integration:2.0.1@aar'
'com.journeyapps:zxing-android-integration:2.0.1@aar'
首先,我创建了一个来自CaptureActivity的活动
First I created an activity extend from the CaptureActivity
或单击此链接以查看类 https://gist.github.com/TheGratefulDev/21a557c9a96333ec037c
or click this link to view the class https://gist.github.com/TheGratefulDev/21a557c9a96333ec037c
public class CaptureActivityPortrait extends CaptureActivity {
//Nothing in side.
}
第二,添加此
integrator.setCaptureActivity(CaptureActivityPortait.class);
integrator.setCaptureActivity(CaptureActivityPortait.class);
进入您的集成商代码.
into your integrator code.
这是我的样子:
CustomIntegrator integrator = new CustomIntegrator(activity);
integrator.setDesiredBarcodeFormats(CustomIntegrator.PDF_417);
integrator.setPrompt("Scan a barcode");
integrator.setCameraId(0); // Use a specific camera of the device
integrator.setOrientationLocked(true);
integrator.setBeepEnabled(true);
integrator.setCaptureActivity(CaptureActivityPortrait.class);
integrator.initiateScan();
最后,在AndroidMaifest中添加
Finally, at the AndroidMaifest add
<activity
android:name=".custom.CaptureActivityPortrait"
android:screenOrientation="portrait" <---this is the most important line
android:stateNotNeeded="true"
android:theme="@style/zxing_CaptureTheme"
android:windowSoftInputMode="stateAlwaysHidden">
</activity>
这篇关于在Android Studio中使用ZXING更改QR扫描仪方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!