In my application I will be constantly using the DirectoryPath of my storage. In my MAIN I am initially creating the directory I would like to store this in a String to use in other methods such as when I create the actual database, I want it to be created in this path. I have gotten myself twisted up with everyone's recommendations and am returning a boolean value instead. Not sure I will use that value at all.
Here is what I have:
private static boolean mCreateDatabaseDirectory(String dbPath) {
boolean directoryCreated = true;
boolean mExternalStorageAvailable = false;
boolean mExternalStorageWriteable = false;
Log.d("GENERAL", "Moving to mExternalStorageAvailable");
mExternalStorageAvailable();
Log.d("GENERAL", "Returning values of Available and Writeable");
if(mExternalStorageAvailable = mExternalStorageWriteable = true){
Log.d("GENERAL", "Booleans are True, creating Directoy");
File directoryPath = new File(Environment.getExternalStorageDirectory().toString()+"/APP/database");
Log.d("GENERAL", "directoryPath = " + directoryPath);
if(!directoryPath.exists()) {
directoryPath.mkdirs();
String databasePath = directoryPath.toString();
Log.d(DATABASE, "Database directory path created as " + databasePath);
//If we try to create the file but there is a problem then Log the error
if(!directoryPath.mkdirs()){
Log.e("DATABASE", "Problem creating Database Directory");
directoryCreated = false;
}
Log.d("GENERAL", "Directory did not exist but was created");
return directoryCreated;
}else {
Log.d("GENERAL", "Directory already exists, nothing to do here");
return directoryCreated;
}
}
return directoryCreated;
}
Another problem is that this does not actually create the directory in the SDCARD as I want it. It creates the directory in the /storage/emulated/0/APP/database which I assume is the internal storage likely designated as external. Well that is going to be a problem if this app starts creating a database that is 100mb or more and they do not have the space. How do I get it to the SDCARD?
Please ignore my million comments. I was debugging a NullPointer Error and needed to find out which line specifically was the problem. I will erase them later.