简体   繁体   English

将文件保存到内部存储(文档文件夹)权限被拒绝

[英]Save File on internal storage (document folder) permission denied

I try to save files on my smartphone. 我尝试将文件保存在智能手机上。 Since I have no SD card installed I must save the data to my internal memory. 由于我没有安装SD卡,因此必须将数据保存到内存中。 The user must have easy access to the data later, so I want to store in an easily accessible location. 用户以后必须可以轻松访问数据,因此我想将其存储在易于访问的位置。 The following variant works without problems but is not easily accessible 以下变体可以正常工作,但不容易使用

File root = new File(getApplicationContext().getFilesDir(),"NAME");
        if(!root.exists()) root.mkdirs();

In this variant, I get the message that the access was denied. 在此变体中,我收到一条消息,表明访问被拒绝。

Environment.DIRECTORY_DOCUMENTS

I also tried the following permissions: 我还尝试了以下权限:

READ_EXTERNAL_STORAGE WRITE_EXTERNAL_STORAGE

Does anyone know how to access these folders? 有谁知道如何访问这些文件夹? The root directory would also be enough. 根目录也足够了。

Thanks! 谢谢!

Besides asking for read and write permission in manifest for Android 6+ you should also add code to let the user confirm those permissions. 除了在Android 6+清单中要求读写权限外,您还应该添加代码以让用户确认这些权限。

Google for runtime permissions. Google的运行时权限。

You are #1258 with this problem this year. 您今年遇到这个问题的排名是#1258。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM