如何在取消拍照时进入上一屏幕?

时间:2012-07-05 13:15:03

标签: android android-camera

我使用的目的是调用相机和onresult来获取拍摄的图像,但如果没有拍摄图像(按下取消时),我想回到我从相机调用相机的屏幕

我现在正在使用它......但是有更好的方法可以做到这一点:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (!(data == null || resultCode == 0)) {

            if (requestCode == CAMERA_REQUEST) {

                photo = (Bitmap) data.getExtras().get("data");
                imageView.setImageBitmap(photo);
            }
        } else {

            Intent intent = new Intent(ImageUploaderActivity.this,
                    ImageUploaderActivity.class);
            startActivity(intent);
            finish();
        }
    }

1 个答案:

答案 0 :(得分:1)

我在我的应用程序中做了类似的事情,这是我的代码:

    if (resultCode == RESULT_OK) {
        if (data != null) {
            //When all was ok
        }
    } else if (resultCode == RESULT_CANCELED) {
        //When it was canceled, when I press a back button while in camera app.
    } else {
        //Some other result
    }