自定义布局Android中的ZXing QRCode扫描仪

时间:2017-02-15 14:45:35

标签: android android-fragments zxing

我想在Android中为ZXing Scanner创建自定义视图,其中相机处于纵向模式自定义相机视图尺寸。我在同一视图中有一个页眉和页脚的片段,但我无法在自定义布局中制作ZXing。我确实是全屏制作的。

抱歉,我可能需要一点勺子喂食。

  compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
  compile 'com.google.zxing:core:3.2.0'

我使用的库以上但使用以下代码使其全屏:

扫描活动:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;

import prizeops.com.merchant.service.CallActivityService;
import prizeops.com.merchant.service.HelperUtil;
import prizeops.com.merchant.service.PrizeService;

public class ScanActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        IntentIntegrator integrator = new IntentIntegrator(this);
        integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
        integrator.setPrompt("Scan QRCode");
        integrator.setCameraId(0);
        integrator.setOrientationLocked(true);
        integrator.setBeepEnabled(true);
        integrator.setCaptureActivity(CaptureCodePortraitActivity.class);
        integrator.initiateScan();
    }
    @Override
    protected void onActivityResult(int req, int res, Intent intent) {
        IntentResult intentResult = IntentIntegrator.parseActivityResult(req, res, intent);
        if(intentResult != null){
            if(intentResult.getContents()==null){
                HelperUtil.makeToast(this, "Scanning been Cancelled.");
                CallActivityService.gotoHomeActivity(this);
            }
            else
                PrizeService.verifyPromoCode(this,intentResult.getContents(),false);
        }
        else {
            super.onActivityResult(req, res, intent);
        }
    }
}

CaptureCodePortraitActivity:

import com.journeyapps.barcodescanner.CaptureActivity;

public final class CaptureCodePortraitActivity extends CaptureActivity {}

我看到了很少的Github帖子,但我无法理解如何自定义如:

https://github.com/journeyapps/zxing-android-embedded

https://github.com/journeyapps/zxing-android-embedded/blob/master/sample/src/main/java/example/zxing/ContinuousCaptureActivity.java

但没有帮助

1 个答案:

答案 0 :(得分:1)

要在纵向模式下打开相机,请在清单中将CaptureActivity添加为:

    android:name="com.journeyapps.barcodescanner.CaptureActivity"
    android:screenOrientation="portrait"
    tools:replace="screenOrientation" />

这将取代Zxing库中默认使用的屏幕方向=横向。