Everything is in the question. Here is my code :
private void createDirectory(File currentDirectory) {
File f = null;
try {
f = new File(currentDirectory.getCanonicalPath() + "/directory"
+ count);
boolean success = f.mkdir();
if (!success) {
Toast.makeText(currentContext,
f.getName() + " could not be created", 15).show();
}
} catch (IOException ioe) {
Toast.makeText(currentContext,
f.getName() + " could not be created", 15).show();
}
count++;
}
I am writing a small file manager in Android and I would like to add the possibility to create a directory. There is no exception and the variable success always return false. Can someone tell me what is wrong my code??
Thx for your advice !!
[EDIT]
BTW, When the phone is in Developpement mode, does an application has a write access on the sdcard? I am programming on my phone (Acer liquid)
Use the mkdir command to create one or more directories specified by the Directory parameter. Each new directory contains the standard entries dot (.) and dot dot (..). You can specify the permissions for the new directories with the -m Mode flag.
Long-press an app and drag it onto another app to create a folder. Long-press the folder to rename it. (On some devices, tap the folder to open it, then tap the name to edit it instead). You can also drag the folder into the row of favorite apps on the bottom of the Home screen on Android phones.
Using mkdir and touch Commands With the combination of both mkdir and touch commands, we can accomplish the task of creating a directory and a file in a single go. Here, the parent option of mkdir helps us to create the parent directory (unless it exists) without any error, while the touch command creates a file.
You have to add this permission:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
By the way, not sure how you are getting the SDcard directory... but it must be this way:
File sdDir = Environment.getExternalStorageDirectory();
It's important, because some programmers use to think that the SDCard is always /sdcard, but it could change.
You're going to need to add
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
to your manifest file to tell Android to ask the user for your application to be allowed to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With