Creating package folder in Android/data with Android Studio

Issue

I’m trying to create a package folder for my application but i can’t understand why I can’t find it.

I’ve set the permission WRITE_INTERNAL_STORAGE and I’ve tried with theese samples called in the MainActivity.onCreate().

//sample 1
File myDir = new File(getCacheDir(), "folder");
boolean created1 = myDir.mkdir(); //this returns True
boolean created2 = myDir.mkdirs(); //this returns False

//sample 2
File myDir = this.getFilesDir();
File documentsFolder = new File(myDir, "documents/data");
boolean Created3 = documentsFolder.mkdirs(); //this returns True

The application is always cleaned and rebuild before each test but when I look for the folder in Android/data i can see the package folders of the other applications but not the mine.

I’ve read somewhere that I could see it only with a rooted device but in this case why can I see the folders of the other applications? I can’t understand :s

Solution

Try below code instead:

File myDir = new File(Environment.getExternalStorageDirectory().toString()
             + "/folder_name");
myDir.mkdir();

Answered By – Krishna Kishore Andhavarapu

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published