安卓上:mkdir()返回false [英] Android: mkdir() returns false
问题描述
我驱动疯狂的:
Log.d("STATE", Environment.getExternalStorageState());
File f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "work_data");
Log.d("PATH", f.getAbsolutePath());
if (!f.exists()) {
Log.d("MAKE DIR", f.mkdirs() + "");
}
输出日志是这样的:
The output log is like this:
STATE mounted
PATH /mnt/sdcard/DCIM/work_data
MAKE DIR false
我甚至已经添加的权限:
I even have added permission:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
但我不知道为什么它不能创建文件夹。我还用的mkdir()
一步,但结果步骤是一样的。请帮我。我用Google搜索了这么多,但他们都不帮我。我花了至少2个一天,在这种愚蠢的事情。感谢您的帮助!
But I don't know why it could not create the folder. I also used mkdir()
step by step but result is the same. Please help me. I have googled so much but none of them helps me. I spent at least 2 day on this stupid thing. Thanks for your help!!
编辑:
对不起大家!我又增加了&LT;使用-权限的Android:名称=android.permission.WRITE_EXTERNAL_STORAGE/&GT;
在&lt;应用&GT;
标记。这是我的错!但还是非常感谢大家的回答。
Sorry everyone! I had added <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
in <application>
tag. this was my mistake! But thank you all for reply.
推荐答案
我有同样的问题,我已经寻找一切一个星期试图找到答案。我想我找到它,我认为这是可笑容易,你必须把用途,权限声明在正确的地方......
I have had the same problem and I have searched everything for a week trying to find the answer. I think I found it and I think it's ridiculously easy, you have to put the uses-permission statement in the right place...
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.company.name"
android:versionCode="1"
android:versionName="0.2">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
当我有它的&lt内;用途&gt;&LT; /用途&gt;部分没有奏效。如果这会有所帮助,请其标记为回答和投票我。谢谢!!!!
When I had it inside the <application></application> section it did not work. If this helps, please mark it as answered and vote me up. Thanks!!!!
这篇关于安卓上:mkdir()返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!