Pass extra data with zxing scanning intent

耗尽温柔 提交于 2021-02-10 18:17:37

问题


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

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