我读到有一个键可以在zxing中启用批量模式扫描.我可以知道如何在Android应用程序中启用此密钥?
我目前正在使用此类代码单独扫描条形码:
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_FORMATS", "PRODUCT_MODE,CODE_39,CODE_93,CODE_128,DATA_MATRIX,ITF");
startActivityForResult(intent, 0); // start the scan
谢谢!
解决方法:
zxing中没有“批量模式”的概念我不认为.
您可以使用zxing在您自己的应用程序中实现您正在寻找的行为.使用您在问题中已有的代码首次启动扫描.将此声明添加到您的班级:
ArrayList<String> results;
然后在开始扫描初始化之前在onCreate中添加:
results = new ArrayList<String>();
在onActivityResult()中,您可以将当前结果添加到ArrayList,然后开始下一次扫描.
/*Here is where we come back after the Barcode Scanner is done*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
// contents contains whatever the code was
String contents = intent.getStringExtra("SCAN_RESULT");
// Format contains the type of code i.e. UPC, EAN, QRCode etc...
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan. In this example add contents to ArrayList
results.add(contents);
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_FORMATS", "PRODUCT_MODE,CODE_39,CODE_93,CODE_128,DATA_MATRIX,ITF");
startActivityForResult(intent, 0); // start the next scan
} else if (resultCode == RESULT_CANCELED) {
// User hass pressed 'back' instead of scanning. They are done.
saveToCSV(results);
//do whatever else you want.
}
}
}
将它们保存为CSV文件超出了此特定问题的范围,但如果您环顾四周,可以找到如何执行此操作的示例.考虑它留空作为练习供你学习.