2

I am trying to create a custom camera app in which I need to switch between the front and back facing camera. So is it mandatory to create new camera instance every time for the type of camera-id to make it work? I have tried setting in camera-id to camera properties but it does not seem to work. Is there any other way to do this without re-instantiating the camera instance?

Michael Celey
  • 12,645
  • 6
  • 57
  • 62
nilMoBile
  • 1,932
  • 4
  • 15
  • 20
  • Look at the code in the link posted in the answer for verification, switching id will work – Jibran Khan Mar 26 '13 at 11:48
  • hi have a look at this. if (Camera.getNumberOfCameras() > 1) { mCamera = Camera.open(CameraInfo.CAMERA_FACING_FRONT); } else { mCamera = Camera.open(); } – itsrajesh4uguys Mar 26 '13 at 13:31

1 Answers1

0

Restart the activity and change the camera id to 2 for switching to back camera and 1 for front i guess. Referenced from here

 @Override
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.photo_camera_main);
    prepareActivity(); 
 }

 private void prepareActivity() {
    cameraView = (SurfaceView) findViewById(R.id.photo_camera_surface_view);
    turnButton = (ImageButton) findViewById(R.id.turn_button);
    turnButton.setOnClickListener(this);
 }

 @Override
 public void onClick(View v) {
    if (v.equals(turnButton)) {
       if (Camera.getNumberOfCameras() > 1 && camId < Camera.getNumberOfCameras() - 1){
          startCamera(camId + 1);
    } else {
        startCamera(Camera.CameraInfo.CAMERA_FACING_BACK);
    }
 }
Community
  • 1
  • 1
Jibran Khan
  • 3,236
  • 4
  • 37
  • 50