Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getExternalFilesDir permissions

My application is live on Play Store, I noticed that I was not asking permissions when calling:

File savedImagesDirectory = getBaseContext.getExternalFilesDir("SavedImages");
if(savedImagesDirectory != null) {
    if (!savedImagesDirectory.exists()) {
        if (savedImagesDirectory.mkdir()) ; //directory is created;
    }
}

Strange thing is, I'm not getting any crashes when calling this without runtime permissions. I tested on my device running Nougat and the files are created and I experienced no crashes.

I only have permissions in my Manifest, but I don't ask runtime permissions.

I've seen A LOT of answers on SO that say that runtime permissions should be asked when creating a folder/file in external file directory.


My question:

Should I ask runtime permissions when calling the above? If yes, why am I not experiencing any crashes?

It would also be helpful if someone can provide a link where I can read up about this.

like image 906
ClassA Avatar asked Sep 21 '18 05:09

ClassA


People also ask

What does allow access to media only mean?

Android needs an app permission between allow 'access to all files' and 'allow access to media only' Something so the app can see anything in the downloads folder but not grant it permission to look anywhere.


1 Answers

Although it returns path to external storage, you don't need permission to access directory returned by getExternalFilesDir().

It is same as getFilesDir() but it is public to other apps as well.

Also note that if you write anything in that directory and clear app data or uninstall the app, everything will be deleted.

For more information, read the documentation at https://developer.android.com/reference/android/content/Context.html#getExternalFilesDir(java.lang.String)

like image 87
Nabin Bhandari Avatar answered Oct 19 '22 10:10

Nabin Bhandari