android - 我无法在外部存储中为我的应用创建文件夹
问题描述
一开始,代码运行良好。但是,当我从内部存储中删除该文件以测试它停止工作的代码时,每次它都从mkdirs()函数返回“ false ”。
我重新安装了几次应用程序,清除了缓存,但仍然无法正常工作。我还授予了在外部存储中写入的权限。
File direct = new File(Environment.getExternalStorageDirectory()+"/My App/Media/Images/Saved Images");
if (!direct.exists()) {
boolean b=direct.mkdirs();
System.out.println("Value"+b);
}
解决方案
好的,我找到了解决方案。在 API 29 中,不推荐使用 getExternalStorageDirectory()。而不是我使用的
File direct=new File(Objects.requireNonNull(getApplicationContext().getExternalFilesDir(null)).getAbsolutePath()+"/My App/Media/Images/Saved Images");
推荐阅读
- mysql - SQL CASE 比较 Text Datarow 和 Int Datarow
- java - 在 Android 中使用 .contains() 对关键字进行字符串匹配
- javascript - 当我使用 d3.js 制作地图时如何显示城市名称?
- odoo - 如果 odoo 中的条件正确,则应用域过滤器
- rest - 通过其余 api 促进 jenkins 的构建
- python - 除了在系统变量“PATH”中交换 python 文件夹的路径顺序 - 交换 python 版本的方法是什么?
- c++ - 重用对象与创建新对象
- spring - cxf + spring boot中的日志管理
- android - RecyclerView 添加Item onclickListener() + 定时器优化
- python - 如何将 2 个功能绑定到一个键以及如何在它们之间交替