开发者

Using Camera activity with Intent MediaStore. INTENT_ACTION_STILL_IMAGE_CAMERA returns Data null

I m using Camera activity using intent

MediaStore. INTENT_ACTION_STILL_IMAGE_CAMERA with startactivityforresult

but as I press back key after taking a pic or video I get resultcode= 0 and data =null.

Any help will b开发者_开发百科e appreciated.


DId u try using MediaStore.ACTION_IMAGE_CAPTURE instead? It works for me with that. I am able to take a picture aand get the URI. Here is the code

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        String fileName = TravellerUtils.generateUniqueID()
                + IMAGE_FILE_EXT;
        File file = new File(Environment.getExternalStorageDirectory(),
                TravellerConstants.IMAGE_PATH + fileName);
        Uri outputFileUri = Uri.fromFile(file);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        startActivityForResult(intent, TAKE_PICTURE);


this intent MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA allows you to take several pictures and send it to gallery, however, you can't capture it right after take the picture. It also allows you to take videos, but you can't capture either.

I suggest you to take pictures and videos with two intents, separately.

for Picture:

 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File imagesFolder = new File(Environment.getExternalStorageDirectory(), "Camera");
    imagesFolder.mkdirs();
    Random random = new Random();
    int n = random.nextInt(10000);
    File image = new File(imagesFolder, "YourApplication" + n + ".jpg");
    photoUri = Uri.fromFile(image);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); // set the image file name

    // start the image capture Intent
    startActivityForResult(intent, Constants.CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

and for video:

 Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);

fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO);  // create a file to save the video
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);  // set the image file name

intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); // set the video image quality to high

// start the Video Capture Intent
startActivityForResult(intent, CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜