How to trigger bulk mode scan in zxing

本小妞迷上赌 提交于 2019-11-30 22:22:07

There is no concept of "bulk mode" within zxing I don't think.

You can certainly implement the behavior that you are looking for though with zxing inside your own application. Use the code that you already have in your question to kick of Scanning for the first time. Add this declaration to your class:

ArrayList<String> results;

Then add this inside onCreate before you start scanning to initialize it:

results = new ArrayList<String>();

Inside your onActivityResult() you can add the current result to your ArrayList and then start the next scan.

/*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.
        }
    }
}

Saving them to a CSV file is beyond the scope of this specific question, but If you look around you can find examples of how to do it. Consider it left blank as an exercise for you to learn from.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!