Hello, I am a beginner in Android development.
I'm using the Camera API, but API 28 has built and the following error:
E/SurfaceView:Exception configuring surface
java.lang.RuntimeException: setParameters failed
at android.hardware.Camera.native_setParameters (Native Method)
at android.hardware.Camera.setParameters (Camera.java:2102)
at jp.image_management.ui.camera.widget.CameraPreview.updateCameraParameters (CameraPreview.java:314)
at jp.image_management.ui.camera.widget.CameraPreview.surfaceCreated (CameraPreview.java:157)
at android.view.SurfaceView.updateSurface(SurfaceView.java:670)
at android.view.SurfaceView $2.onPreDraw (SurfaceView.java:143)
at android.view.ViewTreeObserver.dispatchOnPreDraw (ViewTreeObserver.java:977)
at android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2474)
at android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1460)
at android.view.ViewRootImpl$TraversalRunable.run (ViewRootImpl.java:7183)
at android.view.Choreographer $CallbackRecord.run (Choreographer.java:949)
at android.view.Choreographer.doCallbacks (Choreographer.java:761)
at android.view.Choreographer.doFrame (Choreographer.java:696)
at android.view.Choreographer $FrameDisplayEventReceiver.run (Choreographer.java:935)
at android.os.Handler.handleCallback (Handler.java:873)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loop (Looper.java:193)
at android.app.ActivityThread.main (ActivityThread.java:6669)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:858)
E/Camera: Error 2
API28 and earlier do not produce errors, they are working properly.
Part of the code:
if(mCamera!=null){
Camera.Parameters parameters=mCamera.getParameters();
setParameters (params);
try{
mCamera.setParameters(params);
} catch(RuntimeExceptione){
Camera.Size previewSize=findBestPreviewSize(params);
Camera.Size pictureSize=findPictureSize(params);
params.setPreviewSize(previewSize.width, previewSize.height);
params.setPictureSize(pictureSize.width, pictureSize.height);
// This is where the error occurs (API 28)
mCamera.setParameters(params);
}
}
}
Is there any change in API28?Thank you for your cooperation.
java android
From android api28, boot from the background is not allowed.
See the official for more information.
[Supplement 1]
If only api21 and later are supported, camera2 is recommended.
Please check the official page above for details.
[Supplement 2]
In the past, setParameters failed because the required size (width, height) was
Sometimes it fails because it is not supported by the camera.
It may be a good idea to check the size specified in the running environment.
https://stackoverflow.com/questions/33579918/camera-java-lang-runtimeexception-setparameters-failed
© 2024 OneMinuteCode. All rights reserved.