Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have implemented a bar code scanner by referring [^]

what i'm trying to acheive is to scan 2 bar codes in a single activity. the code i used is able to the the bar code but is not being able to print the result.

Java
@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
                if (requestCode==0){
            if (result != null) {
                if (result.getContents() == null) {
                    Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
                } else {
                    String scannedValue = result.getContents();
                    parentFirstBarCode.setText(scannedValue);
                    String scannedValueLength = String.valueOf(scannedValue.length());
                    Toast.makeText(getApplicationContext(), "Length of the scanned code:" + scannedValueLength, Toast.LENGTH_SHORT).show();
                    operationsAfterScan(scannedValue);
                }
            } else {
                // This is important, otherwise the result will not be passed to the fragment
                super.onActivityResult(requestCode, resultCode, data);
            }
        }
        if (requestCode==1){
            if (result != null) {
                if (result.getContents() == null) {
                    Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
                } else {
                    String scannedValue = result.getContents();
                    parentSecondBarCode.setText(scannedValue);
                    String scannedValueLength = String.valueOf(scannedValue.length());
                    Toast.makeText(getApplicationContext(), "Length of the scanned code:" + scannedValueLength, Toast.LENGTH_SHORT).show();
                    operationsAfterScan(scannedValue);
                }
            } else {
                // This is important, otherwise the result will not be passed to the fragment
                super.onActivityResult(requestCode, resultCode, data);
            }
        }
    }
Posted
Comments
Richard MacCutchan 21-Dec-15 12:15pm    
What exactly is the problem?
Rahul Ramakrishnan 21-Dec-15 22:34pm    
i have two buttons and two input feilds, where on button click it opens up the built-in scanner. now with the code i have. when scan a code on clicking the first button, the result is populated in both the input feilds. what i want to achieve is when i click on the first scanning button the result must be populated in the first input feild
Richard MacCutchan 22-Dec-15 2:32am    
That is just a description of what you want to do, it does not explain the problem. Where does the scanner send its input, how does your code read that input, and what processing is needed to put it into whichever field you are talking about?
Rahul Ramakrishnan 22-Dec-15 2:59am    
this is the function that triggers the scanning function
scanFirstLabel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
IntentIntegrator integrator = new IntentIntegrator(Parent1Scan.this);
integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);
integrator.setPrompt("Scan a barcode or QR Code");
integrator.setCameraId(0); // Use a specific camera of the device
integrator.setBeepEnabled(false);
integrator.setBarcodeImageEnabled(true);
integrator.addExtra(FIRST, 1);
integrator.initiateScan();
//setResult(RESULT_OK, integrator.createScanIntent());
}
});
i am getting the scan result in the variable 'scanedValue' but the value is not being displayed
Xiao Ling 14-Mar-16 2:00am    
Can you get the barcode result? Is your question about how to correctly read multiple barcodes or how to display text? Which line of your code has problem?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900