创建文件夹不起作用
Creating folder not working
我正在尝试为我的应用程序创建一个文件夹,这是我的代码:
File folder= new File( Environment.getExternalStorageDirectory() , "myFolder" );
boolean success = true;
if (!folder.exists()) {
success = folder.mkdirs();
}
if (success) {
// Do something on success
} else {
// Do something else on failure
}
另外,我在 manifest.xml 文件中插入了以下权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
尽管如此,它仍然无法正常工作。
有什么帮助吗?问候。
for marshmallow and above devices you have to handle permissions 运行time for storage, location, mocrophone etc. 所以当 target sdk 大于等于 23 并且具有 marshmallow 或更高版本的设备默认设置权限关闭你必须处理 运行 时间通过这个 link 获取信息 https://developer.android.com/training/permissions/requesting.html
我正在尝试为我的应用程序创建一个文件夹,这是我的代码:
File folder= new File( Environment.getExternalStorageDirectory() , "myFolder" );
boolean success = true;
if (!folder.exists()) {
success = folder.mkdirs();
}
if (success) {
// Do something on success
} else {
// Do something else on failure
}
另外,我在 manifest.xml 文件中插入了以下权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
尽管如此,它仍然无法正常工作。
有什么帮助吗?问候。
for marshmallow and above devices you have to handle permissions 运行time for storage, location, mocrophone etc. 所以当 target sdk 大于等于 23 并且具有 marshmallow 或更高版本的设备默认设置权限关闭你必须处理 运行 时间通过这个 link 获取信息 https://developer.android.com/training/permissions/requesting.html