Something weird is happening in my application im not sure if it is worth uploading all the code...
Intent pictureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
pictureIntent.putExtra( MediaStore.EXTRA_OUTPUT, imageUriToSaveCameraImageTo );
startActivityForResult(Intent.createChooser(pictureIntent, strAvatarPrompt), TAKE_AVATAR_CAMERA_REQUEST);
I use this code to take an photo. The photo gets saved in the DCIM folder and also into imageUriSaveCameraImageto which points to sdcard/folder...The image is given the name image1.jpg..once run it works.
Then i delete the files from DCIM and sdcard/folder and run the application again and take a different photo...for some reason the old photo appears in the folder...it must be caching or storing a copy of it else where...does anyone know where and how i can delete it?thanks
Android indeed caches thumbnails of all the photos in another location.
See here:
http://www.droidforums.net/forum/droid-general-discussions/30998-thumbnail-cache-can-cleared.html
I can't give you an exact answer, but my feeling is that the MediaStore is a ContentProvider, so you may be able to call ContentResolver.delete(URI).
Related
I have a small problem here.
In my application I let the user select a picture from the gallery. I save the path to it before doing anything else.
When the user picks the picture he wants, I want it to be copied in a other folder, and then deleted from the original one.
Well, it kiiinda works. The original picture is deleted, and a copy appears in the other folder.
Buuut. It's still there. The deleted picture can still be seen in the gallery, and the copy can't be seen. When I call Gdx.files.absolute(originalPath).exists() it returns false, and Gdx.files.external(copyPath).exists() it returns true, and I can work with the copy of the picture with no problem.
It looks like the gallery is not updated.
I use this to delete and copy a picture :
public void MoveToCustomFolder() {
if (DoesOriginalPathExist()) {
if (!DoesCopyExist()) {
System.out.println("Copying");
Gdx.files.external("/CustomFolder/" + fileName).write(Gdx.files.absolute(filePath).read(), true);
}
System.out.println("Deleting");
Gdx.files.absolute(filePath).delete();
}
}
filePath being the absolutePath of the original picture in the gallery and fileName the name of the file ("picture.jpg")
I found something during my research. When clear the data of the media storage application, after little time the correct gallery shows up, with no deleted pictures and with copies where they belong.
Also, I do have the WRITE_EXTERNAL_STORAGE permission.
Do you guys know what's wrong ?
Found the solution.
I had to update the Gallery with this function :
public void UpdateGallery(String filePath) {
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(filePath))));
}
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.)
So I'm having the user create a profile, which includes an avatar. I would like the program to, like the user's name and other info, remember the avatar so it appears as their avatar whenever they use the app. I'd prefer for this bitmap to be saved when created, so the app doesn't need to rebuild the avatar (which is scaled and whatnot) each time the app is started. Is this possible? From the looks of it this wouldn't be able to be saved in SharedPrefs... any idea what the best way to do this would be? Thanks.
Followup: Followed CommonWares's suggestion. Saved to SD... but having trouble calling it back when the app is reloaded.
Currently, in onCreate:
String path = "testapp/images/thumbs/"+m_username+".jpg";
File file = new File("testapp/images/thumbs/"+m_username+".jpg");
if(file.exists()) {
Log.e("TRY TO GET THUMB", "I EXIST");
m_thumb = BitmapFactory.decodeFile(path);
Drawable draw = new BitmapDrawable(getResources(), m_thumb);
m_photoButtonE.setBackgroundDrawable(draw);
}
Does not find the file, says it does not exist, though when I check my SD card the image is in that exact spot, with the proper file name and everything. Any ideas? Thanks all.
Is this possible?
Save it in a file.
From the looks of it this wouldn't be able to be saved in SharedPrefs... any idea what the best way to do this would be?
Save it in a file. If you intend on having multiple avatar files, put a path to the saved avatar file in the SharedPreferences.
basically im trying to refresh the sd card in order to have image thumbnails represent their corresponding pictures. The reason for this is a user can send a picture to the server and the server performs image processing on it and then returns it. It shows up in the gallery as expected the first time. Subsequent requests however result in the first thumbnail always being used for the new image. The new image always overwrites the old one (by design) but the thumbnail stays the same.
currently im trying this to refresh the sd card
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
It has not worked however. Based on my implementation below is there anyway I could refresh the sd card before the select image intent is started ?
//if the user selects the file browser
//open the file browser and present the available images
if(v == choose){
//refresh the sd card before viewing the images
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
startActivityForResult(new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), SELECT_IMAGE );
EDIT: I have also tried this http://www.mail-archive.com/android-developers#googlegroups.com/msg24164.html but to no avail
EDIT 2: I have also tried deleting the files before saving the new ones but its no use the thumbnails just stay the same
Edit 3: The device im using is a htc hero , I have also tried it on an lg gt540 and the problem did not occur as the thumbnails refreshed when overwritten , this leaves me to believe it may be a bug with htc's implementation . Has anyone else experienced this ?
In order to refresh the thumbs just rename the folder that the files are located
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.