使用zxing扫描意图传递额外数据

时间:2018-03-15 21:42:53

标签: java android zxing

我正在使用https://github.com/zxing集成条形码扫描仪。我想传递一些额外的数据 - uuid以及条形码。

以下uuid1uuid2都会产生null。我错过了什么?

public void startScanner(String uuid){
    IntentIntegrator integrator = new IntentIntegrator(this);

    integrator.setDesiredBarcodeFormats(IntentIntegrator.PRODUCT_CODE_TYPES);
    integrator.setPrompt("");
    integrator.setCameraId(0);
    integrator.setBeepEnabled(false);

    Intent intent = integrator.createScanIntent();
    intent.putExtra("uuid", uuid);

    startActivityForResult(intent, IntentIntegrator.REQUEST_CODE);
}

public void onActivityResult(int requestCode, int resultCode, Intent intent) 
{
    IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
    if (scanResult != null) {
        String code = scanResult.getContents();
        JSONObject json = new JSONObject();
        try {
            String uuid1 = intent.getStringExtra("uuid");
            String uuid2 = intent.getExtras().getString("uuid");

            json.put("uuid", uuid1);
            json.put("barCode", code);
            this.webViewManager.runScript("startScannerCallback", json);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

0 个答案:

没有答案