2016-05-14 45 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