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?
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.
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.
Related
I want to capture image and upload to server from android client. The supported formats are jpeg,jpg and png. I am not making a custom camera in my application and am calling the camera using below code snippet:-
Intent intent = new Intent();
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);
startActivityForResult(intent, REQUEST_CAMERA);
My doubts :-
Is there any guaranteed format(s) in which the native camera captures the picture?
Is there any way to command the camera to take image in a particular format?
(NB:- I know that I can achieve this by making a custom camera, but I dont want to do that)
Is there any guaranteed format(s) in which the native camera captures the picture?
No. Usually, it will be JPEG, as that is all that many camera apps know about. Possibly, the camera app might examine the MIME type associated with your Uri (e.g., via file extension) and do something based upon that.
But, please understand that there are ~2 billion Android devices, spread across thousands of device models. Those devices ship with hundreds of different pre-installed camera apps, and users can install others from the Play Store and elsewhere. The behavior of camera apps will vary widely, including having bugs.
Is there any way to command the camera to take image in a particular format?
No.
I have a multi platform app - iOS and Android.
One of the features in the app is to capture images. I have a toggle switch in the app settings which allows the user to save the image to the device picture album if the switch is enabled.
This is an issue I can only produce in Android. Even without the toggle switch enabled, the captured photos still save to the device. I have tested this on Android 4.4.2 and 6.0
It does not do this in iOS.
There is nothing in my code to suggest that the photo should still be saved, I have checked it over and over.
Has anyone else come across this? If so what can be done to rectify the issue?
Thanks,
This is simply how FireMonkey captures images on Android. It saves a captured image to a file before handing the pixel data to you. And it does not provide access to the captured image's filename so you can remove the file afterwards.
FireMonkey has an IFMXCameraService interface with a TakePhoto() method, which accepts a NeedSaveToAlbum option:
Taking Pictures Using FireMonkey Interfaces
However, it is currently broken on Android:
RSP-13118: [Android] TTakePhotoFromCameraAction saves Image on Disk unexpectedly
RSP-15820: IFMXCameraService TakePhoto , NeedSaveToAlbum False not working
Until that is fixed, you could use JNI to access Android's camera APIs directly, then you can do whatever you want with the images.
Iam trying to capture a picture using
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (intent.resolveActivity(getPackageManager()) != null) {
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
startActivityForResult(takePictureIntent, REQUEST_CODE);
}
}
but when i get the result, the orientation of the picture is not proper in most of the cases. Since I need to use the picture at a number of places, so I want the picture to be saved with the proper orientation. How can this be done?
Doubt :
1. Doesn't android default camera itself take care of the orientation when saving picture?
2. DO I have to use "ExifInterface" tweak every time when I display the picture from local?
the orientation of the picture is not proper in most of the cases
That depends on your opinion of what is "proper". Various device manufacturers and camera apps believe that having an EXIF orientation tag is perfectly proper.
How can this be done?
You are welcome to scan the image for the EXIF header and rotate the image yourself, but this is slow and memory-intensive.
Doesn't android default camera itself take care of the orientation when saving picture?
First, you are not necessarily using any "android default camera". Any camera app can respond to your Intent. There are thousands of device models, with hundreds of pre-installed camera apps, let alone apps that users might get from the Play Store or elsewhere.
Second, as noted above, some developers feel that "take care of the orientation" is having the appropriate EXIF header.
DO I have to use "ExifInterface" tweak every time when I display the picture from local?
Well, that depends. You could convert it once and save the converted image, then use the converted one going forward, rather than converting it every time. Whether or not it is appropriate for you to saving a converted image or not is up to you and your users.
I currently use this code to call the camera activity with a result which works fine.
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getOutputMediaFile(stockT.getText().toString().toUpperCase())));
startActivityForResult(intent, 10);
I recently flashed latest cyanogenmod 10.2-20130915 and now I no longer have access to some of the stock camera features. I want to use org.cyanogenmod.focal to take the photos, since it supports so many features that I want and need.
Question
Is this possible to use a third party app like focal to return images as a result if so could you post some code to help me out?
Background (in case of another solution):
This app is used by me only. The app scans VINs and creates folder on the sdcard based on the stock number of the vehicle. I then use the camera intnet to take images and once returned the app shrinks them down to a specific size and jpg quality and saves them into their specific folder. Once I am finished with a set of vehicles I simply click a button and the adjusted images are uploaded to our server and pushed out to our vendors.
It turns out that the focal developers are going to actually include this activity. It is actually missing now so when the app is called it just opens like normal since it does not yet support this feature.
I am developing an app which uses the phone's default camera application to capture an image and then allow the user to perform some basic editing.
I use the following snippet...
Intentintent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageCaptureIntent.putExtra(MediaStore.EXTRA_OUTPUT,*<file>*);
startActivityForResult(intent, TAKE_PHOTO_CODE);
I want the image captured to be saved in a location that is consistent with the stock camera application. Can I use the DCIM folder and assume all phones will use that location?
I would expect that the default Android camera app will save images in the DCIM folder. If for some reason a phone manufacturer customized Android with a different camera app, the default location could be different.
You could always check for the existance of the DCIM folder first, and if it doesn't exist, have some kind of a "fall back" location that's specific to your app.
I don't recommend assuming such a thing e.g. Droid Incredible has an internal 8GB storage and I'm not sure how it stores the images inside so check that.