I am a bit confused on where and how Camera images get stored. So I have an API 22 emulator ran on an SD and the below code will only work if ran using an SD card. I then take a couple of pics and see the pictures in the gallery and the camFiles array will get populated.
However, it does not work with API 23/24 emulators even with SD card. Is there a way to get the default camera directory that'll work for any API level?
File cameraDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).toString());
File[] files = cameraDir.listFiles();
//gets the 'Camera' directory
File finalCamDir = files[0];
File[] camFiles = finalCamDir.listFiles();
Is there a way to get the default camera directory that'll work for any API level?
Not really. There is no single "default camera directory". There are thousands of Android devices, with hundreds of different pre-installed camera apps, in addition to camera apps that users install themselves. It is up to the developers of those camera apps to decide where to save photos on the device.
DIRECTORY_DCIM is a recommended starting point. Some camera apps will put photos directly in this directory. Others, such as Open Camera, will use a subdirectory off of DIRECTORY_DCIM (e.g., OpenCamera/). Others are welcome to store their photos wherever they want, not necessarily involving DIRECTORY_DCIM.
Related
I want to query the MediaStore for all photos on the device, but only those taken by the camera. Please note the distinction I'm trying to make on photos vs any other image media (downloads, screenshots etc) on the device. The MediaStore contains many different directories, or "buckets", where the default camera/pictures location is one of them. However, there doesn't seem to be any standard on what this bucket is named -- on my Sony Z5, it's "100ANDRO", on my Samsung Galaxy S3, it's simply "Camera".
Reading various posts on StackOverflow, it seems this varies with manufactorer, but I should be able to find the path to the conventional "camera folder" at
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)
So I can filter the query to MediaStore on that path (e.g. /storage/emulated/0/DCIM on my S3). If the user chooses to store the photos at a totally unconventional location, perhaps using a third-party camera app, then that's OK. I'm only hoping to cover the most "normal" use cases here.
But what if I want to load also the photos on an external SD card, if present?
As far as I can see, the photos on the "internal memory" and those on the SD card will have the same BUCKET_DISPLAY_NAME (and BUCKET_ID) in the MediaStore. But getting the path to the SD card photos directory seems to be very difficult across devices.
So what do you think about this approach (to get all photos):
find the "camera folder" path (as above)
query the MediaStore, filtered on this path. Find the corresponding BUCKET_DISPLAY_NAME
query the MediaStore again, filtered on BUCKET_DISPLAY_NAME from step 2, and where the path differs from that in step 2.
Step 2 will find all the photos on the internal memory.
Step 3 will find any photos on the SD card, if present.
Step 3 will be empty if no card is mounted, or if it contains no photos, so this might seem to be a rather graceful approach.
So I can filter the query to MediaStore on that path (e.g. /storage/emulated/0/DCIM on my S3)
You can achieve that with the code in that link you found, it's the best solution you'll find, yet, like others have said, you have no guarantee that the device's camera app is actually storing pictures inside a directory at Environment.DIRECTORY_DCIM, and there's even the problem that other apps might also be using it to store any images, other than pictures, since it's public...
HelloEveryone! I want to know some principal thing. Is there exists a method to take a picture (with good resolution) from android device without saving it in hard memory (only in RAM). I tried to:
use TakePicture(shutter, raw, jpg), but resolution of the resulting JPG is very low and RAW working with very few number of devices. Was asked here
give the control to Google Camera, but this way required some temporary file in the hard memory (to write picture)
How can I do this. Or is it impossible? Any help! Thank you!
It depends on your phone. Many phones do not need external sd card because they already have a internal one. So I suggest you check the hardware information of your phone first. If it do not have a external sd card, you can try to use camera2
to take videos and pictures. Pictures and videos can be stored in RAM. But if you want to access the pictures stored in RAM, you need to root your phone first.
According to my understanding,
different Android devices have different Camera image paths.
Nexus-One stores its camera files into a folder named Camera (/sdcard/DCIM/Camera).
All HTC devices store their camera files into a folder named 100MEDIA (/sdcard/DCIM/100MEDIA).
Sony Xperia x10 stores its camera files into a folder named 100ANDRO (/sdcard/DCIM/100ANDRO).
Motorola MilesStone stores its camera files into a folder named Camera (/sdcard/DCIM/Camera).
Nexus-One stores its camera files into a folder named Camera (/sdcard/DCIM/Camera).
Is there a common camera image path that is shared by most devices ?
If not, is the API below sufficient to get the image path ?
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
According to my understanding,
different Android devices have different Camera image paths
The locations where camera apps store images is up to the camera app, in conjunction with the device.
Is there a common camera image path that is shared by most devices ?
Not by how you are defining "camera image path". There is no requirement for a camera app to store images anywhere where other apps can get to the images, for example.
If not, is the API below sufficient to get the image path ?
In your examples, that method would return /sdcard/DCIM/. In reality, this value too will vary by device, though not by app.
If you are writing your own camera app, and you want to save pictures to external storage, store them in Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);, in a custom subdirectory off of there, or in getExternalFilesDir() somewhere.
If you are trying to read images (e.g., to write a "gallery" app), use the MediaStore ContentProvider.
Is there a way to save an image to the camera roll directory directly? I was using CameraRoll.addBitmapData() call but that converts the bitmapData to a JPEG and all transparency is lost. And also, the image is being heavily compressed. So I would like to save a PNG with transparency to the camera roll directory.
I'm using Adobe AIR 3.6 and testing on Android 4.latest on a Google Nexus 7.
So I'm able to save an image to the camera roll successfully! The problem now is the native Android Image Gallery app doesn't recognize any images I put there except if I restart the device. It also has a problem with thumbnails (they show a different image or are simply a black background).
Here's what I found:
DCIM – This folder is for Photos and contains another folder named Camera which contains all of the photos and videos taken by the phone’s camera (Created by the OS)
Download – Will be automatically create as needed for downloaded files. Source
Pictures - Not sure.
What doesn't work
Image Gallery doesn't reflect new images added to the directory until the device is restarted. The thumbnails are also incorrect as I stated above.
I've noticed in the Camera directory there is a .ds_store type of file and another directory for thumbnails. Other directories besides DCIM / Camera do not appear to have this file.
UPDATE
I found out that it's a known issue that the camera roll does not refresh! If it is an AIR only problem or not I don't know. But there is an extension to refresh the image gallery after you add the image. http://extensionsforair.com/extensions/refresh-gallery/. I haven't tried it.
Other posts...
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.