title: How to capture barcode values using the new Barcode API in Google Play Services?
body: <p>I've been playing with the sample code from the new Google Barcode API.  It overlays a box and the barcode value over the live camera feed of a barcode.  (Also faces)</p>
  
  <p>I can't tell how to return a barcode value to my app.  A) How to tell when a detection event has occurred and B) how to access the ravValue for use in other parts of my app.  Can anyone help with this?</p>
  
  <p><a href="https://developers.google.com/vision/multi-tracker-tutorial">https://developers.google.com/vision/multi-tracker-tutorial</a></p>
  
  <p><a href="https://github.com/googlesamples/android-vision">https://github.com/googlesamples/android-vision</a></p>
  
  <p><strong>UPDATE:</strong>
  Building on @pm0733464's answer, I added a callback interface (called onFound) to the Tracker class that I could access in the Activity. Adapting the Google multi-tracker sample:</p>
  
  <p><strong>GraphicTracker</strong>:</p>
  
  <pre><code>class GraphicTracker&lt;T&gt; extends Tracker&lt;T&gt; {
      private GraphicOverlay mOverlay;
      private TrackedGraphic&lt;T&gt; mGraphic;
      private Callback mCallback;
  
      GraphicTracker(GraphicOverlay overlay, TrackedGraphic&lt;T&gt; graphic, Callback callback) {
          mOverlay = overlay;
          mGraphic = graphic;
          mCallback = callback;
      }
  
      public interface Callback {
          void onFound(String barcodeValue);
      }
  
      @Override
      public void onUpdate(Detector.Detections&lt;T&gt; detectionResults, T item) {
          mCallback.onFound(((Barcode) item).rawValue);
          mOverlay.add(mGraphic);
          mGraphic.updateItem(item);
      }
  </code></pre>
  
  <p><strong>BarcodeTrackerFactory</strong> :</p>
  
  <pre><code>class BarcodeTrackerFactory implements MultiProcessor.Factory&lt;Barcode&gt; {
      private GraphicOverlay mGraphicOverlay;
      private GraphicTracker.Callback mCallback;
  
      BarcodeTrackerFactory(GraphicOverlay graphicOverlay, GraphicTracker.Callback callback) {
          mGraphicOverlay = graphicOverlay;
          mCallback = callback;
      }
  
      @Override
      public Tracker&lt;Barcode&gt; create(Barcode barcode) {
          BarcodeGraphic graphic = new BarcodeGraphic(mGraphicOverlay);
          return new GraphicTracker&lt;&gt;(mGraphicOverlay, graphic, mCallback);
      }
  }
  </code></pre>
  
  <p><strong>Main Activity:</strong></p>
  
  <pre><code>BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context).build();
  BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(mGraphicOverlay, new GraphicTracker.Callback() {
      @Override
      public void onFound(String barcodeValue) {
          Log.d(TAG, "Barcode in Multitracker = " + barcodeValue);
      }
  });
  MultiProcessor&lt;Barcode&gt; barcodeMultiProcessor = new MultiProcessor.Builder&lt;&gt;(barcodeFactory).build();
  barcodeDetector.setProcessor(barcodeMultiProcessor);
  </code></pre>