App is working fine in four different devices. but client is facing crash on flash buttton ON/OFF on Xperia z2.
Mai
At the request of muku. I answered it my self. for toggling flash
flashBtn.setOnClickListener(new OnClickListener()
{
@Override
public onClick(View view)
{
if(cameraView!=null)//cameraView is the CameraPreview.class
{
if(cameraView.isFlashOn() && isFlashRunning)
{
cameraView.FlashOff(camera);
isFlashRunning = false;
}
else
{
cameraView.FlashOn(camera);
isFlashRunning = true;
}
}
});
And FlashOn and FlashOff methods are
public void FlashOn(Camera mCamera) throws RemoteException
{
// Get Camera Params for customisation
Camera.Parameters parameters = mCamera.getParameters();
// Check Whether device supports AutoFlash, If you YES then set
// AutoFlash
List flashModes = parameters.getSupportedFlashModes();
if (flashModes.contains(android.hardware.Camera.Parameters.FLASH_MODE_TORCH))
{
parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
isFlashOn = true;
}
else if (flashModes.contains(Parameters.FLASH_MODE_ON))
{
parameters.setFlashMode(Parameters.FLASH_MODE_ON);
isFlashOn = true;
}
mCamera.setParameters(parameters);
mCamera.startPreview();
//mCamera.autoFocus(null); // may be this is problem
}
public void FlashOff(Camera mCamera) throws RemoteException
{
// Get Camera Params for customisation
Camera.Parameters parameters = mCamera.getParameters();
// Check Whether device supports AutoFlash, If you YES then set
// AutoFlash
List flashModes = parameters.getSupportedFlashModes();
if (flashModes.contains(android.hardware.Camera.Parameters.FLASH_MODE_OFF))
{
parameters.setFlashMode(Parameters.FLASH_MODE_OFF);
isFlashOn = false;
}
mCamera.setParameters(parameters);
mCamera.startPreview();
}