美文网首页Android适配经验
线上bug修复之takePicture failed

线上bug修复之takePicture failed

作者: shada | 来源:发表于2016-10-24 10:20 被阅读2493次

    友盟日志如下:

    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;

    相关文章

      网友评论

        本文标题:线上bug修复之takePicture failed

        本文链接:https://www.haomeiwen.com/subject/nlfluttx.html