友盟日志如下:
java.lang.RuntimeException: takePicture failed
at android.hardware.Camera.native_takePicture(Native Method)
at android.hardware.Camera.takePicture(Camera.java:1872)
at android.hardware.Camera.takePicture(Camera.java:1817)
at com.xxxx.xxxx.xxxx.CameraActivity.onClick(SourceFile:127)
at android.view.View.performClick(View.java:4909)
at android.view.View$PerformClick.run(View.java:20390)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:192)
at android.app.ActivityThread.main(ActivityThread.java:5878)
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:1089)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:855)
复现原因:拍照按钮被重复点击时会出现这个bug。
修复:申明一个boolean变量
private boolean safeToTakePicture = false;
在startPreview之后safeToTakePicture = true;
在拍照点击事件中
if (safeToTakePicture) {
camera.takePicture(null, null, mPicture);
safeToTakePicture = false;
}
在PictureCallback回调方法中的,safeToTakePicture = true;
参考链接