Before anyone marks this as a duplicate I would like to let you know that I have gone through a lot of the questions about the mkdirs()
method on SO and none have worked for me so I believe I have a special case for this problem worthy of a question.
I have tried using mkdir()
, changed the instantiation of the directory File
as
new File(Environment.getExternalStorageDirectory())
new File(Environment.getExternalStorageDirectory().getAbsolutePath())
new File(Environment.getExternalStorageDirectory(), "Directory")
new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "Directory")
new File(Environment.getExternalStorageDirectory().toString + "/Directory")
and nothing works.
NOTE : I ALSO HAVE THE WRITE_EXTERNAL_STORAGE
permission in my manifest.
Here is my code snippet:
File rootDirectory = new File(Environment.getExternalStorageDirectory(), getActivity().getPackageName());
File directory = new File(rootDirectory, "Directory");
if (!directory.exists()) {
if(directory.mkdirs()){
Log.d("log", "exists");
} else {
Log.d("log", "not exists");
}
}