Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is camera intent automatically saving images to disk?

I'm using a simple camera intent following the basic tutorial from Android. In this section it talks about saving the image file to disk. However, I haven't yet configured any of these steps, but after capturing the image and returning to my activity, it's still automatically saving my image to disk in /storage/emaulated/0/DCIM/Camera. This doesn't seem to be what's implied by the tutorial - I don't even have the WRITE_EXTERNAL_STORAGE permission in my manifest so I'm not sure why it's even allowed to write to disk. I don't want the image to automatically save to this directory, but rather to a directory of my choosing. I know how to save the image to a custom directory, but how can I prevent the default behavior of saving the image to the directory above?

like image 664
ethan123 Avatar asked Nov 09 '22 15:11

ethan123


1 Answers

When you try to take a phto, actually you are start calling Camera App installed in your device. You didn't set WRITE_EXTERNAL_STORAGE, Oh yes, but the App of Camera is set. And when you try to take a picture but want to store the photo into your file, you could try this:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra("return-data", false);
intent.putExtra(MediaStore.EXTRA_OUTPUT,
                Uri.fromFile(AVATAR_FILE_TMP));
intent.putExtra("outputFormat",
                Bitmap.CompressFormat.JPEG.toString());
intent.putExtra("noFaceDetection", true);
startActivityForResult(intent, TAKING_PICTURE_INDEX);

And filePath is the path of the image file you take by Camera. Taking a photo uses Camera App.

like image 80
SilentKnight Avatar answered Dec 16 '22 00:12

SilentKnight