Search code examples
androidandroid-storage

How could I create a file in the "Internal Storage" Directory?


I have a Samsung Galaxy S6. I'm currently working on a test application where I would like quick access to a folder with my files.

Using the provided "My Files" Application, it specifies that all those folders are in the "Internal Storage" folder.

I know that internal storage is private, but I want to create a folder in the default folder that windows accesses when the phone is plugged in. For example, the following code does not create the directory in the correct location.

File storage = new File("/testappplication");
if(!storage.exists()) {
   storage.mkdir();
   System.out.println("Folder Created");
}

I just want to know the path where to create the folder. Many other applications have storage here, so I know its possible.


Solution

  • After a while later I found the answer to this question.

    public void createDirectory() {
        File file = new File(Environment.getExternalStorageDirectory(), "/test");
        if (!file.exists()) {
            file.mkdirs();
            Log.w("DEBUG", "Created default directory.");
    
        }
    }
    

    This is how you create it code wise. The reason it wasn't creating was due to Samsungs weird permissions.

    Make sure you have the storage permission enabled in Settings -> Apps -> App Name -> Permissions. I needed to turn it on so it would create the folder.