0

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.

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
RenegadeEagle
  • 68
  • 2
  • 7

3 Answers3

1

You can't create a directory inside the internal storage of the device. Except you've a root access for the app.

So, the following code won't work:

File storage = new File("/testappplication");

Because it tell the app to create a testappplication in the root folder.

You can only create the directory inside your app private folder within the following path:

String path = getFilesDir().getAbsolutePath();

And make the folder using the path.

Or you can use something like this:

File folder = new File(context.getFilesDir(), "testappplication");
if (!folder.exists()) {
    folder.mkdirs();
} else {
  // folder is exist.
}

Read more at Saving Files

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
  • I understand that, but I don't see how these other files have been created? http://renegadeeagle.co/pics/NVIDIA%20Share_2017-07-23_02-55-46.png All of these files came from somewhere, and I want to create one similar like this. – RenegadeEagle Jul 23 '17 at 07:55
  • Ohh.. I see. Then you need to use [getExternalStorageDirectory](https://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory()) – ישו אוהב אותך Jul 23 '17 at 08:02
  • I tried that as well, unfortunately Environment.getExternalStorageDirectory().getAbsolutePath() + "/TestApplication/" isn't creating the file either. – RenegadeEagle Jul 23 '17 at 08:11
0

First just for trial make runtime permmision and then try the following code

 private void createInternalFile() {
    File mediaStorageDir = new File(Environment.getExternalStorageDirectory()+"/"+getApplicationContext()
            .getPackageName()+"/File/profile");
    if (!mediaStorageDir.exists()) {
        mediaStorageDir.mkdirs();
    } }

then check your internal storage in which you will find a folder whose name is your package name

Ankit9123
  • 1
  • 2
0

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.

RenegadeEagle
  • 68
  • 2
  • 7