简体   繁体   English

由于Android中的相机而崩溃

[英]crash due to camera in android

We created an android native app and it is crashing under certain conditions. 我们创建了一个Android本机应用程序,在某些情况下它崩溃了。 It has to do with the camera certainly, but not exactly sure what it could be. 当然,这与相机有关,但并不完全确定它会是什么。

I would like to highlight that I am not an android developer (I develop mostly in python) but I wonder if the android experts out there can provide some context about the error. 我想强调一点,我不是Android开发人员(我主要使用python开发),但我想知道那里的Android专家是否可以提供有关错误的一些信息。

Here is the stack trace from the google play console: 这是来自Google Play控制台的堆栈跟踪:

java.lang.RuntimeException: 
  at android.hardware.Camera.native_setParameters (Native Method)
  at android.hardware.Camera.setParameters (Camera.java:1946)
  at identidata.br.camera.CameraPicturePreview.surfaceChanged (CameraPicturePreview.java:75)
  at android.view.SurfaceView.updateWindow (SurfaceView.java:611)
  at android.view.SurfaceView$3.onPreDraw (SurfaceView.java:181)
  at android.view.ViewTreeObserver.dispatchOnPreDraw (ViewTreeObserver.java:944)
  at android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2000)
  at android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1073)
  at android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:5985)
  at android.view.Choreographer$CallbackRecord.run (Choreographer.java:767)
  at android.view.Choreographer.doCallbacks (Choreographer.java:580)
  at android.view.Choreographer.doFrame (Choreographer.java:550)
  at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:753)
  at android.os.Handler.handleCallback (Handler.java:739)
  at android.os.Handler.dispatchMessage (Handler.java:95)
  at android.os.Looper.loop (Looper.java:135)
  at android.app.ActivityThread.main (ActivityThread.java:5912)
  at java.lang.reflect.Method.invoke (Native Method)
  at java.lang.reflect.Method.invoke (Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1405)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1200)

Android Camera API documents that Camera.setParameters() may throw a RuntimeException if something goes wrong. Android Camera API文档指出,如果出现问题, Camera.setParameters()可能会抛出RuntimeException。 Taking into account the Android fragmentation, you have a chance to trigger some hidden incompatibility with any innocent call to setParameters(). 考虑到Android碎片,您有机会通过无辜调用setParameters()来引发一些隐藏的不兼容性。 Therefore, I strongly recommend to always try … catch RuntimeException around this call. 因此,我强烈建议始终try … catch在此调用周围try … catch RuntimeException。

I won't be surprised if your specific crash happens because you try to set unsupported preview size when you process the surfaceChanged() callback. 如果您发生特定的崩溃,我不会感到惊讶,因为您在处理surfaceChanged()回调时尝试设置不受支持的预览大小。 This callback comes with width and height parameters, and it is a natural temptation to use these values for Camera.Parameters.setPreviewSize() . 该回调函数带有widthheight参数,因此很自然地将这些值用于Camera.Parameters.setPreviewSize() Unfortunately, this won't work. 不幸的是,这行不通。 You must always choose one of the values from the list of supported Preview Sizes . 您必须始终从支持的“预览大小 ”列表中选择一个值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM