Am I correct in understanding that, on Android, if you want to save/persist images that you take with the camera, you can only create the image on external storage first? And if no external storage exists, then you're out of luck? But assuming the storage does exist, I can always move it to wherever I want (including the private internal storage) after the photo has been taken?
-
Check if your google is working or not? Just go to www.google.com and paste "android save image to internal storage example" and hit enter, go to first 10 links. [Mine just worked fantastic.](https://www.google.co.in/search?q=android%20save%20image%20to%20internal%20storage%20example) – MKJParekh Apr 11 '16 at 14:24
-
@MKJParekh: When I run that search on Google, there is exactly one hit, and it would not appear to be an answer to the question. – CommonsWare Apr 11 '16 at 14:25
-
I got this http://stackoverflow.com/questions/15662258/how-to-save-a-bitmap-on-internal-storage as my second link in top 10. Use it with something like http://stackoverflow.com/questions/5991319/capture-image-from-camera-and-display-in-activity – MKJParekh Apr 11 '16 at 14:26
-
Also a lot of the answers I am finding are using hard-coded paths, which I almost immediately want to ignore because it's bad practice... as far as I know one should be using the built-in getFilesDir(), getExternalFilesDir(), getExternalStoragePublicDirectory(), etc. – KaliMa Apr 11 '16 at 14:28
-
http://stackoverflow.com/questions/5991319/capture-image-from-camera-and-display-in-activity here, isn't this you want? same in previous comment – MKJParekh Apr 11 '16 at 14:30
-
@MKJParekh Those answers aren't relevant to what I am asking. The first isn't about taking pictures from the camera app, and the second uses "Bitmap photo = (Bitmap) data.getExtras().get("data"); " which only generates a thumbnail of the picture stored in RAM -- to my understanding there isn't a full-sized image stored anywhere in internal or external memory – KaliMa Apr 11 '16 at 14:32
-
@KaliMa Check answer by the Legend and tell me if it has anything of your interest or all the same which 10 links and other answers told you so far? – MKJParekh Apr 11 '16 at 14:42
1 Answers
It depends on what you mean by "images that you take with the camera".
If you are using the camera APIs directly (e.g., android.hardware.Camera
), or are using libraries in your app that use the camera APIs directly, you should be able to store the images on internal storage without issue.
If you are trying to use ACTION_IMAGE_CAPTURE
, you are at the mercy of whatever third-party camera app handles the request. One approach is to just ask for a thumbnail, with a plain ACTION_IMAGE_CAPTURE
Intent
, but the image will be thumbnail-sized. However, you get the Bitmap
via an extra on the result Intent
, and you can write that to internal storage.
You are welcome to use EXTRA_OUTPUT
and a content:
Uri
, pointing at a ContentProvider
from your app. Ideally, this works, and your ContentProvider
will get the image and can save it to internal storage. And I would assume that some camera apps can handle this correctly. However, I would also expect:
Some camera apps to not recognize the
content:
scheme, try to use the path as a file, and crashSome camera apps to not recognize the
content:
scheme, try to use the path as a file, fail, catch the exception, and ignore yourEXTRA_OUTPUT
Some camera apps to ignore
EXTRA_OUTPUT
in generalSome camera apps to have other bugs in their
ACTION_IMAGE_CAPTURE
handling that interfere with your app
ACTION_IMAGE_CAPTURE
is intrinsically unreliable. It is easy to try, but it will not work 100% of the time, due to camera app bugs. Use it only if you are in position to tell the user ¯\_(ツ)_/¯
when it does not work.
And if no external storage exists, then you're out of luck?
If the user has no external storage, they have much bigger problems than your app not working.
But assuming the storage does exist, I can always move it to wherever I want (including the private internal storage) after the photo has been taken?
"Always" is a strong statement with respect to ACTION_IMAGE_CAPTURE
. Let's say that if you get a picture that is saved on external storage, and if you have permission to work with external storage, then you can move it to internal storage.

- 986,068
- 189
- 2,389
- 2,491
-
I know that the thumbnails can be saved directly, but I mainly refer to the full size imaged with lines like `takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));` and `startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);`. In this example, must photoFile be pointing to a spot on external storage? Or is there some permission that can allow it to be stored on internal? By the time it hits the onActivityResult method that is and the file has been filled with data. – KaliMa Apr 11 '16 at 14:47
-
@KaliMa: "In this example, must photoFile be pointing to a spot on external storage?" -- see my answer, particularly the portion starting with "You are welcome to use EXTRA_OUTPUT and a content: Uri" and onward. You cannot use a `file:` `Uri` pointing to your app's internal storage, because a third-party camera app has no rights to it. – CommonsWare Apr 11 '16 at 14:49
-
I wasn't familiar with `file: Uri` so thanks for the clarification. I just read your blog posts. Do you recommend working directly with the Camera API due to the unreliability / inconsistency of ACTION_IMAGE_CAPTURE? – KaliMa Apr 11 '16 at 14:54
-
@KaliMa: That depends on the nature of your app. If taking pictures is a significant part of the app's functionality, using the camera APIs directly or a library (e.g., [mine](https://github.com/commonsguy/cwac-cam2)) gives you much greater control, at the cost of pain and suffering on your part. If taking pictures is an ancillary capability of your app, use `ACTION_IMAGE_CAPTURE`, with lots of output validation, and focus on how best to `¯\_(ツ)_/¯` your user when the output does not work as expected. – CommonsWare Apr 11 '16 at 15:03