When i tried to get path from getExternalFilesDir(String type), the directory returned here will be automatically created. How to prevent this scenario. Please help me out ??
Asked
Active
Viewed 606 times
0
-
Question has incomplete information. Please add code snippet etc and more information. – Vikasdeep Singh Dec 05 '14 at 07:14
1 Answers
0
When i tried to get path from getExternalFilesDir(String type), the directory returned here will be automatically created.
That's correct.
How to prevent getExternalFilesDir (String type) from creating directory
You can't.
How to prevent this scenario. Please help me out ??
I don't know of any good reason to try to prevent this from happening. Thus, I suggest that you reconsider your reasoning. Anyway, if you insist on preventing this scenario you'll have to:
- Manually determine the path of the external files directory for your app and supplied type. You can check how Android does this based on the source code of
getExternalFilesDir
. Please note that the linked source code is from the Android 5.0.0_r2 tag. I don't know if and what is different on other versions. - Manually check if this directory exists. You can use the
File
class for this. - Act accordingly, e.g., by not doing whatever you would do if the directory existed when it in fact does not.

cygery
- 2,309
- 3
- 18
- 25