启动我的android应用程序时,我需要在sd卡上创建一个目录,对于少数用户来说这会失败,我无法弄清楚它的原因......
(我发现由于缺少 WRITE_EXTERNAL_STORAGE 权限引起的类似问题,它就在那里,它适用于几乎所有用户,所以我认为这不是原因)
我已经简化了前面的情况以便更容易解释,如果创建目录失败,我会运行一个测试用例,尝试在 sdcard 上创建一个 .test 目录:
new File(Environment.getExternalStorageDirectory(), ".test").mkdir() -> false
new File(Environment.getExternalStorageDirectory(), ".test").mkdirs() -> false
相关目录的文件属性:
/sdcard/.test (exists=false canWrite=false canRead=false canExecute=err isDirectory=false isFile=false)
/sdcard (exists=true canWrite=true canRead=true canExecute=err isDirectory=true isFile=false)
/ (exists=true canWrite=false canRead=true canExecute=err isDirectory=true isFile=false)
getExternalStorageState=已安装
(canExecute 返回 err 因为测试是在 sdk < 9 上运行的)
非常欢迎提出建议和想法...