简体   繁体   中英

Intent is null after taking picture with camera

I'm trying to pass on a file location and an id via the intent of the camera after taking a picture.

That happens in this code:

            btaddphoto.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                Integer vraagnr = Integer.parseInt(lblQuestionNr.getText().toString());

                String _path = Environment.getExternalStorageDirectory().toString() + File.separator + "photo_" + vraagnr.toString() + ".png";
                File file = new File(_path);
                Uri outputFileUri = Uri.fromFile(file);

                Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
                intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
                intent.putExtra("view", newview.Id);

                ((Activity) ctx).startActivityForResult(intent, newview.Id);

            }
        });

In this code the intent exists, aka is not null.

In this code data is null:

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    }

Why is data null? Is it not the same Intent as the Intent in the OnClick event?

rg, Eric

No , this is not the same Intent as you sent in the onClick event. This Intent is returned as response from camera activity (ie android.media.action.IMAGE_CAPTURE ). Here (in onActivityResult ) you need to check if the data object is null then there's no data returned from the camera activity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM