[英]Change QR Scanner orientation with ZXING in Android Studio
我希望你能幫我解決這個問題。 我使用 Zxing 嵌入式庫來使用 QR 掃描儀,問題是在橫向模式下,我想將其更改為縱向。
我在 Gradle 的依賴項上有這個
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類中有這個用按鈕激活掃描儀......
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();
}
謝謝您的幫助!
無需擴展類,只需將其添加到清單中即可:
<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="portrait"
tools:replace="android:screenOrientation"
android:stateNotNeeded="true"/>
奇跡般有效
我在用
編譯'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
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 類並在onclick
偵聽器中編寫此代碼:
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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.