0

我正在启动一台相机ActivityForResult,我resultCode的返回值为 0,而我requestCode的返回值为 -1。有趣的是,这我使用resultCode. 请允许我向您展示

private class ClickListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(intent, CAMERA);
        }    
    }

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

        if (requestCode == CAMERA) {                
            Bundle extras = data.getExtras();
            bmp = (Bitmap) extras.get("data");
            MediaStore.Images.Media.insertImage(getActivity()
            .getContentResolver(), bmp, "picture", "a picture");
            Log.v("HEY", "Your image should be in the gallery now");
        }    
    }

但是我显然需要添加一些代码,以防用户按下取消而不是拍摄照片。所以我添加了一些代码,我的新onActivityResult外观像这样

public void onActivityResult(int resultCode, int requestCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.v("RESULT CODE", "" + resultCode);
        Log.v("REQUEST CODE", "" + requestCode);
        if (requestCode == CAMERA) {

            if (resultCode == Activity.RESULT_OK) {
                Bundle extras = data.getExtras();
                bmp = (Bitmap) extras.get("data");
                MediaStore.Images.Media.insertImage(getActivity()
                        .getContentResolver(), bmp, "picture", "a picture");
                Log.v("HEY", "Your image should be in the gallery now");
            } else if (resultCode == Activity.RESULT_CANCELED) {
                Log.v("CANCELED", "The user has canceled the activity");
            }
        }

    }

我的 logcat 说,它不仅不起作用

06-13 20:53:36.320: V/RESULT CODE(6140): 0
06-13 20:53:36.320: V/REQUEST CODE(6140): -1

为什么会这样?有人遇到过这个吗?

4

1 回答 1

3

这是onActivityResult您的问题的正确原因和原因:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {}

VS你的:

@Override
public void onActivityResult(int resultCode, int requestCode, Intent data) {}
于 2013-06-14T01:58:25.197 回答