0

Is there a "secure" way to invoke the android camera with the intent MediaStore.ACTION_IMAGE_CAPTURE to capture a picture? I am using the following code to take a snapshot from the camera:

Uri tempFile = Uri.fromFile(tempFile()); // returns a temporary stored files that is "Context.MODE_WORLD_WRITEABLE" so that android can put the file in this location
// tempFile looks like: file:///data/data/com.example.myapp/files/temp_picture.jpg
Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
camera.putExtra(MediaStore.EXTRA_OUTPUT, tempFile);
startActivityForResult(camera, Constants.REQUESTCODE_PICTURE_RESULT);

After that (returning from camera "RESULT_OK") I am copying the tempFile to the secured application store Context.MODE_PRIVATE and deleting the tempFile. Everything works fine, the picture is taken and stored on the given Uri. But also the image is placed (in case of my current development device "HTC Sensation") in the galery from my device (location is /mnt/sdcard/DCIM/100MEDIA/IMAG00XX.jpg). Why is the picture stored twice, I didn't even mention this location in my code? Is this a HTC "feature" or does the android camera store the file twice for media scanning?

I also tried to get the Bitmap from the camera by omitting the MediaStore.EXTRA_OUTPUT parameter, but with this code I am only getting a thumbsize-picture from the camera (no full resolution).

I read a lot about the android camera, but I have to fetch an image from the camera in a "secured" way (no other app should read the data taken from the camera). I already thought about implementing my own camera surface to catch a picture, but with this approach I must code a lot of stuff (flash, saturation, effects, zoom...) that the build in camera application already provides. Is it really that hard to take a picture on the android system?

stema
  • 90,351
  • 20
  • 107
  • 135
tim.kaufner
  • 1,247
  • 5
  • 13
  • 22
  • This is a weird behaviour in some android devices, that files gets copied twice in device storage. To resolve this there is a workaround, I have followed the same, and never faced an issue yet: http://stackoverflow.com/questions/6390163/deleting-a-gallery-image-after-camera-intent-photo-taken This solution, finds new files being created with same size, with the file created by uri, and deletes the same. – jeet Oct 22 '12 at 09:10
  • Hm, sound like an evil "workaround" and you cannot be sure that new devices won't behave the same way, do you? – tim.kaufner Oct 23 '12 at 06:53

2 Answers2

1

If you want it to be 'secure', build camera functionality in your app. There is no way to be sure what some random camera app that comes pre-installed on a device does. They may be sending pictures to a server somewhere without you knowing. It's not super easy to do reliably, but you can only build the basic functionality. Failing that, require a specific app which you trust for image capture, by making the intent explicit (specify package name). This will, of course, require users to install it first if it is not already there.

Nikolay Elenkov
  • 52,576
  • 10
  • 84
  • 84
  • That's what I thought too. So I have to write my own camera activity to be sure that nothing went wrong and the picture is stored in a secure way. Thanks for your advice :) – tim.kaufner Oct 23 '12 at 06:56
0

I have implemented the camera in the same way as u have done. It creates the image and save it in the folder that i have created.but at the same time it saves image in the gallery as well. I have checked for this if other apps also does that or not. and found that even other apps does that and its not the issue of only HTC have tested it on various devices.even i am thinking how does it works.

sankettt
  • 2,387
  • 4
  • 23
  • 31