Saving an image file to the Android camera roll directory directly? - android

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...

Related

Default camera images directory path Android

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.

Android: capture image intent, photo file size is zero bytes?

I'm following this tutorial http://developer.android.com/training/camera/photobasics.html
to capture photos and save them to the external storage.
Images are captured and saved successfully but the image size file is zero bytes.
The strange thing is that I can still open the file with the stock gallery app, but when copying the image file to the PC, I can't open it with any image viewer.
What can be wrong here? I'm testing on a Samsung Galaxy Nexus.
Change the directory to save the captured images and copy the saved image and paste it in another directory in mobile itself.
OK, found what was wrong. I left the phone for a couple of hours and returned to check the files and surprisingly I found them with their proper files.
Not sure what's the reason for this, I tested the same code on a Samsung S3 and it worked fine, maybe this happens on slow old phones like the Galaxy Nexus.

Can't save images on internal memory android lollipop

I'm having problem saving jpg and png images on internal memory on Android Lollipop. I'm using a simple application that download (directly or asynchronously) an image from URL an show it on imageview and than it's possible to save it in the internal memory previous create an album on image gallery. The problem is that download the image, after it show it inside imageview but it does not save in the internal memory. It show that it save a file with the right name inside the new album but the file has 0.00 bytes. The app work fine in kit kat. I'm trying with this sample because I'm running the same problem in another app that, as the sample do, works fine in kit kat and does not in lollipop.

Is it good practice to hard-code a camera image path on Android?

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.

Do all Android phones with a built-in camera use a folder called "DCIM" to store captured images?

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.

Categories

Resources