为什么要java.lang.IllegalStateException:无法创建目录错误? [英] why get java.lang.IllegalStateException: Unable to create directory error?
问题描述
我使用的下载管理器类的下载文件中的Android结果
I use DownloadManager class to download a file in android
这是我的code下载:结果
and this is my code for download:
Uri downloadUri = Uri.parse(urlString);
DownloadManager.Request request = new
DownloadManager.Request(downloadUri);
request.setDescription(des).setTitle(titleAudio).setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED).
setDestinationInExternalPublicDir(
"/my file name/" , titleAudio + String.valueOf(colForUrl) + pasvand);
long id = downloadManager.enqueue(request);
SharedPreferences.Editor prefEdit = preferenceManager.edit();
prefEdit.putLong(strPref_Download_ID, id);
prefEdit.commit();
但是当我在某些设备(三星Galaxy S5)上运行的应用程序,我得到这个错误:结果
but when I run app in some device(Samsung Galaxy S5) I get this error:
java.lang.IllegalStateException: Unable to create directory: /storage/emulated/0/my file name
和这在setDestinationInExternalPublicDir引起(..)结果
and this is caused in setDestinationInExternalPublicDir(..)
但在的Nexus 7的每一件事情是对的,我没有任何问题!结果
所以,哪里是我的错吗?!
but in Nexus 7 every thing is right , I have not any problem!!
So, Where is my wrong?!
推荐答案
据该的文档:
setDestinationInExternalPublicDir(字符串dirType,串子路径)
- dirType - 目录式传递给getExternalStoragePublicDirectory(字符串)
- 子路径 - 外部目录中的路径,包括目标文件名
dirType应该是DIRECTORY_MUSIC之一,DIRECTORY_PODCASTS,
DIRECTORY_RINGTONES,DIRECTORY_ALARMS,DIRECTORY_NOTIFICATIONS,
DIRECTORY_PICTURES,DIRECTORY_MOVIES,DIRECTORY_DOWNLOADS,或
DIRECTORY_DCIM。不能为null。
dirType Should be one of DIRECTORY_MUSIC, DIRECTORY_PODCASTS, DIRECTORY_RINGTONES, DIRECTORY_ALARMS, DIRECTORY_NOTIFICATIONS, DIRECTORY_PICTURES, DIRECTORY_MOVIES, DIRECTORY_DOWNLOADS, or DIRECTORY_DCIM. May not be null.
因此,例如,尝试:
So, for example, try:
setDestinationInExternalPublicDir(Environment.DIRECTORY_MUSIC,titleAudio +将String.valueOf(colForUrl)+ pasvand);
从那里走,如果它不正是你想要的文件夹。
And go from there if it's not exactly the folder that you want.
这篇关于为什么要java.lang.IllegalStateException:无法创建目录错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!