Camera intent for temporary storage - android

Is there an intent that takes pictures and doesn't save them automatically to the gallery? I'm currently using android.provider.MediaStore.ACTION_IMAGE_CAPTURE.

You can set the destination file uri with the following extra :
intent.putExtra(MediaStore.EXTRA_OUTPUT,<Uri>);
The file must be writable.
once you finished with your file, simply delete it, and it won't appear in the gallery
if you want to keep the file on the sd, without having it visible in the gallery, you can simply change the extension of it, "file.tmp" will never show in the gallery.

Related

How do I save a captured image into my phone gallery in android?

I want to take a picture using camera intent and save it to the gallery. How can I do that. I tried from:
https://developer.android.com/training/camera/photobasics.html#TaskScalePhoto
But, haven't been able to do it. So, what could be the solution to take a picture and save it to the gallery when the button is clicked. I have been able to save it in the devide_picture/device/dcim.
How do I save a captured image into my phone gallery in android?
You don't. You save a captured image as a file. A gallery app can then display that file.
I have been able to save it in the devide_picture/device/dcim.
Then you are almost done. You need to tell MediaStore that your new file exists, as the camera app might not do that:
MediaScannerConnection
.scanFile(ctxt,
new String[] {f.getAbsolutePath()},
new String[] {"image/jpeg"}, null);
(where ctxt is a Context, such as your Activity, and f is a File object pointing to where you saved the photo)

How to get actual path to video from onActivityResult

I have a video that I save to .../Movies/MyApp/abcde.mp4. So I know where it is. When I load it through my app using an implicit intent to ACTION_GET_CONTENT, the path is returned as content:/media/external/video/media/82 when I do
data.getData().toString()
The problem with that path is that it works when I try to access it with MediaRecorder as
mVideoView.setVideoURI(Uri.parse(mVideoStringPath))
However if I try to convert it to a path in another thread (for a job queue), the file is not found
new File(mVideoStringPath)
when I use the technique (copy and paste) described at How to get file path in onActivityResult in Android 4.4, still get the error
java.lang.RuntimeException: Invalid image file
Also per my logging, the new technique shows the path to the video as
video path: /storage/emulated/0/Movies/MyApp/abc de.mp4
notice the space in abc de.mp4. that indeed is the name of the file. And the phone's camera app has no trouble playing
However if I try to convert it to a path in another thread (for a job queue), the file is not found
That is because it is not a path to a file. It is a Uri, which is an opaque handle to some data.
How to get actual path to video from onActivityResult
You don't. You use the Uri. There is no requirement that the Uri point to a file. There is no requirement that the Uri, if it happens to represent a file, represent one that you have direct filesystem access to.
you need to escape the space the the file path in order to construct a File object from it.
filepath.replace(" ", "\\ ");

Android: Duplicate photo storage in DCIM folder

I am using the native Android camera and save files to a application data folder (/mnt/sdcard/Pictures/). At the same time - on some devices - another copy of photo is saved to DCIM folder.
This is my code:
private void startStockCameraForResult()
{
// create Intent to take a picture and return control to the calling application
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// mediaStorageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
mNextImageFileUri = ImageFileUtils.getOutputMediaFileUri();
intent.putExtra(MediaStore.EXTRA_OUTPUT, mNextImageFileUri); // set the image file name
// start the image capture Intent
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
How can I prevent the saved additional copy of the image in the DCIM folder?
My Problem is that code produces
1 photo : Samsung Galaxy SIII, Huawei HUAWEI P2-6011 etc.
2 photos : Samsung Galaxy SI, Htc HTC One XL etc.
Other threads describe deleting last added image to DCIM. Problems here are devices which have no problem like Galaxy SIII and Imagename on DCIM and on application data folder is different.
Many Thanks
AFAIK, you can't reliably tell the camera apps (device-independently) a) where to save the image AND b) also to save it only once. I had to resort to this approach:
1) Just let the camera app save the picture to wherever it likes, by removing the putExtra(...) statement:
`intent.putExtra(MediaStore.EXTRA_OUTPUT, mNextImageFileUri); // set the image file name`
This (i.e. not setting EXTRA_OUTPUT) will guarantee that only one image will be saved, to the default picture location.
2) Find the last photo taken, and save its ID, for a later safety check. (Query for the last image ID, sorting by DATE_TAKEN.)
3) Fire the capture intent, and in your onActivityResult, again, get the last image taken, and save its ID, URI and path.
4) If your new pic ID is > than the one previously saved, go ahead, otherwise panic out...
5) Move the original image file (using its path) to your preferred location. Now, the original file is removed.
6) Delete the original media image entry, using its URI. Now the image is removed from the gallery, too.
7) If you also want to remove the thumbnails, well, you'll need to query and delete them similarly, but I'd advise against it: a device reboot or another media scan should refresh the thumbnail cache. Also, you may actually quite likely need that thumbnail for a short while after deleting the original image. (If you need it longer, you need be careful: if you moved the photos to the private app dir (getExternalFilesDir(Environment.DIRECTORY_PICTURES)) the media manager will not (be able to) generate thumbnails for you, so you may need to manage your own thumbnails.)

android: different images copied to same file name shows always first image

I copy an image from a server to a local file with constant file name. Then I show the image using
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(constantFileName), mime);
startActivity(intent);
So far, this works. But then I copy another image to the same local file and want to show it: instead of the new image, the old one is shown - this looks like file name dependent caching. How can I prevent this caching?

Android MediaStore setting photo name to NULL

I have an app that allows the user to take and save a new picture using the Intent ACTION_IMAGE_CAPTURE. After the user accepts the newly taken picture, I create a ContentValue object to set the picture information, and then I insert the picture into the MediaStore and send a broadcast so that the user can see the photo when opening a picture viewer app such as gallery:
ContentValues newImage = new ContentValues(3);
newImage.put(Media.DISPLAY_NAME, mPicName);
newImage.put(Media.MIME_TYPE, "image/png");
newImage.put(MediaStore.Images.Media.DATA, path);
mPictureUri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, newImage);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, mPictureUri));
All of this code works fine. The photo is correctly saved, and I can view the photo using gallery. The problem is that when I view the photo in gallery and select "Details" it shows the photo name as "null." And yes, I know for a fact that the variable mPicName above is not null and always has the correct value.
The odd thing is that, when running my app on my Droid running Android 2.1, when I choose to copy files to/from the phone and my computer, I open up the Droid on my Windows computer, and when I go into my app's created folder for photos and view the new photo, the name is correct. Then, when I disable copying files from the phone/computer and go back into gallery to view the file on my Droid, the name is suddenly correct and is no longer null.
Can someone tell me why the name is null after my code runs, and why the name is correct after viewing the file on my computer rather than on the phone? Is there a way to get the name non-null right when the picture is saved? I'd bet that the name would be correct if I turned my phone off and turned it back on, but I'm not sure how exactly to get force things to work immediately.
Answer is by looking at the sources of MediaStore.
One places is here:
http://devdaily.com/java/jwarehouse/android/core/java/android/provider/MediaStore.java.shtml
Basically they also add a thumbnail representation of the image and instead of
Media.DISPLAY_NAME they use Media.TITLE.
I used that code adapted a little and worked fine.

Categories

Resources