Click here to Skip to main content
15,797,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i went throght this web site[^] 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
IntentIntegrator integrator = new IntentIntegrator(MainActivity.this);
               integrator.setPrompt("Scan a barcode or QR Code");
               integrator.setCameraId(0);  // Use a specific camera of the device

in onActivityResult
    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
Error:(50, 52) error: package does not exist

i have imported the following library into my gradle file

compile ''
    compile 'com.journeyapps:zxing-android-embedded:3.0.3@aar'

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

1 solution

Try in this way:
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