I have created a file stored on internal storage from an activity. How can I delete this file from another activity?
I'm thinking I'll have to get the file's directory (which I'm not sure how to) and delete it. I tried using
context.deleteFile();
but it won't work because I'm trying to call it from a non-static method.
Choose a folder you wish to delete files from. Tap and hold each file you wish to delete, to put a check mark on it, then tap the More (three dots) icon in the top right corner. Select Delete from device from the drop-down menu. Then select Delete from device from the pop-up menu at the bottom.
Clear Cache and Storage of Media Storage App Sometimes, the Media Storage app is the reason you cannot delete file from internal storage Android. To fix this, you need to clear the app's cache and data. Head into Settings > Apps & notifications, tap the three dots at the top, and select Show system.
Or, go to Settings > Connected devices > USB and enable the option there. Browse the folders on your phone to locate the file you want to delete. If it's a photo or video, it's likely to be in the DCIM > Camera folder. Right-click the item, choose Delete, and confirm you want to delete it permanently.
You can try getting the instance pointing to the file and deleting it like in this answer or this one
Here is your answer :
File dir = getFilesDir();
File file = new File(dir, "my_filename");
boolean deleted = file.delete();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With