在开始新活动之前用相机拍照

时间:2013-05-21 13:00:27

标签: android android-intent android-camera

我有一项活动会在触摸屏幕时拍照。拍完照片之后,我想切换到另一个活动。代码的结构如下所示:

class MyActivity extends Activity implements onTouchListener {
    ...
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        mCameraView.takePicture();
        // Intent intent = new Intent(whatever);
        // startActivity(intent);
        return false;
    }
   }

如图所示,如果我注释掉startActivity,则会拍摄照片并正确保存。如果我尝试在拍摄照片后开始活动,则图像无法正确保存(尺寸0)。我不确定拍照是否在一个单独的线程中,但即使它是,它应该最终保存,但似乎并非如此。知道如何解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

Camera.PictureCallback()

结束时开始您的活动
mCameraView.takePicture(new Camera.ShutterCallback() {

                    @Override
                    public void onShutter() {
                        Log.e("Shutter closed", "   SHUTTER    callback");

                    }
                }, new Camera.PictureCallback() {

                    @Override
                    public void onPictureTaken(byte[] arg0, Camera arg1) {
                        Log.e("Picture taken",
                                "   RAW    image    callback");
                    }
                }, new Camera.PictureCallback() {

                    @Override
                    public void onPictureTaken(byte[] arg0, Camera arg1) {
                        Log.e("Picture taken",
                                "   POSTVIEW    image    callback");
                    }
                }, new Camera.PictureCallback() {

                    @Override
                    public void onPictureTaken(byte[] data, Camera camera) {
                        // Start Activity here after saving image
                    }
                });


            }
        }
    };