tags:

views:

2873

answers:

3

I am creating a file to send as an attachment to an email. Now I want to delete the image after sending the email. Is there a way to delete the file?

I have tried:

myFile.delete();

but it didn't delete the file.

A: 

i`m using this code for android OS.so the programming language is java...and using usual android ways to access sd card. i am deleting the file in "Onactivityresult();" method,when intent is returned to screen after sending email.

mudit
+4  A: 
File file = new File(selectedFilePath);
boolean deleted = file.delete();

where selectedFilePath is the path of the file you want to delete - for example:

/sdcard/YourCustomDirectory/ExampleFile.mp3

niko
+3  A: 

Also you have to give permission if you are using >1.6 SDK "uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" in Manifes xml file

neeloor2004