2017-02-15 88 views
0

我想在ZXing Scanner中創建自定義視圖,其中相機位於肖像模式,自定義相機視圖尺寸。我在同一視圖中通過片段有頁眉和頁腳,但我無法在自定義佈局中製作ZXing。我確實是全屏製作的。ZXing QRCode掃描儀在自定義佈局Android

對不起,但我可能需要一點勺子餵養。

compile 'com.journeyapps:zxing-android-embedded:[email protected]' 
    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

對於人像模式下打開相機,在清單中添加CaptureActivity爲:

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

這將取代屏幕方向=景觀它在Zxing庫中被用作默認值。

+0

我已經嘗試過。但是,獲取未解析的軟件包journeyapps錯誤即將出現在清單文件中。我用過提到的4個依賴關係。即使在清單聲明中也不接受CaptureActivity類包。 – harikrishnan

+0

您是否在gradle中添加了依賴項?請先在應用程序的gradle中添加ex:compile'c​​om.journeyapps:zxing-android-embedded:3.4.0'的依賴項。 – shell22