0

I am using following code to turn on camera flashlight

public Flashlight(SurfaceView preview, Context context){
    this.preview = preview;
    this.context = context;
    mHolder = preview.getHolder();
    mHolder.addCallback(this);
    mCamera = Camera.open();
    cameraOpened = true;
    try {
        mCamera.setPreviewDisplay(mHolder);
    }catch (Exception e){
        e.printStackTrace();
    }
    params = mCamera.getParameters();
    mCamera.startPreview();
}
private void turnOnFlashlight(){
    params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
    mCamera.setParameters(params);
}
private void turnOffFlashlight(){
    params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
    mCamera.setParameters(params);
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
    mHolder = holder;
    try {
        mCamera.setPreviewDisplay(mHolder);
    }catch(Exception e){
        e.printStackTrace();
    }
}

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

}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    mHolder = null;
}

it uses surface view and it works great on many phones however I cant get it to work on galaxy S3. Have you experienced similary problems? Any ideas how to get it working on S3?

Thanks in forward

fadden
  • 51,356
  • 5
  • 116
  • 166
horin
  • 1,664
  • 6
  • 23
  • 52
  • Why does a flashlight need a surface view ? You just need to turn on flash using FLASH_MODE_TORCH. – inmyth Jun 18 '15 at 03:35
  • surface view is far better solution which works on most devices. There are big problems with flash_mode_torch here is reference http://stackoverflow.com/questions/8876843/led-flashlight-on-galaxy-nexus-controllable-by-what-api/9379765#9379765 – horin Jun 18 '15 at 04:20

0 Answers0