I am trying to create a app specific directory (Internal) to store some images.I have tried many SO answers, but still nothing works. I've tried this from here.
File mydir = getApplicationContext.getDir("mydir", Context.MODE_PRIVATE); //Creating an internal dir;
But still this directory is not created - Android/data/com.packagename/...
.
But when I run this-
File mediaDir = new File("/sdcard/Android/data/com.packagename");
if (!mediaDir.exists()){
mediaDir.mkdir();
}
This though creates the directory in the internal storage but is this the right way to do it ?
getApplicationContext().getDir()
will not create a folder named Android/data/com.packagename/
.
If you log/print the path for the returned File you will see it is "/data/data/<packagename>/app_mydir/"
. This is the way it should be for internal storage.
If you want to create a directory on the sd card (usually referred to as external storage, even when the /sdcard path resides in internal flash storage) then use Context.getExternalFilesDir()
. This will create a folder like "/sdcard/Android/data/<packagename>/files/"