2

Is there a way to take a picture from camera programmatically from my Android app, without writing the file to external storage? I’m trying to minimize the permissions I require from my app users, in particular the “write to external storage” one. I don’t require the pic to be saved to disk, I’m totally fine if the pic is destroyed when I close my app. And it seems a bit of an overkill to ask users a total write permission to their disk just for taking a picture.

I’ve seen that from API 19 you could probably avoid that permission by writing the file to the app directory given by getExternalFilesDir(). Are there other ways? Maybe without passing from disk memory at all?

splinter123
  • 1,183
  • 1
  • 14
  • 34
  • The problem is that you usually don't want to have the whole picture in memory, because it may lead to outofmemory errors on some devices. So you can have the camera either send you a thumbnail, or have it saved as a file. – wvdz Mar 20 '15 at 09:25
  • http://stackoverflow.com/questions/5991319/capture-image-from-camera-and-display-in-activity , this example dosent using any storage permission. – Lavekush Agrawal Mar 20 '15 at 09:45
  • but if you want to use the image inside the app (like showing it full screen, send it to your server, etc...) you'll most likely need to have it in your heap anyways. – splinter123 Mar 20 '15 at 09:45
  • @Lavekush in that example, you just get a thumbnail. I was looking to get some kind of byte array or stream directly from the camera. – splinter123 Mar 20 '15 at 09:57
  • @splinter123 In the post @Lavekush referred to, you can see `Bitmap photo = (Bitmap) data.getExtras().get("data");`. You can use this and convert it to `byte[]`, or whatever you prefer. – Edwin Lambregts Mar 20 '15 at 10:06
  • @EdwinLambregts If you look at the comments to the accepted answer, they say that you can only retrieve a thumbnail with that method. Although I haven't verified it myself. – splinter123 Mar 20 '15 at 10:12
  • @splinter123 True, they do state that. I myself have implemented this in a project at school: [pic on dropbox](https://www.dropbox.com/s/wfogu7564jbmzr6/2015-01-22%2008.29.51.png?dl=0). As you can see, my `ImageView` is not fullscreen, but definitely bigger than a thumbnail. – Edwin Lambregts Mar 20 '15 at 10:50

0 Answers0