Click here to Skip to main content
15,885,933 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i went throght this web site https://github.com/journeyapps/zxing-android-embedded[^] and have implemented a barcode scanner. but i am not able to fetch the value after it has been scanned

the code i used to implement the scanner is as follows
Java
IntentIntegrator integrator = new IntentIntegrator(MainActivity.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(key,value);
               integrator.initiateScan();


in onActivityResult
Java
@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
        if(result != null) {
            if(result.getContents() == null) {
                Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
            }
        } else {
            // This is important, otherwise the result will not be passed to the fragment
            super.onActivityResult(requestCode, resultCode, data);
        }

    }


on running the app i get an error
C#
Error:(50, 52) error: package com.google.zxing.client.androidlegacy.camera does not exist


i have imported the following library into my gradle file

JavaScript
compile 'com.google.zxing:core:3.2.0'
    compile 'com.journeyapps:zxing-android-embedded:3.0.3@aar'



now how do i fetch the scan value? please guide me to achieve this
Posted
Updated 29-Nov-15 21:44pm
v2
Comments
Richard MacCutchan 30-Nov-15 4:37am    
You need to check the documentation for this library.

1 solution

Try in this way:
Java
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
   if (requestCode == 0) {
      if (resultCode == RESULT_OK) {
         String contents = intent.getStringExtra("SCAN_RESULT");
         String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
         // Handle successful scan
      } else if (resultCode == RESULT_CANCELED) {
         // Handle cancel
      }
   }
}

Check :
Integrate zxing barcode scanner into your Android app[^]
Integration ZXing library directly into my Android application[^]
 
Share this answer
 

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