views:

31

answers:

2

Hello.

I have written a program that uses the Intent for the image capture to get a photo using the application in the phone. Using MediaStore.EXTRA_OUTPUT, I get a URI to the image, wich converted to a path results in something like "/external/images/media/NN" where NN is the number of the photo.

Now, in my program, after I read and manipulated the image, I want to delete that image.

How should I do that ??

(File image = new File(path); image.delete(); // returns false, so doesn't work)

Thanks.

A: 

Is it possible that you've failed to request the WRITE_EXTERNAL_STORAGE permission in your app? This would cause deletions to fail. (The camera would be able to write regardless, since it is a separate app with its own permissions.)

It's also possible (but not likely) that the media folder is only writable by the camera app, in which case you'd want to specify a different desired destination in the EXTRA_OUTPUT extra of the intent which invokes the camera so that the file will be written into your app's directory. In fact, you probably want to do that anyway to avoid cluttering up the global space with private resources, even if you are going to delete them immediately.

beekeeper
A: 

Thanks for the answer.

I resolved reading this answer, http://stackoverflow.com/questions/2696298/problems-saving-a-photo-to-a-file

For me it works on Hero, even if in the comment in that code snipped says that Hero behave differently. Now I get the image in "/sdcard/image.tmp", and I can delete it. I think this is the best solution, cause I think it's a trouble trying to get the camera app to write in my app directory.

Thanks again.

Andrea