1

In my android app i am using the camera surface view as the background of the activity.what I want is that the camera should not get closed as soon as I move to another activity.I want camera view behind my each and every layout.But i cant restart the camera view bcoz it takes time to restart the camera.I want to run camera surface view running as the background of the activties.please help.

    Camera camera;
        SurfaceView surfaceView;
        SurfaceHolder surfaceHolder;
        boolean previewing = false;
        LayoutInflater controlInflater = null;

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);        
             setContentView(R.layout.main);

             setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
             getWindow().setFormat(PixelFormat.UNKNOWN);
             surfaceView = (SurfaceView)findViewById(R.id.camerapreview);
             surfaceHolder = surfaceView.getHolder();
             surfaceHolder.addCallback(this);
             surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
             surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

            LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);        
            LinearLayout mainLayout=new LinearLayout(this);
            mainLayout.setOrientation(LinearLayout.VERTICAL);               
            LayoutInflater layoutInflater = getLayoutInflater();        
            mainLayout.addView(layoutInflater.inflate(R.layout.dialpad,null));
            mainLayout.addView(layoutInflater.inflate(R.layout.allbuttons,null));

            this.addContentView(mainLayout, params);
}//end of oncreate method
public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {
        // TODO Auto-generated method stub
        if(previewing){
            camera.stopPreview();
            previewing = false;
        }

        if (camera != null){
            try {
                camera.setPreviewDisplay(surfaceHolder);
                camera.startPreview();
                previewing = true;
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }


    public void surfaceCreated(SurfaceHolder holder) {
        // TODO Auto-generated method stub
        camera = Camera.open();
    }


    public void surfaceDestroyed(SurfaceHolder holder) {
        // TODO Auto-generated method stub
        camera.stopPreview();
        camera.release();
        camera = null;
        previewing = false;


    }

this code i m using to create camera view. Please help me and respond soon.Thanks in advance.

picaso
  • 713
  • 2
  • 14
  • 26

1 Answers1

0

After doing a lot of searching i found the way to do my task.Simply start the camera by using any activity and then start the another activity.make sure that the activity u r starting is the transparent.Apply the transparent theme in android manifest file.The following link helped me to do it in this way. How do I create a transparent Activity on Android?

Community
  • 1
  • 1
picaso
  • 713
  • 2
  • 14
  • 26