Afermin
Afermin

Reputation: 41

Flash camera not working in nexus S and nexus 5, with android 4.4

I have a problem starting the camera on the Nexus S and Nexus 5 devices.

In the console:

  E/SecCamera? ERR(int android::SecCamera::getPreview()):Start Camera Device Reset
  E/CameraHardwareSec? ERR(int android::CameraHardwareSec::previewThread()):Fail on SecCamera-   >getPreview()
  E/SecCamera? initCamera: m_cam_fd(42), m_jpeg_fd(0)
  E/SecCamera? initCamera: m_cam_fd2(43)
  E/CameraHardwareSec? preview window is NULL!

With the following

         Variable declaration:
             public Camera cam;
             public android.hardware.Camera.Parameters p;

         Code:
            if(cam==null){
                cam = Camera.open();
                p = cam.getParameters();
                p.setFlashMode(android.hardware.Camera.Parameters.FLASH_MODE_TORCH);
                cam.setParameters(p);
                cam.startPreview();
            }
            else{
                p.setFlashMode(android.hardware.Camera.Parameters.FLASH_MODE_OFF);
                cam.setParameters(p);
                cam.release();
                cam = null;
            }

     This kind of service understands and implements SensorEventListener.

This works for multiple devices with software 4.4 below. What do I do? Please.

Upvotes: 3

Views: 751

Answers (1)

Tuan
Tuan

Reputation: 84

My solution is: In my activity, implement an SurfaceHolder.Callback and setPreviewDisplay for camera is an SurfaceHolder. In layout add an SurfaceView. My code:

    @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    this.surfaceView = ((SurfaceView) findViewById(R.id.surfaceview));
    this.surfaceHolder = this.surfaceView.getHolder();
    this.surfaceHolder.addCallback(this);
    this.surfaceHolder.setType(3);

}

and then:

    @Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height) {

}

@Override
public void surfaceCreated(SurfaceHolder holder) {
    try {
        this.camera.setPreviewDisplay(holder);
        return;
    } catch (IOException localIOException) {
        localIOException.printStackTrace();
    }
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {

}

Hope useful for you. Sorry if my English is not correct.

Upvotes: 2

Related Questions