Kanttarino
Kanttarino

Reputation: 57

Problem to create directory in Android

I'm developing a simple application for Android devices.

I need to create a directory, but I can't do it.

File folder = new File(Environment.getExternalStorageDirectory ()+"/dir");

if(folder.mkdirs()){
   CrearToast("Directorio creado"); //successfully created
}else{
   CrearToast("fallo"); // error creating directory
}

*CrearToast creates a toast with the text in brackets.

I have set uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"

Upvotes: 3

Views: 4893

Answers (1)

jsp
jsp

Reputation: 2636

are you trying to write on SD card or phone memory?? Have you looked at this?? http://developer.android.com/guide/topics/data/data-storage.html

EDIT: This is how i create my folders

File CheckDirectory;
CheckDirectory = new File(FolderPath);
if (!CheckDirectory.exists()){ 
CheckDirectory.mkdir();
}

SD card directory:

Environment.getExternalStorageDirectory().getAbsolutePath() + "/";

Upvotes: 5

Related Questions