W
W
web_dev2013-02-21 17:10:47
Android
web_dev, 2013-02-21 17:10:47

"Android - taking a photo" returns resultCode=-1 and data=null - everything was fine a day ago!?

Hello, I found a lot of solutions in the open spaces, but I can’t understand what I did wrong, It seems to work.
The photo is taken and saved to the card.

private void takePicture() {
    Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File photoFile = new File(Environment.getExternalStorageDirectory(), StartMenuActivity.DIR_NAME + "/" + travelDirName
        + "/" + travelDirName + "_" + poisArray.size() + ".jpg");

    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));

    imageOrVideoUri = Uri.fromFile(photoFile);

    startActivityForResult(cameraIntent, CAMERA_REQUEST_PICTURE);
  }

  private void takeVideo() {
    Intent cameraIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    File videoFile = new File(Environment.getExternalStorageDirectory(), StartMenuActivity.DIR_NAME + "/" + travelDirName
        + "/" + travelDirName + "_" + poisArray.size() + ".mp4");
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(videoFile));

    imageOrVideoUri = Uri.fromFile(videoFile);

    startActivityForResult(cameraIntent, CAMERA_REQUEST_VIDEO);
  }

  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    //super.onActivityResult(requestCode, resultCode, data);

    if ((resultCode == RESULT_OK)&&(data != null)) {
      if (requestCode == CAMERA_REQUEST_PICTURE) {
        createThumbnail();
        addPoi(PICTURE_POI);
      }
      if (requestCode == CAMERA_REQUEST_VIDEO) {
        addPoi(VIDEO_POI);
      }
    } else {
      Toast.makeText(TravelMapActivity.this, R.string.poi_add_error, Toast.LENGTH_LONG).show();
    }
  }

Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
palmut, 2013-02-23
@palmut

Please explain the question. You take a photo, the answer is returned to you. At the same time, resultCode = -1 (which is RESULT_OK), and data = null, which is also correct, since when calling, they explicitly indicated where to save the image. Everything seems to be in order - the picture will be in imageOrVideoUri and the &&(data != null) check should simply be removed. According to the documentation, if MediaStore.EXTRA_OUTPUT is specified, then there will be a full-size snapshot, if it is not specified, then data will contain a small Bitmap. Or have I misunderstood something?

P
palmut, 2013-02-21
@palmut

Something is not clear at the beginning of takePicture:

private void takePicture() {
        Intent cameraIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
...

It seems that you are going to take a photo, but pass ACTION_VIDEO_CAPTURE to the intent. Maybe this is the issue?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question