在 Android Studio 中使用 ZXING 更改 QR 扫描仪方向 [英] Change QR Scanner orientation with ZXING in Android Studio

查看:72
本文介绍了在 Android Studio 中使用 ZXING 更改 QR 扫描仪方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望你能帮助我解决这个问题.我使用 Zxing Embedded Library 来使用 QR 扫描仪,问题是它处于横向模式,我想将其更改为纵向.

我在 Gradle 的依赖项上有这个

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

我的 java 类中有这个,可以通过按钮激活扫描仪...

public void scanQR(View view){IntentIntegrator 积分器 = 新的 IntentIntegrator(this);积分器.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);integrator.setResultDisplayDuration(0);//文本..integrator.setPrompt("扫描二维码");integrator.setScanningRectangle(450, 450);//大小积分器.setCameraId(0);//使用设备的特定摄像头积分器.initiateScan();}

感谢您的帮助!

解决方案

我正在使用

<块引用>

编译'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.journeyapps:zxing-android-integration:2.0.1@aar'

首先我创建了一个从 CaptureActivity 扩展的活动

或点击此链接查看课程https://gist.github.com/TheGratefulDev/21a557c9a96333ec037c

公共类 CaptureActivityPortrait 扩展 CaptureActivity {//旁边什么都没有.}

其次,添加这个

<块引用>

integrator.setCaptureActivity(CaptureActivityPortait.class);

到您的集成商代码中.

这是我的样子:

CustomIntegrator 积分器 = new CustomIntegrator(activity);积分器.setDesiredBarcodeFormats(CustomIntegrator.PDF_417);integrator.setPrompt("扫描条码");积分器.setCameraId(0);//使用设备的特定摄像头积分器.setOrientationLocked(true);积分器.setBeepEnabled(true);积分器.setCaptureActivity(CaptureActivityPortrait.class);积分器.initiateScan();

最后,在 AndroidMaifest 上添加

<块引用>

 <活动android:name=".custom.CaptureActivityPortrait"android:screenOrientation="portrait" <---这是最重要的一行机器人:stateNotNeeded="真"android:theme="@style/zxing_CaptureTheme"android:windowSoftInputMode="stateAlwaysHidden"></活动>

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!

解决方案

I am using

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.google.zxing:core:3.0.1'

and I did not compile

'com.journeyapps:zxing-android-integration:2.0.1@aar'

First I created an activity extend from the CaptureActivity

or click this link to view the class https://gist.github.com/TheGratefulDev/21a557c9a96333ec037c

public class CaptureActivityPortrait extends CaptureActivity {
//Nothing in side.
}

Second, add this

integrator.setCaptureActivity(CaptureActivityPortait.class);

into your integrator code.

This is how mine looks like:

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();

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆