Is there an universal way to find the location of an external SD card?
Please, do not be confused with External Storage.
Environment.getExternalStorage
I don't know why but I need to call .createNewFile() on a File created in the public storage directories before using it. In the framework the comments for that method say it isn't useful. Here's a sample...
String myPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PODCASTS) + File.separator + "My Directory";
final File myDir = new File(myPath);
try {
myDir.mkdirs();
} catch (Exception ex) {
Toast.makeText(this, "error: " + ex.getMessage(), Toast.LENGTH_LONG).show();
}
String fname = "whatever";
File newFile = new File(myDir, fname);
Log.i(TAG, "File exists --> " + newFile.exists()) //will be false
try {
if (newFile.createNewFile()) {
//continue
} else {
Log.e(TAG, "error creating file");
}
} catch (Exception e) {
Log.e(TAG, e.toString());
}