Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android deleting a file from internal storage

Tags:

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.

like image 407
Malfunction Avatar asked Feb 06 '13 20:02

Malfunction


People also ask

How do I delete files from internal storage?

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.

Why cant I delete some files on my phone?

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.

How do I permanently delete files from my Android?

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.


2 Answers

You can try getting the instance pointing to the file and deleting it like in this answer or this one

like image 34
Terrance Avatar answered Oct 06 '22 00:10

Terrance


Here is your answer :

File dir = getFilesDir();
File file = new File(dir, "my_filename");
boolean deleted = file.delete();
like image 65
hardartcore Avatar answered Oct 06 '22 01:10

hardartcore