无法捕获条码扫描结果

Unable to capture barcode scan results

我正在使用 Zxing 库扫描项目并存储结果。当我扫描时,扫描结果(一组数字)暂时显示在条形码扫描器上,但是当我尝试通过 Toast 捕获并显示它以进行测试时,它 returns 为空。

//this method occurs when I click a button
final String ZXING_SCAN = "com.google.zxing.client.android.SCAN";
public void scanItem(View view){
        try {
            //works. able to activate the barcode scanner. 
            i = new Intent(ZXING_SCAN);
            i.putExtra("SCAN_MODE", "PRODUCT_MODE");
            startActivityForResult(i, 0);
        } catch (ActivityNotFoundException e) {
            e.printStackTrace();
        }
    }

//Using this method to capture the scan result. The toast prints out null for both values.
 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if(requestCode == 0){
            if(resultCode == RESULT_OK){
                String content = i.getStringExtra("SCAN_RESULT");
                String format = i.getStringExtra("SCAN_RESULT_FORMAT");

                //This is he toast that shows null for both. 
                Toast.makeText(getApplicationContext(), "Content: " + content + ", Format: " + format, Toast.LENGTH_LONG).show();
            }
            else {
                //Toast.makeText(getApplicationContext(), "Barcode not working...", Toast.LENGTH_LONG).show();
            }
        }
    }

而不是

String content = i.getStringExtra("SCAN_RESULT");  
String format = i.getStringExtra("SCAN_RESULT_FORMAT"); 

在你的 onActivityResult 中尝试

String content = data.getStringExtra("SCAN_RESULT");
String format = data.getStringExtra("SCAN_RESULT_FORMAT");