mkdirs的SD卡目录返回false而父目录是可写的 [英] mkdirs returns false for directory on sd card while the parent directory is writable

查看:1082
本文介绍了mkdirs的SD卡目录返回false而父目录是可写的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开始我的Andr​​oid应用程序,我需要创建在SD卡上的目录,对于少数用户失败的,我无法找出理由吧...

When starting my android application, I need to create a directory on the sd card, for a small number of users this fails and I can't figure out the reason for it...

(我发现引起WRITE_EXTERNAL_STORAG​​E权限缺少类似的问题,它的存在和它的作品,几乎所有的用户,所以我不认为这是原因)

(I've found similar problems caused by the WRITE_EXTERNAL_STORAGE permission missing, it's there and it works for almost all users so I don't think this is reason)

我已经简化了previous情况,使之更容易解释,如果要创建一个directoy失败,我运行一个测试情况下,我尽量让在SD卡一个.TEST目录:

I've simplified the previous situation to make it easier to explain, if creating a directoy fails, I run a test case where I try to make a .test directory on the sdcard:

new File(Environment.getExternalStorageDirectory(), ".test").mkdir() -> false
new File(Environment.getExternalStorageDirectory(), ".test").mkdirs() -> false

相关的目录中的文件属性:

File properties of the relevant directories:

/sdcard/.test(存在=假canWrite =假的CanRead =假canExecute = ERR isDirectory =假ISFILE = FALSE)

/sdcard/.test (exists=false canWrite=false canRead=false canExecute=err isDirectory=false isFile=false)

/ SD卡(存在=真canWrite =真正的CanRead =真canExecute = ERR isDirectory =真ISFILE = FALSE)

/sdcard (exists=true canWrite=true canRead=true canExecute=err isDirectory=true isFile=false)

/(存在=真canWrite =假的CanRead =真canExecute = ERR isDirectory =真ISFILE = FALSE)

/ (exists=true canWrite=false canRead=true canExecute=err isDirectory=true isFile=false)

getExternalStorageState =安装

getExternalStorageState=mounted

(canExecute回报犯错,因为在测试运行SDK< 9)

(canExecute returns err because the test is run on sdk < 9)

建议和想法都非常欢迎...

Suggestions and ideas are very welcome...

推荐答案

这是常见的,当你没有权限在你的清单。

It is common when you don't have a permission in your manifest.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 

对于我来说,这是唯一的错误的东西。

As for me it was the only wrong thing.

这篇关于mkdirs的SD卡目录返回false而父目录是可写的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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