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

自定义布局Android中的ZXing QRCode扫描仪,android,android-fragments,zxing,Android,Android Fragments,Zxing,我想在Android中为ZXing扫描仪创建自定义视图,其中相机处于纵向模式,自定义相机视图尺寸。我有一个页眉和页脚通过片段在同一个视图,但我不能使ZXing在自定义布局。我确实是全屏拍摄的 对不起,我可能需要用勺子喂食 compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar' compile 'com.google.zxing:core:3.2.0' 我使用了上面的库,但它使用以下代码使其全屏显示: 扫描活动: import

我想在Android中为ZXing扫描仪创建自定义视图,其中相机处于纵向模式自定义相机视图尺寸。我有一个页眉和页脚通过片段在同一个视图,但我不能使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);
        }
    }
}
CaptureCoder活动:

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);
        }
    }
}
import com.journeyapps.barcodescanner.CaptureActivity;

public final class CaptureCodePortraitActivity extends CaptureActivity {}
我看到的Github帖子很少,但我不知道如何定制,例如:


但对于在纵向模式下打开相机没有帮助,请在清单中添加CaptureActivity,如下所示:

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

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

我也尝试过同样的方法。但是,我收到未解决的包journeyapps错误出现在清单文件中。我使用了上面提到的4个依赖项。即使如此,清单声明中也不接受CaptureActivity类包。是否已在gradle中添加依赖项?请先在应用程序的gradle中为ex:compile'com.journeyapps:zxing android embedded:3.4.0'添加依赖项。