Android:无法确保目录 [英] Android: Failed to ensure directory

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

问题描述

我一直在使用Environment.getExternalStorage()"来存储和管理文件.并且 logcat 没有使用该方法发出警告消息,并且运行良好.

I have been using "Environment.getExternalStorage()" to store and manage files. And there is no warning message from logcat with that method and works greatly fine.

但是,我的项目需要使用方法Context.getExternalFilesDir(String type)"并且有一条警告信息

But, My project needs to use method "Context.getExternalFilesDir(String type)" and there is a warning message

ContextImpl:Failed to ensure directory:/storage/external_SD/Android/data/(package name)/files

ContextImpl:Failed to ensure directory: /storage/external_SD/Android/data/(package name)/files

幸运的是 File 对象工作正常(也可以读取或写入或制作文件夹).

Fortunately that File object works fine(reading or write or making folder works, too).

但我想知道如何解决该警告消息.我错过了什么吗?

But I want to know how to resolve that warning message. Do I miss something?

推荐答案

您应该知道警告消息是如何出现的.

You should know how the warning message comes up.

getExternalFilesDir(String type) 将调用 getExternalFilesDirs(String type)(注意第二个方法名称末尾的 's').

The getExternalFilesDir(String type) will call getExternalFilesDirs(String type) (notice the 's' at the final of the second method name).

getExternalFilesDirs(String type) 会找到该类型的所有目录,并在最后调用 ensureDirsExistOrFilter() 以确保目录存在.

The getExternalFilesDirs(String type) will find all dirs of the type, and calls ensureDirsExistOrFilter() at the end to ensure the directories exist.

如果无法访问该目录,则会打印警告!

If the dir can't be reached, it will print a warning!

Log.w(TAG, "Failed to ensure directory: " + dir);
dir = null;

因此,如果您的设备有两个 sdcard 路径,它将生成两个目录.如果一个不可用,就会出现警告.

So, if your device has two sdcard paths, it will produce two dirs. If one is not available, the warning will come up.

结论是警告不需要修复.

The conclusion is the warning does not need to be fixed.

这篇关于Android:无法确保目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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