开发者

How to delete photo just taken in android program

开发者 https://www.devze.com 2023-01-19 20:30 出处:网络
I have written a program that uses the Intent for the image capture to get a photo using the application in the phone.

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, which 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开发者_如何学Go to delete that image.

How should I do that?

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


Thanks for the answer.

I resolved reading this answer, 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消