getExternalFilesDir权限 [英] getExternalFilesDir permissions

查看:1569
本文介绍了getExternalFilesDir权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序位于Play商店中,我注意到我在打电话时没有在询问权限

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.

我在SO上看到了很多答案,说在外部文件目录中创建文件夹/文件时应询问运行时权限.

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.

我的问题:

在调用上面的代码时,我应该问运行时权限吗?如果是,为什么我没有崩溃?

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.

推荐答案

尽管它返回了外部存储的路径,但是您不需要访问getExternalFilesDir()返回的目录的权限.

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

getFilesDir()相同,但对其他应用也是公开的.

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)

这篇关于getExternalFilesDir权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆