Android的下载管理器IllegalStateException异常无法创建目录 [英] Android DownloadManager illegalstateexception unable to create directory
问题描述
我在做Android应用程序是使用下载管理器。 我要下载文件到我做的文件夹。 但这个源不操作。 而发生IllegalStateException异常。 我该怎么办?
urlToDownload = Uri.parse(URL);
名单<字符串> pathSegments = urlToDownload.getPathSegments();
要求=新DownloadManager.Request(urlToDownload);
request.setTitle(TITLENAME);
request.setDescription(MCPE商店);
request.setDestinationInExternalPublicDir(
Environment.getExternalStorageDirectory()。getAbsolutePath()+
/ MCPE商店,pathSegments.get(pathSegments.size() - 1));
Environment.getExternalStoragePublicDirectory(
Environment.getExternalStorageDirectory()。getAbsolutePath()+
/ MCPE商店)的mkdir()。
latestId = downloadManager.enqueue(要求);
我该怎么办?
如果你读<一href="http://developer.android.com/reference/android/app/DownloadManager.Request.html#setDestinationInExternalPublicDir%28java.lang.String,%20java.lang.String%29">the为 setDestinationInExternalPublicDir文档()
,你会看到,第一个参数是目录类型<一href="http://developer.android.com/reference/android/os/Environment.html#getExternalStoragePublicDirectory%28java.lang.String%29">to传递给 getExternalStoragePublicDirectory(字符串)
。这需要是环境中定义
类,如 Environment.DIRECTORY_DOWNLOADS
的常量之一。你是路过别的东西,这是不支持的。
I'm making android app which is using DownloadManager. I want to download file into folder which I made. But this sources don't operate. And happen IllegalstateException. What can I do??
urlToDownload = Uri.parse(URL);
List<String> pathSegments = urlToDownload.getPathSegments();
request = new DownloadManager.Request(urlToDownload);
request.setTitle(Titlename);
request.setDescription("MCPE STORE");
request.setDestinationInExternalPublicDir(
Environment.getExternalStorageDirectory().getAbsolutePath() +
"/MCPE STORE", pathSegments.get(pathSegments.size()-1));
Environment.getExternalStoragePublicDirectory(
Environment.getExternalStorageDirectory().getAbsolutePath() +
"/MCPE STORE").mkdir();
latestId = downloadManager.enqueue(request);
What can I do?
If you read the documentation for setDestinationInExternalPublicDir()
, you will see that the first parameter is "the directory type to pass to getExternalStoragePublicDirectory(String)
". That needs to be one of the constants defined on the Environment
class, like Environment.DIRECTORY_DOWNLOADS
. You are passing something else, which is not supported.
这篇关于Android的下载管理器IllegalStateException异常无法创建目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!