title: How can I find the distance from an object to my android device
body: <p>I want find the distance from an object to my android device.</p>
  
  <p>I want to use camera or sensors but I don't know how to use them.</p>
  
  <p>Thanks for help.</p>
  
  <p>Hear is my code but it does not give correct values </p>
  
  <pre><code>  ..........
  cam=Camera.open();
  Camera.Parameters pa=cam.getParameters();
  pa.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
  cam.setParameters(pa);
  cam.startPreview();
  cam.autoFocus(this);
  ..........
  
  
  @Override
  public void onAutoFocus(boolean arg0, Camera arg1) {
      // TODO Auto-generated method stub
          float f[]=new float[3];
          arg1.getParameters().getFocusDistances(f);
          text.setText(""+f[1]);  //Always returns 1.2
          t2.setText(""+f[0]);    //Always returns .15
          t3.setText(""+f[2]);    //Always returns Infinity
  
      }
  </code></pre>