在 Android Studio 中使用 ZXING 更改 QR 扫描仪方向
Change QR Scanner orientation with ZXING in Android Studio
我希望你能帮我解决这个问题。我使用 Zxing Embedded Library 来使用 QR 扫描仪,问题是它处于横向模式,我想将其更改为纵向。
我在我的 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 class 中有这个,可以通过按钮激活扫描仪...
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();
}
感谢您的帮助!
我正在使用
compile 'com.journeyapps:zxing-android-embedded:3.1.0@aar'
这是不同的版本,所以我不知道这是否适合你,
但这对我有用。
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'
首先,我从 CaptureActivity
创建了一个 activity 扩展
或单击此 link 查看 class https://gist.github.com/TheGratefulDev/21a557c9a96333ec037c
public class CaptureActivityPortrait extends CaptureActivity {
//Nothing in side.
}
其次,添加这个
integrator.setCaptureActivity(CaptureActivityPortait.class);
进入您的集成商代码。
这是我的样子:
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 添加
<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>
我刚刚找到了最简单的方法。我们应该创建另一个 CaptureActivity.java class 并将此代码写入 onclick
listener:
IntentIntegrator integrator = new IntentIntegrator(activity);
integrator.setPrompt("Scan a barcode");
integrator.setDesiredBarcodeFormats(integrator.ALL_CODE_TYPES);
integrator.setCameraId(0);
integrator.setOrientationLocked(false);
// Replace with your own java class location here
integrator.setCaptureActivity(com.share.ants.hotelmenu.CaptureActivity.class);
integrator.setBeepEnabled(true);
对我有用:
IntentIntegrator integrator = new IntentIntegrator(YourActivity.this);
integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);
integrator.setPrompt(getResources().getString(R.string.scan_a_barcode));
integrator.setCameraId(0);
// Use a specific camera of the device
integrator.setBeepEnabled(true);
integrator.setBarcodeImageEnabled(false);
integrator.initiateScan();
无需扩展 class,只需将其添加到清单中即可:
<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="portrait"
tools:replace="android:screenOrientation"
android:stateNotNeeded="true"/>
很有魅力
我希望你能帮我解决这个问题。我使用 Zxing Embedded Library 来使用 QR 扫描仪,问题是它处于横向模式,我想将其更改为纵向。
我在我的 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 class 中有这个,可以通过按钮激活扫描仪...
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();
}
感谢您的帮助!
我正在使用
compile 'com.journeyapps:zxing-android-embedded:3.1.0@aar'
这是不同的版本,所以我不知道这是否适合你, 但这对我有用。
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'
首先,我从 CaptureActivity
创建了一个 activity 扩展或单击此 link 查看 class https://gist.github.com/TheGratefulDev/21a557c9a96333ec037c
public class CaptureActivityPortrait extends CaptureActivity {
//Nothing in side.
}
其次,添加这个
integrator.setCaptureActivity(CaptureActivityPortait.class);
进入您的集成商代码。
这是我的样子:
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 添加
<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>
我刚刚找到了最简单的方法。我们应该创建另一个 CaptureActivity.java class 并将此代码写入 onclick
listener:
IntentIntegrator integrator = new IntentIntegrator(activity);
integrator.setPrompt("Scan a barcode");
integrator.setDesiredBarcodeFormats(integrator.ALL_CODE_TYPES);
integrator.setCameraId(0);
integrator.setOrientationLocked(false);
// Replace with your own java class location here
integrator.setCaptureActivity(com.share.ants.hotelmenu.CaptureActivity.class);
integrator.setBeepEnabled(true);
对我有用:
IntentIntegrator integrator = new IntentIntegrator(YourActivity.this);
integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);
integrator.setPrompt(getResources().getString(R.string.scan_a_barcode));
integrator.setCameraId(0);
// Use a specific camera of the device
integrator.setBeepEnabled(true);
integrator.setBarcodeImageEnabled(false);
integrator.initiateScan();
无需扩展 class,只需将其添加到清单中即可:
<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="portrait"
tools:replace="android:screenOrientation"
android:stateNotNeeded="true"/>
很有魅力