Zbar Qr Code Reader - 在qr代码阅读器后崩溃

时间:2013-10-29 13:03:14

标签: java android zbar-sdk

我正在尝试使用Zbar执行Qr代码阅读器,但在Qr代码检测后应用程序崩溃(当结果!= 0时)

我没有收到错误消息,只是警告:

  

检查表面信息creation = false formatChanged = false   sizeChanged = false visible = false visibleChanged = true   surfaceChanged = true realSizeChanged = false redrawNeeded = false   left = false top = false

这是我遇到崩溃的代码

public void onPreviewFrame(byte[] data, Camera camera) {
        Camera.Parameters parameters = camera.getParameters();
        Camera.Size size = parameters.getPreviewSize();

        Image barcode = new Image(size.width, size.height, "Y800");
        barcode.setData(data);

        int result = mScanner.scanImage(barcode);

        if (result != 0) {
            mCamera.cancelAutoFocus();
            mCamera.setPreviewCallback(null);
            mCamera.stopPreview();
            mPreviewing = false;
            SymbolSet syms = mScanner.getResults();
            for (Symbol sym : syms) {
                String symData = sym.getData();
                if (!TextUtils.isEmpty(symData)) {
                    Intent dataIntent = new Intent();
                    dataIntent.putExtra(SCAN_RESULT, symData);
                    dataIntent.putExtra(SCAN_RESULT_TYPE, sym.getType());
                    setResult(Activity.RESULT_OK, dataIntent);
                    finish();
                    break;
                }
            }
        }
    }

2 个答案:

答案 0 :(得分:0)

尝试这个......为Qr Reader ....

public class QRCodeActivityTest extends Activity implements OnQRCodeReadListener {

QRCodeReaderView qrView;
TextView tvQr;
Image_Sql sql;
String Description;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.qrtest_layout);
    qrView = (QRCodeReaderView) findViewById(R.id.qRCodeReaderView1);
    qrView.setOnQRCodeReadListener(this);
    tvQr = (TextView) findViewById(R.id.txtqr);
    sql= new Image_Sql(this);
    sql.Open();
}

@Override
public void onQRCodeRead(String text, PointF[] points) {
    // TODO Auto-generated method stub
    Cursor desc = sql.fetchNameFromTitle(text);
    while (desc.moveToNext()) {
        Description = desc.getString(desc
                .getColumnIndexOrThrow(Image_Sql.IMAGE_DESCRIPTION));
    }
    if(text.equals(""))
    {
        Dialog d = new Dialog(this);
        TextView tv = new TextView(this);
        tv.setText("Please Sync Catalogue TO Display QRCode Image Information");
        d.setContentView(tv);
        d.setTitle("Required Syncing..");
        d.show();
    }else
    {
     tvQr.setText(Description);
    }
}

@Override
public void cameraNotFound() {
    // TODO Auto-generated method stub

}

@Override
public void QRCodeNotFoundOnCamImage() {
    // TODO Auto-generated method stub

}

@Override
protected void onResume() {
    super.onResume();
    qrView.getCameraManager().startPreview();
}

@Override
protected void onPause() {
    super.onPause();
    qrView.getCameraManager().stopPreview();
}

}

答案 1 :(得分:0)

我确实更新了我的代码,效果很好!全部!

  public void onPreviewFrame(byte[] data, Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    Camera.Size size = parameters.getPreviewSize();

    Image barcode = new Image(size.width, size.height, "Y800");
    barcode.setData(data);

    int result = mScanner.scanImage(barcode);

    if (result != 0) {
        mCamera.cancelAutoFocus();
        mCamera.setPreviewCallback(null);
        mCamera.stopPreview();
        mPreviewing = false;
        SymbolSet syms = mScanner.getResults();
        for (Symbol sym : syms) {
            String symData = sym.getData();
           Log.i("url qr code",symData);
           Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(symData));
           startActivity(browserIntent);

                break;   
        }
    }
}