title: Android - Camera Preview
body: <p>i'm trying the camera preview</p>
  
  <p>This is my code and it doesn't throw any error, but the screen is still black.  Any ideas?</p>
  
  <pre><code>this.setContentView(R.layout.camerapreview);    
  SurfaceView cameraSurface = (SurfaceView)findViewById(R.id.cpPreview);
  SurfaceHolder holder = cameraSurface.getHolder();
  holder.addCallback(this);
  holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  this.camera = Camera.open();
  this.camera.setPreviewDisplay(holder);
  this.camera.startPreview();
  </code></pre>
  
  <p>camerapreview.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"&gt;
      &lt;SurfaceView
          android:id="@+id/cpPreview"
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content"
          android:layout_gravity="center"&gt;
  
      &lt;/SurfaceView&gt;
  &lt;/LinearLayout&gt;
  </code></pre>