I have the following code, in which I want to create a directory (E4) in the SD external memory, however, when I run it I can not create it, and I also want it to be in / sdcard / documents /, but I put it on in ** / storage / emulated / 0 / ** Documents / and I can not find that folder anywhere
The code is as follows:
public static boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
else
{
Log.e("isExtStorageWritable", "Can´t write to Ext. Storage");
return false;
}
}
//Get the path to the Documents Folder
public static File getStorageDir(String folderName) {
// Get the directory for the user's public documents directory.
File documents = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);
//path will be storage/sdcard/documents/foldername
File path = new File(documents, folderName);
Log.e("getStorageDir", path.toString());
if (!path.mkdirs()) {
Log.e("getStorageDir", "Directory not created");
}
else
{ Log.e("getStorageDir", "Directory OK");
}
return path;
}
The LogCat errors I have to check give me the following:
E / getStorageDir: / storage / emulated / 0 / Documents / E4
E / getStorageDir: Directory not created
I am running it on Android 6.0 (in a Cubot Echo Music), however that same code does work as I want on an Android 5.0 from Xiaomi. I'm new to Android Studio