I have implemented custom camera in my app. It is working fine in all device except Nexus 5 and Nexus 7. In both devices, It is crashing with SetParameters failed on camera. I have implemented custom camera with below code:
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
if (mCamera != null) {
Log.e(TAG, "surfaceChanged called");
Camera.Parameters parameters = mCamera.getParameters();
if (mSupportedPreviewSizes != null) {
mPreviewSize = getOptimalPreviewSize(mSupportedPreviewSizes, w,
h);
}
Log.e(TAG, "surfaceChanged : mPreviewSize height:"
+ mPreviewSize.height + " width: " + mPreviewSize.width);
parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
requestLayout();
mCamera.setParameters(parameters);
Log.e(TAG, "surfaceChanged called setParameters success");
}
}
I have found at many places comments that it is due to unsupported preview size but In my case, I am already taking it from supported preview sizes.