How to delete an image from an SD card

How to delete a file from an SD card. I tried:

File file=new File(filepath); file.delete(); 

but I could not remove it. when I try to check it in debug mode, file.delete () returns false. I also added permission to my manifest file.

 uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" 

I also tried:

 public abstract boolean deleteFile (String name) 

out of context andoid. Even this returns false.

+4
source share
2 answers
 File file = new File(selectedFilePath); boolean deleted = file.delete(); 
+3
source

Instead of passing a static value to the sd card storage directory, it would be better to use getExternalStorageDirectory () to get the exact value of the sd-card directory. (Because it could be / sdcard or / mnt / sdcard):

 String dirPath = Environment.getExternalStorageDirectory().getPath(); 

Detailed example: Check and get an external Android storage directory

+2
source

Source: https://habr.com/ru/post/1384466/


All Articles