0

Within Android, an app can use files that are private i.e. it can only be seen and manipulated by this app. It can be stored anywhere, and its management is transparent for the app (it is manipulated as any other file).

Now the app has a life and while it can create and read files, sometimes they are old and might need to be deleted. Obviously, as these files are app-private, only the app can delete them. While it is possible to delete the files one by one, I cannot find any way to filter a directory's files based on the files' app-privacy. In other words, if an app does not keep a list of all app-private files, the only apparent way to delete them is for the user to clear the app data from Android aplication manager.

So my question is, is there a way to programmatically delete all files private to my specific app? Or, if not, is there a best practice to handle the app-private files' lifecycle?

Vince
  • 1,570
  • 3
  • 27
  • 48
  • Using the solution previously suggested and deleted turned out to work. When the private file was created with getExternalFileDir(), listing the files in this folder will only list the private files (and not the public ones). – Vince Oct 09 '15 at 09:47

1 Answers1

2

If you have created your files using Context.openFileOutput(filename, Context.MODE_PRIVATE), you can use Context.fileList() to list the app's private files.

For the others getExternal*Dir (* being Cache, Files, Media) can be used to get the other files.

Community
  • 1
  • 1
Florian Barth
  • 1,392
  • 12
  • 25
  • 1
    I added the `getExternal*Dirs` option to complete the answer. Ofc, credits go to the author of the formerly posted answer. – Florian Barth Oct 09 '15 at 09:54