Hosaz Hosaz - 1 year ago 157
Android Question

Creating package folder in Android/data with Android Studio

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

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

Answer Source

Try below code instead:

File myDir = new File(Environment.getExternalStorageDirectory().toString()
             + "/folder_name");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download