0

Before Android 4.4, we could easily delete files from any sd card directories. After 4.4 this is removed, even with WRITE_EXTERNAL_STORAGE permission you couldn't do it (except with some hacks with ContentProviders). But I heard after 5.0 this ability is re-added (don't know if it's wrong). I tried File.delete() method but it's no different than 4.4 for me. Is there any way of deleting a file from sdcard in Android 5.0+ ?

Insignificant Person
  • 863
  • 2
  • 10
  • 24
  • Which files do you want to delete? Did you put them on the card your self? – greenapps Oct 31 '15 at 09:38
  • Random files in the storage root, no I didn't put them – Insignificant Person Oct 31 '15 at 10:56
  • So how could others apps put hem there if you can't? – greenapps Oct 31 '15 at 11:04
  • @greenapps you are funny xD he talked about removable MicroSD Card which already contains some files and he wanted to delete some of those files from his app (he asked about code which could delete those files on Android 21+, it can be done using `DocumentFile` after requesting SD card write permission using `intent` - `ACTION_OPEN_DOCUMENT_TREE`) – user25 May 28 '18 at 17:36

2 Answers2

1

You can request permissions from the user to the sdcard through SAF: How to use the new SD card access API presented for Android 5.0 (Lollipop)?

Community
  • 1
  • 1
somesh
  • 2,509
  • 3
  • 16
  • 24
-1

I was also facing the same problem in my Android version 5.0 but now I have no worries regarding this as I found the solution of this problem. Just do as I said: go to playstore and download "X-plore File manager" and delete whatever you want from your external storage as well as internal storage.

  • are you kidding? you can give an example of code, not name of app which do something similar, it's Stack Overflow... – user25 May 09 '18 at 13:59