Android拍照int resultCode = -1,Intent data = null?

时间:2013-02-21 12:52:51

标签: android android-intent

看到解决方案,但我曾经工作,一旦没有上网。我不知道是什么。

   int resultCode = -1, Intent data = null

拍照并经常拍照。

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);
    }


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

        if ((resultCode == RESULT_OK)&&(data != null)) {
            if (requestCode == CAMERA_REQUEST_PICTURE) {
                createThumbnail();
                addPoi(PICTURE_POI);
            }
            if (requestCode == CAMERA_REQUEST_VIDEO) {
                addPoi(VIDEO_POI);
            }
            // Uri selectedUri = imageOrVideoUri;
            // Bitmap photo = (Bitmap) data.getExtras().get("data");
            // imageView.setImageBitmap(photo);
        } else {
            Toast.makeText(TravelMapActivity.this, R.string.poi_add_error, Toast.LENGTH_LONG).show();
        }
}

如何解决?感谢。

2 个答案:

答案 0 :(得分:0)

试试这个,

protected void TakePhoto() {

        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");

        File photo = new File(Environment.getExternalStorageDirectory()
                + "/LiveChat", "IMG_temp.jpg");
        System.gc();
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
        imageUri = Uri.fromFile(photo);
        startActivityForResult(intent, 1);

}

  protected void onActivityResult(int requestcode, int resultcode, Intent data) {

        if (resultcode == RESULT_OK) {
            System.gc();
            switch (requestcode) {
            case 0:

         //ADD YOUR STUFF
                    }

        } else {
            Toast.makeText(getApplicationContext(), "No Image Selected",
                    Toast.LENGTH_SHORT).show();
        }

}

答案 1 :(得分:0)

因此,问题在于您指定了将照片写入相机意图的URI。如果您提供URI,则默认功能是不提供缩略图 - 因为您已经知道图像的位置。在您的活动结果中,只需使用URI来检索您的图片。这个issue上有几个相关的帖子。