I use the following code to turn the LED flashlight on and off:
public Flashlight(SurfaceView preview, Context context){ this.preview = preview; this.context = context; mHolder = preview.getHolder(); //mHolder is surfaceHolder mHolder.addCallback(this); try { mCamera = Camera.open(); params = mCamera.getParameters(); mCamera.setPreviewDisplay(mHolder); mCamera.startPreview(); //AUTOFOCUS LASER FIX ON LG G3 List<String> focusModes = params.getSupportedFocusModes(); if (focusModes.contains(params.FOCUS_MODE_INFINITY)) { params.setFocusMode(params.FOCUS_MODE_INFINITY); } else{ if (focusModes.contains(params.FOCUS_MODE_FIXED)) params.setFocusMode(params.FOCUS_MODE_FIXED); } mCamera.setParameters(params); cameraOpened = true; }catch (Exception e){ cameraOpened = false; e.printStackTrace(); } } private void turnOnFlashlight(){ flashlightOn = true; params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); mCamera.setParameters(params); } private void turnOffFlashlight(){ flashlightOn = false; params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF); mCamera.setParameters(params); }
It works great on most phones, but I can't get it to work with xperia Z5. I do not have Z5 for testing, so I only know this from the user's response. Therefore, I would like to ask if there is any other (preferably working) way to turn on the flashlight on the Xperia Z5.
Thanks in advance
horin source share