1

So I want to make a folder right in the main part of my internal storage. So basically the same area that you see when you plug your phone in your computer and you open up internal storage and see all those folders and files.

I've tried the following codes:

String  path = Environment.getDataDirectory().getAbsolutePath().toString()+ "/storage/emulated/0/appFolder";
File mFolder = new File(path);
if (!mFolder.exists()) {
    mFolder.mkdir();
}

Along with

    ContextWrapper contextWrapper = new ContextWrapper(getApplicationContext());
    File myDir = contextWrapper.getFilesDir();
    // Documents Path
    String documents = "appFolder";
    File documentsFolder = new File(myDir, documents);
    documentsFolder.mkdirs(); // this line creates data folder at documents directory

Along with a few others I've found online, but none of these seem to make a folder or at least on the internal storage that I want. I'm not sure if I'm missing something? But any help would be great, I've tried essentially copying a lot of posts I've seen online but none has even gotten me a folder? I don't get any errors either?

I have:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.app.name.app">
    <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />

in my manifest, although I think I'm using gradle if that helps

-------------edit
Unfortunately I tried this from the url aswell, but still no folder.

ContextWrapper contextWrapper = new ContextWrapper(getApplicationContext());
File mydir = contextWrapper.getDir("mydir", Context.MODE_PRIVATE); //Creating an internal dir;
John McKenzie
  • 420
  • 6
  • 16
  • this might be what are you looking for: http://stackoverflow.com/questions/8124612/android-create-folders-in-internal-memory – Umit Kaya Jul 19 '15 at 08:10
  • Unfortuantely I tried ContextWrapper contextWrapper = new ContextWrapper(getApplicationContext()); File mydir = contextWrapper.getDir("mydir", Context.MODE_PRIVATE); //Creating an internal dir; Unfortunately I tried from the URL you sent as well, but still don't seem to find a folder. – John McKenzie Jul 19 '15 at 08:13
  • 'So I want to make a folder right in the main part of my internal storage. So basically the same area that you see when you plug your phone in your computer and you open up internal storage and see all those folders and files.'. All wrong. That is not internal memory what you see then but external. Please start again from scratch. – greenapps Jul 19 '15 at 08:31
  • Could you be a bit more elaborate in "All wrong" and "Please start again", I am more then happy to delete the 2 to 4 lines of code I have. But I was hoping to get some sort of direction in whats wrong? Is it my file path? Do I point it to an external file path instead? Thanks – John McKenzie Jul 19 '15 at 08:36

1 Answers1

3

Okay somehow fixed the problem Turns out if you do

        File Directory = new File("/sdcard/folderName/");
// have the object build the directory structure, if needed.
        Directory.mkdirs();

and use

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

it now works.

I'm not too sure if changing the permission from INTERNAL to EXTERNAL did it, or if it was the directory which is now just /sdcard/folder/or probably both, but either way it worked so I'm happy. Thanks all!!

John McKenzie
  • 420
  • 6
  • 16
  • So you're writing to external storage now? I don't understand @greenapps comment above saying you're looking at external storage when you go to that view? – ntgCleaner Jan 13 '16 at 23:39
  • Unfortunately I found geenapps also confusing albeit not wrong. I could be wrong but my understanding is Internal actually relates to the internal partition of device itself. While External relates to both the folder view you typically see on your computer and you may have another external which is your SD card. – John McKenzie Jan 27 '16 at 11:29
  • 1
    Very confusing indeed. Someone told me to think of it as "mounted vs removable" instead of "internal vs external". Oh well. Thanks to your answer, everything is working now. Thanks! – ntgCleaner Jan 27 '16 at 14:45
  • 1
    Is that created in Internal storage sucessfully> – Akash kumar Oct 11 '17 at 18:18