2016-05-14 68 views
3

當我在Asus_Z00AD(ver-5.0)中運行應用程序時,QR碼掃描完美無缺,但當我在任何其他移動設備上運行它時,如moto-g(版本6.0)它顯示了一個空白的屏幕 ,並沒有別的.. 做什麼.. PLZ建議我..Zxing Qr代碼掃描器不能在所有設備上工作

我的掃描儀活動

  package hashrail.com.aggregate.activity; 

      import android.app.Activity; 
      import android.content.Intent; 
      import android.graphics.PointF; 
      import android.os.Bundle; 
      import android.support.design.widget.Snackbar; 
      import android.support.v7.app.AlertDialog; 
      import android.support.v7.app.AppCompatActivity; 
      import android.support.v7.widget.Toolbar; 
      import android.util.Log; 
      import android.util.SparseArray; 
      import android.view.KeyEvent; 
      import android.view.MenuItem; 
      import android.view.SurfaceHolder; 
      import android.view.SurfaceView; 
      import android.view.View; 
      import android.widget.ImageView; 
      import android.widget.LinearLayout; 
      import android.widget.TextView; 
      import android.widget.Toast; 

      import com.google.zxing.Result; 

      import java.io.IOException; 

      import hashrail.com.aggregate.R; 
      import me.dm7.barcodescanner.zxing.ZXingScannerView; 


      public class BarcodeScanFragment extends AppCompatActivity implements ZXingScannerView.ResultHandler { 
       Toolbar toolbar; 
       LinearLayout rlpditem; 
       private String codeFormat, codeContent; 
       private TextView formatTxt, contentTxt; 
       ImageView imgBarcode; 
       LinearLayout llQRrcode; 
       private ZXingScannerView mScannerView; 


       public BarcodeScanFragment() { 
        // Required empty public constructor 
       } 

       @Override 
       public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.fragment_barcode_scan); 
        toolbar = (Toolbar) findViewById(R.id.toolbar1); 
        llQRrcode = (LinearLayout) findViewById(R.id.llQRrcode); 
        formatTxt = (TextView) findViewById(R.id.scan_format); 
        contentTxt = (TextView) findViewById(R.id.scan_content); 
        imgBarcode = (ImageView) findViewById(R.id.scssan_button); 

        setSupportActionBar(toolbar); 
        getSupportActionBar().setDisplayShowHomeEnabled(true); 
        getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
        setTitle("Barcode Scanner"); 

        /* imgBarcode.setOnClickListener(new View.OnClickListener() { 
         @Override 
         public void onClick(View v) { 

          setContentView(mScannerView); 

          mScannerView.startCamera(); 
         } 
        });*/ 
       } 

       @Override 
       public boolean onOptionsItemSelected(MenuItem item) { 

        switch (item.getItemId()) { 
         case android.R.id.home: 
          onBackPressed(); 
          return true; 
         default: 
          return super.onOptionsItemSelected(item); 
        } 
       } 
       public void QrScanner(View view) { 
         // Start camera 
        mScannerView = new ZXingScannerView(BarcodeScanFragment.this); // Programmatically initialize the scanner view 
        mScannerView.setResultHandler(BarcodeScanFragment.this); // Register ourselves as a handler for scan results. 
        setContentView(mScannerView); 
        mScannerView.startCamera(); 
       } 

       /* @Override 
       public void onPause() { 
        super.onPause(); 
        mScannerView.stopCamera(); // Stop camera on pause 
       } 
      */ 
       @Override 
       public void handleResult(Result rawResult) { 
      // Do something with the result here 

        Log.e("handler", rawResult.getText()); // Prints scan results 
        Log.e("handler", rawResult.getBarcodeFormat().toString()); // Prints the scan format (qrcode) 

        // show the scanner result into dialog box. 
        AlertDialog.Builder builder = new AlertDialog.Builder(this); 
        builder.setTitle("Scan Result"); 
        builder.setMessage(rawResult.getText()); 
        AlertDialog alert1 = builder.create(); 
        alert1.show(); 

        // If you would like to resume scanning, call this method below: 
        mScannerView.resumeCameraPreview(this); 
       } 
      } 

搖籃文件

   apply plugin: 'com.android.application' 

       android { 
        compileSdkVersion 23 
        buildToolsVersion "23.0.3" 

        defaultConfig { 
         applicationId "hashrail.com.aggregate" 
         minSdkVersion 11 
         targetSdkVersion 23 
         versionCode 1 
         versionName "1.0" 
         useLibrary 'org.apache.http.legacy' 
        } 
        buildTypes { 
         release { 
          minifyEnabled false 
          proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
         } 
        } 
       } 

       dependencies { 
        compile fileTree(dir: 'libs', include: ['*.jar']) 
        testCompile 'junit:junit:4.12' 
        compile 'com.android.support:appcompat-v7:23.3.0' 
        compile 'com.android.support:design:23.0.1' 
        compile 'com.android.support:cardview-v7:23.0.1' 
        compile 'com.android.support:palette-v7:23.0.1' 
        compile 'com.android.support:recyclerview-v7:23.0.1' 
        compile 'com.github.lzyzsd:circleprogress:[email protected]' 

        compile 'me.dm7.barcodescanner:zxing:1.8.4' 


        //compile 'com.dlazaro66.qrcodereaderview:qrcodereaderview:1.0.0' 
        /*compile 'com.journeyapps:zxing-android-embedded:[email protected]' 
        compile 'com.journeyapps:zxing-android-legacy:[email protected]' 
        compile 'com.journeyapps:zxing-android-integration:[email protected]' 
        compile 'com.google.zxing:core:3.0.1'*/ 

       } 

回答

0

我正在使用相同的庫,它在6.0和7.0版本的設備上工作正常,但有一些問題與較低版本的設備。我也測試了moto g4在g4和g5上正常工作。

你的代碼是完全正確的我正在做同樣的事情,做一件事來處理它掃描使掃描器視圖單獨的活動,並從handleResult()方法獲取數據,因爲空白屏幕問題導致可能是由於setcontentView覆蓋再次掃描儀view.try這種方式,如果你需要代碼,那麼我也可以分享代碼...

+0

你能分享給我嗎?無論使用什麼設備,我都會遇到白屏問題 – Rekt