0

So here is my problem, when i try to open the camera from my fragment i get the error "Failed to connect to camera service"

right now i have the Camera.open() on onResume() and Camera.release on onPause() and it doesn't work.

if i put the release in the same method with the open it works fine!!!!

this doesn't work

@Override
public void onResume() {
    super.onResume();
    Log.v("this", "camera on resume ");

    camera = Camera.open();
    Camera.Parameters params = camera.getParameters();
    params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
    camera.setParameters(params);

}

@Override
public void onPause() {
    super.onPause();
    Log.v("this", "camera on pause ");
    if (inPreview) {
        camera.stopPreview();
    }

    camera.release();
    camera = null;
    inPreview = false;

}

this works (don't get an error)

@Override
public void onResume() {
    super.onResume();
    Log.v("this", "camera on resume ");

    camera = Camera.open();
    Camera.Parameters params = camera.getParameters();
    params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
    camera.setParameters(params);

    camera.release();
}

what should I do to make this work??

Alex Fragotsis
  • 1,248
  • 18
  • 36
  • Added `` and `` in your AndroidManifest.xml ? – pRaNaY Jan 26 '16 at 17:19
  • Need to check [this](http://stackoverflow.com/questions/12054022/camera-open-returns-null) , [this](http://stackoverflow.com/questions/8262197/android-error-while-camera-open) , [this](http://stackoverflow.com/questions/7942378/android-camera-will-not-work-startpreview-fails) – pRaNaY Jan 26 '16 at 17:21
  • @pRaNaY I have all the permissions , i tried with Camera.open(0) still nothing, also if i create the camera object on the parent activity and pass it to the child activity it works fine..... :/ :/ – Alex Fragotsis Jan 26 '16 at 17:26
  • 1
    This doesn't make sense. There is no way `Camera.open()` can know that `camera.release()` will be called in the same method or not. Maybe, you get the RuntimeException when `onResume()` is called for the second time? What does your logcat show? – Alex Cohn Jan 26 '16 at 21:28
  • ok so i guess it was the second time that onResume() was called, so I added if (camera == null) { camera = Camera.open(); } and i don't get an error, which is weird because I've tried the same statement yesterday and it wasn't working :/ – Alex Fragotsis Jan 28 '16 at 12:27

0 Answers0