问题
I'm integrating a barcode scanner using https://github.com/zxing. I would like to pass some additional data - uuid
below - along with the barcode.
Both uuid1
and uuid2
below yields null
. WHat am I missing?
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();
}
}
}
来源:https://stackoverflow.com/questions/49309732/pass-extra-data-with-zxing-scanning-intent