camera.setParameters failed in android
It is failing because not all devices support arbitrary preview sizes. Apparently some do but you can't rely on it. In your surfaceChanged method you need to do something like this:
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
Camera.Parameters parameters = camera.getParameters();
List<Camera.Size> previewSizes = parameters.getSupportedPreviewSizes();
// You need to choose the most appropriate previewSize for your app
Camera.Size previewSize = // .... select one of previewSizes here
parameters.setPreviewSize(previewSize.width, previewSize.height);
camera.setParameters(parameters);
camera.startPreview();
}
You'll have to figure out a way to scale this so that you don't lose the aspect ratio etc.
For reference here is the Android SDK doc.
Camera java.lang.RuntimeException: setParameters failed
Issue is caused by:
params.setPictureSize(1200, 900);
because required size is not suppoerted by Camera.
Use getSupportedPictureSizes
to get all available preview sizes.
To check which is maximum picture size available from camera:
List<Size> allSizes = param.getSupportedPictureSizes();
Camera.Size size = allSizes.get(0); // get top size
for (int i = 0; i < allSizes.size(); i++) {
if (allSizes.get(i).width > size.width)
size = allSizes.get(i);
}
//set max Picture Size
params.setPictureSize(size.width, size.height);
Exception java.lang.RuntimeException: setParameters failed
Your params could be not supported by device. You can detect available focus modes with getSupportedFocusModes
method of Camera.Parameters
class. If some mode doesn't contain in this list, you can't set it to your camera.
Edit
As Alex said in comment you can see error message in logcat.
java.lang.RuntimeException: setParameters failed, while setting the camera parameters
I guess you are trying to set a preview size which is not supported by Camera object.
You should get the list of supported previewSizes first to check what values you can actually set.
List<Camera.Size> sizes = cam.getParameters().getSupportedPreviewSizes();
Android Camera: setParameters exception on Android
Instead of using static preview sizes try using supported preview sizes which are introduced in API level 5
Camera.Parameters parameters = camera.getParameters();
List<Camera.Size> customSizes = parameters.getSupportedPreviewSizes();
// Choose desired preview size
Camera.Size customSize = //Added size
parameters.setPreviewSize(customSize.width, customSize.height);
camera.setParameters(parameters);
camera.startPreview();
This will be more safer way to use this approach because all devices won't support manual sizes
Camera shutting down VM - java.lang.RuntimeException: setParameters failed
Can you post the code that launches the Camera?
What I can see right now is that you declare a permission that does not exist:
<uses-permission android:name="android.hardware.camera.autofocus" />
There are some features declaration that have typos:
<used-feature android:name="android.hardware.location" />
<used-feature android:name="android.hardware.camera.setParameters" />
You can try fixing these for a start, see if it helps. You can see the list of all features available for declaration here
How to fix setParameters Failed in Android.harware.Camera?
- Do you know the cameras in question support FOCUS_MODE_CONTINUOUS_PICTURE? That's not guaranteed. Check getSupportedFocusModes(). A camera can fail setParameters if you use a non-supported mode of any type.
- Do you know the camera supports a frame rate of 20? That's not guaranteed. Check getSupportedPreviewFpsRange. Again, a camera can fail setParameters if you a non-supported frame rate value.
- And, as Jan says, startFaceDetection() should be called only after preview is started. Though it's a bit surprising that doing that out of order will result in a setParameters error, in all honesty.
Related Topics
Using JSON File in Android App Resources
Android - Swipe to Delete Recyclerview
Display Huge Images in Android
How to Change Viewpager's Page
How to Display Long Messages in Logcat
How to Make an Intent with Multiple Actions
Android Fab Icon Always Black with Materialcomponents Theme
Start a Service in a Separate Process Android
Android Accelerometer Not Working When Screen Is Turned Off
Caused By: Java.Lang.Outofmemoryerror: Bitmap Size Exceeds Vm Budget
Android: Integer from Xml Resource
Android Gridview Draw Dividers
Failure [Install_Failed_Invalid_Apk]