碎片获取分离onPictureTake

时间:2016-06-24 20:08:53

标签: android android-fragments camera

我有一个活动,里面有一个片段,片段中包含一个CUSTOM CAMERA,所以摄像机的所有编码都在片段中完成,但是从活动中调用了Picture。

  <body>
    <script>
      function buildCell() {
        var returnString = '';
        returnString += '<td>';
        returnString += 'Cell Contents';
        returnString += '</td>';
        return(returnString);
      }
      function buildTable(){
        $('body').html(
          '<table>'
          +'<tr>'
          + buildCell()
          +'</tr>'
        );
      }
      buildTable();
    </script>
  </body>

拍照是图书馆方法 现在,

问题是,拍完照片后。 OnPictureTake被调用,并且在此阶段,Fragment与活动分离,因此getActivity返回null,替换为null,如果明确定义活动,则给出错误,片段不附加到活动。

以下是拍照的代码。

private void takePicture() {

    if (CameraFragment.mIsSafeToTakePhoto) {
        camFrag.setSafeToTakePhoto(false);

        //CameraFragment.mOrientationListener.rememberOrientation();

        // Shutter callback occurs after the image is captured. This can
        // be used to trigger a sound to let the user know that image is taken
        Camera.ShutterCallback shutterCallback = null;

        // Raw callback occurs when the raw image data is available
        Camera.PictureCallback raw = null;

        // postView callback occurs when a scaled, fully processed
        // postView image is available.
        Camera.PictureCallback postView = null;

        // jpeg callback occurs when the compressed image is available
        CameraFragment.mCamera.takePicture(shutterCallback, raw, postView, camFrag);
    }
}

这里的cameraModel是DATA的Getter和Setter。

1 个答案:

答案 0 :(得分:1)

我已经通过在Parent活动中实现Camer.PictureCallback而在Fragment中解决了我的问题。