title: Custom camera android
body: <p>I want to use <code>camera preview</code> in an activity. I want to add images(transparent frames on surface view). I tried following code so that i can easily customize the xml layout desirably:</p>
  
  <pre><code>package com.demo;
  
  
  import java.io.IOException;
  
  import android.app.Activity;
  import android.graphics.PixelFormat;
  import android.hardware.Camera;
  import android.os.Bundle;
  import android.view.SurfaceHolder;
  import android.view.SurfaceView;
  import android.widget.Toast;
  
  public class CameraDemoActivity extends Activity implements SurfaceHolder.Callback{
      /** Called when the activity is first created. */
       Camera camera;
       SurfaceView surfaceView;
       SurfaceHolder surfaceHolder;
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          getWindow().setFormat(PixelFormat.UNKNOWN);
          surfaceView = (SurfaceView)findViewById(R.id.surfaceview);
          surfaceHolder = surfaceView.getHolder();
          surfaceHolder.addCallback(this);
          surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
          camera = Camera.open();
          if(camera!=null){
  
              try {
               camera.setPreviewDisplay(surfaceHolder);
               camera.startPreview();
              } catch (IOException e) {
               Toast.makeText(this, (CharSequence) e, Toast.LENGTH_LONG).show();
              }
  
          }
  
  
      }
  
      @Override
      public void surfaceChanged(SurfaceHolder holder, int format, int width,
              int height) {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public void surfaceCreated(SurfaceHolder holder) {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public void surfaceDestroyed(SurfaceHolder holder) {
          // TODO Auto-generated method stub
  
      }
  }
  </code></pre>
  
  <p>Here is my manifest:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.demo"
        android:versionCode="1"
        android:versionName="1.0"&gt;
      &lt;uses-sdk android:minSdkVersion="8" /&gt;
  
      &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;
          &lt;activity android:name=".CameraDemoActivity"
                    android:label="@string/app_name" android:screenOrientation="portrait"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
      &lt;/application&gt;
      &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;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>And here is my layout:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      &gt;
  &lt;SurfaceView 
  android:id="@+id/surfaceview"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Dont know why preview of <code>camera</code> is not displaying?</p>