title: QR Code Scanner , receiveDetections method
body: <p>this is my code and work perfectly</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  private CameraSource cameraSource;
  private SurfaceView cameraView;
  private final int MY_PERMISSIONS_REQUEST_CAMERA = 1;
  private String token = "";
  private String tokenanterior = "";
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      cameraView = (SurfaceView) findViewById(R.id.camera_view);
      initQR();
  }
  
  public void initQR() {
  
      // creo el detector qr
      BarcodeDetector barcodeDetector =
              new BarcodeDetector.Builder(this)
                      .setBarcodeFormats(Barcode.ALL_FORMATS)
                      .build();
  
  
      cameraSource = new CameraSource
              .Builder(this, barcodeDetector)
              .setRequestedPreviewSize(1600, 1024)
              .setAutoFocusEnabled(true) //you should add this feature
              .build();
  
  
      cameraView.getHolder().addCallback(new SurfaceHolder.Callback() {
          @Override
          public void surfaceCreated(SurfaceHolder holder) {
  
  
              if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA)
                      != PackageManager.PERMISSION_GRANTED) {
  
                  if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M) {
  
                      if (shouldShowRequestPermissionRationale(
                              Manifest.permission.CAMERA)) ;
                      requestPermissions(new String[]{Manifest.permission.CAMERA},
                              MY_PERMISSIONS_REQUEST_CAMERA);
                  }
                  return;
              } else {
                  try {
                      cameraSource.start(cameraView.getHolder());
                  } catch (IOException ie) {
                      Log.e("CAMERA SOURCE", ie.getMessage());
                  }
              }
          }
  
          @Override
          public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
          }
  
          @Override
          public void surfaceDestroyed(SurfaceHolder holder) {
              cameraSource.stop();
          }
      });
  
      // preparo el detector de QR
      barcodeDetector.setProcessor(new Detector.Processor&lt;Barcode&gt;() {
          @Override
          public void release() {
          }
  
  
          @Override
          public void receiveDetections(Detector.Detections&lt;Barcode&gt; detections) {
              final SparseArray&lt;Barcode&gt; barcodes = detections.getDetectedItems();
  
              if (barcodes.size() &gt; 0) {
  
                  // get token
                  token = barcodes.valueAt(0).displayValue.toString();
  
  
  
                  if (!token.equals(tokenanterior)) {
  
                      //save last token procesed
                      tokenanterior = token;
                      Log.i("token", token);
  
                      if (URLUtil.isValidUrl(token)) {
                          // if is a URL open browser
                          Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(token));
                          startActivity(browserIntent);
                      } else {
                          // share with other apps
                          Intent shareIntent = new Intent();
                          shareIntent.setAction(Intent.ACTION_SEND);
                          shareIntent.putExtra(Intent.EXTRA_TEXT, token);
                          shareIntent.setType("text/plain");
                          startActivity(shareIntent);
                      }
  
                      new Thread(new Runnable() {
                          public void run() {
                              try {
                                  synchronized (this) {
                                      wait(5000);
                                      // clear token
                                      tokenanterior = "";
                                  }
                              } catch (InterruptedException e) {
                                  // TODO Auto-generated catch block
                                  Log.e("Error", "Waiting didnt work!!");
                                  e.printStackTrace();
                              }
                          }
                      }).start();
  
                  }
              }
          }
      });
  
  }
  
  }
  </code></pre>
  
  <p>but I can not do anything else within the code, for example i added a toast here:</p>
  
  <pre><code>   if (URLUtil.isValidUrl(token)) {
                          // si es una URL valida abre el navegador
                          Intent browserIntent = new 
  Intent(Intent.ACTION_VIEW, Uri.parse(token));
                          startActivity(browserIntent);
                      } else {
                          // comparte en otras apps
                          //EnviarCodigo(token);
                          Toast.makeText(getApplicationContext(),"Se registró correctamente",Toast.LENGTH_SHORT).show();
                          Intent shareIntent = new Intent();
                          shareIntent.setAction(Intent.ACTION_SEND);
                          shareIntent.putExtra(Intent.EXTRA_TEXT, token);
                          shareIntent.setType("text/plain");
                          startActivity(shareIntent);
                      }
  </code></pre>
  
  <p>The toast dont show and the app dont share QR code with other apps, or for example i added a toast here:</p>
  
  <pre><code>@Override
          public void receiveDetections(Detector.Detections&lt;Barcode&gt; detections) {
              final SparseArray&lt;Barcode&gt; barcodes = detections.getDetectedItems();
  
              if (barcodes.size() &gt; 0) {
  
                  // get token
                  token = barcodes.valueAt(0).displayValue.toString();
                  Toast.makeText(getApplicationContext(),"Se registró correctamente",Toast.LENGTH_SHORT).show();
  </code></pre>
  
  <p>and the app does not work either. What am I doing wrong? Help me please.</p>
  
  <p>Source code: <a href="http://www.desarrollolibre.net/blog/tema/267/android/como-crear-un-lector-de-codigos-qr-en-android-con-android-studio#.WftoDteWZPY" rel="nofollow noreferrer">http://www.desarrollolibre.net/blog/tema/267/android/como-crear-un-lector-de-codigos-qr-en-android-con-android-studio#.WftoDteWZPY</a></p>