Oxigen One Plus 3和Galaxy S7上的ZXing黑屏

时间:2017-10-04 20:49:30

标签: android zxing

我正在使用ZXing API读取条形码,但出于某种原因,当我尝试在Oxigen One Plus 3或Samsung Galaxy S7中打开扫描仪时,它只会打开黑屏。我在三星Galaxy S4迷你思想中工作得很好。

我正在使用' me.dm7.barcodescanner:zxing:1.9.8',但也尝试了1.5版。

有关黑屏可能出现的情况的任何想法吗?

这是我的代码:

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.os.Bundle;

import com.google.zxing.Result;

import me.dm7.barcodescanner.zxing.ZXingScannerView;

public class ScanBarCodeActivity extends Activity implements ZXingScannerView.ResultHandler {
private ZXingScannerView zXingScannerView;

@Override
public void onCreate(Bundle state) {
    super.onCreate(state);

    this.zXingScannerView = new ZXingScannerView(this);
    setContentView(zXingScannerView);
}

@Override
public void onResume() {
    super.onResume();

    zXingScannerView.setResultHandler(this);
    zXingScannerView.startCamera();
    zXingScannerView.setAutoFocus(true);
}

@Override
public void handleResult(Result result) {
    String barCode = result.getText();
    Intent returnIntent = new Intent();
    returnIntent.putExtra("BAR_CODE_RESULT", barCode);
    returnIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    setResult(Activity.RESULT_OK,returnIntent);
    finish();
}

@Override
public void onPause() {
    super.onPause();
    zXingScannerView.stopCamera();
}

@Override
public void onBackPressed() {
    Intent returnIntent = new Intent(ScanBarCodeActivity.this, MyActivity.class);
    returnIntent.putExtra("BAR_CODE_RESULT", "");
    returnIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    startActivity(returnIntent);
    finish();
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
}

@Override
public void onDestroy() {
    super.onDestroy();
}}

0 个答案:

没有答案