Currently, I'm using below method to create a path in android external storage.
public void createPath() {
String path = Environment.getExternalStorageDirectory().getPath()+"/myFolder/";
boolean exists = (new File(path)).exists();
if (!exists) {
new File(path).mkdirs();
}
}
As far as I understand getExternalStorageDirectory()
does not exclusively refer to external storage. So this method will create myFolder
in user preferred storage (which is generally internal storage).
Now I have a question:
What happens if the default storage(user preferred storage) has been set to SD Card
and it's not readable/writable? What is the best way to handle this situation?
In another word, How can I create this folder safely?(Internal or External doesn't matter ).