Reputation: 1038
I was trying to delete files from local storage on the Android Lollipop by the following line:
new File(path).delete();
Deleting file that resides in Internal storage works fine. But failed to do so on file that is located on external removable storage. I've checked that the file do exists but cannot be overwritten. Moreover, permission has already been granted to the app.
In order to read or write files on the external storage, your app must acquire the READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE system permissions.
As stated in the documentation, no luck though.
Googled for available solutions, but doesn't satisfy the problem.
Upvotes: 0
Views: 353
Reputation: 3763
You can not delete file on removable media starting from KitKat (API 19). You have to interact with user by means Storage Access Framework, get access object for the file you are going to delete - DocumentFile - and call delete
operation on it. You can read this for deep understanding of this nightmare.
Upvotes: 2