Devrath
Devrath

Reputation: 42854

How to delete all the files stored in Environment.getExternalStorageDirectory() in android

As the question states:

  1. My application has created some files in Environment.getExternalStorageDirectory()
  2. I have to delete all the files of my application in that Environment.getExternalStorageDirectory() location

How to do this

Note: It must not delete other files created by other application

Upvotes: 3

Views: 1170

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007554

Use the delete() method on the File object for each file to be deleted.

You will need to determine for yourself what files are to be deleted. Nobody else will know, including Android. There is no app-specific ownership information on files on external storage, even if such data would necessarily be reliable for your use case.

Also, bear in mind that each account on Android gets its own part of external storage, and you can only delete files that are in the external storage for whatever account it is that is presently running. Other accounts (on Android 4.2+ tablets and Android 5.0+ phones) are not accessible to you.

Upvotes: 2

Related Questions