ZXing扫描意图

时间:2015-01-20 16:01:29

标签: android zxing onactivityresult

我将Zxing库添加到我的项目中。它运行良好但我没有收到扫描结果 MainActivity (扫描成功时,它没有返回 MainActivity ,只是在 capture.xml 上显示结果,我做错了什么?

MainActivity:

public void onActivityResult(int requestCode, int resultCode, Intent i) {
    onActivityResult(requestCode, resultCode, i);
    String contents = null;

    if (requestCode == 1) {

        if (resultCode == RESULT_OK) {
            contents = i.getStringExtra("SCAN_RESULT");
            String format = i.getStringExtra("SCAN_RESULT_FORMAT");
            TextView tv = (TextView) findViewById(R.id.textView);
            tv.setText(contents);
            // Handle successful scan
        } else if (resultCode == RESULT_CANCELED) {
            // Handle cancel
        }
    }
}

public void onCapture(View view) {
    Intent i=new Intent(this, CaptureActivity.class);
    i.putExtra("SCAN_MODE","QR_CODE_MODE");
    startActivityForResult(i,1);


}

}

1 个答案:

答案 0 :(得分:1)

试试:

Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "ONE_D_MODE");
intent.putExtra("SCAN_FORMATS", "CODE_39,CODE_93,CODE_128,DATA_MATRIX,ITF,CODABAR,EAN_13,EAN_8,UPC_A,QR_CODE");
startActivityForResult(intent,1);