title: android scan barcode from camera with google barcode api (what is missing?)
body: <p>in my app dependencies i have</p>
  
  <blockquote>
    <p>compile 'com.google.android.gms:play-services:11.0.4'</p>
  </blockquote>
  
  <p>in manifest file i have </p>
  
  <blockquote>
  <pre><code>&lt;uses-permission android:name="android.permission.CAMERA" /&gt;
  &lt;uses-feature android:name="android.hardware.camera" /&gt;
  &lt;uses-feature android:name="android.hardware.camera.autofocus" /&gt;
  </code></pre>
  </blockquote>
  
  <p>this is my activity_main.xml file</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="cameratest.test.hasan.com.barcodetest.MainActivity"&gt;
  
  
  
  
      &lt;EditText
          android:id="@+id/editText"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:ems="10"
          android:inputType="text"
          android:text="Name"
          android:layout_marginTop="107dp"
          android:layout_marginEnd="39dp" /&gt;
  
      &lt;RelativeLayout
          android:id="@+id/cameraHolder"
          android:layout_width="176dp"
          android:layout_height="144dp"
          android:layout_marginEnd="75dp"
          android:layout_marginTop="74dp"
          android:keepScreenOn="true"&gt;&lt;/RelativeLayout&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>MainActivity.java </p>
  
  <pre><code> public class MainActivity extends AppCompatActivity {
      CameraSurface cameraSurface;
      RelativeLayout relativeLayout;
      EditText etBarkod ;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          etBarkod = (EditText)findViewById(R.id.editText);
          etBarkod.setOnEditorActionListener(new BarkodEditorActionListener(this.getBaseContext()));
          relativeLayout = (RelativeLayout)findViewById(R.id.cameraHolder);
          relativeLayout.setOnTouchListener(new MovingViewListener());
          cameraSurface = new CameraSurface(this.getBaseContext());
          cameraSurface.setBarkodEditText(etBarkod);
          relativeLayout.addView(cameraSurface);
      }
  }
  </code></pre>
  
  <p>and CameraSurface.java class is </p>
  
  <pre><code>    public class CameraSurface extends SurfaceView implements SurfaceHolder.Callback {
      Context context;
      Camera mCamera;
      CameraSource cameraSource;
      SurfaceHolder msurfaceHolder;
      EditText etBarkod;
      public CameraSurface(Context context) {
          super(context);
          super.setKeepScreenOn(true);
          this.context = context;
          RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT);
          super.setLayoutParams(params);
          msurfaceHolder = this.getHolder();
  
          msurfaceHolder.addCallback(this);
          msurfaceHolder.setKeepScreenOn(true);
          msurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
          attachBarcodeDetector();
      }
  
      @Override
      public void surfaceCreated(SurfaceHolder surfaceHolder) {
  
          mCamera = Camera.open(Camera.CameraInfo.CAMERA_FACING_BACK);
  
          try {
              mCamera.setPreviewDisplay(msurfaceHolder);
              mCamera.startPreview();
          } catch (Exception e) {
              e.printStackTrace();
          }
          Camera.Parameters param;
          param = mCamera.getParameters();
          param.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
          param.setPreviewFrameRate(0);
          param.setPreviewSize(176, 144);
          mCamera.setParameters(param);
          try {
              //noinspection MissingPermission
              cameraSource.start(msurfaceHolder);
  
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
      private void attachBarcodeDetector(){
          BarcodeDetector barcodeDetector =
                  new BarcodeDetector.Builder(context)
                          .setBarcodeFormats(Barcode.ALL_FORMATS)
                          .build();
  
      cameraSource = new CameraSource
              .Builder(context, barcodeDetector)
              .setRequestedPreviewSize(176, 144)
              .setAutoFocusEnabled(true)
              .build();
      barcodeDetector.setProcessor(new Detector.Processor&lt;Barcode&gt;() {
          @Override
          public void release() {
  
          }
  
          @Override
          public void receiveDetections(Detector.Detections&lt;Barcode&gt; detections) {
              final EditText barkod= etBarkod;
              final SparseArray&lt;Barcode&gt; barcodes = detections.getDetectedItems();
              if (barcodes.size() != 0) {
                  barkod.post(new Runnable() {    // Use the post method of the TextView
                      public void run() {
                          barkod.setText(    // Update the TextView
                                  barcodes.valueAt(0).displayValue
                          );
                      }
                  });
              }
          }
      });
      }
  
      @Override
      public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {
  
      }
  
      @Override
      public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
          cameraSource.stop();
      }
      public EditText setBarkodEditText(EditText editText){
          return this.etBarkod = editText;
      }
  }
  </code></pre>
  
  <p>Camera works fine , focuses fine supports defined preview size,but barcode detector does not detect barcodes and because of this edittext value does not change .</p>
  
  <p>Note:this code was working perfectly and i dont really know what i have changed but after that it is not working anymore.
  I am trying to understand what is wrong with this code but i cannot figure it out.
  So I need your help.
  thanks in advance.</p>