how to create a directory on android system?

Asked

Viewed 22 times

0

I’m using the following code to create a directory when the user presses a button inside a Fragment, but it’s still not working, and I don’t know why.

            File dir = new File("/novaPasta");
            try{
                if(dir.mkdir()) {
                    System.out.println("diretorio criado");
                } else {
                    System.out.println("diretorio não criado");
                }
            }catch(Exception e){
                e.printStackTrace();
            }

and I am using the following permissions:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />

I have no error in the log, only the message that the directory was not created

  • https://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory() [...]

  • [...] that is to say, new File(Environment.getExternalStorageDirectory(), "novaPasta").mkdir() create a folder named "Novafolder" in the internal memory

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.