扫描多个条形码而不会丢失相机屏幕

时间:2014-06-23 17:16:38

标签: android android-intent zxing barcode-scanner

我目前正在尝试让ZXing库扫描一些条形码。它目前通过Intent工作正常

现在我想让它一次解码多个条形码而无需单独扫描每个条形码。

任何样本都将受到赞赏。这就是我当前代码的样子。

MainActivity:

public class MainActivity extends Activity implements OnClickListener {

public int SCANNER_REQUEST_CODE = 123;

TextView tvScanResults;
Button btnScan;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    initViews();
}

private void initViews() {
    tvScanResults = (TextView) findViewById(R.id.tvResults);
    btnScan = (Button) findViewById(R.id.btnScan);
    btnScan.setOnClickListener(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {

    if (requestCode == SCANNER_REQUEST_CODE) {
        // Handle scan intent
        if (resultCode == Activity.RESULT_OK) {
            // Handle successful scan
            String contents = intent.getStringExtra("SCAN_RESULT");
            String formatName = intent.getStringExtra("SCAN_RESULT_FORMAT");
            byte[] rawBytes = intent.getByteArrayExtra("SCAN_RESULT_BYTES");
            int intentOrientation = intent.getIntExtra("SCAN_RESULT_ORIENTATION", Integer.MIN_VALUE);
            Integer orientation = (intentOrientation == Integer.MIN_VALUE) ? null : intentOrientation;
            String errorCorrectionLevel = intent.getStringExtra("SCAN_RESULT_ERROR_CORRECTION_LEVEL");

            tvScanResults.setText(contents + "\n\n" + formatName);

        } else if (resultCode == Activity.RESULT_CANCELED) {
            // Handle cancel
        }
    } else {
        // Handle other intents
    }

}

@Override
public void onClick(View v) {
    if (v.getId() == R.id.btnScan) {
        // go to fullscreen scan
        Intent intent = new Intent("com.google.zxing.client.android.SCAN");
        intent.putExtra("SCAN_MODE", "SCAN_MODE");
        startActivityForResult(intent, SCANNER_REQUEST_CODE);
    }
}

}

1 个答案:

答案 0 :(得分:0)

我无法找到激活批量模式的方法,但请查看此项目:

https://code.google.com/p/android-quick-response-code/

我刚刚将源代码导入到我的项目中并从那里开始。